mirror of
https://github.com/bitwarden/browser
synced 2025-12-22 19:23:52 +00:00
[PM-6404] Fully Integrate clearOn Events (#8134)
* Add New KeyDefinitionOption * Add New Services * Add WebStorageServiceProvider Tests * Update Error Message * Add `UserKeyDefinition` * Fix Deserialization Helpers * Fix KeyDefinition * Add `UserKeyDefinition` * Fix Deserialization Helpers * Fix KeyDefinition * Move `ClearEvent` * Cleanup * Fix Imports * Integrate onClear Events * Remove Accidental Addition * Fix Test * Add VaultTimeoutService Tests * Only Register When Current State is Null * Address Feedback
This commit is contained in:
@@ -93,6 +93,7 @@ import { KeyGenerationService } from "@bitwarden/common/platform/services/key-ge
|
||||
import { MemoryStorageService } from "@bitwarden/common/platform/services/memory-storage.service";
|
||||
import { MigrationBuilderService } from "@bitwarden/common/platform/services/migration-builder.service";
|
||||
import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner";
|
||||
import { StorageServiceProvider } from "@bitwarden/common/platform/services/storage-service.provider";
|
||||
import { SystemService } from "@bitwarden/common/platform/services/system.service";
|
||||
import { WebCryptoFunctionService } from "@bitwarden/common/platform/services/web-crypto-function.service";
|
||||
import {
|
||||
@@ -100,6 +101,7 @@ import {
|
||||
DerivedStateProvider,
|
||||
GlobalStateProvider,
|
||||
SingleUserStateProvider,
|
||||
StateEventRunnerService,
|
||||
StateProvider,
|
||||
} from "@bitwarden/common/platform/state";
|
||||
/* eslint-disable import/no-restricted-paths -- We need the implementation to inject, but generally these should not be accessed */
|
||||
@@ -107,6 +109,7 @@ import { DefaultActiveUserStateProvider } from "@bitwarden/common/platform/state
|
||||
import { DefaultGlobalStateProvider } from "@bitwarden/common/platform/state/implementations/default-global-state.provider";
|
||||
import { DefaultSingleUserStateProvider } from "@bitwarden/common/platform/state/implementations/default-single-user-state.provider";
|
||||
import { DefaultStateProvider } from "@bitwarden/common/platform/state/implementations/default-state.provider";
|
||||
import { StateEventRegistrarService } from "@bitwarden/common/platform/state/state-event-registrar.service";
|
||||
/* eslint-enable import/no-restricted-paths */
|
||||
import { AvatarUpdateService } from "@bitwarden/common/services/account/avatar-update.service";
|
||||
import { ApiService } from "@bitwarden/common/services/api.service";
|
||||
@@ -299,6 +302,7 @@ export default class MainBackground {
|
||||
organizationVaultExportService: OrganizationVaultExportServiceAbstraction;
|
||||
vaultSettingsService: VaultSettingsServiceAbstraction;
|
||||
biometricStateService: BiometricStateService;
|
||||
stateEventRunnerService: StateEventRunnerService;
|
||||
ssoLoginService: SsoLoginServiceAbstraction;
|
||||
|
||||
// Passed to the popup for Safari to workaround issues with theming, downloading, etc.
|
||||
@@ -366,10 +370,24 @@ export default class MainBackground {
|
||||
this.keyGenerationService,
|
||||
)
|
||||
: new BackgroundMemoryStorageService();
|
||||
this.globalStateProvider = new DefaultGlobalStateProvider(
|
||||
this.memoryStorageForStateProviders,
|
||||
|
||||
const storageServiceProvider = new StorageServiceProvider(
|
||||
this.storageService as BrowserLocalStorageService,
|
||||
this.memoryStorageForStateProviders,
|
||||
);
|
||||
|
||||
this.globalStateProvider = new DefaultGlobalStateProvider(storageServiceProvider);
|
||||
|
||||
const stateEventRegistrarService = new StateEventRegistrarService(
|
||||
this.globalStateProvider,
|
||||
storageServiceProvider,
|
||||
);
|
||||
|
||||
this.stateEventRunnerService = new StateEventRunnerService(
|
||||
this.globalStateProvider,
|
||||
storageServiceProvider,
|
||||
);
|
||||
|
||||
this.encryptService = flagEnabled("multithreadDecryption")
|
||||
? new MultithreadEncryptServiceImplementation(
|
||||
this.cryptoFunctionService,
|
||||
@@ -379,8 +397,8 @@ export default class MainBackground {
|
||||
: new EncryptServiceImplementation(this.cryptoFunctionService, this.logService, true);
|
||||
|
||||
this.singleUserStateProvider = new DefaultSingleUserStateProvider(
|
||||
this.memoryStorageForStateProviders,
|
||||
this.storageService as BrowserLocalStorageService,
|
||||
storageServiceProvider,
|
||||
stateEventRegistrarService,
|
||||
);
|
||||
this.accountService = new AccountServiceImplementation(
|
||||
this.messagingService,
|
||||
@@ -389,8 +407,8 @@ export default class MainBackground {
|
||||
);
|
||||
this.activeUserStateProvider = new DefaultActiveUserStateProvider(
|
||||
this.accountService,
|
||||
this.memoryStorageForStateProviders,
|
||||
this.storageService as BrowserLocalStorageService,
|
||||
storageServiceProvider,
|
||||
stateEventRegistrarService,
|
||||
);
|
||||
this.derivedStateProvider = new BackgroundDerivedStateProvider(
|
||||
this.memoryStorageForStateProviders,
|
||||
@@ -666,6 +684,7 @@ export default class MainBackground {
|
||||
this.stateService,
|
||||
this.authService,
|
||||
this.vaultTimeoutSettingsService,
|
||||
this.stateEventRunnerService,
|
||||
lockedCallback,
|
||||
logoutCallback,
|
||||
);
|
||||
@@ -1113,6 +1132,8 @@ export default class MainBackground {
|
||||
this.searchService.clearIndex();
|
||||
}
|
||||
|
||||
await this.stateEventRunnerService.handleEvent("logout", currentUserId as UserId);
|
||||
|
||||
if (newActiveUser != null) {
|
||||
// we have a new active user, do not continue tearing down application
|
||||
await this.switchAccount(newActiveUser as UserId);
|
||||
|
||||
@@ -21,6 +21,10 @@ import {
|
||||
platformUtilsServiceFactory,
|
||||
PlatformUtilsServiceInitOptions,
|
||||
} from "../../platform/background/service-factories/platform-utils-service.factory";
|
||||
import {
|
||||
stateEventRunnerServiceFactory,
|
||||
StateEventRunnerServiceInitOptions,
|
||||
} from "../../platform/background/service-factories/state-event-runner-service.factory";
|
||||
import {
|
||||
StateServiceInitOptions,
|
||||
stateServiceFactory,
|
||||
@@ -62,7 +66,8 @@ export type VaultTimeoutServiceInitOptions = VaultTimeoutServiceFactoryOptions &
|
||||
SearchServiceInitOptions &
|
||||
StateServiceInitOptions &
|
||||
AuthServiceInitOptions &
|
||||
VaultTimeoutSettingsServiceInitOptions;
|
||||
VaultTimeoutSettingsServiceInitOptions &
|
||||
StateEventRunnerServiceInitOptions;
|
||||
|
||||
export function vaultTimeoutServiceFactory(
|
||||
cache: { vaultTimeoutService?: AbstractVaultTimeoutService } & CachedServices,
|
||||
@@ -84,6 +89,7 @@ export function vaultTimeoutServiceFactory(
|
||||
await stateServiceFactory(cache, opts),
|
||||
await authServiceFactory(cache, opts),
|
||||
await vaultTimeoutSettingsServiceFactory(cache, opts),
|
||||
await stateEventRunnerServiceFactory(cache, opts),
|
||||
opts.vaultTimeoutServiceOptions.lockedCallback,
|
||||
opts.vaultTimeoutServiceOptions.loggedOutCallback,
|
||||
),
|
||||
|
||||
@@ -9,18 +9,20 @@ import {
|
||||
|
||||
import { CachedServices, FactoryOptions, factory } from "./factory-options";
|
||||
import {
|
||||
DiskStorageServiceInitOptions,
|
||||
MemoryStorageServiceInitOptions,
|
||||
observableDiskStorageServiceFactory,
|
||||
observableMemoryStorageServiceFactory,
|
||||
} from "./storage-service.factory";
|
||||
StateEventRegistrarServiceInitOptions,
|
||||
stateEventRegistrarServiceFactory,
|
||||
} from "./state-event-registrar-service.factory";
|
||||
import {
|
||||
StorageServiceProviderInitOptions,
|
||||
storageServiceProviderFactory,
|
||||
} from "./storage-service-provider.factory";
|
||||
|
||||
type ActiveUserStateProviderFactory = FactoryOptions;
|
||||
|
||||
export type ActiveUserStateProviderInitOptions = ActiveUserStateProviderFactory &
|
||||
AccountServiceInitOptions &
|
||||
MemoryStorageServiceInitOptions &
|
||||
DiskStorageServiceInitOptions;
|
||||
StorageServiceProviderInitOptions &
|
||||
StateEventRegistrarServiceInitOptions;
|
||||
|
||||
export async function activeUserStateProviderFactory(
|
||||
cache: { activeUserStateProvider?: ActiveUserStateProvider } & CachedServices,
|
||||
@@ -33,8 +35,8 @@ export async function activeUserStateProviderFactory(
|
||||
async () =>
|
||||
new DefaultActiveUserStateProvider(
|
||||
await accountServiceFactory(cache, opts),
|
||||
await observableMemoryStorageServiceFactory(cache, opts),
|
||||
await observableDiskStorageServiceFactory(cache, opts),
|
||||
await storageServiceProviderFactory(cache, opts),
|
||||
await stateEventRegistrarServiceFactory(cache, opts),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,17 +4,14 @@ import { DefaultGlobalStateProvider } from "@bitwarden/common/platform/state/imp
|
||||
|
||||
import { CachedServices, FactoryOptions, factory } from "./factory-options";
|
||||
import {
|
||||
DiskStorageServiceInitOptions,
|
||||
MemoryStorageServiceInitOptions,
|
||||
observableDiskStorageServiceFactory,
|
||||
observableMemoryStorageServiceFactory,
|
||||
} from "./storage-service.factory";
|
||||
StorageServiceProviderInitOptions,
|
||||
storageServiceProviderFactory,
|
||||
} from "./storage-service-provider.factory";
|
||||
|
||||
type GlobalStateProviderFactoryOptions = FactoryOptions;
|
||||
|
||||
export type GlobalStateProviderInitOptions = GlobalStateProviderFactoryOptions &
|
||||
MemoryStorageServiceInitOptions &
|
||||
DiskStorageServiceInitOptions;
|
||||
StorageServiceProviderInitOptions;
|
||||
|
||||
export async function globalStateProviderFactory(
|
||||
cache: { globalStateProvider?: GlobalStateProvider } & CachedServices,
|
||||
@@ -24,10 +21,6 @@ export async function globalStateProviderFactory(
|
||||
cache,
|
||||
"globalStateProvider",
|
||||
opts,
|
||||
async () =>
|
||||
new DefaultGlobalStateProvider(
|
||||
await observableMemoryStorageServiceFactory(cache, opts),
|
||||
await observableDiskStorageServiceFactory(cache, opts),
|
||||
),
|
||||
async () => new DefaultGlobalStateProvider(await storageServiceProviderFactory(cache, opts)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,17 +4,19 @@ import { DefaultSingleUserStateProvider } from "@bitwarden/common/platform/state
|
||||
|
||||
import { CachedServices, FactoryOptions, factory } from "./factory-options";
|
||||
import {
|
||||
DiskStorageServiceInitOptions,
|
||||
MemoryStorageServiceInitOptions,
|
||||
observableDiskStorageServiceFactory,
|
||||
observableMemoryStorageServiceFactory,
|
||||
} from "./storage-service.factory";
|
||||
StateEventRegistrarServiceInitOptions,
|
||||
stateEventRegistrarServiceFactory,
|
||||
} from "./state-event-registrar-service.factory";
|
||||
import {
|
||||
StorageServiceProviderInitOptions,
|
||||
storageServiceProviderFactory,
|
||||
} from "./storage-service-provider.factory";
|
||||
|
||||
type SingleUserStateProviderFactoryOptions = FactoryOptions;
|
||||
|
||||
export type SingleUserStateProviderInitOptions = SingleUserStateProviderFactoryOptions &
|
||||
MemoryStorageServiceInitOptions &
|
||||
DiskStorageServiceInitOptions;
|
||||
StorageServiceProviderInitOptions &
|
||||
StateEventRegistrarServiceInitOptions;
|
||||
|
||||
export async function singleUserStateProviderFactory(
|
||||
cache: { singleUserStateProvider?: SingleUserStateProvider } & CachedServices,
|
||||
@@ -26,8 +28,8 @@ export async function singleUserStateProviderFactory(
|
||||
opts,
|
||||
async () =>
|
||||
new DefaultSingleUserStateProvider(
|
||||
await observableMemoryStorageServiceFactory(cache, opts),
|
||||
await observableDiskStorageServiceFactory(cache, opts),
|
||||
await storageServiceProviderFactory(cache, opts),
|
||||
await stateEventRegistrarServiceFactory(cache, opts),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { StateEventRunnerService } from "@bitwarden/common/platform/state";
|
||||
|
||||
import { CachedServices, FactoryOptions, factory } from "./factory-options";
|
||||
import {
|
||||
GlobalStateProviderInitOptions,
|
||||
globalStateProviderFactory,
|
||||
} from "./global-state-provider.factory";
|
||||
import {
|
||||
StorageServiceProviderInitOptions,
|
||||
storageServiceProviderFactory,
|
||||
} from "./storage-service-provider.factory";
|
||||
|
||||
type StateEventRunnerServiceFactoryOptions = FactoryOptions;
|
||||
|
||||
export type StateEventRunnerServiceInitOptions = StateEventRunnerServiceFactoryOptions &
|
||||
GlobalStateProviderInitOptions &
|
||||
StorageServiceProviderInitOptions;
|
||||
|
||||
export function stateEventRunnerServiceFactory(
|
||||
cache: { stateEventRunnerService?: StateEventRunnerService } & CachedServices,
|
||||
opts: StateEventRunnerServiceInitOptions,
|
||||
): Promise<StateEventRunnerService> {
|
||||
return factory(
|
||||
cache,
|
||||
"stateEventRunnerService",
|
||||
opts,
|
||||
async () =>
|
||||
new StateEventRunnerService(
|
||||
await globalStateProviderFactory(cache, opts),
|
||||
await storageServiceProviderFactory(cache, opts),
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user