Introduce ArcBrowserContextKeyedServiceFactoryBase.
While migrating ArcService into BrowserContextKeyedService,
it turned out the boilerplate looks much bigger than what we expected.
To minimize it reasonably, this CL introduces
ArcBrowserContextKeyedServiceFactoryBase and use it for
already migrated service classes.
BUG=739097
TEST=Ran trybot. Ran on DUT.
Change-Id: I13a1e7019c06ea64fa48cec6ecf7a9e589e84b00
Reviewed-on: https://chromium-review.googlesource.com/569847
Reviewed-by: Paweł Hajdan Jr. <[email protected]>
Reviewed-by: Luis Hector Chavez <[email protected]>
Reviewed-by: Yusuke Sato <[email protected]>
Commit-Queue: Hidehiko Abe <[email protected]>
Cr-Commit-Position: refs/heads/master@{#486759}
diff --git a/chrome/browser/chromeos/BUILD.gn b/chrome/browser/chromeos/BUILD.gn
index 2612ddb..5652731 100644
--- a/chrome/browser/chromeos/BUILD.gn
+++ b/chrome/browser/chromeos/BUILD.gn
@@ -282,8 +282,6 @@
"app_mode/startup_app_launcher.h",
"arc/accessibility/arc_accessibility_helper_bridge.cc",
"arc/accessibility/arc_accessibility_helper_bridge.h",
- "arc/accessibility/arc_accessibility_helper_bridge_factory.cc",
- "arc/accessibility/arc_accessibility_helper_bridge_factory.h",
"arc/accessibility/ax_tree_source_arc.cc",
"arc/accessibility/ax_tree_source_arc.h",
"arc/arc_auth_notification.cc",
@@ -310,8 +308,6 @@
"arc/auth/arc_auth_context.h",
"arc/auth/arc_auth_service.cc",
"arc/auth/arc_auth_service.h",
- "arc/auth/arc_auth_service_factory.cc",
- "arc/auth/arc_auth_service_factory.h",
"arc/auth/arc_background_auth_code_fetcher.cc",
"arc/auth/arc_background_auth_code_fetcher.h",
"arc/auth/arc_fetcher_base.h",
diff --git a/chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge.cc b/chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge.cc
index 5855392..6bc5d34 100644
--- a/chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge.cc
+++ b/chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge.cc
@@ -7,10 +7,13 @@
#include <utility>
#include "base/command_line.h"
+#include "base/memory/singleton.h"
#include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h"
#include "chromeos/chromeos_switches.h"
#include "components/arc/arc_bridge_service.h"
+#include "components/arc/arc_browser_context_keyed_service_factory_base.h"
#include "components/arc/arc_service_manager.h"
#include "components/exo/shell_surface.h"
#include "components/exo/surface.h"
@@ -96,10 +99,47 @@
namespace arc {
+namespace {
+
+// Singleton factory for ArcAccessibilityHelperBridge.
+class ArcAccessibilityHelperBridgeFactory
+ : public internal::ArcBrowserContextKeyedServiceFactoryBase<
+ ArcAccessibilityHelperBridge,
+ ArcAccessibilityHelperBridgeFactory> {
+ public:
+ // Factory name used by ArcBrowserContextKeyedServiceFactoryBase.
+ static constexpr const char* kName = "ArcAccessibilityHelperBridgeFactory";
+
+ static ArcAccessibilityHelperBridgeFactory* GetInstance() {
+ return base::Singleton<ArcAccessibilityHelperBridgeFactory>::get();
+ }
+
+ private:
+ friend struct base::DefaultSingletonTraits<
+ ArcAccessibilityHelperBridgeFactory>;
+
+ ArcAccessibilityHelperBridgeFactory() {
+ // ArcAccessibilityHelperBridge needs to track task creation and
+ // destruction in the container, which are notified to ArcAppListPrefs
+ // via Mojo.
+ DependsOn(ArcAppListPrefsFactory::GetInstance());
+ }
+ ~ArcAccessibilityHelperBridgeFactory() override = default;
+};
+
+} // namespace
+
+// static
+ArcAccessibilityHelperBridge*
+ArcAccessibilityHelperBridge::GetForBrowserContext(
+ content::BrowserContext* context) {
+ return ArcAccessibilityHelperBridgeFactory::GetForBrowserContext(context);
+}
+
ArcAccessibilityHelperBridge::ArcAccessibilityHelperBridge(
- Profile* profile,
+ content::BrowserContext* browser_context,
ArcBridgeService* arc_bridge_service)
- : profile_(profile),
+ : profile_(Profile::FromBrowserContext(browser_context)),
arc_bridge_service_(arc_bridge_service),
binding_(this),
current_task_id_(kNoTaskId) {
diff --git a/chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge.h b/chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge.h
index bf0f63f..fdf036b 100644
--- a/chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge.h
+++ b/chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge.h
@@ -21,6 +21,10 @@
class Profile;
+namespace content {
+class BrowserContext;
+} // namespace content
+
namespace arc {
class AXTreeSourceArc;
@@ -37,7 +41,12 @@
public AXTreeSourceArc::Delegate,
public ArcAppListPrefs::Observer {
public:
- ArcAccessibilityHelperBridge(Profile* profile,
+ // Returns singleton instance for the given BrowserContext,
+ // or nullptr if the browser |context| is not allowed to use ARC.
+ static ArcAccessibilityHelperBridge* GetForBrowserContext(
+ content::BrowserContext* context);
+
+ ArcAccessibilityHelperBridge(content::BrowserContext* browser_context,
ArcBridgeService* arc_bridge_service);
~ArcAccessibilityHelperBridge() override;
diff --git a/chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge_factory.cc b/chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge_factory.cc
deleted file mode 100644
index f435893..0000000
--- a/chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge_factory.cc
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge_factory.h"
-
-#include "base/memory/singleton.h"
-#include "chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h"
-#include "components/arc/arc_service_manager.h"
-#include "components/keyed_service/content/browser_context_dependency_manager.h"
-
-namespace arc {
-
-// static
-ArcAccessibilityHelperBridge*
-ArcAccessibilityHelperBridgeFactory::GetForBrowserContext(
- content::BrowserContext* context) {
- return static_cast<ArcAccessibilityHelperBridge*>(
- GetInstance()->GetServiceForBrowserContext(context, true /* create */));
-}
-
-// static
-ArcAccessibilityHelperBridgeFactory*
-ArcAccessibilityHelperBridgeFactory::GetInstance() {
- return base::Singleton<ArcAccessibilityHelperBridgeFactory>::get();
-}
-
-ArcAccessibilityHelperBridgeFactory::ArcAccessibilityHelperBridgeFactory()
- : BrowserContextKeyedServiceFactory(
- "ArcAccessibilityHelperBridgeFactory",
- BrowserContextDependencyManager::GetInstance()) {
- // ArcAccessibilityHelperBridge needs to track task creation and destruction
- // in the container, which are notified to ArcAppListPrefs via Mojo.
- DependsOn(ArcAppListPrefsFactory::GetInstance());
-}
-
-ArcAccessibilityHelperBridgeFactory::~ArcAccessibilityHelperBridgeFactory() =
- default;
-
-KeyedService* ArcAccessibilityHelperBridgeFactory::BuildServiceInstanceFor(
- content::BrowserContext* context) const {
- auto* arc_service_manager = arc::ArcServiceManager::Get();
-
- // Practically, this is in testing case.
- if (!arc_service_manager) {
- VLOG(2) << "ArcServiceManager is not available.";
- return nullptr;
- }
-
- if (arc_service_manager->browser_context() != context) {
- VLOG(2) << "Non ARC allowed browser context.";
- return nullptr;
- }
-
- return new ArcAccessibilityHelperBridge(
- Profile::FromBrowserContext(context),
- arc_service_manager->arc_bridge_service());
-}
-
-} // namespace arc
diff --git a/chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge_factory.h b/chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge_factory.h
deleted file mode 100644
index 8dadd2a..0000000
--- a/chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge_factory.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_CHROMEOS_ARC_ACCESSIBILITY_ARC_ACCESSIBILITY_HELPER_BRIDGE_FACTORY_H_
-#define CHROME_BROWSER_CHROMEOS_ARC_ACCESSIBILITY_ARC_ACCESSIBILITY_HELPER_BRIDGE_FACTORY_H_
-
-#include "base/macros.h"
-#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
-
-namespace base {
-template <typename T>
-struct DefaultSingletonTraits;
-} // namespace base
-
-namespace arc {
-
-class ArcAccessibilityHelperBridge;
-
-// Factory for ArcAccessibilityHelperBridge.
-class ArcAccessibilityHelperBridgeFactory
- : public BrowserContextKeyedServiceFactory {
- public:
- // Returns the ArcAccessibilityHelperBridge for the given |context|,
- // or nullptr if |context| is not allowed to use ARC.
- // If the instance is not yet created, this creates a new service instance.
- static ArcAccessibilityHelperBridge* GetForBrowserContext(
- content::BrowserContext* context);
-
- // Return the factory instance.
- static ArcAccessibilityHelperBridgeFactory* GetInstance();
-
- private:
- friend struct base::DefaultSingletonTraits<
- ArcAccessibilityHelperBridgeFactory>;
-
- ArcAccessibilityHelperBridgeFactory();
- ~ArcAccessibilityHelperBridgeFactory() override;
-
- // BrowserContextKeyedServiceFactory overrides:
- KeyedService* BuildServiceInstanceFor(
- content::BrowserContext* context) const override;
-
- DISALLOW_COPY_AND_ASSIGN(ArcAccessibilityHelperBridgeFactory);
-};
-
-} // namespace arc
-
-#endif // CHROME_BROWSER_CHROMEOS_ARC_ACCESSIBILITY_ARC_ACCESSIBILITY_HELPER_BRIDGE_FACTORY_H_
diff --git a/chrome/browser/chromeos/arc/arc_service_launcher.cc b/chrome/browser/chromeos/arc/arc_service_launcher.cc
index fab7b60..fe90ab5 100644
--- a/chrome/browser/chromeos/arc/arc_service_launcher.cc
+++ b/chrome/browser/chromeos/arc/arc_service_launcher.cc
@@ -10,11 +10,11 @@
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service.h"
-#include "chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge_factory.h"
+#include "chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge.h"
#include "chrome/browser/chromeos/arc/arc_play_store_enabled_preference_handler.h"
#include "chrome/browser/chromeos/arc/arc_session_manager.h"
#include "chrome/browser/chromeos/arc/arc_util.h"
-#include "chrome/browser/chromeos/arc/auth/arc_auth_service_factory.h"
+#include "chrome/browser/chromeos/arc/auth/arc_auth_service.h"
#include "chrome/browser/chromeos/arc/boot_phase_monitor/arc_boot_phase_monitor_bridge.h"
#include "chrome/browser/chromeos/arc/downloads_watcher/arc_downloads_watcher_service.h"
#include "chrome/browser/chromeos/arc/enterprise/arc_enterprise_reporting_service.h"
@@ -196,9 +196,12 @@
// Instantiate ARC related BrowserContextKeyedService classes which need
// to be running at the beginning of the container run.
+ // Note that, to keep this list as small as possible, services which don't
+ // need to be initialized at the beginning should not be listed here.
+ // Those services will be initialized lazily.
// List in lexicographical order.
- ArcAccessibilityHelperBridgeFactory::GetForBrowserContext(profile);
- ArcAuthServiceFactory::GetForBrowserContext(profile);
+ ArcAccessibilityHelperBridge::GetForBrowserContext(profile);
+ ArcAuthService::GetForBrowserContext(profile);
arc_service_manager_->AddService(base::MakeUnique<ArcBootPhaseMonitorBridge>(
arc_service_manager_->arc_bridge_service(),
diff --git a/chrome/browser/chromeos/arc/auth/arc_auth_service.cc b/chrome/browser/chromeos/arc/auth/arc_auth_service.cc
index be4bc340..8ee7e29 100644
--- a/chrome/browser/chromeos/arc/auth/arc_auth_service.cc
+++ b/chrome/browser/chromeos/arc/auth/arc_auth_service.cc
@@ -8,6 +8,7 @@
#include "base/command_line.h"
#include "base/memory/ptr_util.h"
+#include "base/memory/singleton.h"
#include "base/time/time.h"
#include "chrome/browser/chromeos/arc/arc_optin_uma.h"
#include "chrome/browser/chromeos/arc/arc_session_manager.h"
@@ -21,6 +22,7 @@
#include "chrome/common/pref_names.h"
#include "chromeos/chromeos_switches.h"
#include "components/arc/arc_bridge_service.h"
+#include "components/arc/arc_browser_context_keyed_service_factory_base.h"
#include "components/arc/arc_features.h"
#include "components/arc/arc_service_manager.h"
#include "components/arc/arc_util.h"
@@ -29,8 +31,29 @@
#include "content/public/browser/browser_thread.h"
namespace arc {
+
namespace {
+// Singleton factory for ArcAuthService.
+class ArcAuthServiceFactory
+ : public internal::ArcBrowserContextKeyedServiceFactoryBase<
+ ArcAuthService,
+ ArcAuthServiceFactory> {
+ public:
+ // Factory name used by ArcBrowserContextKeyedServiceFactoryBase.
+ static constexpr const char* kName = "ArcAuthServiceFactory";
+
+ static ArcAuthServiceFactory* GetInstance() {
+ return base::Singleton<ArcAuthServiceFactory>::get();
+ }
+
+ private:
+ friend struct base::DefaultSingletonTraits<ArcAuthServiceFactory>;
+
+ ArcAuthServiceFactory() = default;
+ ~ArcAuthServiceFactory() override = default;
+};
+
// Convers mojom::ArcSignInFailureReason into ProvisiningResult.
ProvisioningResult ConvertArcSignInFailureReasonToProvisioningResult(
mojom::ArcSignInFailureReason reason) {
@@ -74,6 +97,12 @@
// static
const char ArcAuthService::kArcServiceName[] = "arc::ArcAuthService";
+// static
+ArcAuthService* ArcAuthService::GetForBrowserContext(
+ content::BrowserContext* context) {
+ return ArcAuthServiceFactory::GetForBrowserContext(context);
+}
+
// TODO(lhchavez): Get rid of this class once we can safely remove all the
// deprecated interfaces and only need to care about one type of callback.
class ArcAuthService::AccountInfoNotifier {
@@ -135,9 +164,9 @@
const AccountInfoCallback account_info_callback_;
};
-ArcAuthService::ArcAuthService(Profile* profile,
+ArcAuthService::ArcAuthService(content::BrowserContext* browser_context,
ArcBridgeService* arc_bridge_service)
- : profile_(profile),
+ : profile_(Profile::FromBrowserContext(browser_context)),
arc_bridge_service_(arc_bridge_service),
binding_(this),
weak_ptr_factory_(this) {
diff --git a/chrome/browser/chromeos/arc/auth/arc_auth_service.h b/chrome/browser/chromeos/arc/auth/arc_auth_service.h
index 42d8ffea..08a61c92 100644
--- a/chrome/browser/chromeos/arc/auth/arc_auth_service.h
+++ b/chrome/browser/chromeos/arc/auth/arc_auth_service.h
@@ -18,6 +18,10 @@
class Profile;
+namespace content {
+class BrowserContext;
+} // namespace content
+
namespace arc {
class ArcFetcherBase;
@@ -28,7 +32,12 @@
public mojom::AuthHost,
public InstanceHolder<mojom::AuthInstance>::Observer {
public:
- ArcAuthService(Profile* profile, ArcBridgeService* bridge_service);
+ // Returns singleton instance for the given BrowserContext,
+ // or nullptr if the browser |context| is not allowed to use ARC.
+ static ArcAuthService* GetForBrowserContext(content::BrowserContext* context);
+
+ ArcAuthService(content::BrowserContext* profile,
+ ArcBridgeService* bridge_service);
~ArcAuthService() override;
// For supporting ArcServiceManager::GetService<T>().
diff --git a/chrome/browser/chromeos/arc/auth/arc_auth_service_browsertest.cc b/chrome/browser/chromeos/arc/auth/arc_auth_service_browsertest.cc
index b38b65d5..2889dcd 100644
--- a/chrome/browser/chromeos/arc/auth/arc_auth_service_browsertest.cc
+++ b/chrome/browser/chromeos/arc/auth/arc_auth_service_browsertest.cc
@@ -16,7 +16,6 @@
#include "chrome/browser/chromeos/arc/arc_util.h"
#include "chrome/browser/chromeos/arc/auth/arc_auth_context.h"
#include "chrome/browser/chromeos/arc/auth/arc_auth_service.h"
-#include "chrome/browser/chromeos/arc/auth/arc_auth_service_factory.h"
#include "chrome/browser/chromeos/arc/auth/arc_background_auth_code_fetcher.h"
#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
#include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
@@ -199,7 +198,7 @@
FakeAuthInstance auth_instance;
ArcAuthService* auth_service =
- ArcAuthServiceFactory::GetForBrowserContext(profile());
+ ArcAuthService::GetForBrowserContext(profile());
ASSERT_TRUE(auth_service);
ArcBridgeService* arc_bridge_service =
diff --git a/chrome/browser/chromeos/arc/auth/arc_auth_service_factory.cc b/chrome/browser/chromeos/arc/auth/arc_auth_service_factory.cc
deleted file mode 100644
index 20f766e..0000000
--- a/chrome/browser/chromeos/arc/auth/arc_auth_service_factory.cc
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/chromeos/arc/auth/arc_auth_service_factory.h"
-
-#include "base/logging.h"
-#include "base/memory/singleton.h"
-#include "chrome/browser/chromeos/arc/auth/arc_auth_service.h"
-#include "chrome/browser/profiles/profile.h"
-#include "components/arc/arc_service_manager.h"
-#include "components/keyed_service/content/browser_context_dependency_manager.h"
-
-namespace arc {
-
-ArcAuthService* ArcAuthServiceFactory::GetForBrowserContext(
- content::BrowserContext* context) {
- return static_cast<ArcAuthService*>(
- GetInstance()->GetServiceForBrowserContext(context, true /* create */));
-}
-
-// static
-ArcAuthServiceFactory* ArcAuthServiceFactory::GetInstance() {
- return base::Singleton<ArcAuthServiceFactory>::get();
-}
-
-ArcAuthServiceFactory::ArcAuthServiceFactory()
- : BrowserContextKeyedServiceFactory(
- "ArcAuthServiceFactory",
- BrowserContextDependencyManager::GetInstance()) {}
-
-ArcAuthServiceFactory::~ArcAuthServiceFactory() = default;
-
-KeyedService* ArcAuthServiceFactory::BuildServiceInstanceFor(
- content::BrowserContext* context) const {
- auto* arc_service_manager = arc::ArcServiceManager::Get();
-
- // Practically, this is in testing case.
- if (!arc_service_manager) {
- VLOG(2) << "ArcServiceManager is not available.";
- return nullptr;
- }
-
- if (arc_service_manager->browser_context() != context) {
- VLOG(2) << "Non ARC allowed browser context.";
- return nullptr;
- }
-
- return new ArcAuthService(Profile::FromBrowserContext(context),
- arc_service_manager->arc_bridge_service());
-}
-
-} // namespace arc
diff --git a/chrome/browser/chromeos/arc/auth/arc_auth_service_factory.h b/chrome/browser/chromeos/arc/auth/arc_auth_service_factory.h
deleted file mode 100644
index d7d5c8e..0000000
--- a/chrome/browser/chromeos/arc/auth/arc_auth_service_factory.h
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_CHROMEOS_ARC_AUTH_ARC_AUTH_SERVICE_FACTORY_H_
-#define CHROME_BROWSER_CHROMEOS_ARC_AUTH_ARC_AUTH_SERVICE_FACTORY_H_
-
-#include "base/macros.h"
-#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
-
-namespace base {
-template <typename T>
-struct DefaultSingletonTraits;
-} // namespace base
-
-namespace arc {
-
-class ArcAuthService;
-
-// Factory for ArcAuthService.
-class ArcAuthServiceFactory : public BrowserContextKeyedServiceFactory {
- public:
- // Returns the ArcAuthService for the given |context|,
- // or nullptr if |context| is not allowed to use ARC.
- // If the instance is not yet createad, this creates a new service instance.
- static ArcAuthService* GetForBrowserContext(content::BrowserContext* context);
-
- // Returns the factory instance.
- static ArcAuthServiceFactory* GetInstance();
-
- private:
- friend struct base::DefaultSingletonTraits<ArcAuthServiceFactory>;
-
- ArcAuthServiceFactory();
- ~ArcAuthServiceFactory() override;
-
- // BrowserContextKeyedServiceFactory overrides:
- KeyedService* BuildServiceInstanceFor(
- content::BrowserContext* context) const override;
-
- DISALLOW_COPY_AND_ASSIGN(ArcAuthServiceFactory);
-};
-
-} // namespace arc
-
-#endif // CHROME_BROWSER_CHROMEOS_ARC_AUTH_ARC_AUTH_SERVICE_FACTORY_H_
diff --git a/components/arc/BUILD.gn b/components/arc/BUILD.gn
index f78810a8..5e2bad5 100644
--- a/components/arc/BUILD.gn
+++ b/components/arc/BUILD.gn
@@ -7,8 +7,6 @@
static_library("arc") {
sources = [
- "arc_service_manager.cc",
- "arc_service_manager.h",
"arc_util.cc",
"arc_util.h",
"audio/arc_audio_bridge.cc",
@@ -104,10 +102,13 @@
"arc_bridge_host_impl.h",
"arc_bridge_service.cc",
"arc_bridge_service.h",
+ "arc_browser_context_keyed_service_factory_base.h",
"arc_features.cc",
"arc_features.h",
"arc_service.cc",
"arc_service.h",
+ "arc_service_manager.cc",
+ "arc_service_manager.h",
"arc_session.cc",
"arc_session.h",
"arc_session_runner.cc",
@@ -120,6 +121,7 @@
deps = [
"//base",
"//chromeos",
+ "//components/keyed_service/content",
"//components/user_manager",
"//mojo/edk/system",
]
diff --git a/components/arc/DEPS b/components/arc/DEPS
index 197623b..7ea6dac 100644
--- a/components/arc/DEPS
+++ b/components/arc/DEPS
@@ -4,6 +4,7 @@
"+chromeos/cryptohome",
"+chromeos/dbus",
"+components/exo",
+ "+components/keyed_service",
"+components/prefs",
"+components/signin/core/account_id",
"+components/user_manager",
diff --git a/components/arc/arc_browser_context_keyed_service_factory_base.h b/components/arc/arc_browser_context_keyed_service_factory_base.h
new file mode 100644
index 0000000..f0152a42
--- /dev/null
+++ b/components/arc/arc_browser_context_keyed_service_factory_base.h
@@ -0,0 +1,119 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_ARC_ARC_BROWSER_CONTEXT_KEYED_SERVICE_FACTORY_BASE_H_
+#define COMPONENTS_ARC_ARC_BROWSER_CONTEXT_KEYED_SERVICE_FACTORY_BASE_H_
+
+#include "base/logging.h"
+#include "base/macros.h"
+#include "components/arc/arc_service_manager.h"
+#include "components/keyed_service/content/browser_context_dependency_manager.h"
+#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
+
+namespace content {
+class BrowserContext;
+} // namespace content
+
+namespace arc {
+namespace internal {
+
+// Implementation of BrowserContextKeyedServiceFactory for ARC related
+// services. The ARC related BrowserContextKeyedService can make its factory
+// class derived from this class.
+//
+// How to use:
+// In .h:
+// #include "components/keyed_service/core/keyed_service.h"
+//
+// namespace content {
+// class BrowserContext;
+// } // namespace content
+//
+// class ArcFooService : public KeyedService, ... {
+// public:
+// static ArcFooService* GetForBrowserContext(
+// content::BrowserContext* context);
+//
+// ArcFooService(content::BrowserContext* context,
+// ArcBridgeService* arc_bridge_service);
+// };
+//
+// In .cc:
+//
+// namespace {
+// class ArcFooServiceFactory
+// : public internal::ArcBrowserContextKeyedServiceFactoryBase<
+// ArcFooService,
+// ArcFooServiceFactory> {
+// public:
+// static constexpr const char* kName = "ArcFooServiceFactory";
+//
+// static ArcFooServiceFactory* GetInstance() {
+// return base::Singleton<ArcFooServiceFactory>::get();
+// }
+//
+// private:
+// friend struct base::DefaultSingletonTraits<ArcFooServiceFactory>;
+// ArcFooServiceFactory() = default;
+// ~ArcFooServiceFactory() override = default;
+// };
+// } // namespace
+//
+// ArcFooService* ArcFooService::GetForBrowserContext(
+// content::BrowserContext* context) {
+// return ArcFooServiceFactory::GetForBrowserContext(context);
+// }
+//
+// If the service depends on other KeyedService, DependsOn() can be called in
+// the factory's ctor similar to other BrowserContextKeyedServiceFactory
+// subclasses.
+//
+// This header is intended to be included only from the .cc file directly.
+template <typename Service, typename Factory>
+class ArcBrowserContextKeyedServiceFactoryBase
+ : public BrowserContextKeyedServiceFactory {
+ public:
+ // Returns the instance of the service for the given |context|,
+ // or nullptr if |context| is not allowed to use ARC.
+ // If the instance is not yet created, this creates a new service instance.
+ static Service* GetForBrowserContext(content::BrowserContext* context) {
+ return static_cast<Service*>(
+ Factory::GetInstance()->GetServiceForBrowserContext(context,
+ true /* create */));
+ }
+
+ protected:
+ ArcBrowserContextKeyedServiceFactoryBase()
+ : BrowserContextKeyedServiceFactory(
+ Factory::kName,
+ BrowserContextDependencyManager::GetInstance()) {}
+ ~ArcBrowserContextKeyedServiceFactoryBase() override = default;
+
+ // BrowserContextKeyedServiceFactory override:
+ KeyedService* BuildServiceInstanceFor(
+ content::BrowserContext* context) const override {
+ auto* arc_service_manager = arc::ArcServiceManager::Get();
+
+ // Practically, this is in testing case.
+ if (!arc_service_manager) {
+ VLOG(2) << "ArcServiceManager is not available.";
+ return nullptr;
+ }
+
+ if (arc_service_manager->browser_context() != context) {
+ VLOG(2) << "Non ARC allowed browser context.";
+ return nullptr;
+ }
+
+ return new Service(context, arc_service_manager->arc_bridge_service());
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ArcBrowserContextKeyedServiceFactoryBase);
+};
+
+} // namespace internal
+} // namespace arc
+
+#endif // COMPONENTS_ARC_ARC_BROWSER_CONTEXT_KEYED_SERVICE_FACTORY_BASE_H_
diff --git a/components/arc/arc_service_manager.cc b/components/arc/arc_service_manager.cc
index 3eb7e88..3ecd33b 100644
--- a/components/arc/arc_service_manager.cc
+++ b/components/arc/arc_service_manager.cc
@@ -9,7 +9,6 @@
#include "components/arc/arc_bridge_service.h"
#include "components/arc/arc_session.h"
#include "components/arc/arc_session_runner.h"
-#include "components/arc/intent_helper/arc_intent_helper_observer.h"
namespace arc {
namespace {