Skip to content

Commit 4224ae0

Browse files
committed
Review + extra cleanup
1 parent 5447cd5 commit 4224ae0

File tree

2 files changed

+16
-40
lines changed

2 files changed

+16
-40
lines changed

FirebaseRemoteConfig/SwiftNew/ConfigSettings.swift

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ let RCNHTTPDefaultConnectionTimeout: TimeInterval = 60
4242
/// Device conditions since last successful fetch from the backend. Device conditions including
4343
/// app version, iOS version, device locale, language, GMP project ID and Game project ID.
4444
/// Used for determining whether to throttle.
45-
private var _deviceContext: [String: Any] = [:]
45+
@objc public private(set) var deviceContext: [String: String] = [:]
4646

4747
/// Custom variables (aka App context digest). This is the pending custom variables
4848
/// request before fetching.
49-
private var _customVariables: [String: Any] = [:]
49+
private var _customVariables: [String: Sendable] = [:]
5050

5151
/// Last fetch status.
52-
private var _lastFetchStatus: RemoteConfigFetchStatus = .noFetchYet
52+
@objc public var lastFetchStatus: RemoteConfigFetchStatus = .noFetchYet
5353

5454
/// Last fetch Error.
5555
private var _lastFetchError: RemoteConfigError
@@ -85,12 +85,6 @@ let RCNHTTPDefaultConnectionTimeout: TimeInterval = 60
8585
/// Bundle Identifier
8686
public let bundleIdentifier: String
8787

88-
/// Last fetch status.
89-
@objc public var lastFetchStatus: RemoteConfigFetchStatus {
90-
get { _lastFetchStatus }
91-
set { _lastFetchStatus = newValue }
92-
}
93-
9488
/// Last fetched template version.
9589
@objc public var lastFetchedTemplateVersion: String
9690

