FIRStorageTask.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 "FirebaseStorage/Sources/Public/FIRStorageTask.h"
  15. #import "FirebaseStorage/Sources/Public/FIRStorage.h"
  16. #import "FirebaseStorage/Sources/Public/FIRStorageReference.h"
  17. #import "FirebaseStorage/Sources/Public/FIRStorageTaskSnapshot.h"
  18. #import "FirebaseStorage/Sources/FIRStorageReference_Private.h"
  19. #import "FirebaseStorage/Sources/FIRStorageTaskSnapshot_Private.h"
  20. #import "FirebaseStorage/Sources/FIRStorageTask_Private.h"
  21. #import "FirebaseStorage/Sources/FIRStorage_Private.h"
  22. #if SWIFT_PACKAGE
  23. @import GTMSessionFetcherCore;
  24. #else
  25. #import <GTMSessionFetcher/GTMSessionFetcherService.h>
  26. #endif
  27. @implementation FIRStorageTask
  28. - (instancetype)init {
  29. @throw [NSException exceptionWithName:@"Attempt to call unavailable initializer."
  30. reason:@"init unavailable, use designated initializer"
  31. userInfo:nil];
  32. }
  33. - (instancetype)initWithReference:(FIRStorageReference *)reference
  34. fetcherService:(GTMSessionFetcherService *)service
  35. dispatchQueue:(dispatch_queue_t)queue {
  36. self = [super init];
  37. if (self) {
  38. _reference = reference;
  39. _baseRequest = [FIRStorageUtils defaultRequestForPath:reference.path];
  40. _fetcherService = service;
  41. _fetcherService.maxRetryInterval = _reference.storage.maxOperationRetryTime;
  42. _dispatchQueue = queue;
  43. }
  44. return self;
  45. }
  46. - (FIRStorageTaskSnapshot *)snapshot {
  47. @synchronized(self) {
  48. NSProgress *progress = [NSProgress progressWithTotalUnitCount:self.progress.totalUnitCount];
  49. progress.completedUnitCount = self.progress.completedUnitCount;
  50. FIRStorageTaskSnapshot *snapshot =
  51. [[FIRStorageTaskSnapshot alloc] initWithTask:self
  52. state:self.state
  53. metadata:self.metadata
  54. reference:self.reference
  55. progress:progress
  56. error:[self.error copy]];
  57. return snapshot;
  58. }
  59. }
  60. - (void)dispatchAsync:(void (^)(void))block {
  61. dispatch_async(self.dispatchQueue, block);
  62. }
  63. @end