-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Report Autofill failures #893
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ff9a4e8
Slight refactoring for re-use by autofill failure reports
amddg44 1098bed
New feature flag
amddg44 bccf001
Merge remote-tracking branch 'origin/main' into anya/autofill-report-…
amddg44 e0a6fb2
Update unit tests
amddg44 2a54954
Merge remote-tracking branch 'origin/main' into anya/autofill-report-…
amddg44 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,22 +21,37 @@ import Persistence | |
|
||
public typealias KeyValueStoringDictionaryRepresentable = KeyValueStoring & DictionaryRepresentable | ||
|
||
public struct ExpiryStorageConfiguration { | ||
|
||
var expiryDatesStorageKey: String | ||
var valueExpiryDateKey: String | ||
var valueDataKey: String | ||
|
||
public static let defaultConfig = ExpiryStorageConfiguration( | ||
expiryDatesStorageKey: "com.duckduckgo.UserDefaultExpiryStorage", | ||
valueExpiryDateKey: "com.duckduckgo.UserDefaultExpiryStorage.valueExpiryDate", | ||
valueDataKey: "com.duckduckgo.UserDefaultExpiryStorage.valueData" | ||
) | ||
|
||
public static let autofillConfig = ExpiryStorageConfiguration( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created Autofill specific storage keys so that broken site reports and autofill breakage reports are stored separately |
||
expiryDatesStorageKey: "com.duckduckgo.AutofillUserDefaultExpiryStorage", | ||
valueExpiryDateKey: "com.duckduckgo.AutofillUserDefaultExpiryStorage.valueExpiryDate", | ||
valueDataKey: "com.duckduckgo.AutofillUserDefaultExpiryStorage.valueData" | ||
) | ||
} | ||
|
||
/// A storage solution were each entry has an expiry date and a function for removing all expired entries is provided. | ||
/// Any persistency solution implementing `KeyValueStoringDictionaryRepresentable` can be used. | ||
public class ExpiryStorage { | ||
|
||
enum Keys: String { | ||
case expiryDatesStorage = "com.duckduckgo.UserDefaultExpiryStorage" | ||
case valueExpiryDate = "com.duckduckgo.UserDefaultExpiryStorage.valueExpiryDate" | ||
case valueData = "com.duckduckgo.UserDefaultExpiryStorage.valueData" | ||
} | ||
|
||
let localStorage: KeyValueStoringDictionaryRepresentable | ||
let config: ExpiryStorageConfiguration | ||
|
||
/// Default initialiser | ||
/// - Parameter keyValueStoring: An object managing the persistency of the key-value pairs that implements `KeyValueStoringDictionaryRepresentable` | ||
public init(keyValueStoring: KeyValueStoringDictionaryRepresentable) { | ||
public init(keyValueStoring: KeyValueStoringDictionaryRepresentable, configuration: ExpiryStorageConfiguration = .defaultConfig) { | ||
self.localStorage = keyValueStoring | ||
self.config = configuration | ||
} | ||
|
||
/// Store a value and the desired expiry date (or removes the value if nil is passed as the value) for the provided key | ||
|
@@ -46,11 +61,11 @@ public class ExpiryStorage { | |
/// - expiryDate: A date stored alongside the value, used by `removeExpiredItems(...)` for removing expired values. | ||
public func set(value: Any?, forKey key: String, expiryDate: Date) { | ||
|
||
let valueDic = [Keys.valueExpiryDate.rawValue: expiryDate, Keys.valueData.rawValue: value] | ||
let valueDic = [config.valueExpiryDateKey: expiryDate, config.valueDataKey: value] | ||
localStorage.set(valueDic, forKey: key) | ||
} | ||
|
||
/// - Returns: The stored value assiciated to the key, nil if not existent | ||
/// - Returns: The stored value associated to the key, nil if not existent | ||
public func value(forKey key: String) -> Any? { | ||
|
||
return entry(forKey: key)?.value | ||
|
@@ -59,8 +74,8 @@ public class ExpiryStorage { | |
/// - Returns: The tuple expiryDate+value associated to the key, nil if they don't exist | ||
public func entry(forKey key: String) -> (expiryDate: Date, value: Any)? { | ||
guard let valueDic = localStorage.object(forKey: key) as? [String: Any], | ||
let expiryDate = valueDic[Keys.valueExpiryDate.rawValue] as? Date, | ||
let value = valueDic[Keys.valueData.rawValue] | ||
let expiryDate = valueDic[config.valueExpiryDateKey] as? Date, | ||
let value = valueDic[config.valueDataKey] | ||
else { | ||
return nil | ||
} | ||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
daysToExpiry
here since it will dynamic for autofill reports depending on the privacy config defined value