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_service.h"
12 #include "chrome/browser/signin/easy_unlock_service_regular.h"
13 #include "components/keyed_service/content/browser_context_dependency_manager.h"
14 #include "extensions/browser/extension_system_provider.h"
15 #include "extensions/browser/extensions_browser_client.h"
17 #if defined(OS_CHROMEOS)
18 #include "chrome/browser/chromeos/profiles/profile_helper.h"
19 #include "chrome/browser/signin/easy_unlock_service_signin_chromeos.h"
20 #include "chromeos/chromeos_switches.h"
24 EasyUnlockServiceFactory* EasyUnlockServiceFactory::GetInstance() {
25 return Singleton<EasyUnlockServiceFactory>::get();
29 EasyUnlockService* EasyUnlockServiceFactory::GetForProfile(Profile* profile) {
30 return static_cast<EasyUnlockService*>(
31 EasyUnlockServiceFactory::GetInstance()->GetServiceForBrowserContext(
35 EasyUnlockServiceFactory::EasyUnlockServiceFactory()
36 : BrowserContextKeyedServiceFactory(
38 BrowserContextDependencyManager::GetInstance()) {
40 extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
43 EasyUnlockServiceFactory::~EasyUnlockServiceFactory() {
46 KeyedService* EasyUnlockServiceFactory::BuildServiceInstanceFor(
47 content::BrowserContext* context) const {
48 #if defined(OS_CHROMEOS)
49 if (chromeos::ProfileHelper::IsSigninProfile(
50 Profile::FromBrowserContext(context))) {
51 if (CommandLine::ForCurrentProcess()->HasSwitch(
52 chromeos::switches::kEnableEasySignin)) {
53 return new EasyUnlockServiceSignin(Profile::FromBrowserContext(context));
59 return new EasyUnlockServiceRegular(Profile::FromBrowserContext(context));
62 content::BrowserContext* EasyUnlockServiceFactory::GetBrowserContextToUse(
63 content::BrowserContext* context) const {
64 return chrome::GetBrowserContextRedirectedInIncognito(context);
67 bool EasyUnlockServiceFactory::ServiceIsCreatedWithBrowserContext() const {
71 bool EasyUnlockServiceFactory::ServiceIsNULLWhileTesting() const {
72 // Don't create the service for TestingProfile used in unit_tests because
73 // EasyUnlockService uses ExtensionSystem::ready().Post, which expects
74 // a MessageLoop that does not exit in many unit_tests cases.