Skip to content

Commit

Permalink
[rc-swift] RemoteConfig.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
paulb777 committed Jan 7, 2025
1 parent b79b6d8 commit 79914ad
Show file tree
Hide file tree
Showing 19 changed files with 1,039 additions and 1,221 deletions.
701 changes: 0 additions & 701 deletions FirebaseRemoteConfig/Sources/FIRRemoteConfig.m

Large diffs are not rendered by default.

Large diffs are not rendered by default.

72 changes: 0 additions & 72 deletions FirebaseRemoteConfig/Sources/RCNConfigConstants.h

This file was deleted.

37 changes: 0 additions & 37 deletions FirebaseRemoteConfig/Sources/RCNConfigDefines.h

This file was deleted.

5 changes: 5 additions & 0 deletions FirebaseRemoteConfig/SwiftNew/ConfigConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ enum ConfigConstants {

static let remoteConfigQueueLabel = "com.google.GoogleConfigService.FIRRemoteConfig"

/// Remote Config Error Domain.
static let RemoteConfigErrorDomain = "com.google.remoteconfig.ErrorDomain"
// Remote Config Realtime Error Domain
static let RemoteConfigUpdateErrorDomain = "com.google.remoteconfig.update.ErrorDomain"

// MARK: - Fetch Response Keys

static let fetchResponseKeyEntries = "entries"
Expand Down
4 changes: 2 additions & 2 deletions FirebaseRemoteConfig/SwiftNew/ConfigExperiment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import Foundation
private let experimentStartTimeDateFormatter: DateFormatter

/// Designated initializer;
@objc public init(DBManager: ConfigDBManager,
@objc public init(dbManager: ConfigDBManager,
experimentController controller: ExperimentController?) {
experimentPayloads = []
experimentMetadata = [:]
Expand All @@ -48,7 +48,7 @@ import Foundation
dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
return dateFormatter
}()
dbManager = DBManager
self.dbManager = dbManager
experimentController = controller
super.init()
loadExperimentFromTable()
Expand Down
26 changes: 13 additions & 13 deletions FirebaseRemoteConfig/SwiftNew/ConfigFetch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ extension URLSession: RCNConfigFetchSession {
@objc(RCNConfigFetch) public class ConfigFetch: NSObject {
private let content: ConfigContent

private let settings: ConfigSettings
let settings: ConfigSettings

private let analytics: (any FIRAnalyticsInterop)?

Expand Down Expand Up @@ -241,11 +241,11 @@ extension URLSession: RCNConfigFetchSession {
if strongSelf.settings.shouldThrottle() && !hasDeviceContextChanged {
// Must set lastFetchStatus before FailReason.
strongSelf.settings.lastFetchStatus = .throttled
strongSelf.settings.lastFetchError = .throttled
strongSelf.settings.lastFetchError = RemoteConfigError.throttled
let throttledEndTime = strongSelf.settings.exponentialBackoffThrottleEndTime

let error = NSError(
domain: RemoteConfigErrorDomain,
domain: ConfigConstants.RemoteConfigErrorDomain,
code: RemoteConfigError.throttled.rawValue,
userInfo: [throttledEndTimeInSecondsKey: throttledEndTime]
)
Expand Down Expand Up @@ -291,11 +291,11 @@ extension URLSession: RCNConfigFetchSession {
if strongSelf.settings.shouldThrottle() && !hasDeviceContextChanged {
// Must set lastFetchStatus before FailReason.
strongSelf.settings.lastFetchStatus = .throttled
strongSelf.settings.lastFetchError = .throttled
strongSelf.settings.lastFetchError = RemoteConfigError.throttled
let throttledEndTime = strongSelf.settings.exponentialBackoffThrottleEndTime

let error = NSError(
domain: RemoteConfigErrorDomain,
domain: ConfigConstants.RemoteConfigErrorDomain,
code: RemoteConfigError.throttled.rawValue,
userInfo: [throttledEndTimeInSecondsKey: throttledEndTime]
)
Expand Down Expand Up @@ -339,7 +339,7 @@ extension URLSession: RCNConfigFetchSession {
on: completionHandler,
status: .failure,
error: NSError(
domain: RemoteConfigErrorDomain,
domain: ConfigConstants.RemoteConfigErrorDomain,
code: RemoteConfigError.internalError.rawValue,
userInfo: [NSLocalizedDescriptionKey: errorDescription]
)
Expand All @@ -366,7 +366,7 @@ extension URLSession: RCNConfigFetchSession {
on: completionHandler,
status: .failure,
error: NSError(
domain: RemoteConfigErrorDomain,
domain: ConfigConstants.RemoteConfigErrorDomain,
code: RemoteConfigError.internalError.rawValue,
userInfo: userInfo
)
Expand Down Expand Up @@ -400,7 +400,7 @@ extension URLSession: RCNConfigFetchSession {
on: completionHandler,
status: .failure,
error: NSError(
domain: RemoteConfigErrorDomain,
domain: ConfigConstants.RemoteConfigErrorDomain,
code: RemoteConfigError.internalError.rawValue,
userInfo: userInfo
)
Expand Down Expand Up @@ -502,7 +502,7 @@ extension URLSession: RCNConfigFetchSession {
let errorString = "Failed to compress the config request."
RCLog.warning("I-RCN000033", errorString)
let error = NSError(
domain: RemoteConfigErrorDomain,
domain: ConfigConstants.RemoteConfigErrorDomain,
code: RemoteConfigError.internalError.rawValue,
userInfo: [NSLocalizedDescriptionKey: errorString]
)
Expand Down Expand Up @@ -566,11 +566,11 @@ extension URLSession: RCNConfigFetchSession {
if strongSelf.settings.shouldThrottle() {
// Must set lastFetchStatus before FailReason.
strongSelf.settings.lastFetchStatus = .throttled
strongSelf.settings.lastFetchError = .throttled
strongSelf.settings.lastFetchError = RemoteConfigError.throttled
let throttledEndTime = strongSelf.settings.exponentialBackoffThrottleEndTime

let error = NSError(
domain: RemoteConfigErrorDomain,
domain: ConfigConstants.RemoteConfigErrorDomain,
code: RemoteConfigError.throttled.rawValue,
userInfo: [throttledEndTimeInSecondsKey: throttledEndTime]
)
Expand Down Expand Up @@ -600,7 +600,7 @@ extension URLSession: RCNConfigFetchSession {
status: .failure,
update: nil,
error: NSError(
domain: RemoteConfigErrorDomain,
domain: ConfigConstants.RemoteConfigErrorDomain,
code: RemoteConfigError.internalError.rawValue,
userInfo: userInfo
),
Expand Down Expand Up @@ -651,7 +651,7 @@ extension URLSession: RCNConfigFetchSession {
}
RCLog.error("I-RCN000044", errStr + ".")
let error = NSError(
domain: RemoteConfigErrorDomain,
domain: ConfigConstants.RemoteConfigErrorDomain,
code: RemoteConfigError.internalError.rawValue,
userInfo: [NSLocalizedDescriptionKey: errStr]
)
Expand Down
18 changes: 9 additions & 9 deletions FirebaseRemoteConfig/SwiftNew/ConfigRealtime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class ConfigRealtime: NSObject, URLSessionDataDelegate {
onHandler: completionHandler,
withStatus: .failure,
withError: NSError(
domain: RemoteConfigErrorDomain,
domain: ConfigConstants.RemoteConfigErrorDomain,
code: RemoteConfigError.internalError.rawValue,
userInfo: [NSLocalizedDescriptionKey: errorDescription]
)
Expand All @@ -236,7 +236,7 @@ class ConfigRealtime: NSObject, URLSessionDataDelegate {
self.reportCompletion(
onHandler: completionHandler,
withStatus: .failure,
withError: NSError(domain: RemoteConfigErrorDomain,
withError: NSError(domain: ConfigConstants.RemoteConfigErrorDomain,
code: RemoteConfigError.internalError.rawValue,
userInfo: userInfo)
)
Expand All @@ -248,7 +248,7 @@ class ConfigRealtime: NSObject, URLSessionDataDelegate {
self.isRequestInProgress = false
reportCompletion(onHandler: completionHandler,
withStatus: .failure,
withError: NSError(domain: RemoteConfigErrorDomain,
withError: NSError(domain: ConfigConstants.RemoteConfigErrorDomain,
code: RemoteConfigError.internalError.rawValue,
userInfo: [
NSLocalizedDescriptionKey: errorDescription,
Expand All @@ -273,7 +273,7 @@ class ConfigRealtime: NSObject, URLSessionDataDelegate {
self.reportCompletion(
onHandler: completionHandler,
withStatus: .failure,
withError: NSError(domain: RemoteConfigErrorDomain,
withError: NSError(domain: ConfigConstants.RemoteConfigErrorDomain,
code: RemoteConfigError.internalError.rawValue,
userInfo: userInfo)
)
Expand Down Expand Up @@ -341,7 +341,7 @@ class ConfigRealtime: NSObject, URLSessionDataDelegate {
realtimeLockQueue.async { [weak self] in
guard let self, !self.isInBackground else { return }
guard self.remainingRetryCount > 0 else {
let error = NSError(domain: RemoteConfigUpdateErrorDomain,
let error = NSError(domain: ConfigConstants.RemoteConfigUpdateErrorDomain,
code: RemoteConfigUpdateError.streamError.rawValue,
userInfo: [
NSLocalizedDescriptionKey: "Unable to connect to the server. Check your connection and try again.",
Expand Down Expand Up @@ -458,7 +458,7 @@ class ConfigRealtime: NSObject, URLSessionDataDelegate {
realtimeLockQueue.async { [weak self] in
guard let self else { return }
guard attempts > 0 else {
let error = NSError(domain: RemoteConfigUpdateErrorDomain,
let error = NSError(domain: ConfigConstants.RemoteConfigUpdateErrorDomain,
code: RemoteConfigUpdateError.notFetched.rawValue,
userInfo: [
NSLocalizedDescriptionKey: "Unable to fetch the latest version of the template.",
Expand All @@ -481,7 +481,7 @@ class ConfigRealtime: NSObject, URLSessionDataDelegate {
// If response data contains the API enablement link, return the entire
// message to the user in the form of a error.
if strData.contains(serverForbiddenStatusCode) {
let error = NSError(domain: RemoteConfigUpdateErrorDomain,
let error = NSError(domain: ConfigConstants.RemoteConfigUpdateErrorDomain,
code: RemoteConfigUpdateError.streamError.rawValue,
userInfo: [NSLocalizedDescriptionKey: strData])
RCLog.error("I-RCN000021", "Cannot establish connection. \(error)")
Expand Down Expand Up @@ -524,7 +524,7 @@ class ConfigRealtime: NSObject, URLSessionDataDelegate {
}
if isRealtimeDisabled {
pauseRealtimeStream()
let error = NSError(domain: RemoteConfigUpdateErrorDomain,
let error = NSError(domain: ConfigConstants.RemoteConfigUpdateErrorDomain,
code: RemoteConfigUpdateError.unavailable.rawValue,
userInfo: [
NSLocalizedDescriptionKey: "The server is temporarily unavailable. Try again in a few minutes.",
Expand Down Expand Up @@ -565,7 +565,7 @@ class ConfigRealtime: NSObject, URLSessionDataDelegate {
retryHTTPConnection()
} else {
let error = NSError(
domain: RemoteConfigUpdateErrorDomain,
domain: ConfigConstants.RemoteConfigUpdateErrorDomain,
code: RemoteConfigUpdateError.streamError.rawValue,
userInfo: [
NSLocalizedDescriptionKey:
Expand Down
14 changes: 7 additions & 7 deletions FirebaseRemoteConfig/SwiftNew/ConfigSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ let RCNHTTPDefaultConnectionTimeout: TimeInterval = 60
.currentRealtimeThrottlingRetryIntervalSeconds
realtimeRetryCount = _userDefaultsManager.realtimeRetryCount

_lastFetchError = RemoteConfigError(.unknown)
_lastFetchError = .unknown
exponentialBackoffRetryInterval = 0
_fetchTimeout = 0
exponentialBackoffThrottleEndTime = 0
Expand Down Expand Up @@ -326,10 +326,10 @@ let RCNHTTPDefaultConnectionTimeout: TimeInterval = 60
/// @param fetchSuccess True if fetch was successful.
@objc public func updateMetadata(withFetchSuccessStatus fetchSuccess: Bool,
templateVersion: String?) {
RCLog.debug("I-RCN000056", "Updating metadata with fetch result.")
RCLog.debug("I-RCN000056", "Updating metadata with fetch result: \(fetchSuccess).")
updateFetchTime(success: fetchSuccess)
lastFetchStatus = fetchSuccess ? .success : .failure
_lastFetchError = RemoteConfigError(fetchSuccess ? .unknown : .internalError)
_lastFetchError = fetchSuccess ? .unknown : .internalError
if fetchSuccess, let templateVersion {
updateLastFetchTimeInterval(Date().timeIntervalSince1970)
// Note: We expect the googleAppID to always be available.
Expand Down Expand Up @@ -400,7 +400,7 @@ let RCNHTTPDefaultConnectionTimeout: TimeInterval = 60
RCNKeySuccessFetchTime: serializedSuccessTime,
RCNKeyFailureFetchTime: serializedFailureTime,
RCNKeyLastFetchStatus: lastFetchStatus.rawValue,
RCNKeyLastFetchError: _lastFetchError.errorCode,
RCNKeyLastFetchError: _lastFetchError.rawValue,
RCNKeyLastApplyTime: _lastApplyTimeInterval,
RCNKeyLastSetDefaultsTime: _lastSetDefaultsTimeInterval,
]
Expand Down Expand Up @@ -466,10 +466,10 @@ let RCNHTTPDefaultConnectionTimeout: TimeInterval = 60
// MARK: - Getter/Setter

/// The reason that last fetch failed.
@objc public var lastFetchError: RemoteConfigError.Code {
get { _lastFetchError.code }
@objc public var lastFetchError: RemoteConfigError {
get { _lastFetchError }
set {
_lastFetchError = RemoteConfigError(newValue)
_lastFetchError = newValue
_DBManager
.updateMetadata(
withOption: .fetchStatus,
Expand Down
Loading

0 comments on commit 79914ad

Please sign in to comment.