Skip to content

Commit 3211a7f

Browse files
authored
[Performance] Migrate to GoogleUtilities's storage container (#12759)
1 parent 1cde471 commit 3211a7f

File tree

6 files changed

+59
-49
lines changed

6 files changed

+59
-49
lines changed

FirebasePerformance.podspec

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ Firebase Performance library to measure performance of Mobile and Web Apps.
6464
s.dependency 'FirebaseRemoteConfig', '~> 10.0'
6565
s.dependency 'FirebaseSessions', '~> 10.5'
6666
s.dependency 'GoogleDataTransport', '~> 9.2'
67-
s.dependency 'GoogleUtilities/Environment', '~> 7.8'
68-
s.dependency 'GoogleUtilities/ISASwizzler', '~> 7.8'
69-
s.dependency 'GoogleUtilities/MethodSwizzler', '~> 7.8'
67+
s.dependency 'GoogleUtilities/Environment', '~> 7.13'
68+
s.dependency 'GoogleUtilities/ISASwizzler', '~> 7.13'
69+
s.dependency 'GoogleUtilities/MethodSwizzler', '~> 7.13'
70+
s.dependency 'GoogleUtilities/UserDefaults', '~> 7.13'
7071
s.dependency 'nanopb', '>= 2.30908.0', '< 2.30911.0'
7172

7273
s.test_spec 'unit' do |unit_tests|

FirebasePerformance/Sources/Configurations/FPRConfigurations+Private.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
NS_ASSUME_NONNULL_BEGIN
1919

