Skip to content

Commit 58151fd

Browse files
committed
[rc-swift] ConfigDBManager.swift (#14126)
1 parent 8c8fe3a commit 58151fd

27 files changed

+1817
-1758
lines changed

.github/workflows/remoteconfig.yml

Lines changed: 76 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -84,83 +84,83 @@ jobs:
8484
scripts/third_party/travis/retry.sh scripts/pod_lib_lint.rb ${{ matrix.podspec }} --platforms=${{ matrix.target }} \
8585
${{ matrix.build-env.tests }}
8686
87-
spm-package-resolved:
88-
env:
89-
FIREBASECI_USE_LATEST_GOOGLEAPPMEASUREMENT: 1
90-
runs-on: macos-14
91-
outputs:
92-
cache_key: ${{ steps.generate_cache_key.outputs.cache_key }}
93-
steps:
94-
- uses: actions/checkout@v4
95-
- name: Generate Swift Package.resolved
96-
id: swift_package_resolve
97-
run: |
98-
swift package resolve
99-
- name: Generate cache key
100-
id: generate_cache_key
101-
run: |
102-
cache_key="${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}"
103-
echo "cache_key=${cache_key}" >> "$GITHUB_OUTPUT"
104-
- uses: actions/cache/save@v4
105-
id: cache
106-
with:
107-
path: .build
108-
key: ${{ steps.generate_cache_key.outputs.cache_key }}
87+
# spm-package-resolved:
88+
# env:
89+
# FIREBASECI_USE_LATEST_GOOGLEAPPMEASUREMENT: 1
90+
# runs-on: macos-14
91+
# outputs:
92+
# cache_key: ${{ steps.generate_cache_key.outputs.cache_key }}
93+
# steps:
94+
# - uses: actions/checkout@v4
95+
# - name: Generate Swift Package.resolved
96+
# id: swift_package_resolve
97+
# run: |
98+
# swift package resolve
99+
# - name: Generate cache key
100+
# id: generate_cache_key
101+
# run: |
102+
# cache_key="${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}"
103+
# echo "cache_key=${cache_key}" >> "$GITHUB_OUTPUT"
104+
# - uses: actions/cache/save@v4
105+
# id: cache
106+
# with:
107+
# path: .build
108+
# key: ${{ steps.generate_cache_key.outputs.cache_key }}
109109

110-
spm:
111-
# Don't run on private repo unless it is a PR.
112-
if: (github.repository == 'Firebase/firebase-ios-sdk' && github.event_name == 'schedule') || github.event_name == 'pull_request'
113-
needs: [spm-package-resolved]
114-
strategy:
115-
matrix:
116-
include:
117-
- os: macos-13
118-
xcode: Xcode_15.2
119-
target: iOS
120-
test: spm
121-
- os: macos-14
122-
xcode: Xcode_15.4
123-
target: iOS
124-
test: spm
125-
- os: macos-15
126-
xcode: Xcode_16.1
127-
target: iOS
128-
test: spm
129-
- os: macos-15
130-
xcode: Xcode_16.1
131-
target: tvOS
132-
test: spm
133-
- os: macos-15
134-
xcode: Xcode_16.1
135-
target: macOS
136-
test: spm
137-
- os: macos-15
138-
xcode: Xcode_16.1
139-
target: watchOS
140-
test: spmbuildonly
141-
- os: macos-15
142-
xcode: Xcode_16.1
143-
target: catalyst
144-
test: spm
145-
- os: macos-15
146-
xcode: Xcode_16.1
147-
target: visionOS
148-
test: spm
149-
runs-on: ${{ matrix.os }}
150-
steps:
151-
- uses: actions/checkout@v4
152-
- uses: actions/cache/restore@v4
153-
with:
154-
path: .build
155-
key: ${{needs.spm-package-resolved.outputs.cache_key}}
156-
- name: Xcode
157-
run: sudo xcode-select -s /Applications/${{ matrix.xcode }}.app/Contents/Developer
158-
- name: Initialize xcodebuild
159-
run: scripts/setup_spm_tests.sh
160-
- name: Unit Tests
161-
run: scripts/third_party/travis/retry.sh ./scripts/build.sh RemoteConfigUnit ${{ matrix.target }} spm
162-
- name: Fake Console tests
163-
run: scripts/third_party/travis/retry.sh ./scripts/build.sh RemoteConfigFakeConsole ${{ matrix.target }} ${{ matrix.test }}
110+
# spm:
111+
# # Don't run on private repo unless it is a PR.
112+
# if: (github.repository == 'Firebase/firebase-ios-sdk' && github.event_name == 'schedule') || github.event_name == 'pull_request'
113+
# needs: [spm-package-resolved]
114+
# strategy:
115+
# matrix:
116+
# include:
117+
# - os: macos-13
118+
# xcode: Xcode_15.2
119+
# target: iOS
120+
# test: spm
121+
# - os: macos-14
122+
# xcode: Xcode_15.4
123+
# target: iOS
124+
# test: spm
125+
# - os: macos-15
126+
# xcode: Xcode_16.1
127+
# target: iOS
128+
# test: spm
129+
# - os: macos-15
130+
# xcode: Xcode_16.1
131+
# target: tvOS
132+
# test: spm
133+
# - os: macos-15
134+
# xcode: Xcode_16.1
135+
# target: macOS
136+
# test: spm
137+
# - os: macos-15
138+
# xcode: Xcode_16.1
139+
# target: watchOS
140+
# test: spmbuildonly
141+
# - os: macos-15
142+
# xcode: Xcode_16.1
143+
# target: catalyst
144+
# test: spm
145+
# - os: macos-15
146+
# xcode: Xcode_16.1
147+
# target: visionOS
148+
# test: spm
149+
# runs-on: ${{ matrix.os }}
150+
# steps:
151+
# - uses: actions/checkout@v4
152+
# - uses: actions/cache/restore@v4
153+
# with:
154+
# path: .build
155+
# key: ${{needs.spm-package-resolved.outputs.cache_key}}
156+
# - name: Xcode
157+
# run: sudo xcode-select -s /Applications/${{ matrix.xcode }}.app/Contents/Developer
158+
# - name: Initialize xcodebuild
159+
# run: scripts/setup_spm_tests.sh
160+
# - name: Unit Tests
161+
# run: scripts/third_party/travis/retry.sh ./scripts/build.sh RemoteConfigUnit ${{ matrix.target }} spm
162+
# - name: Fake Console tests
163+
# run: scripts/third_party/travis/retry.sh ./scripts/build.sh RemoteConfigFakeConsole ${{ matrix.target }} ${{ matrix.test }}
164164

165165
catalyst:
166166
# Don't run on private repo unless it is a PR.

FirebaseRemoteConfig.podspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ app update.
5454
s.dependency 'FirebaseABTesting', '~> 11.0'
5555
s.dependency 'FirebaseSharedSwift', '~> 11.0'
5656
s.dependency 'FirebaseCore', '~> 11.7.0'
57+
s.dependency 'FirebaseCoreExtension', '~> 11.7.0'
5758
s.dependency 'FirebaseInstallations', '~> 11.0'
5859
s.dependency 'GoogleUtilities/Environment', '~> 8.0'
5960
s.dependency 'GoogleUtilities/NSData+zlib', '~> 8.0'

FirebaseRemoteConfig/Sources/FIRConfigValue.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ @implementation FIRRemoteConfigValue {
2626
}
2727

2828
/// Designated initializer
29-
- (instancetype)initWithData:(NSData *)data source:(FIRRemoteConfigSource)source {
29+
- (instancetype)initWithData:(nullable NSData *)data source:(FIRRemoteConfigSource)source {
3030
self = [super init];
3131
if (self) {
3232
_data = [data copy];

FirebaseRemoteConfig/Sources/FIRRemoteConfig.m

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#import "FirebaseRemoteConfig/Sources/Private/RCNConfigSettings.h"
2525
#import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h"
2626
#import "FirebaseRemoteConfig/Sources/RCNConfigContent.h"
27-
#import "FirebaseRemoteConfig/Sources/RCNConfigDBManager.h"
2827
#import "FirebaseRemoteConfig/Sources/RCNConfigExperiment.h"
2928
#import "FirebaseRemoteConfig/Sources/RCNConfigRealtime.h"
3029
#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h"
@@ -142,6 +141,7 @@ - (instancetype)initWithAppName:(NSString *)appName
142141
namespace:(NSString *)FIRNamespace
143142
DBManager:(RCNConfigDBManager *)DBManager
144143
configContent:(RCNConfigContent *)configContent
144+
userDefaults:(nullable NSUserDefaults *)userDefaults
145145
analytics:(nullable id<FIRAnalyticsInterop>)analytics {
146146
self = [super init];
147147
if (self) {
@@ -155,7 +155,8 @@ - (instancetype)initWithAppName:(NSString *)appName
155155
_settings = [[RCNConfigSettings alloc] initWithDatabaseManager:_DBManager
156156
namespace:_FIRNamespace
157157
firebaseAppName:appName
158-
googleAppID:options.googleAppID];
158+
googleAppID:options.googleAppID
159+
userDefaults:userDefaults];
159160

160161
FIRExperimentController *experimentController = [FIRExperimentController sharedInstance];
161162
_configExperiment = [[RCNConfigExperiment alloc] initWithDBManager:_DBManager
@@ -193,6 +194,21 @@ - (instancetype)initWithAppName:(NSString *)appName
193194
return self;
194195
}
195196

197+
- (instancetype)initWithAppName:(NSString *)appName
198+
FIROptions:(FIROptions *)options
199+
namespace:(NSString *)FIRNamespace
200+
DBManager:(RCNConfigDBManager *)DBManager
201+
configContent:(RCNConfigContent *)configContent
202+
analytics:(nullable id<FIRAnalyticsInterop>)analytics {
203+
return [self initWithAppName:appName
204+
FIROptions:options
205+
namespace:FIRNamespace
206+
DBManager:DBManager
207+
configContent:configContent
208+
userDefaults:nil
209+
analytics:analytics];
210+
}
211+
196212
// Initialize with default config settings.
197213
- (void)setDefaultConfigSettings {
198214
// Set the default config settings.

FirebaseRemoteConfig/Sources/FIRRemoteConfigComponent.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
#import "FirebaseCore/Extension/FirebaseCoreInternal.h"
2020
#import "FirebaseRemoteConfig/Sources/Private/FIRRemoteConfig_Private.h"
2121
#import "FirebaseRemoteConfig/Sources/RCNConfigContent.h"
22-
#import "FirebaseRemoteConfig/Sources/RCNConfigDBManager.h"
2322
#import "Interop/Analytics/Public/FIRAnalyticsInterop.h"
2423

24+
#import "FirebaseRemoteConfig/FirebaseRemoteConfig-Swift.h"
25+
2526
@implementation FIRRemoteConfigComponent
2627

2728
// Because Component now need to register two protocols (provider and interop), we need a way to

FirebaseRemoteConfig/Sources/Private/FIRRemoteConfig_Private.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ NS_ASSUME_NONNULL_BEGIN
7373
configContent:(RCNConfigContent *)configContent
7474
analytics:(nullable id<FIRAnalyticsInterop>)analytics;
7575

76+
- (instancetype)initWithAppName:(NSString *)appName
77+
FIROptions:(FIROptions *)options
78+
namespace:(NSString *)FIRNamespace
79+
DBManager:(RCNConfigDBManager *)DBManager
80+
configContent:(RCNConfigContent *)configContent
81+
userDefaults:(nullable NSUserDefaults *)userDefaults
82+
analytics:(nullable id<FIRAnalyticsInterop>)analytics;
83+
7684
/// Register RolloutsStateSubcriber to FIRRemoteConfig instance
7785
- (void)addRemoteConfigInteropSubscriber:(id<FIRRolloutsStateSubscriber> _Nonnull)subscriber;
7886

FirebaseRemoteConfig/Sources/Private/RCNConfigSettings.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
@class RCNConfigDBManager;
2222

2323
/// 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
24+
/// It also handles all metadata. This class is not thread safe and does not
2525
/// inherently allow for synchronized access. Callers are responsible for synchronization
2626
/// (currently using serial dispatch queues).
2727
@interface RCNConfigSettings : NSObject
@@ -108,14 +108,20 @@
108108
firebaseAppName:(NSString *)appName
109109
googleAppID:(NSString *)googleAppID;
110110

111+
- (instancetype)initWithDatabaseManager:(RCNConfigDBManager *)manager
112+
namespace:(NSString *)FIRNamespace
113+
firebaseAppName:(NSString *)appName
114+
googleAppID:(NSString *)googleAppID
115+
userDefaults:(NSUserDefaults *)userDefaults;
116+
111117
/// Returns a fetch request with the latest device and config change.
112118
/// Whenever user issues a fetch api call, collect the latest request.
113119
/// @param userProperties User properties to set to config request.
114120
/// @return Config fetch request string
115121
- (NSString *)nextRequestWithUserProperties:(NSDictionary *)userProperties;
116122

117123
/// Returns metadata from metadata table.
118-
- (NSDictionary *)loadConfigFromMetadataTable;
124+
- (void)loadConfigFromMetadataTable;
119125

120126
/// Updates the metadata table with the current fetch status.
121127
/// @param fetchSuccess True if fetch was successful.

FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ NS_SWIFT_NAME(RemoteConfigValue)
151151
@property(nonatomic, readonly, nullable) id JSONValue NS_SWIFT_NAME(jsonValue);
152152
/// Identifies the source of the fetched value.
153153
@property(nonatomic, readonly) FIRRemoteConfigSource source;
154+
155+
/// TODO: internal API for temporary bridging
156+
/// Designated initializer.
157+
- (instancetype _Nonnull)initWithData:(nullable NSData *)data
158+
source:(FIRRemoteConfigSource)source NS_DESIGNATED_INITIALIZER;
154159
@end
155160

156161
#pragma mark - FIRRemoteConfigSettings

FirebaseRemoteConfig/Sources/RCNConfigContent.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@
1616

1717
#import <Foundation/Foundation.h>
1818

19+
#import "FirebaseRemoteConfig/FirebaseRemoteConfig-Swift.h"
1920
#import "FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h"
2021

21-
typedef NS_ENUM(NSInteger, RCNDBSource) {
22-
RCNDBSourceActive,
23-
RCNDBSourceDefault,
24-
RCNDBSourceFetched,
25-
};
26-
2722
@class RCNConfigDBManager;
2823

2924
/// This class handles all the config content that is fetched from the server, cached in local

FirebaseRemoteConfig/Sources/RCNConfigContent.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#import "FirebaseRemoteConfig/Sources/Private/FIRRemoteConfig_Private.h"
2222
#import "FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h"
2323
#import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h"
24-
#import "FirebaseRemoteConfig/Sources/RCNConfigDBManager.h"
2524
#import "FirebaseRemoteConfig/Sources/RCNConfigDefines.h"
2625
#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h"
2726

0 commit comments

Comments
 (0)