mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-26 12:25:20 +01:00
add hack to get around duplicate instances of disk cache on browser
This commit is contained in:
parent
7b7fa276be
commit
301028f8db
@ -1,5 +1,12 @@
|
||||
import { BehaviorSubject } from "rxjs";
|
||||
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
import { StateMigrationService } from "@bitwarden/common/platform/abstractions/state-migration.service";
|
||||
import {
|
||||
AbstractStorageService,
|
||||
AbstractMemoryStorageService,
|
||||
} from "@bitwarden/common/platform/abstractions/storage.service";
|
||||
import { StateFactory } from "@bitwarden/common/platform/factories/state-factory";
|
||||
import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state";
|
||||
import { StorageOptions } from "@bitwarden/common/platform/models/domain/storage-options";
|
||||
import { StateService as BaseStateService } from "@bitwarden/common/platform/services/state.service";
|
||||
@ -26,14 +33,42 @@ export class BrowserStateService
|
||||
protected activeAccountSubject: BehaviorSubject<string>;
|
||||
@sessionSync({ initializer: (b: boolean) => b })
|
||||
protected activeAccountUnlockedSubject: BehaviorSubject<boolean>;
|
||||
@sessionSync({
|
||||
initializer: Account.fromJSON as any, // TODO: Remove this any when all any types are removed from Account
|
||||
initializeAs: "record",
|
||||
})
|
||||
protected accountDiskCache: BehaviorSubject<Record<string, Account>>;
|
||||
|
||||
protected accountDeserializer = Account.fromJSON;
|
||||
|
||||
constructor(
|
||||
storageService: AbstractStorageService,
|
||||
secureStorageService: AbstractStorageService,
|
||||
memoryStorageService: AbstractMemoryStorageService,
|
||||
logService: LogService,
|
||||
stateMigrationService: StateMigrationService,
|
||||
stateFactory: StateFactory<GlobalState, Account>,
|
||||
useAccountCache = true
|
||||
) {
|
||||
super(
|
||||
storageService,
|
||||
secureStorageService,
|
||||
memoryStorageService,
|
||||
logService,
|
||||
stateMigrationService,
|
||||
stateFactory,
|
||||
useAccountCache
|
||||
);
|
||||
|
||||
// TODO: This is a hack to fix having a disk cache on both the popup and
|
||||
// the background page that can get out of sync. We need to have a single
|
||||
// instance of our state service that is shared so we can remove this.
|
||||
chrome.storage.onChanged.addListener((changes, namespace) => {
|
||||
if (namespace === "local") {
|
||||
for (const key of Object.keys(changes)) {
|
||||
if (key !== "accountActivity" && this.accountDiskCache.value[key]) {
|
||||
this.deleteDiskCache(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async addAccount(account: Account) {
|
||||
// Apply browser overrides to default account values
|
||||
account = new Account(account);
|
||||
|
@ -3169,7 +3169,7 @@ export class StateService<
|
||||
}
|
||||
}
|
||||
|
||||
private deleteDiskCache(key: string) {
|
||||
protected deleteDiskCache(key: string) {
|
||||
if (this.useAccountCache) {
|
||||
delete this.accountDiskCache.value[key];
|
||||
this.accountDiskCache.next(this.accountDiskCache.value);
|
||||
|
Loading…
Reference in New Issue
Block a user