diff --git a/apps/browser/src/auth/background/service-factories/login-strategy-service.factory.ts b/apps/browser/src/auth/background/service-factories/login-strategy-service.factory.ts index 2cc4692ca9..15b1910e45 100644 --- a/apps/browser/src/auth/background/service-factories/login-strategy-service.factory.ts +++ b/apps/browser/src/auth/background/service-factories/login-strategy-service.factory.ts @@ -54,6 +54,10 @@ import { stateServiceFactory, StateServiceInitOptions, } from "../../../platform/background/service-factories/state-service.factory"; +import { + taskSchedulerServiceFactory, + TaskSchedulerServiceInitOptions, +} from "../../../platform/background/service-factories/task-scheduler-service.factory"; import { passwordStrengthServiceFactory, PasswordStrengthServiceInitOptions, @@ -99,7 +103,8 @@ export type LoginStrategyServiceInitOptions = LoginStrategyServiceFactoryOptions AuthRequestServiceInitOptions & UserDecryptionOptionsServiceInitOptions & GlobalStateProviderInitOptions & - BillingAccountProfileStateServiceInitOptions; + BillingAccountProfileStateServiceInitOptions & + TaskSchedulerServiceInitOptions; export function loginStrategyServiceFactory( cache: { loginStrategyService?: LoginStrategyServiceAbstraction } & CachedServices, @@ -131,6 +136,7 @@ export function loginStrategyServiceFactory( await internalUserDecryptionOptionServiceFactory(cache, opts), await globalStateProviderFactory(cache, opts), await billingAccountProfileStateServiceFactory(cache, opts), + await taskSchedulerServiceFactory(cache, opts), ), ); } diff --git a/apps/browser/src/autofill/browser/context-menu-clicked-handler.ts b/apps/browser/src/autofill/browser/context-menu-clicked-handler.ts index 55f7608ef0..367e78f53e 100644 --- a/apps/browser/src/autofill/browser/context-menu-clicked-handler.ts +++ b/apps/browser/src/autofill/browser/context-menu-clicked-handler.ts @@ -36,9 +36,9 @@ import { openUnlockPopout } from "../../auth/popup/utils/auth-popout-window"; import { autofillSettingsServiceFactory } from "../../autofill/background/service_factories/autofill-settings-service.factory"; import { eventCollectionServiceFactory } from "../../background/service-factories/event-collection-service.factory"; import { Account } from "../../models/account"; -import { browserTaskSchedulerServiceFactory } from "../../platform/background/service-factories/browser-task-scheduler-service.factory"; import { CachedServices } from "../../platform/background/service-factories/factory-options"; import { stateServiceFactory } from "../../platform/background/service-factories/state-service.factory"; +import { taskSchedulerServiceFactory } from "../../platform/background/service-factories/task-scheduler-service.factory"; import { BrowserApi } from "../../platform/browser/browser-api"; import { passwordGenerationServiceFactory } from "../../tools/background/service_factories/password-generation-service.factory"; import { @@ -117,7 +117,7 @@ export class ContextMenuClickedHandler { const generatePasswordToClipboardCommand = new GeneratePasswordToClipboardCommand( await passwordGenerationServiceFactory(cachedServices, serviceOptions), await autofillSettingsServiceFactory(cachedServices, serviceOptions), - await browserTaskSchedulerServiceFactory(cachedServices, serviceOptions), + await taskSchedulerServiceFactory(cachedServices, serviceOptions), ); const autofillCommand = new AutofillTabCommand( diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index b824f86f41..80393e8419 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -613,6 +613,7 @@ export default class MainBackground { this.userDecryptionOptionsService, this.globalStateProvider, this.billingAccountProfileStateService, + this.taskSchedulerService, ); this.ssoLoginService = new SsoLoginService(this.stateProvider); diff --git a/apps/browser/src/platform/background/service-factories/browser-task-scheduler-service.factory.ts b/apps/browser/src/platform/background/service-factories/task-scheduler-service.factory.ts similarity index 74% rename from apps/browser/src/platform/background/service-factories/browser-task-scheduler-service.factory.ts rename to apps/browser/src/platform/background/service-factories/task-scheduler-service.factory.ts index 1d078ae5db..218566a32b 100644 --- a/apps/browser/src/platform/background/service-factories/browser-task-scheduler-service.factory.ts +++ b/apps/browser/src/platform/background/service-factories/task-scheduler-service.factory.ts @@ -4,15 +4,15 @@ import { CachedServices, factory, FactoryOptions } from "./factory-options"; import { logServiceFactory, LogServiceInitOptions } from "./log-service.factory"; import { stateProviderFactory, StateProviderInitOptions } from "./state-provider.factory"; -type BrowserTaskSchedulerServiceFactoryOptions = FactoryOptions; +type TaskSchedulerServiceFactoryOptions = FactoryOptions; -export type BrowserTaskSchedulerServiceInitOptions = BrowserTaskSchedulerServiceFactoryOptions & +export type TaskSchedulerServiceInitOptions = TaskSchedulerServiceFactoryOptions & LogServiceInitOptions & StateProviderInitOptions; -export function browserTaskSchedulerServiceFactory( +export function taskSchedulerServiceFactory( cache: { browserTaskSchedulerService?: BrowserTaskSchedulerService } & CachedServices, - opts: BrowserTaskSchedulerServiceInitOptions, + opts: TaskSchedulerServiceInitOptions, ): Promise { return factory( cache, diff --git a/apps/browser/src/platform/listeners/on-command-listener.ts b/apps/browser/src/platform/listeners/on-command-listener.ts index 4820e3214d..f4d3659871 100644 --- a/apps/browser/src/platform/listeners/on-command-listener.ts +++ b/apps/browser/src/platform/listeners/on-command-listener.ts @@ -12,9 +12,9 @@ import { passwordGenerationServiceFactory, PasswordGenerationServiceInitOptions, } from "../../tools/background/service_factories/password-generation-service.factory"; -import { browserTaskSchedulerServiceFactory } from "../background/service-factories/browser-task-scheduler-service.factory"; import { CachedServices } from "../background/service-factories/factory-options"; import { logServiceFactory } from "../background/service-factories/log-service.factory"; +import { taskSchedulerServiceFactory } from "../background/service-factories/task-scheduler-service.factory"; import { BrowserApi } from "../browser/browser-api"; export const onCommandListener = async (command: string, tab: chrome.tabs.Tab) => { @@ -103,7 +103,7 @@ const doGeneratePasswordToClipboard = async (tab: chrome.tabs.Tab): Promise; private loginStrategyCacheState: GlobalState; private loginStrategyCacheExpirationState: GlobalState; @@ -101,6 +103,7 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction { protected userDecryptionOptionsService: InternalUserDecryptionOptionsServiceAbstraction, protected stateProvider: GlobalStateProvider, protected billingAccountProfileStateService: BillingAccountProfileStateService, + protected taskSchedulerService: TaskSchedulerService, ) { this.currentAuthnTypeState = this.stateProvider.get(CURRENT_LOGIN_STRATEGY_KEY); this.loginStrategyCacheState = this.stateProvider.get(CACHE_KEY); @@ -300,12 +303,19 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction { await this.loginStrategyCacheExpirationState.update( (_) => new Date(Date.now() + sessionTimeoutLength), ); - this.sessionTimeout = setTimeout(() => this.clearCache(), sessionTimeoutLength); + this.sessionTimeout = await this.taskSchedulerService.setTimeout( + () => this.clearCache(), + sessionTimeoutLength, + ScheduledTaskNames.loginStrategySessionTimeout, + ); } private async clearSessionTimeout(): Promise { await this.loginStrategyCacheExpirationState.update((_) => null); - this.sessionTimeout = null; + await this.taskSchedulerService.clearScheduledTask({ + taskName: ScheduledTaskNames.loginStrategySessionTimeout, + timeoutId: this.sessionTimeout, + }); } private async isSessionValid(): Promise {