FIRIAMClearcutLogStorage.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. NS_ASSUME_NONNULL_BEGIN
  18. @interface FIRIAMClearcutLogRecord : NSObject <NSSecureCoding>
  19. @property(nonatomic, copy, readonly) NSString *eventExtensionJsonString;
  20. @property(nonatomic, readonly) NSInteger eventTimestampInSeconds;
  21. - (instancetype)initWithExtensionJsonString:(NSString *)jsonString
  22. eventTimestampInSeconds:(NSInteger)eventTimestampInSeconds;
  23. @end
  24. @protocol FIRIAMTimeFetcher;
  25. // A local persistent storage for saving FIRIAMClearcutLogRecord objects
  26. // so that they can be delivered to clearcut server.
  27. // Based on the clearcut log structure, our strategy is to store the json string
  28. // for the source extension since it does not need to be modified upon delivery retries.
  29. // The envelope of the clearcut log will be reconstructed when delivery is
  30. // attempted.
  31. @interface FIRIAMClearcutLogStorage : NSObject
  32. - (instancetype)initWithExpireAfterInSeconds:(NSInteger)expireInSeconds
  33. withTimeFetcher:(id<FIRIAMTimeFetcher>)timeFetcher
  34. cachePath:(nullable NSString *)cachePath;
  35. - (instancetype)initWithExpireAfterInSeconds:(NSInteger)expireInSeconds
  36. withTimeFetcher:(id<FIRIAMTimeFetcher>)timeFetcher;
  37. // add new records into the storage
  38. - (void)pushRecords:(NSArray<FIRIAMClearcutLogRecord *> *)newRecords;
  39. // pop all the records that have not expired yet. With this call, these
  40. // records are removed from the book of this local storage object.
  41. // @param upTo the cap on how many records to be popped.
  42. - (NSArray<FIRIAMClearcutLogRecord *> *)popStillValidRecordsForUpTo:(NSInteger)upTo;
  43. @end
  44. NS_ASSUME_NONNULL_END