Skip to content

Commit

Permalink
[rc-swift] RemoteConfigValue (#14245)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulb777 authored Dec 12, 2024
1 parent 0f9af07 commit f922738
Show file tree
Hide file tree
Showing 19 changed files with 112 additions and 177 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ jobs:
matrix:
target: [ios, tvos]
build-env:
- os: macos-14
xcode: Xcode_15.2
- os: macos-15
xcode: Xcode_16.1
runs-on: ${{ matrix.build-env.os }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,23 @@

#import "FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags.h"

#import "FirebaseRemoteConfig/Sources/Private/FIRRemoteConfig_Private.h"
@import FirebaseRemoteConfig;

NS_ASSUME_NONNULL_BEGIN

@interface FIRRemoteConfig ()
+ (FIRRemoteConfig *)remoteConfigWithFIRNamespace:(NSString *)remoteConfigNamespace
app:(FIRApp *)app;
@end

@interface FIRRemoteConfigValue ()
@property(nonatomic, readwrite, assign) FIRRemoteConfigSource source;

/// Designated initializer.
- (instancetype)initWithData:(nullable NSData *)data
source:(FIRRemoteConfigSource)source NS_DESIGNATED_INITIALIZER;
@end

@class GULUserDefaults;

static NSString *const kFPRConfigPrefix = @"com.fireperf";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#import "FirebaseCore/Extension/FirebaseCoreInternal.h"

@import FirebaseRemoteConfig;

#define ONE_DAY_SECONDS 24 * 60 * 60

static NSDate *FPRAppStartTime = nil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

#import <Foundation/Foundation.h>

#import "FirebaseRemoteConfig/Sources/Private/FIRRemoteConfig_Private.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h"
@import FirebaseRemoteConfig;

@import FirebaseRemoteConfig;

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -37,6 +38,8 @@ NS_ASSUME_NONNULL_BEGIN
/** @brief Different configurations values that needs to be stored and returned. */
@property(nonatomic) NSMutableDictionary<NSString *, FIRRemoteConfigValue *> *configValues;

- (instancetype)init;

/**
* Fake fetch call for fetching configs. Calling this method will just call the completionHandler.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#import "FirebasePerformance/Tests/Unit/Configurations/FPRFakeRemoteConfig.h"

@import FirebaseRemoteConfig;

static NSInteger const kLogSource = 462; // LogRequest_LogSource_Fireperf

@interface FPRRemoteConfigFlagsTest : XCTestCase
Expand Down Expand Up @@ -65,7 +67,7 @@ - (void)testCacheResetAfterEverySuccessfulFetch {
forKey:@"fpr_vc_session_sampling_rate"];

// Trigger the RC config fetch
remoteConfig.fetchStatus = FIRRemoteConfigFetchStatusSuccess;
remoteConfig.fetchStatus = FIRRemoteConfigFetchAndActivateStatusSuccessUsingPreFetchedData;
remoteConfig.lastFetchTime = nil;
configFlags.appStartConfigFetchDelayInSeconds = 0.0;
[configFlags update];
Expand All @@ -92,7 +94,7 @@ - (void)testCacheResetAfterEverySuccessfulFetch {
forKey:@"fpr_vc_session_sampling_rate"];

// Retrigger the RC config fetch
remoteConfig.fetchStatus = FIRRemoteConfigFetchStatusSuccess;
remoteConfig.fetchStatus = FIRRemoteConfigFetchAndActivateStatusSuccessUsingPreFetchedData;
remoteConfig.lastFetchTime = nil;
[configFlags update];

Expand All @@ -112,7 +114,7 @@ - (void)testConfigUpdate {

FPRRemoteConfigFlags *configFlags =
[[FPRRemoteConfigFlags alloc] initWithRemoteConfig:(FIRRemoteConfig *)remoteConfig];
remoteConfig.fetchStatus = FIRRemoteConfigFetchStatusSuccess;
remoteConfig.fetchStatus = FIRRemoteConfigFetchAndActivateStatusSuccessUsingPreFetchedData;
configFlags.appStartConfigFetchDelayInSeconds = 0.0;
[configFlags update];
XCTAssertNotNil(configFlags.lastFetchedTime);
Expand Down Expand Up @@ -179,7 +181,7 @@ - (void)testConfigUpdateDoesNotHappenImmediately {
FPRRemoteConfigFlags *configFlags =
[[FPRRemoteConfigFlags alloc] initWithRemoteConfig:(FIRRemoteConfig *)remoteConfig];

remoteConfig.fetchStatus = FIRRemoteConfigFetchStatusSuccess;
remoteConfig.fetchStatus = FIRRemoteConfigFetchAndActivateStatusSuccessUsingPreFetchedData;
configFlags.appStartConfigFetchDelayInSeconds = 0.0;
[configFlags update];
XCTAssertNotNil(configFlags.lastFetchedTime);
Expand All @@ -203,7 +205,7 @@ - (void)testConfigUpdateHappensIfInitialFetchHasNotHappened {
FPRRemoteConfigFlags *configFlags =
[[FPRRemoteConfigFlags alloc] initWithRemoteConfig:(FIRRemoteConfig *)remoteConfig];

remoteConfig.fetchStatus = FIRRemoteConfigFetchStatusSuccess;
remoteConfig.fetchStatus = FIRRemoteConfigFetchAndActivateStatusSuccessUsingPreFetchedData;
configFlags.appStartConfigFetchDelayInSeconds = 0.0;
[configFlags update];
XCTAssertNotNil(configFlags.lastFetchedTime);
Expand All @@ -224,7 +226,7 @@ - (void)testConfigFetchHappensDoesNotHappenImmediately {
[[FPRRemoteConfigFlags alloc] initWithRemoteConfig:(FIRRemoteConfig *)remoteConfig];
// Setting the status to success. Calling update on the config flags should trigger updation of
// fetch time. Fetch would trigger activation.
remoteConfig.fetchStatus = FIRRemoteConfigFetchStatusSuccess;
remoteConfig.fetchStatus = FIRRemoteConfigFetchAndActivateStatusSuccessUsingPreFetchedData;
NSDate *lastActivatedTime = configFlags.lastFetchedTime;
[configFlags update];
XCTAssert([configFlags.lastFetchedTime timeIntervalSinceDate:lastActivatedTime] == 0);
Expand All @@ -240,7 +242,7 @@ - (void)testConfigFetchHappensAfterDelay {
[[FPRRemoteConfigFlags alloc] initWithRemoteConfig:(FIRRemoteConfig *)remoteConfig];
configFlags.appStartConfigFetchDelayInSeconds = 0.0;

remoteConfig.fetchStatus = FIRRemoteConfigFetchStatusSuccess;
remoteConfig.fetchStatus = FIRRemoteConfigFetchAndActivateStatusSuccessUsingPreFetchedData;
XCTestExpectation *expectation =
[self expectationWithDescription:@"Dummy expectation to wait for the fetch delay."];
dispatch_after(
Expand Down
2 changes: 1 addition & 1 deletion FirebasePerformance/Tests/Unit/Timer/FIRTraceTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#import "FirebasePerformance/Tests/Unit/Configurations/FPRFakeRemoteConfig.h"
#import "FirebasePerformance/Tests/Unit/FPRTestCase.h"

#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h"
@import FirebaseRemoteConfig;

#import <OCMock/OCMock.h>

Expand Down
91 changes: 0 additions & 91 deletions FirebaseRemoteConfig/Sources/FIRConfigValue.m

This file was deleted.

1 change: 0 additions & 1 deletion FirebaseRemoteConfig/Sources/FIRRemoteConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#import "FirebaseRemoteConfig/Sources/Private/RCNConfigSettings.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigRealtime.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h"
#import "FirebaseRemoteConfig/Sources/RCNPersonalization.h"

#import "FirebaseRemoteConfig/FirebaseRemoteConfig-Swift.h"
Expand Down
12 changes: 0 additions & 12 deletions FirebaseRemoteConfig/Sources/Private/FIRRemoteConfig_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,6 @@ NS_ASSUME_NONNULL_BEGIN
+ (FIRRemoteConfig *)remoteConfigWithFIRNamespace:(NSString *)remoteConfigNamespace
NS_SWIFT_NAME(remoteConfig(FIRNamespace:));

/// Returns the FIRRemoteConfig instance for your namespace and for the default 3P developer's app.
/// This singleton object contains the complete set of Remote Config parameter values available to
/// the app, including the Active Config and Default Config. This object also caches values fetched
/// from the Remote Config Server until they are copied to the Active Config by calling
/// activateFetched. When you fetch values from the Remote Config Server using the default Firebase
/// namespace service, you should use this class method to create a shared instance of the
/// FIRRemoteConfig object to ensure that your app will function properly with the Remote Config
/// Server and the Firebase service.
+ (FIRRemoteConfig *)remoteConfigWithFIRNamespace:(NSString *)remoteConfigNamespace
app:(FIRApp *)app
NS_SWIFT_NAME(remoteConfig(FIRNamespace:app:));

/// Register RolloutsStateSubcriber to FIRRemoteConfig instance
- (void)addRemoteConfigInteropSubscriber:(id<FIRRolloutsStateSubscriber> _Nonnull)subscriber;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@class RCNConfigContent;
@class FIROptions;
@class RCNConfigSettings;
@class FIRRemoteConfigValue;
@protocol FIRAnalyticsInterop;

/// The Firebase Remote Config service default namespace, to be used if the API method does not
Expand Down Expand Up @@ -139,31 +140,6 @@ typedef void (^FIRRemoteConfigFetchAndActivateCompletion)(
FIRRemoteConfigFetchAndActivateStatus status, NSError *_Nullable error)
NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead.");

#pragma mark - FIRRemoteConfigValue
/// This class provides a wrapper for Remote Config parameter values, with methods to get parameter
/// values as different data types.
NS_SWIFT_NAME(RemoteConfigValue)
@interface FIRRemoteConfigValue : NSObject <NSCopying>
/// Gets the value as a string.
@property(nonatomic, readonly, nonnull) NSString *stringValue;
/// Gets the value as a number value.
@property(nonatomic, readonly, nonnull) NSNumber *numberValue;
/// Gets the value as a NSData object.
@property(nonatomic, readonly, nonnull) NSData *dataValue;
/// Gets the value as a boolean.
@property(nonatomic, readonly) BOOL boolValue;
/// Gets a foundation object (NSDictionary / NSArray) by parsing the value as JSON. This method uses
/// NSJSONSerialization's JSONObjectWithData method with an options value of 0.
@property(nonatomic, readonly, nullable) id JSONValue NS_SWIFT_NAME(jsonValue);
/// Identifies the source of the fetched value.
@property(nonatomic, readonly) FIRRemoteConfigSource source;

/// TODO: internal API for temporary bridging
/// Designated initializer.
- (instancetype _Nonnull)initWithData:(nullable NSData *)data
source:(FIRRemoteConfigSource)source NS_DESIGNATED_INITIALIZER;
@end

#pragma mark - FIRRemoteConfigSettings
/// Firebase Remote Config settings.
NS_SWIFT_NAME(RemoteConfigSettings)
Expand Down
1 change: 0 additions & 1 deletion FirebaseRemoteConfig/Sources/RCNConfigSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#import "FirebaseRemoteConfig/FirebaseRemoteConfig-Swift.h"

#import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h"

#import <GoogleUtilities/GULAppEnvironmentUtil.h>
#import "FirebaseCore/Extension/FirebaseCoreInternal.h"
Expand Down
27 changes: 0 additions & 27 deletions FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h

This file was deleted.

2 changes: 1 addition & 1 deletion FirebaseRemoteConfig/Sources/RCNPersonalization.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#import "FirebaseRemoteConfig/Sources/RCNPersonalization.h"

#import "FirebaseRemoteConfig/FirebaseRemoteConfig-Swift.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h"

@implementation RCNPersonalization

Expand Down
Loading

0 comments on commit f922738

Please sign in to comment.