Skip to content

Commit 314c701

Browse files
author
Firefox Sync Engineering
committed
Nightly auto-update (120.0.20231014050328)
1 parent 17de69a commit 314c701

File tree

14 files changed

+180
-40
lines changed

14 files changed

+180
-40
lines changed

Package.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// swift-tools-version:5.4
22
import PackageDescription
33

4-
let checksum = "2eb94b2393b6b8cae51c237dc055b8593fa7f7ce4d41949d3c9b9af07fd444ed"
5-
let version = "120.0.20231013050343"
6-
let url = "https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/project.application-services.v2.swift.120.20231013050343/artifacts/public/build/MozillaRustComponents.xcframework.zip"
4+
let checksum = "ab662923bad291baca19c355cbd02ec0739a98b25ee40d5a53b70bd4db50b317"
5+
let version = "120.0.20231014050328"
6+
let url = "https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/project.application-services.v2.swift.120.20231014050328/artifacts/public/build/MozillaRustComponents.xcframework.zip"
77

88
// Focus xcframework
9-
let focusChecksum = "084bd8be1c3579a40a4f771f26ae5ea96746d9052696e72b3660d7d942903d69"
10-
let focusUrl = "https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/project.application-services.v2.swift.120.20231013050343/artifacts/public/build/FocusRustComponents.xcframework.zip"
9+
let focusChecksum = "4612cbbf65c3e60858790ca26a7e136f49adce0482d55a200ec45990bedb575a"
10+
let focusUrl = "https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/project.application-services.v2.swift.120.20231014050328/artifacts/public/build/FocusRustComponents.xcframework.zip"
1111
let package = Package(
1212
name: "MozillaRustComponentsSwift",
1313
platforms: [.iOS(.v14)],

swift-source/all/Generated/Metrics/Metrics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension GleanMetrics {
2525
// Intentionally left private, no external user can instantiate a new global object.
2626
}
2727

28-
public static let info = BuildInfo(buildDate: DateComponents(calendar: Calendar.current, timeZone: TimeZone(abbreviation: "UTC"), year: 2023, month: 10, day: 13, hour: 5, minute: 31, second: 17))
28+
public static let info = BuildInfo(buildDate: DateComponents(calendar: Calendar.current, timeZone: TimeZone(abbreviation: "UTC"), year: 2023, month: 10, day: 14, hour: 5, minute: 26, second: 30))
2929
}
3030

