1 |
efrain |
1 |
/*
|
|
|
2 |
* Copyright 2019 Google
|
|
|
3 |
*
|
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
|
6 |
* You may obtain a copy of the License at
|
|
|
7 |
*
|
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
9 |
*
|
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
13 |
* See the License for the specific language governing permissions and
|
|
|
14 |
* limitations under the License.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
#import <Foundation/Foundation.h>
|
|
|
18 |
|
|
|
19 |
#import <FirebaseRemoteConfig/FIRRemoteConfig.h>
|
|
|
20 |
|
|
|
21 |
@class RCNConfigDBManager;
|
|
|
22 |
|
|
|
23 |
/// This internal class contains a set of variables that are unique among all the config instances.
|
|
|
24 |
/// It also handles all metadata and internal metadata. This class is not thread safe and does not
|
|
|
25 |
/// inherently allow for synchronized accesss. Callers are responsible for synchronization
|
|
|
26 |
/// (currently using serial dispatch queues).
|
|
|
27 |
@interface RCNConfigSettings : NSObject
|
|
|
28 |
|
|
|
29 |
/// The time interval that config data stays fresh.
|
|
|
30 |
@property(nonatomic, readwrite, assign) NSTimeInterval minimumFetchInterval;
|
|
|
31 |
|
|
|
32 |
/// The timeout to set for outgoing fetch requests.
|
|
|
33 |
@property(nonatomic, readwrite, assign) NSTimeInterval fetchTimeout;
|
|
|
34 |
|
|
|
35 |
#pragma mark - Data required by config request.
|
|
|
36 |
/// Device authentication ID required by config request.
|
|
|
37 |
@property(nonatomic, copy) NSString *deviceAuthID;
|
|
|
38 |
/// Secret Token required by config request.
|
|
|
39 |
@property(nonatomic, copy) NSString *secretToken;
|
|
|
40 |
/// Device data version of checkin information.
|
|
|
41 |
@property(nonatomic, copy) NSString *deviceDataVersion;
|
|
|
42 |
/// InstallationsID.
|
|
|
43 |
@property(nonatomic, copy) NSString *configInstallationsIdentifier;
|
|
|
44 |
/// Installations token.
|
|
|
45 |
@property(nonatomic, copy) NSString *configInstallationsToken;
|
|
|
46 |
|
|
|
47 |
/// A list of successful fetch timestamps in milliseconds.
|
|
|
48 |
/// TODO Not used anymore. Safe to remove.
|
|
|
49 |
@property(nonatomic, readonly, copy) NSArray *successFetchTimes;
|
|
|
50 |
/// A list of failed fetch timestamps in milliseconds.
|
|
|
51 |
@property(nonatomic, readonly, copy) NSArray *failureFetchTimes;
|
|
|
52 |
/// Custom variable (aka App context digest). This is the pending custom variables request before
|
|
|
53 |
/// fetching.
|
|
|
54 |
@property(nonatomic, copy) NSDictionary *customVariables;
|
|
|
55 |
/// Cached internal metadata from internal metadata table. It contains customized information such
|
|
|
56 |
/// as HTTP connection timeout, HTTP read timeout, success/failure throttling rate and time
|
|
|
57 |
/// interval. Client has the default value of each parameters, they are only saved in
|
|
|
58 |
/// internalMetadata if they have been customize by developers.
|
|
|
59 |
@property(nonatomic, readonly, copy) NSDictionary *internalMetadata;
|
|
|
60 |
/// Device conditions since last successful fetch from the backend. Device conditions including
|
|
|
61 |
/// app
|
|
|
62 |
/// version, iOS version, device localte, language, GMP project ID and Game project ID. Used for
|
|
|
63 |
/// determing whether to throttle.
|
|
|
64 |
@property(nonatomic, readonly, copy) NSDictionary *deviceContext;
|
|
|
65 |
/// Bundle Identifier
|
|
|
66 |
@property(nonatomic, readonly, copy) NSString *bundleIdentifier;
|
|
|
67 |
/// The time of last successful config fetch.
|
|
|
68 |
@property(nonatomic, readonly, assign) NSTimeInterval lastFetchTimeInterval;
|
|
|
69 |
/// Last fetch status.
|
|
|
70 |
@property(nonatomic, readwrite, assign) FIRRemoteConfigFetchStatus lastFetchStatus;
|
|
|
71 |
/// The reason that last fetch failed.
|
|
|
72 |
@property(nonatomic, readwrite, assign) FIRRemoteConfigError lastFetchError;
|
|
|
73 |
/// The time of last apply timestamp.
|
|
|
74 |
@property(nonatomic, readwrite, assign) NSTimeInterval lastApplyTimeInterval;
|
|
|
75 |
/// The time of last setDefaults timestamp.
|
|
|
76 |
@property(nonatomic, readwrite, assign) NSTimeInterval lastSetDefaultsTimeInterval;
|
|
|
77 |
/// The latest eTag value stored from the last successful response.
|
|
|
78 |
@property(nonatomic, readwrite, assign) NSString *lastETag;
|
|
|
79 |
/// The timestamp of the last eTag update.
|
|
|
80 |
@property(nonatomic, readwrite, assign) NSTimeInterval lastETagUpdateTime;
|
|
|
81 |
|
|
|
82 |
#pragma mark Throttling properties
|
|
|
83 |
|
|
|
84 |
/// Throttling intervals are based on https://cloud.google.com/storage/docs/exponential-backoff
|
|
|
85 |
/// Returns true if client has fetched config and has not got back from server. This is used to
|
|
|
86 |
/// determine whether there is another config task infight when fetching.
|
|
|
87 |
@property(atomic, readwrite, assign) BOOL isFetchInProgress;
|
|
|
88 |
/// Returns the current retry interval in seconds set for exponential backoff.
|
|
|
89 |
@property(nonatomic, readwrite, assign) double exponentialBackoffRetryInterval;
|
|
|
90 |
/// Returns the time in seconds until the next request is allowed while in exponential backoff mode.
|
|
|
91 |
@property(nonatomic, readonly, assign) NSTimeInterval exponentialBackoffThrottleEndTime;
|
|
|
92 |
|
|
|
93 |
#pragma mark Throttling Methods
|
|
|
94 |
|
|
|
95 |
/// Designated initializer.
|
|
|
96 |
- (instancetype)initWithDatabaseManager:(RCNConfigDBManager *)manager
|
|
|
97 |
namespace:(NSString *)FIRNamespace
|
|
|
98 |
firebaseAppName:(NSString *)appName
|
|
|
99 |
googleAppID:(NSString *)googleAppID;
|
|
|
100 |
|
|
|
101 |
/// Returns a fetch request with the latest device and config change.
|
|
|
102 |
/// Whenever user issues a fetch api call, collect the latest request.
|
|
|
103 |
/// @param userProperties User properties to set to config request.
|
|
|
104 |
/// @return Config fetch request string
|
|
|
105 |
- (NSString *)nextRequestWithUserProperties:(NSDictionary *)userProperties;
|
|
|
106 |
|
|
|
107 |
/// Returns metadata from metadata table.
|
|
|
108 |
- (NSDictionary *)loadConfigFromMetadataTable;
|
|
|
109 |
|
|
|
110 |
/// Updates internal content with the latest successful config response.
|
|
|
111 |
- (void)updateInternalContentWithResponse:(NSDictionary *)response;
|
|
|
112 |
|
|
|
113 |
/// Updates the metadata table with the current fetch status.
|
|
|
114 |
/// @param fetchSuccess True if fetch was successful.
|
|
|
115 |
- (void)updateMetadataWithFetchSuccessStatus:(BOOL)fetchSuccess;
|
|
|
116 |
|
|
|
117 |
/// Increases the throttling time. Should only be called if the fetch error indicates a server
|
|
|
118 |
/// issue.
|
|
|
119 |
- (void)updateExponentialBackoffTime;
|
|
|
120 |
|
|
|
121 |
/// Returns true if we are in exponential backoff mode and it is not yet the next request time.
|
|
|
122 |
- (BOOL)shouldThrottle;
|
|
|
123 |
|
|
|
124 |
/// Returns true if the last fetch is outside the minimum fetch interval supplied.
|
|
|
125 |
- (BOOL)hasMinimumFetchIntervalElapsed:(NSTimeInterval)minimumFetchInterval;
|
|
|
126 |
|
|
|
127 |
@end
|