4e90429c3732d0537ce0523a1e28513cc726b95c
[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 "components/keyed_service/content/browser_context_dependency_manager.h"
12 #include "extensions/browser/extension_system_provider.h"
13 #include "extensions/browser/extensions_browser_client.h"
14
15 #if defined(OS_CHROMEOS)
16 #include "chrome/browser/chromeos/profiles/profile_helper.h"
17 #endif
18
19 // static
20 EasyUnlockServiceFactory* EasyUnlockServiceFactory::GetInstance() {
21   return Singleton<EasyUnlockServiceFactory>::get();
22 }
23
24 // static
25 EasyUnlockService* EasyUnlockServiceFactory::GetForProfile(Profile* profile) {
26   return static_cast<EasyUnlockService*>(
27       EasyUnlockServiceFactory::GetInstance()->GetServiceForBrowserContext(
28           profile, true));
29 }
30
31 EasyUnlockServiceFactory::EasyUnlockServiceFactory()
32     : BrowserContextKeyedServiceFactory(
33           "EasyUnlockService",
34           BrowserContextDependencyManager::GetInstance()) {
35   DependsOn(
36       extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
37 }
38
39 EasyUnlockServiceFactory::~EasyUnlockServiceFactory() {
40 }
41
42 KeyedService* EasyUnlockServiceFactory::BuildServiceInstanceFor(
43     content::BrowserContext* context) const {
44   return new EasyUnlockService(Profile::FromBrowserContext(context));
45 }
46
47 content::BrowserContext* EasyUnlockServiceFactory::GetBrowserContextToUse(
48       content::BrowserContext* context) const {
49 #if defined(OS_CHROMEOS)
50   if (chromeos::ProfileHelper::IsSigninProfile(
51           Profile::FromBrowserContext(context))) {
52     return NULL;
53   }
54 #endif
55   return chrome::GetBrowserContextRedirectedInIncognito(context);
56 }
57
58 bool EasyUnlockServiceFactory::ServiceIsCreatedWithBrowserContext() const {
59   return true;
60 }
61
62 bool EasyUnlockServiceFactory::ServiceIsNULLWhileTesting() const {
63   // Don't create the service for TestingProfile used in unit_tests because
64   // EasyUnlockService uses ExtensionSystem::ready().Post, which expects
65   // a MessageLoop that does not exit in many unit_tests cases.
66   return true;
67 }