1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00:00

Ps/pm 2910/add browser storage services (#6849)

* Allow for update logic in state update callbacks

* Prefer reading updates to sending in stream

* Inform state providers when they must deserialize

* Update DefaultGlobalState to act more like DefaultUserState

* Fully Implement AbstractStorageService

* Add KeyDefinitionOptions

* Address PR feedback

* Prefer testing interactions for ports

* Synced memory storage for browser

* Fix port handling

* Do not stringify port message data

* Use messaging storage

* Initialize new foreground memory storage services

This will need to be rethought for short-lived background pages, but for
now the background is the source of truth for memory storage

* Use global state for account service

* Use BrowserApi listener to avoid safari memory leaks

* Fix build errors: debugging and missed impls

* Prefer bound arrow functions

* JSON Stringify Messages

* Prefer `useClass`

* Use noop services

* extract storage observable to new interface

This also reverts changes for the existing services to use
foreground/background services. Those are now used only in state
providers

* Fix web DI

* Prefer initializing observable in constructor

* Do not use jsonify as equality operator

* Remove port listener to avoid memory leaks

* Fix logic and type issues

---------

Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>
This commit is contained in:
Matt Gibson
2023-11-21 16:35:37 -05:00
committed by GitHub
parent 1ecf019397
commit 24c240d0d4
36 changed files with 744 additions and 160 deletions

View File

@@ -45,6 +45,9 @@ import { FileUploadService } from "@bitwarden/common/platform/services/file-uplo
import { MemoryStorageService } from "@bitwarden/common/platform/services/memory-storage.service";
import { NoopMessagingService } from "@bitwarden/common/platform/services/noop-messaging.service";
import { StateService } from "@bitwarden/common/platform/services/state.service";
import { GlobalStateProvider } from "@bitwarden/common/platform/state";
// eslint-disable-next-line import/no-restricted-paths -- We need the implementation to inject, but generally this should not be accessed
import { DefaultGlobalStateProvider } from "@bitwarden/common/platform/state/implementations/default-global-state.provider";
import { AuditService } from "@bitwarden/common/services/audit.service";
import { EventCollectionService } from "@bitwarden/common/services/event/event-collection.service";
import { EventUploadService } from "@bitwarden/common/services/event/event-upload.service";
@@ -161,6 +164,7 @@ export class Main {
configApiService: ConfigApiServiceAbstraction;
configService: CliConfigService;
accountService: AccountService;
globalStateProvider: GlobalStateProvider;
constructor() {
let p = null;
@@ -200,7 +204,18 @@ export class Main {
this.memoryStorageService = new MemoryStorageService();
this.accountService = new AccountServiceImplementation(null, this.logService);
this.globalStateProvider = new DefaultGlobalStateProvider(
this.memoryStorageService,
this.storageService
);
this.messagingService = new NoopMessagingService();
this.accountService = new AccountServiceImplementation(
this.messagingService,
this.logService,
this.globalStateProvider
);
this.stateService = new StateService(
this.storageService,
@@ -221,7 +236,6 @@ export class Main {
this.appIdService = new AppIdService(this.storageService);
this.tokenService = new TokenService(this.stateService);
this.messagingService = new NoopMessagingService();
this.environmentService = new EnvironmentService(this.stateService);
const customUserAgent =

View File

@@ -29,6 +29,7 @@ export class LowdbStorageService implements AbstractStorageService {
private defaults: any;
private ready = false;
private updatesSubject = new Subject<StorageUpdate>();
updates$;
constructor(
protected logService: LogService,
@@ -38,6 +39,7 @@ export class LowdbStorageService implements AbstractStorageService {
private requireLock = false
) {
this.defaults = defaults;
this.updates$ = this.updatesSubject.asObservable();
}
@sequentialize(() => "lowdbStorageInit")
@@ -110,9 +112,6 @@ export class LowdbStorageService implements AbstractStorageService {
get valuesRequireDeserialization(): boolean {
return true;
}
get updates$() {
return this.updatesSubject.asObservable();
}
async get<T>(key: string): Promise<T> {
await this.waitForReady();