Skip to content

Commit

Permalink
Merge tag '144.0.1-1'
Browse files Browse the repository at this point in the history
  • Loading branch information
amddg44 committed May 9, 2024
2 parents 8b8092d + 6ceabf1 commit 151737e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/duckduckgo-autofill.git",
"state" : {
"revision" : "6053999d6af384a716ab0ce7205dbab5d70ed1b3",
"version" : "11.0.1"
"revision" : "10aeff1ec7f533d1705233a9b14f9393a699b1c0",
"version" : "11.0.2"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let package = Package(
.library(name: "PixelKitTestingUtilities", targets: ["PixelKitTestingUtilities"]),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/duckduckgo-autofill.git", exact: "11.0.1"),
.package(url: "https://github.com/duckduckgo/duckduckgo-autofill.git", exact: "11.0.2"),
.package(url: "https://github.com/duckduckgo/GRDB.swift.git", exact: "2.3.0"),
.package(url: "https://github.com/duckduckgo/TrackerRadarKit", exact: "2.0.0"),
.package(url: "https://github.com/duckduckgo/sync_crypto", exact: "0.2.0"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import SecureStorage
public protocol AutofillDatabaseProvider: SecureStorageDatabaseProvider {

func accounts() throws -> [SecureVaultModels.WebsiteAccount]
func accountsCount() throws -> Int
func hasAccountFor(username: String?, domain: String?) throws -> Bool

@discardableResult
Expand Down Expand Up @@ -119,6 +120,13 @@ public final class DefaultAutofillDatabaseProvider: GRDBSecureStorageDatabasePro
}
}

public func accountsCount() throws -> Int {
let count = try db.read {
try SecureVaultModels.WebsiteAccount.fetchCount($0)
}
return count
}

public func hasAccountFor(username: String?, domain: String?) throws -> Bool {
let account = try db.read {
try SecureVaultModels.WebsiteAccount
Expand Down
29 changes: 29 additions & 0 deletions Sources/BrowserServicesKit/SecureVault/AutofillSecureVault.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public protocol AutofillSecureVault: SecureVault {
func resetL2Password(oldPassword: Data?, newPassword: Data) throws

func accounts() throws -> [SecureVaultModels.WebsiteAccount]
func accountsCount() throws -> Int
func accountsCountBucket() throws -> String
func accountsFor(domain: String) throws -> [SecureVaultModels.WebsiteAccount]
func accountsWithPartialMatchesFor(eTLDplus1: String) throws -> [SecureVaultModels.WebsiteAccount]
func hasAccountFor(username: String?, domain: String?) throws -> Bool
Expand Down Expand Up @@ -228,6 +230,33 @@ public class DefaultAutofillSecureVault<T: AutofillDatabaseProvider>: AutofillSe
}
}

public func accountsCount() throws -> Int {
lock.lock()
defer {
lock.unlock()
}

do {
return try self.providers.database.accountsCount()
} catch {
throw SecureStorageError.databaseError(cause: error)
}
}

public func accountsCountBucket() throws -> String {
let accountsCount = try accountsCount()

if accountsCount < 3 {
return "none"
} else if accountsCount < 11 {
return "some"
} else if accountsCount < 50 {
return "many"
} else {
return "lots"
}
}

public func accountsFor(domain: String) throws -> [SecureVaultModels.WebsiteAccount] {
lock.lock()
defer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ internal class MockAutofillDatabaseProvider: AutofillDatabaseProvider {
return _accounts
}

func accountsCount() throws -> Int {
return _accounts.count
}

func notes() throws -> [SecureVaultModels.Note] {
return _notes
}
Expand Down

0 comments on commit 151737e

Please sign in to comment.