Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / signin / easy_unlock_service_factory.cc
blob5c53d10c874e70e441f537dea37f258f45610dcc
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/memory/singleton.h"
9 #include "chrome/browser/profiles/incognito_helpers.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/signin/easy_unlock_app_manager.h"
12 #include "chrome/browser/signin/easy_unlock_service.h"
13 #include "chrome/browser/signin/easy_unlock_service_regular.h"
14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
15 #include "chrome/browser/signin/signin_manager_factory.h"
16 #include "chrome/common/chrome_switches.h"
17 #include "components/keyed_service/content/browser_context_dependency_manager.h"
18 #include "extensions/browser/extension_system.h"
19 #include "extensions/browser/extension_system_provider.h"
20 #include "extensions/browser/extensions_browser_client.h"
21 #include "grit/browser_resources.h"
23 #if defined(OS_CHROMEOS)
24 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_factory.h"
25 #include "chrome/browser/chromeos/profiles/profile_helper.h"
26 #include "chrome/browser/signin/easy_unlock_service_signin_chromeos.h"
27 #endif
29 namespace {
31 // Gets the file path from which easy unlock app should be loaded.
32 base::FilePath GetEasyUnlockAppPath() {
33 #if defined(GOOGLE_CHROME_BUILD)
34 #ifndef NDEBUG
35 // Only allow app path override switch for debug build.
36 const base::CommandLine* command_line =
37 base::CommandLine::ForCurrentProcess();
38 if (command_line->HasSwitch(switches::kEasyUnlockAppPath))
39 return command_line->GetSwitchValuePath(switches::kEasyUnlockAppPath);
40 #endif // !defined(NDEBUG)
42 #if defined(OS_CHROMEOS)
43 return base::FilePath("/usr/share/chromeos-assets/easy_unlock");
44 #endif // defined(OS_CHROMEOS)
45 #endif // defined(GOOGLE_CHROME_BUILD)
47 return base::FilePath();
50 } // namespace
52 // static
53 EasyUnlockServiceFactory* EasyUnlockServiceFactory::GetInstance() {
54 return Singleton<EasyUnlockServiceFactory>::get();
57 // static
58 EasyUnlockService* EasyUnlockServiceFactory::GetForBrowserContext(
59 content::BrowserContext* browser_context) {
60 return static_cast<EasyUnlockService*>(
61 EasyUnlockServiceFactory::GetInstance()->GetServiceForBrowserContext(
62 browser_context, true));
65 EasyUnlockServiceFactory::EasyUnlockServiceFactory()
66 : BrowserContextKeyedServiceFactory(
67 "EasyUnlockService",
68 BrowserContextDependencyManager::GetInstance()) {
69 DependsOn(
70 extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
71 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
72 DependsOn(SigninManagerFactory::GetInstance());
73 #if defined(OS_CHROMEOS)
74 DependsOn(EasyUnlockTpmKeyManagerFactory::GetInstance());
75 #endif
78 EasyUnlockServiceFactory::~EasyUnlockServiceFactory() {
81 KeyedService* EasyUnlockServiceFactory::BuildServiceInstanceFor(
82 content::BrowserContext* context) const {
83 EasyUnlockService* service = NULL;
84 int manifest_id = 0;
86 #if defined(OS_CHROMEOS)
87 if (chromeos::ProfileHelper::IsSigninProfile(
88 Profile::FromBrowserContext(context))) {
89 if (!EasyUnlockService::IsSignInEnabled() || !context->IsOffTheRecord())
90 return NULL;
92 service = new EasyUnlockServiceSignin(Profile::FromBrowserContext(context));
93 manifest_id = IDR_EASY_UNLOCK_MANIFEST_SIGNIN;
95 #endif
97 if (!service) {
98 service =
99 new EasyUnlockServiceRegular(Profile::FromBrowserContext(context));
100 manifest_id = IDR_EASY_UNLOCK_MANIFEST;
103 const base::FilePath app_path = app_path_for_testing_.empty()
104 ? GetEasyUnlockAppPath()
105 : app_path_for_testing_;
107 service->Initialize(EasyUnlockAppManager::Create(
108 extensions::ExtensionSystem::Get(context), manifest_id, app_path));
109 return service;
112 content::BrowserContext* EasyUnlockServiceFactory::GetBrowserContextToUse(
113 content::BrowserContext* context) const {
114 #if defined(OS_CHROMEOS)
115 if (chromeos::ProfileHelper::IsSigninProfile(
116 Profile::FromBrowserContext(context))) {
117 return chrome::GetBrowserContextOwnInstanceInIncognito(context);
119 #endif
120 return chrome::GetBrowserContextRedirectedInIncognito(context);
123 bool EasyUnlockServiceFactory::ServiceIsCreatedWithBrowserContext() const {
124 return true;
127 bool EasyUnlockServiceFactory::ServiceIsNULLWhileTesting() const {
128 // Don't create the service for TestingProfile used in unit_tests because
129 // EasyUnlockService uses ExtensionSystem::ready().Post, which expects
130 // a MessageLoop that does not exit in many unit_tests cases.
131 return true;