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/memory/singleton.h"
8 #include "chrome/browser/profiles/incognito_helpers.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/signin/easy_unlock_service.h"
11 #include "chrome/browser/signin/easy_unlock_service_regular.h"
12 #include "components/keyed_service/content/browser_context_dependency_manager.h"
13 #include "extensions/browser/extension_system_provider.h"
14 #include "extensions/browser/extensions_browser_client.h"
16 #if defined(OS_CHROMEOS)
17 #include "chrome/browser/chromeos/profiles/profile_helper.h"
18 #include "chrome/browser/signin/easy_unlock_service_signin_chromeos.h"
22 EasyUnlockServiceFactory
* EasyUnlockServiceFactory::GetInstance() {
23 return Singleton
<EasyUnlockServiceFactory
>::get();
27 EasyUnlockService
* EasyUnlockServiceFactory::GetForProfile(Profile
* profile
) {
28 return static_cast<EasyUnlockService
*>(
29 EasyUnlockServiceFactory::GetInstance()->GetServiceForBrowserContext(
33 EasyUnlockServiceFactory::EasyUnlockServiceFactory()
34 : BrowserContextKeyedServiceFactory(
36 BrowserContextDependencyManager::GetInstance()) {
38 extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
41 EasyUnlockServiceFactory::~EasyUnlockServiceFactory() {
44 KeyedService
* EasyUnlockServiceFactory::BuildServiceInstanceFor(
45 content::BrowserContext
* context
) const {
46 #if defined(OS_CHROMEOS)
47 if (chromeos::ProfileHelper::IsSigninProfile(
48 Profile::FromBrowserContext(context
))) {
49 if (EasyUnlockService::IsSignInEnabled()) {
50 return new EasyUnlockServiceSignin(Profile::FromBrowserContext(context
));
56 return new EasyUnlockServiceRegular(Profile::FromBrowserContext(context
));
59 content::BrowserContext
* EasyUnlockServiceFactory::GetBrowserContextToUse(
60 content::BrowserContext
* context
) const {
61 return chrome::GetBrowserContextRedirectedInIncognito(context
);
64 bool EasyUnlockServiceFactory::ServiceIsCreatedWithBrowserContext() const {
68 bool EasyUnlockServiceFactory::ServiceIsNULLWhileTesting() const {
69 // Don't create the service for TestingProfile used in unit_tests because
70 // EasyUnlockService uses ExtensionSystem::ready().Post, which expects
71 // a MessageLoop that does not exit in many unit_tests cases.