FIRExperimentController.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. // Forward declaration to avoid importing into the module header
  16. typedef NS_ENUM(int32_t, ABTExperimentPayload_ExperimentOverflowPolicy);
  17. NS_ASSUME_NONNULL_BEGIN
  18. @class FIRLifecycleEvents;
  19. /// The default experiment overflow policy, that is to discard the experiment with the oldest start
  20. /// time when users start the experiment on the web console.
  21. extern const ABTExperimentPayload_ExperimentOverflowPolicy FIRDefaultExperimentOverflowPolicy;
  22. /// This class is for Firebase services to handle experiments updates to Firebase Analytics.
  23. /// Experiments can be set, cleared and updated through this controller.
  24. NS_SWIFT_NAME(ExperimentController)
  25. @interface FIRExperimentController : NSObject
  26. /// Returns the FIRExperimentController singleton.
  27. + (FIRExperimentController *)sharedInstance;
  28. /// Updates the list of experiments. Experiments already existing in payloads are not affected,
  29. /// whose state and payload is preserved. This method compares whether the experiments have changed
  30. /// or not by their variant ID. This runs in a background queue.
  31. /// @param origin The originating service affected by the experiment, it is defined at
  32. /// Firebase Analytics FIREventOrigins.h.
  33. /// @param events A list of event names to be used for logging experiment lifecycle events,
  34. /// if they are not defined in the payload.
  35. /// @param policy The policy to handle new experiments when slots are full.
  36. /// @param lastStartTime The last known experiment start timestamp for this affected service.
  37. /// (Timestamps are specified by the number of seconds from 00:00:00 UTC on 1
  38. /// January 1970.).
  39. /// @param payloads List of experiment metadata.
  40. - (void)updateExperimentsWithServiceOrigin:(NSString *)origin
  41. events:(FIRLifecycleEvents *)events
  42. policy:(ABTExperimentPayload_ExperimentOverflowPolicy)policy
  43. lastStartTime:(NSTimeInterval)lastStartTime
  44. payloads:(NSArray<NSData *> *)payloads;
  45. /// Returns the latest experiment start timestamp given a current latest timestamp and a list of
  46. /// experiment payloads. Timestamps are specified by the number of seconds from 00:00:00 UTC on 1
  47. /// January 1970.
  48. /// @param timestamp Current latest experiment start timestamp. If not known, affected service
  49. /// should specify -1;
  50. /// @param payloads List of experiment metadata.
  51. - (NSTimeInterval)latestExperimentStartTimestampBetweenTimestamp:(NSTimeInterval)timestamp
  52. andPayloads:(NSArray<NSData *> *)payloads;
  53. @end
  54. NS_ASSUME_NONNULL_END