ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / signin / easy_unlock_service_factory.cc
blob1bb3156074567c8f294c33ec65214af3e3930ece
1 // Copyright 2014 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.
5 #include "chrome/browser/signin/easy_unlock_service_factory.h"
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/memory/singleton.h"
10 #include "chrome/browser/profiles/incognito_helpers.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/signin/easy_unlock_app_manager.h"
13 #include "chrome/browser/signin/easy_unlock_service.h"
14 #include "chrome/browser/signin/easy_unlock_service_regular.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "components/keyed_service/content/browser_context_dependency_manager.h"
17 #include "extensions/browser/extension_system.h"
18 #include "extensions/browser/extension_system_provider.h"
19 #include "extensions/browser/extensions_browser_client.h"
20 #include "grit/browser_resources.h"
22 #if defined(OS_CHROMEOS)
23 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_factory.h"
24 #include "chrome/browser/chromeos/profiles/profile_helper.h"
25 #include "chrome/browser/signin/easy_unlock_service_signin_chromeos.h"
26 #endif
28 namespace {
30 // Gets the file path from which easy unlock app should be loaded.
31 base::FilePath GetEasyUnlockAppPath() {
32 #if defined(GOOGLE_CHROME_BUILD)
33 #ifndef NDEBUG
34 // Only allow app path override switch for debug build.
35 const base::CommandLine* command_line =
36 base::CommandLine::ForCurrentProcess();
37 if (command_line->HasSwitch(switches::kEasyUnlockAppPath))
38 return command_line->GetSwitchValuePath(switches::kEasyUnlockAppPath);
39 #endif // !defined(NDEBUG)
41 #if defined(OS_CHROMEOS)
42 return base::FilePath("/usr/share/chromeos-assets/easy_unlock");
43 #endif // defined(OS_CHROMEOS)
44 #endif // defined(GOOGLE_CHROME_BUILD)
46 return base::FilePath();
49 } // namespace
51 // static
52 EasyUnlockServiceFactory* EasyUnlockServiceFactory::GetInstance() {
53 return Singleton<EasyUnlockServiceFactory>::get();
56 // static
57 EasyUnlockService* EasyUnlockServiceFactory::GetForProfile(Profile* profile) {
58 return static_cast<EasyUnlockService*>(
59 EasyUnlockServiceFactory::GetInstance()->GetServiceForBrowserContext(
60 profile, true));
63 EasyUnlockServiceFactory::EasyUnlockServiceFactory()
64 : BrowserContextKeyedServiceFactory(
65 "EasyUnlockService",
66 BrowserContextDependencyManager::GetInstance()) {
67 DependsOn(
68 extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
69 #if defined(OS_CHROMEOS)
70 DependsOn(EasyUnlockTpmKeyManagerFactory::GetInstance());
71 #endif
74 EasyUnlockServiceFactory::~EasyUnlockServiceFactory() {
77 KeyedService* EasyUnlockServiceFactory::BuildServiceInstanceFor(
78 content::BrowserContext* context) const {
79 EasyUnlockService* service = NULL;
80 int manifest_id = 0;
82 #if defined(OS_CHROMEOS)
83 if (chromeos::ProfileHelper::IsSigninProfile(
84 Profile::FromBrowserContext(context))) {
85 if (!EasyUnlockService::IsSignInEnabled() || !context->IsOffTheRecord())
86 return NULL;
88 service = new EasyUnlockServiceSignin(Profile::FromBrowserContext(context));
89 manifest_id = IDR_EASY_UNLOCK_MANIFEST_SIGNIN;
91 #endif
93 if (!service) {
94 service =
95 new EasyUnlockServiceRegular(Profile::FromBrowserContext(context));
96 manifest_id = IDR_EASY_UNLOCK_MANIFEST;
99 service->Initialize(
100 EasyUnlockAppManager::Create(extensions::ExtensionSystem::Get(context),
101 manifest_id, GetEasyUnlockAppPath()));
102 return service;
105 content::BrowserContext* EasyUnlockServiceFactory::GetBrowserContextToUse(
106 content::BrowserContext* context) const {
107 #if defined(OS_CHROMEOS)
108 if (chromeos::ProfileHelper::IsSigninProfile(
109 Profile::FromBrowserContext(context))) {
110 return chrome::GetBrowserContextOwnInstanceInIncognito(context);
112 #endif
113 return chrome::GetBrowserContextRedirectedInIncognito(context);
116 bool EasyUnlockServiceFactory::ServiceIsCreatedWithBrowserContext() const {
117 return true;
120 bool EasyUnlockServiceFactory::ServiceIsNULLWhileTesting() const {
121 // Don't create the service for TestingProfile used in unit_tests because
122 // EasyUnlockService uses ExtensionSystem::ready().Post, which expects
123 // a MessageLoop that does not exit in many unit_tests cases.
124 return true;