47d89bdf8ef5d5c0df0dd7fd2202f2d821994691
[platform/framework/web/crosswalk.git] / src / chrome / browser / signin / easy_unlock_service_factory.cc
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.
4
5 #include "chrome/browser/signin/easy_unlock_service_factory.h"
6
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"
15
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"
19 #endif
20
21 // static
22 EasyUnlockServiceFactory* EasyUnlockServiceFactory::GetInstance() {
23   return Singleton<EasyUnlockServiceFactory>::get();
24 }
25
26 // static
27 EasyUnlockService* EasyUnlockServiceFactory::GetForProfile(Profile* profile) {
28   return static_cast<EasyUnlockService*>(
29       EasyUnlockServiceFactory::GetInstance()->GetServiceForBrowserContext(
30           profile, true));
31 }
32
33 EasyUnlockServiceFactory::EasyUnlockServiceFactory()
34     : BrowserContextKeyedServiceFactory(
35           "EasyUnlockService",
36           BrowserContextDependencyManager::GetInstance()) {
37   DependsOn(
38       extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
39 }
40
41 EasyUnlockServiceFactory::~EasyUnlockServiceFactory() {
42 }
43
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));
51     } else {
52       return NULL;
53     }
54   }
55 #endif
56   return new EasyUnlockServiceRegular(Profile::FromBrowserContext(context));
57 }
58
59 content::BrowserContext* EasyUnlockServiceFactory::GetBrowserContextToUse(
60       content::BrowserContext* context) const {
61   return chrome::GetBrowserContextRedirectedInIncognito(context);
62 }
63
64 bool EasyUnlockServiceFactory::ServiceIsCreatedWithBrowserContext() const {
65   return true;
66 }
67
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.
72   return true;
73 }