FIRCLSMockReportUploader.m 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2019 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 "FIRCLSMockReportUploader.h"
  15. #import "FIRCLSFileManager.h"
  16. #import "FIRCLSInternalReport.h"
  17. @interface FIRCLSMockReportUploader () {
  18. NSMutableArray *_prepareAndSubmitReportArray;
  19. NSMutableArray *_uploadReportArray;
  20. }
  21. @end
  22. @implementation FIRCLSMockReportUploader
  23. - (instancetype)initWithQueue:(NSOperationQueue *)queue
  24. delegate:(id<FIRCLSReportUploaderDelegate>)delegate
  25. dataSource:(id<FIRCLSReportUploaderDataSource>)dataSource
  26. client:(FIRCLSNetworkClient *)client
  27. fileManager:(FIRCLSFileManager *)fileManager
  28. analytics:(id<FIRAnalyticsInterop>)analytics {
  29. self = [super initWithQueue:queue
  30. delegate:delegate
  31. dataSource:dataSource
  32. client:client
  33. fileManager:fileManager
  34. analytics:analytics];
  35. if (!self) {
  36. return nil;
  37. }
  38. _prepareAndSubmitReportArray = [[NSMutableArray alloc] init];
  39. _uploadReportArray = [[NSMutableArray alloc] init];
  40. return self;
  41. }
  42. - (BOOL)prepareAndSubmitReport:(FIRCLSInternalReport *)report
  43. dataCollectionToken:(FIRCLSDataCollectionToken *)dataCollectionToken
  44. asUrgent:(BOOL)urgent
  45. withProcessing:(BOOL)shouldProcess {
  46. [_prepareAndSubmitReportArray
  47. addObject:@{@"report" : report, @"urgent" : @(urgent), @"process" : @(shouldProcess)}];
  48. // report should be from active/processing here. We just need to "move" it.
  49. [self.fileManager removeItemAtPath:report.path];
  50. return YES;
  51. }
  52. - (BOOL)uploadPackagedReportAtPath:(NSString *)path
  53. dataCollectionToken:(FIRCLSDataCollectionToken *)dataCollectionToken
  54. asUrgent:(BOOL)urgent {
  55. [_uploadReportArray addObject:@{@"path" : path, @"urgent" : @(urgent)}];
  56. // After upload, the file should be removed.
  57. [self.fileManager removeItemAtPath:path];
  58. return YES;
  59. }
  60. @end