1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-09 21:20:27 +00:00

[PM-19814] Fix race condition in feature flag check.

This commit is contained in:
Jimmy Vo
2025-04-15 16:12:21 -04:00
parent a07d8485ab
commit 3df333b5d3
2 changed files with 37 additions and 23 deletions

View File

@@ -1317,23 +1317,13 @@ export default class MainBackground {
this.inlineMenuFieldQualificationService = new InlineMenuFieldQualificationService();
this.configService
.getFeatureFlag(FeatureFlag.PhishingDetection)
.then((enabled) => {
if (enabled) {
PhishingDetectionService.initialize(
this.auditService,
this.logService,
this.storageService,
this.taskSchedulerService,
);
} else {
this.logService.info("phishing detection feature flag is disabled.");
}
})
.catch((error) =>
this.logService.error("Failed to check phishing detection feature flag", error),
);
PhishingDetectionService.initialize(
this.configService,
this.auditService,
this.logService,
this.storageService,
this.taskSchedulerService,
);
this.ipcContentScriptManagerService = new IpcContentScriptManagerService(this.configService);
this.ipcService = new IpcBackgroundService(this.logService);

View File

@@ -1,9 +1,8 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { Subscription } from "rxjs";
import { mergeMap, Subscription } from "rxjs";
import { AuditService } from "@bitwarden/common/abstractions/audit.service";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service";
import { ScheduledTaskNames } from "@bitwarden/common/platform/scheduling";
@@ -39,11 +38,36 @@ export class PhishingDetectionService {
private static retryCount = 0;
static initialize(
configService: ConfigService,
auditService: AuditService,
logService: LogService,
storageService: AbstractStorageService,
taskSchedulerService: TaskSchedulerService,
) {
): void {
configService
.getFeatureFlag$(FeatureFlag.PhishingDetection)
.pipe(
mergeMap(async (enabled) => {
if (!enabled) {
logService.info("phishing detection feature flag is disabled.");
}
await PhishingDetectionService.enable(
auditService,
logService,
storageService,
taskSchedulerService,
);
}),
)
.subscribe();
}
static async enable(
auditService: AuditService,
logService: LogService,
storageService: AbstractStorageService,
taskSchedulerService: TaskSchedulerService,
): Promise<void> {
PhishingDetectionService.auditService = auditService;
PhishingDetectionService.logService = logService;
PhishingDetectionService.storageService = storageService;
@@ -64,7 +88,7 @@ export class PhishingDetectionService {
);
// Initial load of cached domains
void this.loadCachedDomains();
await this.loadCachedDomains();
// Set up periodic updates every 24 hours
this.setupPeriodicUpdates();