FIRExperimentController.h 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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, ABTExperimentPayloadExperimentOverflowPolicy);
  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 ABTExperimentPayloadExperimentOverflowPolicy 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:(ABTExperimentPayloadExperimentOverflowPolicy)policy
  46. lastStartTime:(NSTimeInterval)lastStartTime
  47. payloads:(NSArray<NSData *> *)payloads
  48. completionHandler:
  49. (nullable void (^)(NSError *_Nullable error))completionHandler;
  50. /// Returns the latest experiment start timestamp given a current latest timestamp and a list of
  51. /// experiment payloads. Timestamps are specified by the number of seconds from 00:00:00 UTC on 1
  52. /// January 1970.
  53. /// @param timestamp Current latest experiment start timestamp. If not known, affected service
  54. /// should specify -1;
  55. /// @param payloads List of experiment metadata.
  56. - (NSTimeInterval)latestExperimentStartTimestampBetweenTimestamp:(NSTimeInterval)timestamp
  57. andPayloads:(NSArray<NSData *> *)payloads;
  58. /// Expires experiments that aren't in the list of running experiment payloads.
  59. /// @param origin The originating service affected by the experiment.
  60. /// @param payloads The list of valid, running experiments.
  61. - (void)validateRunningExperimentsForServiceOrigin:(NSString *)origin
  62. runningExperimentPayloads:(NSArray<ABTExperimentPayload *> *)payloads;
  63. /// Directly sets a given experiment to be active.
  64. /// @param experimentPayload The payload for the experiment that should be activated.
  65. /// @param origin The originating service affected by the experiment.
  66. - (void)activateExperiment:(ABTExperimentPayload *)experimentPayload
  67. forServiceOrigin:(NSString *)origin;
  68. @end
  69. NS_ASSUME_NONNULL_END