FIRStorageTask.m 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. FIRStorage *storage = [FIRStorage storage];
  26. FIRStorageReference *reference = [storage reference];
  27. FIRStorageTask *task =
  28. [self initWithReference:reference fetcherService:storage.fetcherServiceForApp];
  29. return task;
  30. }
  31. - (instancetype)initWithReference:(FIRStorageReference *)reference
  32. fetcherService:(GTMSessionFetcherService *)service {
  33. self = [super init];
  34. if (self) {
  35. _reference = reference;
  36. _baseRequest = [FIRStorageUtils defaultRequestForPath:reference.path];
  37. _fetcherService = service;
  38. _fetcherService.maxRetryInterval = _reference.storage.maxOperationRetryTime;
  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. @end