OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/services/gcm/gcm_profile_service_factory.h" | 5 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "chrome/browser/profiles/incognito_helpers.h" | 8 #include "chrome/browser/profiles/incognito_helpers.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/services/gcm/gcm_profile_service.h" | 10 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
12 #include "chrome/browser/signin/signin_manager_factory.h" | 12 #include "chrome/browser/signin/signin_manager_factory.h" |
13 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 13 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
14 | 14 |
15 #if !defined(OS_ANDROID) | 15 #if !defined(OS_ANDROID) |
16 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 16 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
17 #include "components/gcm_driver/gcm_client_factory.h" | 17 #include "components/gcm_driver/gcm_client_factory.h" |
18 #endif | 18 #endif |
19 | 19 |
20 namespace gcm { | 20 namespace gcm { |
21 namespace { | |
22 BrowserContextKeyedServiceFactory::TestingFactoryFunction | |
23 global_testing_factory = NULL; | |
Peter Beverloo
2015/03/03 15:54:18
nit: g_testing_factory
| |
24 } | |
21 | 25 |
22 // static | 26 // static |
23 GCMProfileService* GCMProfileServiceFactory::GetForProfile( | 27 GCMProfileService* GCMProfileServiceFactory::GetForProfile( |
24 content::BrowserContext* profile) { | 28 content::BrowserContext* profile) { |
25 // GCM is not supported in incognito mode. | 29 // GCM is not supported in incognito mode. |
26 if (profile->IsOffTheRecord()) | 30 if (profile->IsOffTheRecord()) |
27 return NULL; | 31 return NULL; |
28 | 32 |
29 return static_cast<GCMProfileService*>( | 33 return static_cast<GCMProfileService*>( |
30 GetInstance()->GetServiceForBrowserContext(profile, true)); | 34 GetInstance()->GetServiceForBrowserContext(profile, true)); |
31 } | 35 } |
32 | 36 |
33 // static | 37 // static |
34 GCMProfileServiceFactory* GCMProfileServiceFactory::GetInstance() { | 38 GCMProfileServiceFactory* GCMProfileServiceFactory::GetInstance() { |
35 return Singleton<GCMProfileServiceFactory>::get(); | 39 return Singleton<GCMProfileServiceFactory>::get(); |
36 } | 40 } |
37 | 41 |
42 // static | |
43 void GCMProfileServiceFactory::SetGlobalTestingFactory( | |
44 GCMProfileServiceFactory::TestingFactoryFunction factory) { | |
45 global_testing_factory = factory; | |
46 } | |
47 | |
38 GCMProfileServiceFactory::GCMProfileServiceFactory() | 48 GCMProfileServiceFactory::GCMProfileServiceFactory() |
39 : BrowserContextKeyedServiceFactory( | 49 : BrowserContextKeyedServiceFactory( |
40 "GCMProfileService", | 50 "GCMProfileService", |
41 BrowserContextDependencyManager::GetInstance()) { | 51 BrowserContextDependencyManager::GetInstance()) { |
42 DependsOn(SigninManagerFactory::GetInstance()); | 52 DependsOn(SigninManagerFactory::GetInstance()); |
43 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); | 53 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); |
44 #if !defined(OS_ANDROID) | 54 #if !defined(OS_ANDROID) |
45 DependsOn(LoginUIServiceFactory::GetInstance()); | 55 DependsOn(LoginUIServiceFactory::GetInstance()); |
46 #endif | 56 #endif |
47 } | 57 } |
48 | 58 |
49 GCMProfileServiceFactory::~GCMProfileServiceFactory() { | 59 GCMProfileServiceFactory::~GCMProfileServiceFactory() { |
50 } | 60 } |
51 | 61 |
52 KeyedService* GCMProfileServiceFactory::BuildServiceInstanceFor( | 62 KeyedService* GCMProfileServiceFactory::BuildServiceInstanceFor( |
53 content::BrowserContext* context) const { | 63 content::BrowserContext* context) const { |
64 if (global_testing_factory) { | |
65 return (*global_testing_factory)(context); | |
66 } | |
Peter Beverloo
2015/03/03 15:54:18
nit: no need for {}
| |
54 #if defined(OS_ANDROID) | 67 #if defined(OS_ANDROID) |
55 return new GCMProfileService(Profile::FromBrowserContext(context)); | 68 return new GCMProfileService(Profile::FromBrowserContext(context)); |
56 #else | 69 #else |
57 return new GCMProfileService( | 70 return new GCMProfileService( |
58 Profile::FromBrowserContext(context), | 71 Profile::FromBrowserContext(context), |
59 scoped_ptr<GCMClientFactory>(new GCMClientFactory)); | 72 scoped_ptr<GCMClientFactory>(new GCMClientFactory)); |
60 #endif | 73 #endif |
61 } | 74 } |
62 | 75 |
63 content::BrowserContext* GCMProfileServiceFactory::GetBrowserContextToUse( | 76 content::BrowserContext* GCMProfileServiceFactory::GetBrowserContextToUse( |
64 content::BrowserContext* context) const { | 77 content::BrowserContext* context) const { |
65 return chrome::GetBrowserContextOwnInstanceInIncognito(context); | 78 return chrome::GetBrowserContextOwnInstanceInIncognito(context); |
66 } | 79 } |
67 | 80 |
68 } // namespace gcm | 81 } // namespace gcm |
OLD | NEW |