FPRRemoteConfigFlags+Private.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright 2020 Google LLC
  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 "FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags.h"
  15. #import "FirebaseRemoteConfig/Sources/Private/FIRRemoteConfig_Private.h"
  16. NS_ASSUME_NONNULL_BEGIN
  17. @class GULUserDefaults;
  18. static NSString *const kFPRConfigPrefix = @"com.fireperf";
  19. /** Interval at which the configurations can be fetched. Specified in seconds. */
  20. static NSInteger const kFPRConfigFetchIntervalInSeconds = 12 * 60 * 60;
  21. /** Interval after which the configurations can be fetched. Specified in seconds. */
  22. static NSInteger const kFPRMinAppStartConfigFetchDelayInSeconds = 5;
  23. /** This extension should only be used for testing. */
  24. @interface FPRRemoteConfigFlags ()
  25. /** @brief Instance of remote config used for firebase performance namespace. */
  26. @property(nonatomic) FIRRemoteConfig *fprRemoteConfig;
  27. /** @brief Last activated time of the configurations. */
  28. @property(atomic, nullable) NSDate *lastFetchedTime;
  29. /** @brief User defaults used for caching. */
  30. @property(nonatomic) GULUserDefaults *userDefaults;
  31. /** @brief Last activated time of the configurations. */
  32. @property(nonatomic) NSDate *applicationStartTime;
  33. /** @brief Number of seconds delayed until the first config is made during app start. */
  34. @property(nonatomic) NSTimeInterval appStartConfigFetchDelayInSeconds;
  35. /** @brief Status of the last remote config fetch. */
  36. @property(nonatomic) FIRRemoteConfigFetchStatus lastFetchStatus;
  37. /**
  38. * Creates an instance of FPRRemoteConfigFlags.
  39. *
  40. * @param config RemoteConfig object to be used for configuration management.
  41. * @return Instance of remote config.
  42. */
  43. - (instancetype)initWithRemoteConfig:(FIRRemoteConfig *)config NS_DESIGNATED_INITIALIZER;
  44. #pragma mark - Config fetch methods
  45. /**
  46. * Gets and returns the string value for the provided remote config flag. If there are no values
  47. * returned from remote config, default value will be returned.
  48. * @param flagName Name of the flag for which the value needs to be fetched from RC.
  49. * @param defaultValue Default value that will be returned if no value is fetched from RC.
  50. *
  51. * @return string value for the flag from RC if available. Default value, otherwise.
  52. */
  53. - (NSString *)getStringValueForFlag:(NSString *)flagName defaultValue:(NSString *)defaultValue;
  54. /**
  55. * Gets and returns the int value for the provided remote config flag. If there are no values
  56. * returned from remote config, default value will be returned.
  57. * @param flagName Name of the flag for which the value needs to be fetched from RC.
  58. * @param defaultValue Default value that will be returned if no value is fetched from RC.
  59. *
  60. * @return Int value for the flag from RC if available. Default value, otherwise.
  61. */
  62. - (int)getIntValueForFlag:(NSString *)flagName defaultValue:(int)defaultValue;
  63. /**
  64. * Gets and returns the float value for the provided remote config flag. If there are no values
  65. * returned from remote config, default value will be returned.
  66. * @param flagName Name of the flag for which the value needs to be fetched from RC.
  67. * @param defaultValue Default value that will be returned if no value is fetched from RC.
  68. *
  69. * @return Float value for the flag from RC if available. Default value, otherwise.
  70. */
  71. - (float)getFloatValueForFlag:(NSString *)flagName defaultValue:(float)defaultValue;
  72. /**
  73. * Gets and returns the boolean value for the provided remote config flag. If there are no values
  74. * returned from remote config, default value will be returned.
  75. * @param flagName Name of the flag for which the value needs to be fetched from RC.
  76. * @param defaultValue Default value that will be returned if no value is fetched from RC.
  77. *
  78. * @return Bool value for the flag from RC if available. Default value, otherwise.
  79. */
  80. - (BOOL)getBoolValueForFlag:(NSString *)flagName defaultValue:(BOOL)defaultValue;
  81. /**
  82. * Caches the remote config values.
  83. */
  84. - (void)cacheConfigValues;
  85. /**
  86. * Reset (Clears) all the remote config keys and values that were cached.
  87. */
  88. - (void)resetCache;
  89. @end
  90. NS_ASSUME_NONNULL_END