FIRStorageDeleteTask.m 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 "FIRStorageDeleteTask.h"
  15. #import "FIRStorageTask_Private.h"
  16. @implementation FIRStorageDeleteTask {
  17. @private
  18. FIRStorageVoidError _completion;
  19. }
  20. - (instancetype)initWithReference:(FIRStorageReference *)reference
  21. fetcherService:(GTMSessionFetcherService *)service
  22. completion:(FIRStorageVoidError)completion {
  23. self = [super initWithReference:reference fetcherService:service];
  24. if (self) {
  25. _completion = [completion copy];
  26. }
  27. return self;
  28. }
  29. - (void)enqueue {
  30. NSMutableURLRequest *request = [self.baseRequest mutableCopy];
  31. request.HTTPMethod = @"DELETE";
  32. request.timeoutInterval = self.reference.storage.maxOperationRetryTime;
  33. FIRStorageVoidError callback = _completion;
  34. _completion = nil;
  35. GTMSessionFetcher *fetcher = [self.fetcherService fetcherWithRequest:request];
  36. fetcher.comment = @"DeleteTask";
  37. [fetcher beginFetchWithCompletionHandler:^(NSData *_Nullable data, NSError *_Nullable error) {
  38. if (!self.error) {
  39. self.error = [FIRStorageErrors errorWithServerError:error reference:self.reference];
  40. }
  41. if (callback) {
  42. callback(self.error);
  43. }
  44. }];
  45. }
  46. @end