Commit e665e3f7 authored by Hidehiko Abe's avatar Hidehiko Abe Committed by Commit Bot

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/569847Reviewed-by: default avatarPaweł Hajdan Jr. <phajdan.jr@chromium.org>
Reviewed-by: default avatarLuis Hector Chavez <lhchavez@chromium.org>
Reviewed-by: default avatarYusuke Sato <yusukes@chromium.org>
Commit-Queue: Hidehiko Abe <hidehiko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#486759}
parent b8dacd14
...@@ -282,8 +282,6 @@ source_set("chromeos") { ...@@ -282,8 +282,6 @@ source_set("chromeos") {
"app_mode/startup_app_launcher.h", "app_mode/startup_app_launcher.h",
"arc/accessibility/arc_accessibility_helper_bridge.cc", "arc/accessibility/arc_accessibility_helper_bridge.cc",
"arc/accessibility/arc_accessibility_helper_bridge.h", "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.cc",
"arc/accessibility/ax_tree_source_arc.h", "arc/accessibility/ax_tree_source_arc.h",
"arc/arc_auth_notification.cc", "arc/arc_auth_notification.cc",
...@@ -310,8 +308,6 @@ source_set("chromeos") { ...@@ -310,8 +308,6 @@ source_set("chromeos") {
"arc/auth/arc_auth_context.h", "arc/auth/arc_auth_context.h",
"arc/auth/arc_auth_service.cc", "arc/auth/arc_auth_service.cc",
"arc/auth/arc_auth_service.h", "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.cc",
"arc/auth/arc_background_auth_code_fetcher.h", "arc/auth/arc_background_auth_code_fetcher.h",
"arc/auth/arc_fetcher_base.h", "arc/auth/arc_fetcher_base.h",
......
...@@ -7,10 +7,13 @@ ...@@ -7,10 +7,13 @@
#include <utility> #include <utility>
#include "base/command_line.h" #include "base/command_line.h"
#include "base/memory/singleton.h"
#include "chrome/browser/chromeos/accessibility/accessibility_manager.h" #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
#include "chrome/browser/profiles/profile.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 "chromeos/chromeos_switches.h"
#include "components/arc/arc_bridge_service.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/arc/arc_service_manager.h"
#include "components/exo/shell_surface.h" #include "components/exo/shell_surface.h"
#include "components/exo/surface.h" #include "components/exo/surface.h"
...@@ -96,10 +99,47 @@ arc::mojom::AccessibilityFilterType GetFilterTypeForProfile(Profile* profile) { ...@@ -96,10 +99,47 @@ arc::mojom::AccessibilityFilterType GetFilterTypeForProfile(Profile* profile) {
namespace arc { 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( ArcAccessibilityHelperBridge::ArcAccessibilityHelperBridge(
Profile* profile, content::BrowserContext* browser_context,
ArcBridgeService* arc_bridge_service) ArcBridgeService* arc_bridge_service)
: profile_(profile), : profile_(Profile::FromBrowserContext(browser_context)),
arc_bridge_service_(arc_bridge_service), arc_bridge_service_(arc_bridge_service),
binding_(this), binding_(this),
current_task_id_(kNoTaskId) { current_task_id_(kNoTaskId) {
......
...@@ -21,6 +21,10 @@ ...@@ -21,6 +21,10 @@
class Profile; class Profile;
namespace content {
class BrowserContext;
} // namespace content
namespace arc { namespace arc {
class AXTreeSourceArc; class AXTreeSourceArc;
...@@ -37,7 +41,12 @@ class ArcAccessibilityHelperBridge ...@@ -37,7 +41,12 @@ class ArcAccessibilityHelperBridge
public AXTreeSourceArc::Delegate, public AXTreeSourceArc::Delegate,
public ArcAppListPrefs::Observer { public ArcAppListPrefs::Observer {
public: 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); ArcBridgeService* arc_bridge_service);
~ArcAccessibilityHelperBridge() override; ~ArcAccessibilityHelperBridge() override;
......
// 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
// 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_
...@@ -10,11 +10,11 @@ ...@@ -10,11 +10,11 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service.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_play_store_enabled_preference_handler.h"
#include "chrome/browser/chromeos/arc/arc_session_manager.h" #include "chrome/browser/chromeos/arc/arc_session_manager.h"
#include "chrome/browser/chromeos/arc/arc_util.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/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/downloads_watcher/arc_downloads_watcher_service.h"
#include "chrome/browser/chromeos/arc/enterprise/arc_enterprise_reporting_service.h" #include "chrome/browser/chromeos/arc/enterprise/arc_enterprise_reporting_service.h"
...@@ -196,9 +196,12 @@ void ArcServiceLauncher::OnPrimaryUserProfilePrepared(Profile* profile) { ...@@ -196,9 +196,12 @@ void ArcServiceLauncher::OnPrimaryUserProfilePrepared(Profile* profile) {
// Instantiate ARC related BrowserContextKeyedService classes which need // Instantiate ARC related BrowserContextKeyedService classes which need
// to be running at the beginning of the container run. // 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. // List in lexicographical order.
ArcAccessibilityHelperBridgeFactory::GetForBrowserContext(profile); ArcAccessibilityHelperBridge::GetForBrowserContext(profile);
ArcAuthServiceFactory::GetForBrowserContext(profile); ArcAuthService::GetForBrowserContext(profile);
arc_service_manager_->AddService(base::MakeUnique<ArcBootPhaseMonitorBridge>( arc_service_manager_->AddService(base::MakeUnique<ArcBootPhaseMonitorBridge>(
arc_service_manager_->arc_bridge_service(), arc_service_manager_->arc_bridge_service(),
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/memory/singleton.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/chromeos/arc/arc_optin_uma.h" #include "chrome/browser/chromeos/arc/arc_optin_uma.h"
#include "chrome/browser/chromeos/arc/arc_session_manager.h" #include "chrome/browser/chromeos/arc/arc_session_manager.h"
...@@ -21,6 +22,7 @@ ...@@ -21,6 +22,7 @@
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chromeos/chromeos_switches.h" #include "chromeos/chromeos_switches.h"
#include "components/arc/arc_bridge_service.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_features.h"
#include "components/arc/arc_service_manager.h" #include "components/arc/arc_service_manager.h"
#include "components/arc/arc_util.h" #include "components/arc/arc_util.h"
...@@ -29,8 +31,29 @@ ...@@ -29,8 +31,29 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
namespace arc { namespace arc {
namespace { 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. // Convers mojom::ArcSignInFailureReason into ProvisiningResult.
ProvisioningResult ConvertArcSignInFailureReasonToProvisioningResult( ProvisioningResult ConvertArcSignInFailureReasonToProvisioningResult(
mojom::ArcSignInFailureReason reason) { mojom::ArcSignInFailureReason reason) {
...@@ -74,6 +97,12 @@ mojom::ChromeAccountType GetAccountType() { ...@@ -74,6 +97,12 @@ mojom::ChromeAccountType GetAccountType() {
// static // static
const char ArcAuthService::kArcServiceName[] = "arc::ArcAuthService"; 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 // 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. // deprecated interfaces and only need to care about one type of callback.
class ArcAuthService::AccountInfoNotifier { class ArcAuthService::AccountInfoNotifier {
...@@ -135,9 +164,9 @@ class ArcAuthService::AccountInfoNotifier { ...@@ -135,9 +164,9 @@ class ArcAuthService::AccountInfoNotifier {
const AccountInfoCallback account_info_callback_; const AccountInfoCallback account_info_callback_;
}; };
ArcAuthService::ArcAuthService(Profile* profile, ArcAuthService::ArcAuthService(content::BrowserContext* browser_context,
ArcBridgeService* arc_bridge_service) ArcBridgeService* arc_bridge_service)
: profile_(profile), : profile_(Profile::FromBrowserContext(browser_context)),
arc_bridge_service_(arc_bridge_service), arc_bridge_service_(arc_bridge_service),
binding_(this), binding_(this),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
......
...@@ -18,6 +18,10 @@ ...@@ -18,6 +18,10 @@
class Profile; class Profile;
namespace content {
class BrowserContext;
} // namespace content
namespace arc { namespace arc {
class ArcFetcherBase; class ArcFetcherBase;
...@@ -28,7 +32,12 @@ class ArcAuthService : public KeyedService, ...@@ -28,7 +32,12 @@ class ArcAuthService : public KeyedService,
public mojom::AuthHost, public mojom::AuthHost,
public InstanceHolder<mojom::AuthInstance>::Observer { public InstanceHolder<mojom::AuthInstance>::Observer {
public: 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; ~ArcAuthService() override;
// For supporting ArcServiceManager::GetService<T>(). // For supporting ArcServiceManager::GetService<T>().
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "chrome/browser/chromeos/arc/arc_util.h" #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_context.h"
#include "chrome/browser/chromeos/arc/auth/arc_auth_service.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/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/fake_chrome_user_manager.h"
#include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
...@@ -199,7 +198,7 @@ IN_PROC_BROWSER_TEST_F(ArcAuthServiceTest, SuccessfulBackgroundFetch) { ...@@ -199,7 +198,7 @@ IN_PROC_BROWSER_TEST_F(ArcAuthServiceTest, SuccessfulBackgroundFetch) {
FakeAuthInstance auth_instance; FakeAuthInstance auth_instance;
ArcAuthService* auth_service = ArcAuthService* auth_service =
ArcAuthServiceFactory::GetForBrowserContext(profile()); ArcAuthService::GetForBrowserContext(profile());
ASSERT_TRUE(auth_service); ASSERT_TRUE(auth_service);
ArcBridgeService* arc_bridge_service = ArcBridgeService* arc_bridge_service =
......
// 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
// 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_
...@@ -7,8 +7,6 @@ import("//testing/test.gni") ...@@ -7,8 +7,6 @@ import("//testing/test.gni")
static_library("arc") { static_library("arc") {
sources = [ sources = [
"arc_service_manager.cc",
"arc_service_manager.h",
"arc_util.cc", "arc_util.cc",
"arc_util.h", "arc_util.h",
"audio/arc_audio_bridge.cc", "audio/arc_audio_bridge.cc",
...@@ -104,10 +102,13 @@ static_library("arc_base") { ...@@ -104,10 +102,13 @@ static_library("arc_base") {
"arc_bridge_host_impl.h", "arc_bridge_host_impl.h",
"arc_bridge_service.cc", "arc_bridge_service.cc",
"arc_bridge_service.h", "arc_bridge_service.h",
"arc_browser_context_keyed_service_factory_base.h",
"arc_features.cc", "arc_features.cc",
"arc_features.h", "arc_features.h",
"arc_service.cc", "arc_service.cc",
"arc_service.h", "arc_service.h",
"arc_service_manager.cc",
"arc_service_manager.h",
"arc_session.cc", "arc_session.cc",
"arc_session.h", "arc_session.h",
"arc_session_runner.cc", "arc_session_runner.cc",
...@@ -120,6 +121,7 @@ static_library("arc_base") { ...@@ -120,6 +121,7 @@ static_library("arc_base") {
deps = [ deps = [
"//base", "//base",
"//chromeos", "//chromeos",
"//components/keyed_service/content",
"//components/user_manager", "//components/user_manager",
"//mojo/edk/system", "//mojo/edk/system",
] ]
......
...@@ -4,6 +4,7 @@ include_rules = [ ...@@ -4,6 +4,7 @@ include_rules = [
"+chromeos/cryptohome", "+chromeos/cryptohome",
"+chromeos/dbus", "+chromeos/dbus",
"+components/exo", "+components/exo",
"+components/keyed_service",
"+components/prefs", "+components/prefs",
"+components/signin/core/account_id", "+components/signin/core/account_id",
"+components/user_manager", "+components/user_manager",
......
// 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_
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "components/arc/arc_bridge_service.h" #include "components/arc/arc_bridge_service.h"
#include "components/arc/arc_session.h" #include "components/arc/arc_session.h"
#include "components/arc/arc_session_runner.h" #include "components/arc/arc_session_runner.h"
#include "components/arc/intent_helper/arc_intent_helper_observer.h"
namespace arc { namespace arc {
namespace { namespace {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment