FIRStorageTask.m 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2017 Google
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "FIRStorageTask.h"
  15. #import "FIRStorage.h"
  16. #import "FIRStorageReference.h"
  17. #import "FIRStorageReference_Private.h"
  18. #import "FIRStorageTaskSnapshot.h"
  19. #import "FIRStorageTaskSnapshot_Private.h"
  20. #import "FIRStorageTask_Private.h"
  21. #import "FIRStorage_Private.h"
  22. #import "GTMSessionFetcherService.h"
  23. @implementation FIRStorageTask
  24. - (instancetype)init {
  25. @throw [NSException exceptionWithName:@"Attempt to call unavailable initializer."
  26. reason:@"init unavailable, use designated initializer"
  27. userInfo:nil];
  28. }
  29. - (instancetype)initWithReference:(FIRStorageReference *)reference
  30. fetcherService:(GTMSessionFetcherService *)service
  31. dispatchQueue:(dispatch_queue_t)queue {
  32. self = [super init];
  33. if (self) {
  34. _reference = reference;
  35. _baseRequest = [FIRStorageUtils defaultRequestForPath:reference.path];
  36. _fetcherService = service;
  37. _fetcherService.maxRetryInterval = _reference.storage.maxOperationRetryTime;
  38. _dispatchQueue = queue;
  39. }
  40. return self;
  41. }
  42. - (FIRStorageTaskSnapshot *)snapshot {
  43. @synchronized(self) {
  44. NSProgress *progress = [NSProgress progressWithTotalUnitCount:self.progress.totalUnitCount];
  45. progress.completedUnitCount = self.progress.completedUnitCount;
  46. FIRStorageTaskSnapshot *snapshot =
  47. [[FIRStorageTaskSnapshot alloc] initWithTask:self
  48. state:self.state
  49. metadata:self.metadata
  50. reference:self.reference
  51. progress:progress
  52. error:[self.error copy]];
  53. return snapshot;
  54. }
  55. }
  56. - (void)dispatchAsync:(void (^)(void))block {
  57. dispatch_async(self.dispatchQueue, block);
  58. }
  59. @end