Skip to content

Commit

Permalink
Merge Hotfix 74.0.1-1 (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoy authored Aug 17, 2023
1 parent 3649259 commit 9a0eb00
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class LinkCleaner {

public func isURLExcluded(url: URL, feature: PrivacyFeature = .ampLinks) -> Bool {
guard let host = url.host else { return true }
guard url.scheme == "http" || url.scheme == "https" else { return true }

return !privacyConfig.isFeature(feature, enabledForDomain: host)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ public struct AppPrivacyConfiguration: PrivacyConfiguration {
}

private func isRolloutEnabled(subfeature: any PrivacySubfeature,
rollouts: [PrivacyConfigurationData.PrivacyFeature.Feature.Rollout],
rolloutSteps: [PrivacyConfigurationData.PrivacyFeature.Feature.RolloutStep],
randomizer: (Range<Double>) -> Double) -> Bool {
// Empty rollouts should be default enabled
guard !rollouts.isEmpty else { return true }
guard !rolloutSteps.isEmpty else { return true }

let defsPrefix = "config.\(subfeature.parent.rawValue).\(subfeature.rawValue)"
if userDefaults.bool(forKey: "\(defsPrefix).\(Constants.enabledKey)") {
return true
}

var willEnable = false
let rollouts = Array(Set(rollouts.filter({ $0.percent >= 0.0 && $0.percent <= 100.0 }))).sorted(by: { $0.percent < $1.percent })
let rollouts = Array(Set(rolloutSteps.filter({ $0.percent >= 0.0 && $0.percent <= 100.0 }))).sorted(by: { $0.percent < $1.percent })
if let rolloutSize = userDefaults.value(forKey: "\(defsPrefix).\(Constants.lastRolloutCountKey)") as? Int {
guard rolloutSize < rollouts.count else { return false }
// Sanity check as we need at least two values to compute the new probability
Expand Down Expand Up @@ -150,8 +150,8 @@ public struct AppPrivacyConfiguration: PrivacyConfiguration {
let satisfiesMinVersion = satisfiesMinVersion(subfeatureData?.minSupportedVersion, versionProvider: versionProvider)

// Handle Rollouts
if let rollouts = subfeatureData?.rollouts {
if !isRolloutEnabled(subfeature: subfeature, rollouts: rollouts, randomizer: randomizer) {
if let rollout = subfeatureData?.rollout {
if !isRolloutEnabled(subfeature: subfeature, rolloutSteps: rollout.steps, randomizer: randomizer) {
return false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public enum PrivacyFeature: String {
case windowsDownloadLink
case incontextSignup
case newTabContinueSetUp
case incrementalRolloutTest // Temporary feature flag for testing incremental rollouts
}

/// An abstraction to be implemented by any "subfeature" of a given `PrivacyConfiguration` feature.
Expand All @@ -62,3 +63,11 @@ public enum AutofillSubfeature: String, PrivacySubfeature {
case accessCredentialManagement
case autofillPasswordGeneration
}

public enum IncrementalRolloutTestSubfeature: String, PrivacySubfeature {
public var parent: PrivacyFeature {
.incrementalRolloutTest
}

case rollout
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,34 @@ public struct PrivacyConfigurationData {
enum CodingKeys: String {
case state
case minSupportedVersion
case rollouts
case rollout
}

public struct Rollout: Hashable {
public let percent: Double

enum CodingKeys: String {
case steps
}

public let steps: [RolloutStep]

public init(json: [String: Any]) {
var rolloutSteps = [RolloutStep]()
if let steps = json[CodingKeys.steps.rawValue] as? [[String: Any]] {
for step in steps {
rolloutSteps.append(RolloutStep(json: step))
}
}

self.steps = rolloutSteps
}
}

public struct RolloutStep: Hashable {
enum CodingKeys: String {
case percent
}

public let percent: Double

public init(json: [String: Any]) {
self.percent = json[CodingKeys.percent.rawValue] as? Double ?? 0
Expand All @@ -129,20 +148,21 @@ public struct PrivacyConfigurationData {

public let state: FeatureState
public let minSupportedVersion: FeatureSupportedVersion?
public let rollouts: [Rollout]?
public let rollout: Rollout?

public init?(json: [String: Any]) {
guard let state = json[CodingKeys.state.rawValue] as? String else {
return nil
}

self.state = state
self.minSupportedVersion = json[CodingKeys.minSupportedVersion.rawValue] as? String
var rollouts = [Rollout]()
if let rolloutArr = json[CodingKeys.rollouts.rawValue] as? [[String: Any]] {
for rollout in rolloutArr {
rollouts.append(Rollout(json: rollout))
}

if let rollout = json[CodingKeys.rollout.rawValue] as? [String: Any] {
self.rollout = Rollout(json: rollout)
} else {
self.rollout = nil
}
self.rollouts = rollouts
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,11 @@ class AppPrivacyConfigurationTests: XCTestCase {
"features": {
"credentialsSaving": {
"state": "enabled",
"rollouts": [{
"percent": 5.0
}]
"rollout": {
"steps": [{
"percent": 5.0
}]
}
}
},
}
Expand Down Expand Up @@ -612,33 +614,41 @@ class AppPrivacyConfigurationTests: XCTestCase {
"features": {
"credentialsSaving": {
"state": "enabled",
"rollouts": [{
"percent": 5.0
}, {
"percent": 15.0
}]
"rollout": {
"steps": [{
"percent": 5.0
}, {
"percent": 15.0
}]
}
},
"credentialsAutofill": {
"state": "enabled",
"rollouts": [{
"percent": 5.0
}, {
"percent": 15.0
}, {
"percent": 25.0
}]
"rollout": {
"steps": [{
"percent": 5.0
}, {
"percent": 15.0
}, {
"percent": 25.0
}]
}
},
"inlineIconCredentials": {
"state": "enabled",
"rollouts": []
"rollout": {
"steps": []
}
},
"accessCredentialManagement": {
"state": "diabled",
"rollouts": [{
"percent": 5.0
}, {
"percent": 15.0
}]
"state": "disabled",
"rollout": {
"steps": [{
"percent": 5.0
}, {
"percent": 15.0
}]
}
}
}
}
Expand Down

0 comments on commit 9a0eb00

Please sign in to comment.