FIRIAMActivityLogger.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright 2017 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. /// Values for different fiam activity types.
  18. typedef NS_ENUM(NSInteger, FIRIAMActivityType) {
  19. FIRIAMActivityTypeFetchMessage = 0,
  20. FIRIAMActivityTypeRenderMessage = 1,
  21. FIRIAMActivityTypeDismissMessage = 2,
  22. // Triggered checks
  23. FIRIAMActivityTypeCheckForOnOpenMessage = 3,
  24. FIRIAMActivityTypeCheckForAnalyticsEventMessage = 4,
  25. FIRIAMActivityTypeCheckForFetch = 5,
  26. };
  27. NS_ASSUME_NONNULL_BEGIN
  28. @interface FIRIAMActivityRecord : NSObject <NSSecureCoding>
  29. @property(nonatomic, nonnull, readonly) NSDate *timestamp;
  30. @property(nonatomic, readonly) FIRIAMActivityType activityType;
  31. @property(nonatomic, readonly) BOOL success;
  32. @property(nonatomic, copy, nonnull, readonly) NSString *detail;
  33. - (instancetype)init NS_UNAVAILABLE;
  34. // Current timestamp would be fetched if parameter 'timestamp' is passed in as null
  35. - (instancetype)initWithActivityType:(FIRIAMActivityType)type
  36. isSuccessful:(BOOL)isSuccessful
  37. withDetail:(NSString *)detail
  38. timestamp:(nullable NSDate *)timestamp;
  39. - (NSString *)displayStringForActivityType;
  40. @end
  41. /**
  42. * This is the class for tracking fiam flow related activity logs. Its content can later on be
  43. * retrieved for debugging/reporting purpose.
  44. */
  45. @interface FIRIAMActivityLogger : NSObject
  46. // If it's NO, activity logs of certain types won't get recorded by Logger. Consult
  47. // isMandatoryType implementation to tell what are the types belong to verbose mode
  48. // Turn it on for debugging cases
  49. @property(nonatomic, readonly) BOOL verboseMode;
  50. - (instancetype)init NS_UNAVAILABLE;
  51. /**
  52. * Parameter maxBeforeReduce and sizeAfterReduce defines the shrinking behavior when we reach
  53. * the size cap of log storage: when we see the number of log records goes beyond
  54. * maxBeforeReduce, we would trigger a reduction action which would bring the array length to be
  55. * the size as defined by sizeAfterReduce
  56. *
  57. * @param verboseMode see the comments for the verboseMode property
  58. * @param loadFromCache loads from cache to initialize the log list if it's true. Be aware that
  59. * in this case, you should not call this method in main thread since reading the cache file
  60. * can take time.
  61. */
  62. - (instancetype)initWithMaxCountBeforeReduce:(NSInteger)maxBeforeReduce
  63. withSizeAfterReduce:(NSInteger)sizeAfterReduce
  64. verboseMode:(BOOL)verboseMode
  65. loadFromCache:(BOOL)loadFromCache;
  66. /**
  67. * Inserting a new record into activity log.
  68. *
  69. * @param newRecord new record to be inserted
  70. */
  71. - (void)addLogRecord:(FIRIAMActivityRecord *)newRecord;
  72. /**
  73. * Get a immutable copy of the existing activity log records.
  74. */
  75. - (NSArray<FIRIAMActivityRecord *> *)readRecords;
  76. @end
  77. NS_ASSUME_NONNULL_END