FIRExperimentController.h 5.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 with an optional completion handler. Experiments already
  29. /// existing in payloads are not affected, whose state and payload is preserved. This method
  30. /// compares whether the experiments have changed or not by their variant ID. This runs in a
  31. /// background queue and calls the completion handler when finished executing.
  32. /// @param origin The originating service affected by the experiment, it is defined at
  33. /// Firebase Analytics FIREventOrigins.h.
  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, it is defined at
  55. /// Firebase Analytics FIREventOrigins.h.
  56. /// @param events A list of event names to be used for logging experiment lifecycle events,
  57. /// if they are not defined in the payload.
  58. /// @param policy The policy to handle new experiments when slots are full.
  59. /// @param lastStartTime The last known experiment start timestamp for this affected service.
  60. /// (Timestamps are specified by the number of seconds from 00:00:00 UTC on 1
  61. /// January 1970.).
  62. /// @param payloads List of experiment metadata.
  63. /// thread.
  64. - (void)updateExperimentsWithServiceOrigin:(NSString *)origin
  65. events:(FIRLifecycleEvents *)events
  66. policy:(ABTExperimentPayload_ExperimentOverflowPolicy)policy
  67. lastStartTime:(NSTimeInterval)lastStartTime
  68. payloads:(NSArray<NSData *> *)payloads
  69. DEPRECATED_MSG_ATTRIBUTE("Please use updateExperimentsWithServiceOrigin:events:policy:"
  70. "lastStartTime:payloads:completionHandler: instead.");
  71. /// Returns the latest experiment start timestamp given a current latest timestamp and a list of
  72. /// experiment payloads. Timestamps are specified by the number of seconds from 00:00:00 UTC on 1
  73. /// January 1970.
  74. /// @param timestamp Current latest experiment start timestamp. If not known, affected service
  75. /// should specify -1;
  76. /// @param payloads List of experiment metadata.
  77. - (NSTimeInterval)latestExperimentStartTimestampBetweenTimestamp:(NSTimeInterval)timestamp
  78. andPayloads:(NSArray<NSData *> *)payloads;
  79. @end
  80. NS_ASSUME_NONNULL_END