Skip to content

Commit

Permalink
Update to AutofillCredentialIdentityStoreManager for lazy vault initi…
Browse files Browse the repository at this point in the history
…alisation (#3763)

Task/Issue URL:
https://app.asana.com/0/414709148257752/1209045090157949/f
Tech Design URL:
CC:

**Description**:
Fixes an occasional crash in SyncCredentialsAdapter due to vault being
initialised unnecessarily early for
AutofillCredentialIdentityStoreManager in the app startup flow
  • Loading branch information
amddg44 authored Jan 8, 2025
1 parent 5591a5a commit b9a6688
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
private lazy var authenticator = UserAuthenticator(reason: UserText.credentialProviderListAuthenticationReason,
cancelTitle: UserText.credentialProviderListAuthenticationCancelButton)

private lazy var credentialIdentityStoreManager: AutofillCredentialIdentityStoreManaging = AutofillCredentialIdentityStoreManager(credentialStore: ASCredentialIdentityStore.shared,
vault: secureVault,
tld: tld)
private lazy var credentialIdentityStoreManager: AutofillCredentialIdentityStoreManaging = AutofillCredentialIdentityStoreManager(
credentialStore: ASCredentialIdentityStore.shared,
vault: secureVault,
reporter: SecureVaultReporter(),
tld: tld)

private lazy var secureVault: (any AutofillSecureVault)? = {
if findKeychainItemsWithV4() {
Expand Down
3 changes: 1 addition & 2 deletions Core/SyncCredentialsAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public final class SyncCredentialsAdapter {
secureVaultErrorReporter: secureVaultErrorReporter,
errorEvents: CredentialsCleanupErrorHandling()
)
credentialIdentityStoreManager = AutofillCredentialIdentityStoreManager(
vault: try? secureVaultFactory.makeVault(reporter: secureVaultErrorReporter), tld: tld)
credentialIdentityStoreManager = AutofillCredentialIdentityStoreManager(reporter: secureVaultErrorReporter, tld: tld)
}

public func cleanUpDatabaseAndUpdateSchedule(shouldEnable: Bool) {
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11865,7 +11865,7 @@
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 224.0.0;
version = 224.1.0;
};
};
9F8FE9472BAE50E50071E372 /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/DuckDuckGo/BrowserServicesKit",
"state" : {
"revision" : "bb43f0c2a489d7eed4b33baf2201f9b2b6512588",
"version" : "224.0.0"
"revision" : "14384f05a6e43842c4626e06736e2c4f5d758057",
"version" : "224.1.0"
}
},
{
Expand All @@ -59,8 +59,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/duckduckgo-autofill.git",
"state" : {
"revision" : "88982a3802ac504e2f1a118a73bfdf2d8f4a7735",
"version" : "16.0.0"
"revision" : "47c26dc32b94cdbcef3e6157497147917678c25c",
"version" : "16.1.0"
}
},
{
Expand Down
4 changes: 3 additions & 1 deletion DuckDuckGo/AutofillLoginListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ final class AutofillLoginListViewModel: ObservableObject {
return settings["monitorIntervalDays"] as? Int ?? 42
}()

private lazy var credentialIdentityStoreManager: AutofillCredentialIdentityStoreManaging = AutofillCredentialIdentityStoreManager(vault: secureVault, tld: tld)
private lazy var credentialIdentityStoreManager: AutofillCredentialIdentityStoreManaging = AutofillCredentialIdentityStoreManager(vault: secureVault,
reporter: SecureVaultReporter(),
tld: tld)

private lazy var syncPromoManager: SyncPromoManaging = SyncPromoManager(syncService: syncService)

Expand Down
10 changes: 3 additions & 7 deletions DuckDuckGo/AutofillUsageMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ import BrowserServicesKit

final class AutofillUsageMonitor {

private lazy var credentialIdentityStoreManager: AutofillCredentialIdentityStoreManager? = {
guard let vault = try? AutofillSecureVaultFactory.makeVault(reporter: SecureVaultReporter()) else {
return nil
}

return AutofillCredentialIdentityStoreManager(vault: vault,
private lazy var credentialIdentityStoreManager: AutofillCredentialIdentityStoreManager = {
return AutofillCredentialIdentityStoreManager(reporter: SecureVaultReporter(),
tld: AppDependencyProvider.shared.storageCache.tld)
}()

Expand All @@ -43,7 +39,7 @@ final class AutofillUsageMonitor {
if state.isEnabled {
if self?.autofillExtensionEnabled == nil {
Task {
await self?.credentialIdentityStoreManager?.populateCredentialStore()
await self?.credentialIdentityStoreManager.populateCredentialStore()
}
}
self?.autofillExtensionEnabled = true
Expand Down
12 changes: 4 additions & 8 deletions DuckDuckGo/TabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,8 @@ class TabViewController: UIViewController {
return manager
}()

private lazy var credentialIdentityStoreManager: AutofillCredentialIdentityStoreManager? = {
guard let vault = try? AutofillSecureVaultFactory.makeVault(reporter: SecureVaultReporter()) else {
return nil
}

return AutofillCredentialIdentityStoreManager(vault: vault,
private lazy var credentialIdentityStoreManager: AutofillCredentialIdentityStoreManager = {
return AutofillCredentialIdentityStoreManager(reporter: SecureVaultReporter(),
tld: AppDependencyProvider.shared.storageCache.tld)
}()

Expand Down Expand Up @@ -2851,7 +2847,7 @@ extension TabViewController: SecureVaultManagerDelegate {

guard let domain = account?.domain else { return }
Task {
await self?.credentialIdentityStoreManager?.updateCredentialStore(for: domain)
await self?.credentialIdentityStoreManager.updateCredentialStore(for: domain)
}
} completionHandler: { account in
if account != nil {
Expand Down Expand Up @@ -3049,7 +3045,7 @@ extension TabViewController: SaveLoginViewControllerDelegate {

guard let domain = newCredential.account.domain else { return }
Task {
await credentialIdentityStoreManager?.updateCredentialStore(for: domain)
await credentialIdentityStoreManager.updateCredentialStore(for: domain)
}
}
} catch {
Expand Down

0 comments on commit b9a6688

Please sign in to comment.