@@ -140,7 +134,7 @@ let RCNHTTPDefaultConnectionTimeout: TimeInterval = 60
140134
)
141135
}
142136
_minimumFetchInterval = ConfigConstants.defaultMinimumFetchInterval
143-
_deviceContext = [:]
137+
deviceContext = [:]
144138
_customVariables = [:]
145139
_successFetchTimes = []
146140
_failureFetchTimes = []
@@ -228,9 +222,9 @@ let RCNHTTPDefaultConnectionTimeout: TimeInterval = 60
228222
// TODO: Remove (all metadata in general) once ready to
229223
// migrate to user defaults completely.
230224
if let deviceContext = metadata[RCNKeyDeviceContext] as? [String: String] {
231-
self._deviceContext = deviceContext
225+
self.deviceContext = deviceContext
232226
}
233-
if let customVariables = metadata[RCNKeyAppContext] as? [String: Any] {
227+
if let customVariables = metadata[RCNKeyAppContext] as? [String: Sendable] {
234228
self._customVariables = customVariables
235229
}
236230
if let successFetchTimes = metadata[RCNKeySuccessFetchTime] as? [TimeInterval] {
@@ -240,7 +234,7 @@ let RCNHTTPDefaultConnectionTimeout: TimeInterval = 60
240234
self._failureFetchTimes = failureFetchTimes
241235
}
242236
if let lastFetchStatus = metadata[RCNKeyLastFetchStatus] as? RemoteConfigFetchStatus {
243-
self._lastFetchStatus = lastFetchStatus
237+
self.lastFetchStatus = lastFetchStatus
244238
}
245239
if let lastFetchError = metadata[RCNKeyLastFetchError] as? RemoteConfigError {
246240
self._lastFetchError = lastFetchError
@@ -260,7 +254,7 @@ let RCNHTTPDefaultConnectionTimeout: TimeInterval = 60
260254
/// period that we wait until fetching again. Any subsequent fetch requests
261255
/// will be checked and allowed only if past this throttle end time.
262256
@objc public func updateExponentialBackoffTime() {
263-
if _lastFetchStatus == .success {
257+
if lastFetchStatus == .success {
264258
RCLog.debug("I-RCN000057", "Throttling: Entering exponential backoff mode.")
265259
exponentialBackoffRetryInterval = Double(kRCNExponentialBackoffMinimumInterval)
266260
} else {
@@ -331,12 +325,12 @@ let RCNHTTPDefaultConnectionTimeout: TimeInterval = 60
331325
templateVersion: String?) {
332326
RCLog.debug("I-RCN000056", "Updating metadata with fetch result.")
333327
updateFetchTime(success: fetchSuccess)
334-
_lastFetchStatus = fetchSuccess ? .success : .failure
328+
lastFetchStatus = fetchSuccess ? .success : .failure
335329
_lastFetchError = RemoteConfigError(fetchSuccess ? .unknown : .internalError)
336330
if fetchSuccess, let templateVersion {
337331
updateLastFetchTimeInterval(Date().timeIntervalSince1970)
338332
// Note: We expect the googleAppID to always be available.
339-
_deviceContext = Device.remoteConfigDeviceContext(with: _googleAppID)
333+
deviceContext = Device.remoteConfigDeviceContext(with: _googleAppID)
340334
lastFetchedTemplateVersion = templateVersion
341335
_userDefaultsManager.lastFetchedTemplateVersion = templateVersion
342336
}
@@ -360,7 +354,7 @@ let RCNHTTPDefaultConnectionTimeout: TimeInterval = 60
360354
RCLog.error("I-RCN000028", "Invalid custom variables to be serialized.")
361355
return
362356
}
363-
guard JSONSerialization.isValidJSONObject(_deviceContext) else {
357+
guard JSONSerialization.isValidJSONObject(deviceContext) else {
364358
RCLog.error("I-RCN000029", "Invalid device context to be serialized.")
365359
return
366360
}
@@ -375,7 +369,7 @@ let RCNHTTPDefaultConnectionTimeout: TimeInterval = 60
375369

376370
let serializedAppContext = try? JSONSerialization.data(withJSONObject: _customVariables,
377371
options: [.prettyPrinted])
378-
let serializedDeviceContext = try? JSONSerialization.data(withJSONObject: _deviceContext,
372+
let serializedDeviceContext = try? JSONSerialization.data(withJSONObject: deviceContext,
379373
options: [.prettyPrinted])
380374
// The digestPerNamespace is not used and only meant for backwards DB compatibility.
381375
let serializedDigestPerNamespace = try? JSONSerialization.data(withJSONObject: [:],
@@ -402,7 +396,7 @@ let RCNHTTPDefaultConnectionTimeout: TimeInterval = 60
402396
RCNKeyAppContext: serializedAppContext,
403397
RCNKeySuccessFetchTime: serializedSuccessTime,
404398
RCNKeyFailureFetchTime: serializedFailureTime,
405-
RCNKeyLastFetchStatus: _lastFetchStatus.rawValue,
399+
RCNKeyLastFetchStatus: lastFetchStatus.rawValue,
406400
RCNKeyLastFetchError: _lastFetchError.errorCode,
407401
RCNKeyLastApplyTime: _lastApplyTimeInterval,
408402
RCNKeyLastSetDefaultsTime: _lastSetDefaultsTimeInterval,
@@ -478,29 +472,11 @@ let RCNHTTPDefaultConnectionTimeout: TimeInterval = 60
478472
.updateMetadata(
479473
withOption: .fetchStatus,
480474
namespace: _FIRNamespace,
481-
values: [_lastFetchStatus, _lastFetchError]
475+
values: [lastFetchStatus, _lastFetchError]
482476
)
483477
}
484478
}
485479

486-
/// Device conditions since last successful fetch from the backend. Device conditions including
487-
/// app version, iOS version, device localte, language, GMP project ID and Game project ID. Used
488-
/// for determing whether to throttle.
489-
@objc public var deviceContext: [String: Any] {
490-
_deviceContext
491-
}
492-
493-
// TODO(ncooke3): Maybe just add a didSet
494-
/// Custom variable (aka App context digest). This is the pending custom variables request before
495-
/// fetching.
496-
open var customVariables: [String: Any] {
497-
get { _customVariables }
498-
set {
499-
_customVariables = newValue
500-
updateMetadataTable()
501-
}
502-
}
503-
504480
private var _minimumFetchInterval: TimeInterval
505481

506482
/// The time interval that config data stays fresh.

FirebaseRemoteConfig/SwiftNew/Device.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ import GoogleUtilities
208208
}
209209

210210
@objc public static func remoteConfigDeviceContext(with projectIdentifier: String?)
211-
-> [String: Any] {
212-
var deviceContext: [String: Any] = [:]
211+
-> [String: String] {
212+
var deviceContext: [String: String] = [:]
213213
deviceContext[RCNDeviceContextKeyVersion] = remoteConfigAppVersion()
214214
deviceContext[RCNDeviceContextKeyBuild] = remoteConfigAppBuildVersion()
215215
deviceContext[RCNDeviceContextKeyOSVersion] = GULAppEnvironmentUtil.systemVersion()

0 commit comments

Comments
 (0)