1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-22 19:23:52 +00:00

[PM-5277] Migrate Sync Service to State Provider (#7680)

* [PM-5277] Introduce lastSync state via State Providers

* [PM-5277] Add migrator and tests

* [PM-5277] Use memory for web storage location

* [PM-5277] Remove lastSync methods from state service

* [PM-5277] Remove lastSync from AccountProfile

* [PM-5277] Use string instead of Date to fix serialization for chrome.storage API in Browser

* [PM-5277] Only set account if lastSync was deleted during migration

* [PM-5277] Fix spec file
This commit is contained in:
Shane Melton
2024-02-06 12:00:41 -08:00
committed by GitHub
parent 7e00ece092
commit 78008a9e1e
15 changed files with 210 additions and 55 deletions

View File

@@ -139,10 +139,10 @@ import {
VaultExportServiceAbstraction,
} from "@bitwarden/exporter/vault-export";
import {
ImportApiServiceAbstraction,
ImportApiService,
ImportServiceAbstraction,
ImportApiServiceAbstraction,
ImportService,
ImportServiceAbstraction,
} from "@bitwarden/importer/core";
import { BrowserOrganizationService } from "../admin-console/services/browser-organization.service";
@@ -634,6 +634,7 @@ export default class MainBackground {
this.folderApiService,
this.organizationService,
this.sendApiService,
this.stateProvider,
logoutCallback,
);
this.eventUploadService = new EventUploadService(
@@ -1009,7 +1010,7 @@ export default class MainBackground {
await this.eventUploadService.uploadEvents(userId);
await Promise.all([
this.syncService.setLastSync(new Date(0), userId),
this.syncService.setLastSync(new Date(0), userId as UserId),
this.cryptoService.clearKeys(userId),
this.settingsService.clear(userId),
this.cipherService.clear(userId),

View File

@@ -519,6 +519,7 @@ export class Main {
this.folderApiService,
this.organizationService,
this.sendApiService,
this.stateProvider,
async (expired: boolean) => await this.logout(),
);

View File

@@ -39,6 +39,7 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { SystemService } from "@bitwarden/common/platform/abstractions/system.service";
import { PasswordGenerationServiceAbstraction } from "@bitwarden/common/tools/generator/password";
import { UserId } from "@bitwarden/common/types/guid";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { CollectionService } from "@bitwarden/common/vault/abstractions/collection.service";
import { InternalFolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
@@ -565,7 +566,7 @@ export class AppComponent implements OnInit, OnDestroy {
let preLogoutActiveUserId;
try {
await this.eventUploadService.uploadEvents(userBeingLoggedOut);
await this.syncService.setLastSync(new Date(0), userBeingLoggedOut);
await this.syncService.setLastSync(new Date(0), userBeingLoggedOut as UserId);
await this.cryptoService.clearKeys(userBeingLoggedOut);
await this.settingsService.clear(userBeingLoggedOut);
await this.cipherService.clear(userBeingLoggedOut);

View File

@@ -93,14 +93,4 @@ export class StateService extends BaseStateService<GlobalState, Account> {
options = this.reconcileOptions(options, await this.defaultInMemoryOptions());
return await super.setEncryptedSends(value, options);
}
override async getLastSync(options?: StorageOptions): Promise<string> {
options = this.reconcileOptions(options, await this.defaultInMemoryOptions());
return await super.getLastSync(options);
}
override async setLastSync(value: string, options?: StorageOptions): Promise<void> {
options = this.reconcileOptions(options, await this.defaultInMemoryOptions());
return await super.setLastSync(value, options);
}
}