Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 5 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/incognito_helpers.h" | 7 #include "chrome/browser/profiles/incognito_helpers.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 9 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 10 #include "chrome/browser/supervised_user/supervised_user_service.h" | 10 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 11 #include "chrome/browser/sync/profile_sync_service_factory.h" | 11 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 12 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 12 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 13 #include "extensions/features/features.h" | 13 #include "extensions/features/features.h" |
| 14 | 14 |
| 15 #if BUILDFLAG(ENABLE_EXTENSIONS) | 15 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 16 #include "extensions/browser/extension_system_provider.h" | 16 #include "extensions/browser/extension_system_provider.h" |
| 17 #include "extensions/browser/extensions_browser_client.h" | 17 #include "extensions/browser/extensions_browser_client.h" |
| 18 #endif | 18 #endif |
| 19 | 19 |
| 20 // static | 20 // static |
| 21 SupervisedUserService* SupervisedUserServiceFactory::GetForProfile( | 21 SupervisedUserService* SupervisedUserServiceFactory::GetForProfile( |
| 22 Profile* profile) { | 22 Profile* profile) { |
| 23 return static_cast<SupervisedUserService*>( | 23 return static_cast<SupervisedUserService*>( |
| 24 GetInstance()->GetServiceForBrowserContext(profile, true)); | 24 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 25 } | 25 } |
| 26 | 26 |
| 27 // static | 27 // static |
| 28 SupervisedUserService* SupervisedUserServiceFactory::GetForProfileIfExists( | |
| 29 Profile* profile) { | |
| 30 return static_cast<SupervisedUserService*>( | |
| 31 GetInstance()->GetServiceForBrowserContext(profile, false /* create */)); | |
|
Marc Treib
2017/05/08 08:14:13
nit: Prefer
/*create=*/true
because some tools suc
rishiag
2017/05/08 17:55:14
Done.
| |
| 32 } | |
| 33 | |
| 34 // static | |
| 28 SupervisedUserServiceFactory* SupervisedUserServiceFactory::GetInstance() { | 35 SupervisedUserServiceFactory* SupervisedUserServiceFactory::GetInstance() { |
| 29 return base::Singleton<SupervisedUserServiceFactory>::get(); | 36 return base::Singleton<SupervisedUserServiceFactory>::get(); |
| 30 } | 37 } |
| 31 | 38 |
| 32 // static | 39 // static |
| 33 KeyedService* SupervisedUserServiceFactory::BuildInstanceFor(Profile* profile) { | 40 KeyedService* SupervisedUserServiceFactory::BuildInstanceFor(Profile* profile) { |
| 34 return new SupervisedUserService(profile); | 41 return new SupervisedUserService(profile); |
| 35 } | 42 } |
| 36 | 43 |
| 37 SupervisedUserServiceFactory::SupervisedUserServiceFactory() | 44 SupervisedUserServiceFactory::SupervisedUserServiceFactory() |
| 38 : BrowserContextKeyedServiceFactory( | 45 : BrowserContextKeyedServiceFactory( |
| 39 "SupervisedUserService", | 46 "SupervisedUserService", |
| 40 BrowserContextDependencyManager::GetInstance()) { | 47 BrowserContextDependencyManager::GetInstance()) { |
| 41 #if BUILDFLAG(ENABLE_EXTENSIONS) | 48 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 42 DependsOn( | 49 DependsOn( |
| 43 extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); | 50 extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); |
| 44 #endif | 51 #endif |
| 45 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); | 52 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); |
| 46 | |
| 47 // TODO(skym, crbug.com/705545): Fix this circular dependency. | |
| 48 DependsOn(ProfileSyncServiceFactory::GetInstance()); | 53 DependsOn(ProfileSyncServiceFactory::GetInstance()); |
| 49 } | 54 } |
| 50 | 55 |
| 51 SupervisedUserServiceFactory::~SupervisedUserServiceFactory() {} | 56 SupervisedUserServiceFactory::~SupervisedUserServiceFactory() {} |
| 52 | 57 |
| 53 content::BrowserContext* SupervisedUserServiceFactory::GetBrowserContextToUse( | 58 content::BrowserContext* SupervisedUserServiceFactory::GetBrowserContextToUse( |
| 54 content::BrowserContext* context) const { | 59 content::BrowserContext* context) const { |
| 55 return chrome::GetBrowserContextRedirectedInIncognito(context); | 60 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 56 } | 61 } |
| 57 | 62 |
| 58 KeyedService* SupervisedUserServiceFactory::BuildServiceInstanceFor( | 63 KeyedService* SupervisedUserServiceFactory::BuildServiceInstanceFor( |
| 59 content::BrowserContext* profile) const { | 64 content::BrowserContext* profile) const { |
| 60 return BuildInstanceFor(static_cast<Profile*>(profile)); | 65 return BuildInstanceFor(static_cast<Profile*>(profile)); |
| 61 } | 66 } |
| OLD | NEW |