FIRIAMClearcutUploader.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. @class GULUserDefaults;
  21. @protocol FIRIAMTimeFetcher;
  22. NS_ASSUME_NONNULL_BEGIN
  23. // class for defining a number of configs to control clearcut upload behavior
  24. @interface FIRIAMClearcutStrategy : NSObject
  25. // minimalWaitTimeInMills and maximumWaitTimeInMills defines the bottom and
  26. // upper bound of the wait time before next upload if prior upload attempt was
  27. // successful. Clearcut may return a value to give the wait time guidance in
  28. // the upload response, but we also use these two values for sanity check to avoid
  29. // too crazy behavior if the guidance value from server does not make sense
  30. @property(nonatomic, readonly) NSInteger minimalWaitTimeInMills;
  31. @property(nonatomic, readonly) NSInteger maximumWaitTimeInMills;
  32. // back off wait time in mills if a prior upload attempt fails
  33. @property(nonatomic, readonly) NSInteger failureBackoffTimeInMills;
  34. // the maximum number of log records to be sent in one upload attempt
  35. @property(nonatomic, readonly) NSInteger batchSendSize;
  36. - (instancetype)init NS_UNAVAILABLE;
  37. - (instancetype)initWithMinWaitTimeInMills:(NSInteger)minWaitTimeInMills
  38. maxWaitTimeInMills:(NSInteger)maxWaitTimeInMills
  39. failureBackoffTimeInMills:(NSInteger)failureBackoffTimeInMills
  40. batchSendSize:(NSInteger)batchSendSize;
  41. - (NSString *)description;
  42. @end
  43. // A class for accepting new clearcut logs and scheduling the uploading of the logs in batches
  44. // based on defined strategies.
  45. @interface FIRIAMClearcutUploader : NSObject
  46. - (instancetype)init NS_UNAVAILABLE;
  47. /**
  48. *
  49. * @param userDefaults needed for tracking upload timing info persistently.If nil, using
  50. * GULUserDefaults standardUserDefaults. It's defined as a parameter to help with
  51. * unit testing mocking
  52. */
  53. - (instancetype)initWithRequestSender:(FIRIAMClearcutHttpRequestSender *)requestSender
  54. timeFetcher:(id<FIRIAMTimeFetcher>)timeFetcher
  55. logStorage:(FIRIAMClearcutLogStorage *)retryStorage
  56. usingStrategy:(FIRIAMClearcutStrategy *)strategy
  57. usingUserDefaults:(nullable GULUserDefaults *)userDefaults;
  58. /**
  59. * This should return very quickly without blocking on and actual log uploading to
  60. * clearcut server, which is done asynchronously
  61. */
  62. - (void)addNewLogRecord:(FIRIAMClearcutLogRecord *)record;
  63. @end
  64. NS_ASSUME_NONNULL_END