Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / signin / easy_unlock_service_factory.cc
blob47d89bdf8ef5d5c0df0dd7fd2202f2d821994691
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"
19 #endif
21 // static
22 EasyUnlockServiceFactory* EasyUnlockServiceFactory::GetInstance() {
23 return Singleton<EasyUnlockServiceFactory>::get();
26 // static
27 EasyUnlockService* EasyUnlockServiceFactory::GetForProfile(Profile* profile) {
28 return static_cast<EasyUnlockService*>(
29 EasyUnlockServiceFactory::GetInstance()->GetServiceForBrowserContext(
30 profile, true));
33 EasyUnlockServiceFactory::EasyUnlockServiceFactory()
34 : BrowserContextKeyedServiceFactory(
35 "EasyUnlockService",
36 BrowserContextDependencyManager::GetInstance()) {
37 DependsOn(
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));
51 } else {
52 return NULL;
55 #endif
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 {
65 return true;
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;