Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / signin / easy_unlock_service_factory.cc
blob771e38da1d8876700e8bd56fd9ef5a8f588af111
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/common/chrome_switches.h"
15 #include "components/keyed_service/content/browser_context_dependency_manager.h"
16 #include "extensions/browser/extension_system.h"
17 #include "extensions/browser/extension_system_provider.h"
18 #include "extensions/browser/extensions_browser_client.h"
19 #include "grit/browser_resources.h"
21 #if defined(OS_CHROMEOS)
22 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_factory.h"
23 #include "chrome/browser/chromeos/profiles/profile_helper.h"
24 #include "chrome/browser/signin/easy_unlock_service_signin_chromeos.h"
25 #endif
27 namespace {
29 // Gets the file path from which easy unlock app should be loaded.
30 base::FilePath GetEasyUnlockAppPath() {
31 #if defined(GOOGLE_CHROME_BUILD)
32 #ifndef NDEBUG
33 // Only allow app path override switch for debug build.
34 const base::CommandLine* command_line =
35 base::CommandLine::ForCurrentProcess();
36 if (command_line->HasSwitch(switches::kEasyUnlockAppPath))
37 return command_line->GetSwitchValuePath(switches::kEasyUnlockAppPath);
38 #endif // !defined(NDEBUG)
40 #if defined(OS_CHROMEOS)
41 return base::FilePath("/usr/share/chromeos-assets/easy_unlock");
42 #endif // defined(OS_CHROMEOS)
43 #endif // defined(GOOGLE_CHROME_BUILD)
45 return base::FilePath();
48 } // namespace
50 // static
51 EasyUnlockServiceFactory* EasyUnlockServiceFactory::GetInstance() {
52 return Singleton<EasyUnlockServiceFactory>::get();
55 // static
56 EasyUnlockService* EasyUnlockServiceFactory::GetForProfile(Profile* profile) {
57 return static_cast<EasyUnlockService*>(
58 EasyUnlockServiceFactory::GetInstance()->GetServiceForBrowserContext(
59 profile, true));
62 EasyUnlockServiceFactory::EasyUnlockServiceFactory()
63 : BrowserContextKeyedServiceFactory(
64 "EasyUnlockService",
65 BrowserContextDependencyManager::GetInstance()) {
66 DependsOn(
67 extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
68 #if defined(OS_CHROMEOS)
69 DependsOn(EasyUnlockTpmKeyManagerFactory::GetInstance());
70 #endif
73 EasyUnlockServiceFactory::~EasyUnlockServiceFactory() {
76 KeyedService* EasyUnlockServiceFactory::BuildServiceInstanceFor(
77 content::BrowserContext* context) const {
78 EasyUnlockService* service = NULL;
79 int manifest_id = 0;
81 #if defined(OS_CHROMEOS)
82 if (chromeos::ProfileHelper::IsSigninProfile(
83 Profile::FromBrowserContext(context))) {
84 if (!EasyUnlockService::IsSignInEnabled() || !context->IsOffTheRecord())
85 return NULL;
87 service = new EasyUnlockServiceSignin(Profile::FromBrowserContext(context));
88 manifest_id = IDR_EASY_UNLOCK_MANIFEST_SIGNIN;
90 #endif
92 if (!service) {
93 service =
94 new EasyUnlockServiceRegular(Profile::FromBrowserContext(context));
95 manifest_id = IDR_EASY_UNLOCK_MANIFEST;
98 const base::FilePath app_path = app_path_for_testing_.empty()
99 ? GetEasyUnlockAppPath()
100 : app_path_for_testing_;
102 service->Initialize(EasyUnlockAppManager::Create(
103 extensions::ExtensionSystem::Get(context), manifest_id, app_path));
104 return service;
107 content::BrowserContext* EasyUnlockServiceFactory::GetBrowserContextToUse(
108 content::BrowserContext* context) const {
109 #if defined(OS_CHROMEOS)
110 if (chromeos::ProfileHelper::IsSigninProfile(
111 Profile::FromBrowserContext(context))) {
112 return chrome::GetBrowserContextOwnInstanceInIncognito(context);
114 #endif
115 return chrome::GetBrowserContextRedirectedInIncognito(context);
118 bool EasyUnlockServiceFactory::ServiceIsCreatedWithBrowserContext() const {
119 return true;
122 bool EasyUnlockServiceFactory::ServiceIsNULLWhileTesting() const {
123 // Don't create the service for TestingProfile used in unit_tests because
124 // EasyUnlockService uses ExtensionSystem::ready().Post, which expects
125 // a MessageLoop that does not exit in many unit_tests cases.
126 return true;