app_lifetime_monitor_factory.cc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "apps/app_lifetime_monitor_factory.h"
  5. #include "apps/app_lifetime_monitor.h"
  6. #include "components/keyed_service/content/browser_context_dependency_manager.h"
  7. #include "content/public/browser/browser_context.h"
  8. #include "extensions/browser/app_window/app_window_registry.h"
  9. #include "extensions/browser/extension_host_registry.h"
  10. #include "extensions/browser/extensions_browser_client.h"
  11. namespace apps {
  12. // static
  13. AppLifetimeMonitor* AppLifetimeMonitorFactory::GetForBrowserContext(
  14. content::BrowserContext* context) {
  15. return static_cast<AppLifetimeMonitor*>(
  16. GetInstance()->GetServiceForBrowserContext(context, false));
  17. }
  18. AppLifetimeMonitorFactory* AppLifetimeMonitorFactory::GetInstance() {
  19. return base::Singleton<AppLifetimeMonitorFactory>::get();
  20. }
  21. AppLifetimeMonitorFactory::AppLifetimeMonitorFactory()
  22. : BrowserContextKeyedServiceFactory(
  23. "AppLifetimeMonitor",
  24. BrowserContextDependencyManager::GetInstance()) {
  25. DependsOn(extensions::AppWindowRegistry::Factory::GetInstance());
  26. DependsOn(extensions::ExtensionHostRegistry::GetFactory());
  27. }
  28. AppLifetimeMonitorFactory::~AppLifetimeMonitorFactory() = default;
  29. KeyedService* AppLifetimeMonitorFactory::BuildServiceInstanceFor(
  30. content::BrowserContext* context) const {
  31. return new AppLifetimeMonitor(context);
  32. }
  33. bool AppLifetimeMonitorFactory::ServiceIsCreatedWithBrowserContext() const {
  34. return true;
  35. }
  36. content::BrowserContext* AppLifetimeMonitorFactory::GetBrowserContextToUse(
  37. content::BrowserContext* context) const {
  38. return extensions::ExtensionsBrowserClient::Get()->
  39. GetOriginalContext(context);
  40. }
  41. } // namespace apps