-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task/Issue URL: https://app.asana.com/0/0/1206046777189407/f Description: This change add support for Sync feature in Privacy Configuration, together with 4 subfeatures defining availability of various parts of Sync experience. DDGSyncing gets a read-only feature flag variable as well as a publisher. PrivacyConfigurationManager is now a Sync dependency, and DDGSync takes care internally of listening to Privacy Config changes and updating feature flags as needed. Feature flag responsible for actual data syncing is handled internally in DDGSync by cancelling all pending sync operations and disabling adding new operations. Other feature flags should be handled by client apps.
- Loading branch information
Showing
11 changed files
with
244 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// | ||
// SyncFeatureFlags.swift | ||
// | ||
// Copyright © 2023 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import BrowserServicesKit | ||
import Foundation | ||
|
||
/** | ||
* This enum describes available Sync features. | ||
*/ | ||
public struct SyncFeatureFlags: OptionSet { | ||
public let rawValue: Int | ||
|
||
public init(rawValue: Int) { | ||
self.rawValue = rawValue | ||
} | ||
|
||
// MARK: - Individual Flags | ||
|
||
/// Sync UI is visible | ||
public static let userInterface = SyncFeatureFlags(rawValue: 1 << 0) | ||
|
||
/// Data syncing is available | ||
public static let dataSyncing = SyncFeatureFlags(rawValue: 1 << 1) | ||
|
||
/// Logging in to existing accounts is available (connect flows + account recovery) | ||
public static let accountLogin = SyncFeatureFlags(rawValue: 1 << 2) | ||
|
||
/// Creating new accounts is available | ||
public static let accountCreation = SyncFeatureFlags(rawValue: 1 << 4) | ||
|
||
// MARK: - Helper Flags | ||
|
||
public static let connectFlows = SyncFeatureFlags.accountLogin | ||
public static let accountRecovery = SyncFeatureFlags.accountLogin | ||
|
||
// MARK: - Support levels | ||
|
||
/// Used when all feature flags are disabled | ||
public static let unavailable: SyncFeatureFlags = [] | ||
|
||
/// Level 0 feature flag as defined in Privacy Configuration | ||
public static let level0ShowSync: SyncFeatureFlags = [.userInterface] | ||
/// Level 1 feature flag as defined in Privacy Configuration | ||
public static let level1AllowDataSyncing: SyncFeatureFlags = [.userInterface, .dataSyncing] | ||
/// Level 2 feature flag as defined in Privacy Configuration | ||
public static let level2AllowSetupFlows: SyncFeatureFlags = [.userInterface, .dataSyncing, .accountLogin] | ||
/// Level 3 feature flag as defined in Privacy Configuration | ||
public static let level3AllowCreateAccount: SyncFeatureFlags = [.userInterface, .dataSyncing, .accountLogin, .accountCreation] | ||
|
||
/// Alias for the state when all features are available | ||
public static let all: SyncFeatureFlags = .level3AllowCreateAccount | ||
|
||
// MARK: - | ||
|
||
init(privacyConfig: PrivacyConfiguration) { | ||
guard privacyConfig.isEnabled(featureKey: .sync) else { | ||
self = .unavailable | ||
return | ||
} | ||
if !privacyConfig.isSubfeatureEnabled(SyncSubfeature.level0ShowSync) { | ||
self = .unavailable | ||
} else if !privacyConfig.isSubfeatureEnabled(SyncSubfeature.level1AllowDataSyncing) { | ||
self = .level0ShowSync | ||
} else if !privacyConfig.isSubfeatureEnabled(SyncSubfeature.level2AllowSetupFlows) { | ||
self = .level1AllowDataSyncing | ||
} else if !privacyConfig.isSubfeatureEnabled(SyncSubfeature.level3AllowCreateAccount) { | ||
self = .level2AllowSetupFlows | ||
} else { | ||
self = .level3AllowCreateAccount | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.