FIRExperimentController.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 <Foundation/Foundation.h>
  15. @class ABTExperimentPayload;
  16. // Forward declaration to avoid importing into the module header
  17. typedef NS_ENUM(int32_t, ABTExperimentPayload_ExperimentOverflowPolicy);
  18. NS_ASSUME_NONNULL_BEGIN
  19. @class FIRLifecycleEvents;
  20. /// The default experiment overflow policy, that is to discard the experiment with the oldest start
  21. /// time when users start the experiment on the web console.
  22. extern const ABTExperimentPayload_ExperimentOverflowPolicy FIRDefaultExperimentOverflowPolicy;
  23. /// This class is for Firebase services to handle experiments updates to Firebase Analytics.
  24. /// Experiments can be set, cleared and updated through this controller.
  25. NS_SWIFT_NAME(ExperimentController)
  26. @interface FIRExperimentController : NSObject
  27. /// Returns the FIRExperimentController singleton.
  28. + (FIRExperimentController *)sharedInstance;
  29. /// Updates the list of experiments with an optional completion handler. Experiments already
  30. /// existing in payloads are not affected, whose state and payload is preserved. This method
  31. /// compares whether the experiments have changed or not by their variant ID. This runs in a
  32. /// background queue and calls the completion handler when finished executing.
  33. /// @param origin The originating service affected by the experiment.
  34. /// @param events A list of event names to be used for logging experiment lifecycle events,
  35. /// if they are not defined in the payload.
  36. /// @param policy The policy to handle new experiments when slots are full.
  37. /// @param lastStartTime The last known experiment start timestamp for this affected service.
  38. /// (Timestamps are specified by the number of seconds from 00:00:00 UTC on 1
  39. /// January 1970.).
  40. /// @param payloads List of experiment metadata.
  41. /// @param completionHandler Code to be executed after experiments are updated in the background
  42. /// thread.
  43. - (void)updateExperimentsWithServiceOrigin:(NSString *)origin
  44. events:(FIRLifecycleEvents *)events
  45. policy:(ABTExperimentPayload_ExperimentOverflowPolicy)policy
  46. lastStartTime:(NSTimeInterval)lastStartTime
  47. payloads:(NSArray<NSData *> *)payloads
  48. completionHandler:
  49. (nullable void (^)(NSError *_Nullable error))completionHandler;
  50. /// Updates the list of experiments. Experiments already
  51. /// existing in payloads are not affected, whose state and payload is preserved. This method
  52. /// compares whether the experiments have changed or not by their variant ID. This runs in a
  53. /// background queue..
  54. /// @param origin The originating service affected by the experiment.
  55. /// @param events A list of event names to be used for logging experiment lifecycle events,
  56. /// if they are not defined in the payload.
  57. /// @param policy The policy to handle new experiments when slots are full.
  58. /// @param lastStartTime The last known experiment start timestamp for this affected service.
  59. /// (Timestamps are specified by the number of seconds from 00:00:00 UTC on 1
  60. /// January 1970.).
  61. /// @param payloads List of experiment metadata.
  62. - (void)updateExperimentsWithServiceOrigin:(NSString *)origin
  63. events:(FIRLifecycleEvents *)events
  64. policy:(ABTExperimentPayload_ExperimentOverflowPolicy)policy
  65. lastStartTime:(NSTimeInterval)lastStartTime
  66. payloads:(NSArray<NSData *> *)payloads
  67. DEPRECATED_MSG_ATTRIBUTE("Please use updateExperimentsWithServiceOrigin:events:policy:"
  68. "lastStartTime:payloads:completionHandler: instead.");
  69. /// Returns the latest experiment start timestamp given a current latest timestamp and a list of
  70. /// experiment payloads. Timestamps are specified by the number of seconds from 00:00:00 UTC on 1
  71. /// January 1970.
  72. /// @param timestamp Current latest experiment start timestamp. If not known, affected service
  73. /// should specify -1;
  74. /// @param payloads List of experiment metadata.
  75. - (NSTimeInterval)latestExperimentStartTimestampBetweenTimestamp:(NSTimeInterval)timestamp
  76. andPayloads:(NSArray<NSData *> *)payloads;
  77. /// Expires experiments that aren't in the list of running experiment payloads.
  78. /// @param origin The originating service affected by the experiment.
  79. /// @param payloads The list of valid, running experiments.
  80. - (void)validateRunningExperimentsForServiceOrigin:(NSString *)origin
  81. runningExperimentPayloads:(NSArray<ABTExperimentPayload *> *)payloads;
  82. /// Directly sets a given experiment to be active.
  83. /// @param experimentPayload The payload for the experiment that should be activated.
  84. /// @param origin The originating service affected by the experiment.
  85. - (void)activateExperiment:(ABTExperimentPayload *)experimentPayload
  86. forServiceOrigin:(NSString *)origin;
  87. @end
  88. NS_ASSUME_NONNULL_END