Upstream version 10.39.225.0
[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/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"
16
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"
21 #endif
22
23 // static
24 EasyUnlockServiceFactory* EasyUnlockServiceFactory::GetInstance() {
25   return Singleton<EasyUnlockServiceFactory>::get();
26 }
27
28 // static
29 EasyUnlockService* EasyUnlockServiceFactory::GetForProfile(Profile* profile) {
30   return static_cast<EasyUnlockService*>(
31       EasyUnlockServiceFactory::GetInstance()->GetServiceForBrowserContext(
32           profile, true));
33 }
34
35 EasyUnlockServiceFactory::EasyUnlockServiceFactory()
36     : BrowserContextKeyedServiceFactory(
37           "EasyUnlockService",
38           BrowserContextDependencyManager::GetInstance()) {
39   DependsOn(
40       extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
41 }
42
43 EasyUnlockServiceFactory::~EasyUnlockServiceFactory() {
44 }
45
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));
54     } else {
55       return NULL;
56     }
57   }
58 #endif
59   return new EasyUnlockServiceRegular(Profile::FromBrowserContext(context));
60 }
61
62 content::BrowserContext* EasyUnlockServiceFactory::GetBrowserContextToUse(
63       content::BrowserContext* context) const {
64   return chrome::GetBrowserContextRedirectedInIncognito(context);
65 }
66
67 bool EasyUnlockServiceFactory::ServiceIsCreatedWithBrowserContext() const {
68   return true;
69 }
70
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.
75   return true;
76 }