3131
enum NimbusEvents {

swift-source/all/Generated/suggest.swift

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -566,15 +566,13 @@ public func FfiConverterTypeSuggestIngestionConstraints_lower(_ value: SuggestIn
566566

567567
public struct SuggestionQuery {
568568
public var `keyword`: String
569-
public var `includeSponsored`: Bool
570-
public var `includeNonSponsored`: Bool
569+
public var `providers`: [SuggestionProvider]
571570

572571
// Default memberwise initializers are never public by default, so we
573572
// declare one manually.
574-
public init(`keyword`: String, `includeSponsored`: Bool, `includeNonSponsored`: Bool) {
573+
public init(`keyword`: String, `providers`: [SuggestionProvider]) {
575574
self.`keyword` = `keyword`
576-
self.`includeSponsored` = `includeSponsored`
577-
self.`includeNonSponsored` = `includeNonSponsored`
575+
self.`providers` = `providers`
578576
}
579577
}
580578

@@ -584,19 +582,15 @@ extension SuggestionQuery: Equatable, Hashable {
584582
if lhs.`keyword` != rhs.`keyword` {
585583
return false
586584
}
587-
if lhs.`includeSponsored` != rhs.`includeSponsored` {
588-
return false
589-
}
590-
if lhs.`includeNonSponsored` != rhs.`includeNonSponsored` {
585+
if lhs.`providers` != rhs.`providers` {
591586
return false
592587
}
593588
return true
594589
}
595590

596591
public func hash(into hasher: inout Hasher) {
597592
hasher.combine(`keyword`)
598-
hasher.combine(`includeSponsored`)
599-
hasher.combine(`includeNonSponsored`)
593+
hasher.combine(`providers`)
600594
}
601595
}
602596

@@ -605,15 +599,13 @@ public struct FfiConverterTypeSuggestionQuery: FfiConverterRustBuffer {
605599
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SuggestionQuery {
606600
return try SuggestionQuery(
607601
`keyword`: FfiConverterString.read(from: &buf),
608-
`includeSponsored`: FfiConverterBool.read(from: &buf),
609-
`includeNonSponsored`: FfiConverterBool.read(from: &buf)
602+
`providers`: FfiConverterSequenceTypeSuggestionProvider.read(from: &buf)
610603
)
611604
}
612605

613606
public static func write(_ value: SuggestionQuery, into buf: inout [UInt8]) {
614607
FfiConverterString.write(value.`keyword`, into: &buf)
615-
FfiConverterBool.write(value.`includeSponsored`, into: &buf)
616-
FfiConverterBool.write(value.`includeNonSponsored`, into: &buf)
608+
FfiConverterSequenceTypeSuggestionProvider.write(value.`providers`, into: &buf)
617609
}
618610
}
619611

@@ -994,6 +986,28 @@ fileprivate struct FfiConverterSequenceTypeSuggestion: FfiConverterRustBuffer {
994986
}
995987
}
996988

989+
fileprivate struct FfiConverterSequenceTypeSuggestionProvider: FfiConverterRustBuffer {
990+
typealias SwiftType = [SuggestionProvider]
991+
992+
public static func write(_ value: [SuggestionProvider], into buf: inout [UInt8]) {
993+
let len = Int32(value.count)
994+
writeInt(&buf, len)
995+
for item in value {
996+
FfiConverterTypeSuggestionProvider.write(item, into: &buf)
997+
}
998+
}
999+
1000+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [SuggestionProvider] {
1001+
let len: Int32 = try readInt(&buf)
1002+
var seq = [SuggestionProvider]()
1003+
seq.reserveCapacity(Int(len))
1004+
for _ in 0 ..< len {
1005+
seq.append(try FfiConverterTypeSuggestionProvider.read(from: &buf))
1006+
}
1007+
return seq
1008+
}
1009+
}
1010+
9971011

9981012

9991013
public func `rawSuggestionUrlMatches`(`rawUrl`: String, `url`: String) -> Bool {

swift-source/all/Nimbus/FeatureHolder.swift

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ public typealias GetSdk = () -> FeaturesInterface?
1212
///
1313
/// There are methods useful for testing, and more advanced uses: these all start with `with`.
1414
///
15-
public class FeatureHolder<T> {
15+
public class FeatureHolder<T: FMLFeatureInterface> {
1616
private let lock = NSLock()
1717
private var cachedValue: T?
1818

1919
private var getSdk: GetSdk
2020
private let featureId: String
2121

22-
private var create: (Variables) -> T
22+
private var create: (Variables, UserDefaults?) -> T
2323

2424
public init(_ getSdk: @escaping () -> FeaturesInterface?,
2525
featureId: String,
26-
with create: @escaping (Variables) -> T)
26+
with create: @escaping (Variables, UserDefaults?) -> T)
2727
{
2828
self.getSdk = getSdk
2929
self.featureId = featureId
@@ -43,18 +43,22 @@ public class FeatureHolder<T> {
4343
return v
4444
}
4545
var variables: Variables = NilVariables.instance
46+
var defaults: UserDefaults?
4647
if let sdk = getSdk() {
4748
variables = sdk.getVariables(featureId: featureId, sendExposureEvent: false)
49+
defaults = sdk.userDefaults
4850
}
49-
let v = create(variables)
51+
let v = create(variables, defaults)
5052
cachedValue = v
5153
return v
5254
}
5355

5456
/// Send an exposure event for this feature. This should be done when the user is shown the feature, and may change
5557
/// their behavior because of it.
5658
public func recordExposure() {
57-
getSdk()?.recordExposureEvent(featureId: featureId, experimentSlug: nil)
59+
if !value().isModified() {
60+
getSdk()?.recordExposureEvent(featureId: featureId, experimentSlug: nil)
61+
}
5862
}
5963

6064
/// Send an exposure event for this feature, in the given experiment.
@@ -67,7 +71,9 @@ public class FeatureHolder<T> {
6771
///
6872
/// - Parameter slug the experiment identifier, likely derived from the {value}.
6973
public func recordExperimentExposure(slug: String) {
70-
getSdk()?.recordExposureEvent(featureId: featureId, experimentSlug: slug)
74+
if !value().isModified() {
75+
getSdk()?.recordExposureEvent(featureId: featureId, experimentSlug: slug)
76+
}
7177
}
7278

7379
/// Send a malformed feature event for this feature.
@@ -121,10 +127,33 @@ public class FeatureHolder<T> {
121127
/// This changes the mapping between a `Variables` and the feature configuration object.
122128
///
123129
/// This is most likely useful during testing and other generated code.
124-
public func with(initializer: @escaping (Variables) -> T) {
130+
public func with(initializer: @escaping (Variables, UserDefaults?) -> T) {
125131
lock.lock()
126132
defer { self.lock.unlock() }
127133
cachedValue = nil
128134
create = initializer
129135
}
130136
}
137+
138+
/// A bare-bones interface for the FML generated objects.
139+
public protocol FMLObjectInterface {}
140+
141+
/// A bare-bones interface for the FML generated features.
142+
///
143+
/// App developers should use the generated concrete classes, which
144+
/// implement this interface.
145+
///
146+
public protocol FMLFeatureInterface: FMLObjectInterface {
147+
/// A test if the feature configuration has been modified somehow, invalidating any experiment
148+
/// that uses it.
149+
///
150+
/// This may be `true` if a `pref-key` has been set in the feature manifest and the user has
151+
/// set that preference.
152+
func isModified() -> Bool
153+
}
154+
155+
public extension FMLFeatureInterface {
156+
func isModified() -> Bool {
157+
return false
158+
}
159+
}

swift-source/all/Nimbus/FeatureInterface.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import Foundation
77
///
88
/// This is intended to be standalone to allow for testing the Nimbus FML.
99
public protocol FeaturesInterface: AnyObject {
10+
var userDefaults: UserDefaults? { get }
11+
1012
/// Get the variables needed to configure the feature given by `featureId`.
1113
///
1214
/// - Parameters:
@@ -56,3 +58,9 @@ public protocol FeaturesInterface: AnyObject {
5658
/// is malformed, providing more detail to experiment owners of where to look for the problem.
5759
func recordMalformedConfiguration(featureId: String, with partId: String)
5860
}
61+
62+
public extension FeaturesInterface {
63+
var userDefaults: UserDefaults? {
64+
nil
65+
}
66+
}

swift-source/all/Nimbus/Nimbus.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import Foundation
66
import Glean
77

88
public class Nimbus: NimbusInterface {
9+
private let _userDefaults: UserDefaults?
10+
911
private let nimbusClient: NimbusClientProtocol
1012

1113
private let resourceBundles: [Bundle]
@@ -28,11 +30,13 @@ public class Nimbus: NimbusInterface {
2830

2931
init(nimbusClient: NimbusClientProtocol,
3032
resourceBundles: [Bundle],
33+
userDefaults: UserDefaults?,
3134
errorReporter: @escaping NimbusErrorReporter)
3235
{
3336
self.errorReporter = errorReporter
3437
self.nimbusClient = nimbusClient
3538
self.resourceBundles = resourceBundles
39+
_userDefaults = userDefaults
3640
NilVariables.instance.set(bundles: resourceBundles)
3741
}
3842
}
@@ -102,6 +106,10 @@ extension Nimbus: NimbusEventStore {
102106
}
103107

104108
extension Nimbus: FeaturesInterface {
109+
public var userDefaults: UserDefaults? {
110+
_userDefaults
111+
}
112+
105113
public func recordExposureEvent(featureId: String, experimentSlug: String? = nil) {
106114
if let experimentSlug = experimentSlug {
107115
recordExposureFromExperiment(featureId: featureId, experimentSlug: experimentSlug)

swift-source/all/Nimbus/NimbusBuilder.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public class NimbusBuilder {
132132
var resourceBundles: [Bundle] = [.main]
133133

134134
/**
135-
* The object generated from the `nimbus.fml.yaml` file and the nimbus-gradle-plugin.
135+
* The object generated from the `nimbus.fml.yaml` file.
136136
*/
137137
@discardableResult
138138
public func with(featureManifest: FeatureManifestInterface) -> NimbusBuilder {
@@ -142,6 +142,17 @@ public class NimbusBuilder {
142142

143143
var featureManifest: FeatureManifestInterface?
144144

145+
/**
146+
* Main user defaults for the app.
147+
*/
148+
@discardableResult
149+
public func with(userDefaults: UserDefaults) -> NimbusBuilder {
150+
self.userDefaults = userDefaults
151+
return self
152+
}
153+
154+
var userDefaults = UserDefaults.standard
155+
145156
/**
146157
* The command line arguments for the app. This is useful for QA, and can be safely left in the app in production.
147158
*/
@@ -240,6 +251,7 @@ public class NimbusBuilder {
240251
coenrollingFeatureIds: getCoenrollingFeatureIds(),
241252
dbPath: dbFilePath,
242253
resourceBundles: resourceBundles,
254+
userDefaults: userDefaults,
243255
errorReporter: errorReporter)
244256
}
245257

swift-source/all/Nimbus/NimbusCreate.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public extension Nimbus {
5555
dbPath: String,
5656
resourceBundles: [Bundle] = [Bundle.main],
5757
enabled: Bool = true,
58+
userDefaults: UserDefaults? = nil,
5859
errorReporter: @escaping NimbusErrorReporter = defaultErrorReporter
5960
) throws -> NimbusInterface {
6061
guard enabled else {
@@ -84,7 +85,12 @@ public extension Nimbus {
8485
metricsHandler: GleanMetricsHandler()
8586
)
8687

87-
return Nimbus(nimbusClient: nimbusClient, resourceBundles: resourceBundles, errorReporter: errorReporter)
88+
return Nimbus(
89+
nimbusClient: nimbusClient,
90+
resourceBundles: resourceBundles,
91+
userDefaults: userDefaults,
92+
errorReporter: errorReporter
93+
)
8894
}
8995

9096
static func buildExperimentContext(

swift-source/focus/Generated/Metrics/Metrics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension GleanMetrics {
2525
// Intentionally left private, no external user can instantiate a new global object.
2626
}
2727

28-
public static let info = BuildInfo(buildDate: DateComponents(calendar: Calendar.current, timeZone: TimeZone(abbreviation: "UTC"), year: 2023, month: 10, day: 13, hour: 5, minute: 31, second: 20))
28+
public static let info = BuildInfo(buildDate: DateComponents(calendar: Calendar.current, timeZone: TimeZone(abbreviation: "UTC"), year: 2023, month: 10, day: 14, hour: 5, minute: 26, second: 33))
2929
}
3030

3131
enum NimbusEvents {

0 commit comments

Comments
 (0)