Skip to content

Commit

Permalink
Handle Keystore events using EventMapping, fire Pixels via PixelKit
Browse files Browse the repository at this point in the history
  • Loading branch information
aataraxiaa committed Apr 17, 2024
1 parent 077969e commit b41ad3f
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion DuckDuckGo/SecureVault/SecureVaultReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,44 @@
// limitations under the License.
//

import Common
import Foundation
import BrowserServicesKit
import PixelKit
import SecureStorage

extension SecureStorageKeyStoreEvent: PixelKitEvent {
public var name: String {
switch self {
case .l1KeyMigration: return "m_mac_secure_vault_keystore_event_l1-key-migration"
case .l2KeyMigration: return "m_mac_secure_vault_keystore_event_l2-key-migration"
case .l2KeyPasswordMigration: return "m_mac_secure_vault_keystore_event_l2-key-password-migration"
}
}

public var parameters: [String: String]? {
nil
}
}

final class SecureVaultKeyStoreEventMapper: EventMapping<SecureStorageKeyStoreEvent> {
public init() {
super.init { event, _, _, _ in
PixelKit.fire(DebugEvent(event))
}
}

override init(mapping: @escaping EventMapping<SecureStorageKeyStoreEvent>.Mapping) {
fatalError("Use init()")
}
}

final class SecureVaultReporter: SecureVaultReporting {
static let shared = SecureVaultReporter()
private init() {}
private var keyStoreMapper: SecureVaultKeyStoreEventMapper
private init(keyStoreMapper: SecureVaultKeyStoreEventMapper = SecureVaultKeyStoreEventMapper()) {
self.keyStoreMapper = keyStoreMapper
}

func secureVaultError(_ error: SecureStorageError) {
guard NSApp.runType.requiresEnvironment else { return }
Expand All @@ -35,4 +66,7 @@ final class SecureVaultReporter: SecureVaultReporting {
}
}

func secureVaultKeyStoreEvent(_ event: SecureStorageKeyStoreEvent) {
keyStoreMapper.fire(event)
}
}

0 comments on commit b41ad3f

Please sign in to comment.