20+
@class GULUserDefaults;
21+
2022
/** List of gauges the gauge manager controls. */
2123
typedef NS_OPTIONS(NSUInteger, FPRConfigurationSource) {
2224
FPRConfigurationSourceNone = 0,
@@ -36,7 +38,7 @@ typedef NS_OPTIONS(NSUInteger, FPRConfigurationSource) {
3638
@property(nonatomic) Class FIRAppClass;
3739

3840
/** @brief User defaults used for user preference config fetches . */
39-
@property(nonatomic) NSUserDefaults *userDefaults;
41+
@property(nonatomic) GULUserDefaults *userDefaults;
4042

4143
/** @brief The main bundle identifier used by config system. */
4244
@property(nonatomic) NSString *mainBundleIdentifier;

FirebasePerformance/Sources/Configurations/FPRConfigurations.m

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#import <UIKit/UIKit.h>
1616

17+
#import <GoogleUtilities/GULUserDefaults.h>
18+
1719
#import "FirebasePerformance/Sources/Common/FPRConstants.h"
1820
#import "FirebasePerformance/Sources/Configurations/FPRConfigurations+Private.h"
1921
#import "FirebasePerformance/Sources/Configurations/FPRConfigurations.h"
@@ -58,9 +60,9 @@ + (instancetype)sharedInstance {
5860
+ (void)reset {
5961
// TODO(b/120032990): Reset the singletons that this singleton uses.
6062
gSharedInstanceToken = 0;
61-
[[NSUserDefaults standardUserDefaults]
63+
[[GULUserDefaults standardUserDefaults]
6264
removeObjectForKey:kFPRConfigInstrumentationUserPreference];
63-
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kFPRConfigCollectionUserPreference];
65+
[[GULUserDefaults standardUserDefaults] removeObjectForKey:kFPRConfigCollectionUserPreference];
6466
}
6567

6668
- (instancetype)initWithSources:(FPRConfigurationSource)source {
@@ -73,7 +75,7 @@ - (instancetype)initWithSources:(FPRConfigurationSource)source {
7375
[self registerForNotifications];
7476

7577
self.FIRAppClass = [FIRApp class];
76-
self.userDefaults = [NSUserDefaults standardUserDefaults];
78+
self.userDefaults = [GULUserDefaults standardUserDefaults];
7779
self.infoDictionary = [NSBundle mainBundle].infoDictionary;
7880
self.mainBundleIdentifier = [NSBundle mainBundle].bundleIdentifier;
7981
self.updateQueue = dispatch_queue_create("com.google.perf.configUpdate", DISPATCH_QUEUE_SERIAL);
@@ -141,7 +143,7 @@ - (void)setDataCollectionEnabled:(BOOL)dataCollectionEnabled {
141143

142144
// The data collection flag is determined by this order:
143145
// 1. A plist flag for permanently disabling data collection
144-
// 2. The runtime flag (NSUserDefaults)
146+
// 2. The runtime flag (GULUserDefaults)
145147
// 3. A plist flag for enabling/disabling (overrideable)
146148
// 4. The global data collection switch from Core.
147149
- (BOOL)isDataCollectionEnabled {
@@ -165,7 +167,7 @@ - (BOOL)isDataCollectionEnabled {
165167
}
166168
}
167169
/**
168-
* Check if the performance collection preference key is available in NSUserDefaults.
170+
* Check if the performance collection preference key is available in GULUserDefaults.
169171
* If it exists - Just honor that and return that value.
170172
* If it does not exist - Check if firebase_performance_collection_enabled exists in Info.plist.
171173
* If it exists - honor that and return that value.
@@ -196,7 +198,7 @@ - (BOOL)isInstrumentationEnabled {
196198
[self.userDefaults objectForKey:kFPRConfigInstrumentationUserPreference];
197199

198200
/**
199-
* Check if the performance instrumentation preference key is available in NSUserDefaults.
201+
* Check if the performance instrumentation preference key is available in GULUserDefaults.
200202
* If it exists - Just honor that and return that value.
201203
* If not - Check if firebase_performance_instrumentation_enabled exists in Info.plist.
202204
* If it exists - honor that and return that value.
@@ -242,7 +244,7 @@ - (BOOL)diagnosticsEnabled {
242244
BOOL enabled = NO;
243245

244246
/**
245-
* Check if the diagnostics preference key is available in NSUserDefaults.
247+
* Check if the diagnostics preference key is available in GULUserDefaults.
246248
* If it exists - Just honor that and return that value.
247249
* If not - Check if firebase_performance_instrumentation_enabled exists in Info.plist.
248250
* If it exists - honor that and return that value.
@@ -282,8 +284,8 @@ - (int)logSource {
282284
* Order of preference of returning the log source.
283285
* If it is an autopush build (based on environment variable), always return
284286
* LogRequest_LogSource_FireperfAutopush (461). If there is a recent value of remote config fetch,
285-
* honor that value. If logSource cached value (NSUserDefaults value) exists, honor that. Fallback
286-
* to the default value LogRequest_LogSource_Fireperf (462).
287+
* honor that value. If logSource cached value (GULUserDefaults value) exists, honor that.
288+
* Fallback to the default value LogRequest_LogSource_Fireperf (462).
287289
*/
288290
int logSource = 462;
289291

FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags+Private.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
NS_ASSUME_NONNULL_BEGIN
2020

21+
@class GULUserDefaults;
22+
2123
static NSString *const kFPRConfigPrefix = @"com.fireperf";
2224

2325
/** Interval at which the configurations can be fetched. Specified in seconds. */
@@ -36,7 +38,7 @@ static NSInteger const kFPRMinAppStartConfigFetchDelayInSeconds = 5;
3638
@property(atomic, nullable) NSDate *lastFetchedTime;
3739

3840
/** @brief User defaults used for caching. */
39-
@property(nonatomic) NSUserDefaults *userDefaults;
41+
@property(nonatomic) GULUserDefaults *userDefaults;
4042

4143
/** @brief Last activated time of the configurations. */
4244
@property(nonatomic) NSDate *applicationStartTime;

FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#import "FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags.h"
15+
#import <GoogleUtilities/GULUserDefaults.h>
16+
1617
#import "FirebasePerformance/Sources/Configurations/FPRConfigurations+Private.h"
1718
#import "FirebasePerformance/Sources/Configurations/FPRConfigurations.h"
1819
#import "FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags+Private.h"
20+
#import "FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags.h"
1921

2022
#import "FirebasePerformance/Sources/FPRConsoleLogger.h"
2123

0 commit comments

Comments
 (0)