FIRIAMClearcutUploader.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright 2018 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. @class FIRIAMClearcutLogRecord;
  18. @class FIRIAMClearcutHttpRequestSender;
  19. @class FIRIAMClearcutLogStorage;
  20. @protocol FIRIAMTimeFetcher;
  21. NS_ASSUME_NONNULL_BEGIN
  22. // class for defining a number of configs to control clearcut upload behavior
  23. @interface FIRIAMClearcutStrategy : NSObject
  24. // minimalWaitTimeInMills and maximumWaitTimeInMills defines the bottom and
  25. // upper bound of the wait time before next upload if prior upload attempt was
  26. // successful. Clearcut may return a value to give the wait time guidance in
  27. // the upload response, but we also use these two values for sanity check to avoid
  28. // too crazy behavior if the guidance value from server does not make sense
  29. @property(nonatomic, readonly) NSInteger minimalWaitTimeInMills;
  30. @property(nonatomic, readonly) NSInteger maximumWaitTimeInMills;
  31. // back off wait time in mills if a prior upload attempt fails
  32. @property(nonatomic, readonly) NSInteger failureBackoffTimeInMills;
  33. // the maximum number of log records to be sent in one upload attempt
  34. @property(nonatomic, readonly) NSInteger batchSendSize;
  35. - (instancetype)init NS_UNAVAILABLE;
  36. - (instancetype)initWithMinWaitTimeInMills:(NSInteger)minWaitTimeInMills
  37. maxWaitTimeInMills:(NSInteger)maxWaitTimeInMills
  38. failureBackoffTimeInMills:(NSInteger)failureBackoffTimeInMills
  39. batchSendSize:(NSInteger)batchSendSize;
  40. - (NSString *)description;
  41. @end
  42. // A class for accepting new clearcut logs and scheduling the uploading of the logs in batches
  43. // based on defined strategies.
  44. @interface FIRIAMClearcutUploader : NSObject
  45. - (instancetype)init NS_UNAVAILABLE;
  46. /**
  47. *
  48. * @param userDefaults needed for tracking upload timing info persistently.If nil, using
  49. * NSUserDefaults standardUserDefaults. It's defined as a parameter to help with
  50. * unit testing mocking
  51. */
  52. - (instancetype)initWithRequestSender:(FIRIAMClearcutHttpRequestSender *)requestSender
  53. timeFetcher:(id<FIRIAMTimeFetcher>)timeFetcher
  54. logStorage:(FIRIAMClearcutLogStorage *)retryStorage
  55. usingStrategy:(FIRIAMClearcutStrategy *)strategy
  56. usingUserDefaults:(nullable NSUserDefaults *)userDefaults;
  57. /**
  58. * This should return very quickly without blocking on and actual log uploading to
  59. * clearcut server, which is done asynchronously
  60. */
  61. - (void)addNewLogRecord:(FIRIAMClearcutLogRecord *)record;
  62. @end
  63. NS_ASSUME_NONNULL_END