1 // Copyright 2013 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "apps/app_lifetime_monitor_factory.h"
7 #include "apps/app_lifetime_monitor.h"
8 #include "components/keyed_service/content/browser_context_dependency_manager.h"
9 #include "content/public/browser/browser_context.h"
10 #include "extensions/browser/app_window/app_window_registry.h"
11 #include "extensions/browser/extension_host_registry.h"
12 #include "extensions/browser/extensions_browser_client.h"
17 AppLifetimeMonitor* AppLifetimeMonitorFactory::GetForBrowserContext(
18 content::BrowserContext* context) {
19 return static_cast<AppLifetimeMonitor*>(
20 GetInstance()->GetServiceForBrowserContext(context, false));
23 AppLifetimeMonitorFactory* AppLifetimeMonitorFactory::GetInstance() {
24 return base::Singleton<AppLifetimeMonitorFactory>::get();
27 AppLifetimeMonitorFactory::AppLifetimeMonitorFactory()
28 : BrowserContextKeyedServiceFactory(
30 BrowserContextDependencyManager::GetInstance()) {
31 DependsOn(extensions::AppWindowRegistry::Factory::GetInstance());
32 DependsOn(extensions::ExtensionHostRegistry::GetFactory());
35 AppLifetimeMonitorFactory::~AppLifetimeMonitorFactory() = default;
37 KeyedService* AppLifetimeMonitorFactory::BuildServiceInstanceFor(
38 content::BrowserContext* context) const {
39 return new AppLifetimeMonitor(context);
42 bool AppLifetimeMonitorFactory::ServiceIsCreatedWithBrowserContext() const {
46 content::BrowserContext* AppLifetimeMonitorFactory::GetBrowserContextToUse(
47 content::BrowserContext* context) const {
48 return extensions::ExtensionsBrowserClient::Get()
49 ->GetContextRedirectedToOriginal(context, /*force_guest_profile=*/true);