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/invalidation/invalidation_service_factory.h" | 5 #include "chrome/browser/invalidation/invalidation_service_factory.h" |
6 | 6 |
7 #include "chrome/browser/invalidation/invalidation_frontend.h" | 7 #include "base/prefs/pref_registry.h" |
| 8 #include "chrome/browser/invalidation/fake_invalidation_service.h" |
| 9 #include "chrome/browser/invalidation/invalidation_service.h" |
8 #include "chrome/browser/invalidation/invalidation_service_android.h" | 10 #include "chrome/browser/invalidation/invalidation_service_android.h" |
| 11 #include "chrome/browser/invalidation/invalidator_storage.h" |
9 #include "chrome/browser/invalidation/p2p_invalidation_service.h" | 12 #include "chrome/browser/invalidation/p2p_invalidation_service.h" |
10 #include "chrome/browser/invalidation/ticl_invalidation_service.h" | 13 #include "chrome/browser/invalidation/ticl_invalidation_service.h" |
11 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
12 #include "chrome/browser/signin/signin_manager.h" | 17 #include "chrome/browser/signin/signin_manager.h" |
13 #include "chrome/browser/signin/signin_manager_factory.h" | 18 #include "chrome/browser/signin/signin_manager_factory.h" |
| 19 #include "chrome/browser/signin/token_service.h" |
14 #include "chrome/browser/signin/token_service_factory.h" | 20 #include "chrome/browser/signin/token_service_factory.h" |
15 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" | 21 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
16 | 22 |
17 class TokenService; | 23 class TokenService; |
18 | 24 |
19 namespace invalidation { | 25 namespace invalidation { |
20 | 26 |
21 // TODO(rlarocque): Re-enable this once InvalidationFrontend can | 27 // static |
22 // extend BrowserContextKeyedService. | 28 InvalidationService* InvalidationServiceFactory::GetForProfile( |
23 // // static | 29 Profile* profile) { |
24 // InvalidationFrontend* InvalidationServiceFactory::GetForProfile( | 30 return static_cast<InvalidationService*>( |
25 // Profile* profile) { | 31 GetInstance()->GetServiceForBrowserContext(profile, true)); |
26 // return static_cast<InvalidationFrontend*>( | 32 } |
27 // GetInstance()->GetServiceForBrowserContext(profile, true)); | |
28 // } | |
29 | 33 |
30 // static | 34 // static |
31 InvalidationServiceFactory* InvalidationServiceFactory::GetInstance() { | 35 InvalidationServiceFactory* InvalidationServiceFactory::GetInstance() { |
32 return Singleton<InvalidationServiceFactory>::get(); | 36 return Singleton<InvalidationServiceFactory>::get(); |
33 } | 37 } |
34 | 38 |
35 InvalidationServiceFactory::InvalidationServiceFactory() | 39 InvalidationServiceFactory::InvalidationServiceFactory() |
36 : BrowserContextKeyedServiceFactory( | 40 : BrowserContextKeyedServiceFactory( |
37 "InvalidationService", | 41 "InvalidationService", |
38 BrowserContextDependencyManager::GetInstance()) { | 42 BrowserContextDependencyManager::GetInstance()), |
| 43 build_fake_invalidators_(false) { |
39 #if !defined(OS_ANDROID) | 44 #if !defined(OS_ANDROID) |
40 DependsOn(SigninManagerFactory::GetInstance()); | 45 DependsOn(SigninManagerFactory::GetInstance()); |
41 DependsOn(TokenServiceFactory::GetInstance()); | 46 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); |
42 #endif | 47 #endif |
43 } | 48 } |
44 | 49 |
45 InvalidationServiceFactory::~InvalidationServiceFactory() {} | 50 InvalidationServiceFactory::~InvalidationServiceFactory() {} |
46 | 51 |
47 // static | 52 namespace { |
48 BrowserContextKeyedService* | 53 |
49 InvalidationServiceFactory::BuildP2PInvalidationServiceFor(Profile* profile) { | 54 BrowserContextKeyedService* BuildP2PInvalidationService( |
| 55 content::BrowserContext* context) { |
| 56 Profile* profile = static_cast<Profile*>(context); |
50 return new P2PInvalidationService(profile); | 57 return new P2PInvalidationService(profile); |
51 } | 58 } |
52 | 59 |
| 60 BrowserContextKeyedService* BuildFakeInvalidationService( |
| 61 content::BrowserContext* context) { |
| 62 return new FakeInvalidationService(); |
| 63 } |
| 64 |
| 65 } // namespace |
| 66 |
| 67 void InvalidationServiceFactory::SetBuildOnlyFakeInvalidatorsForTest( |
| 68 bool test_mode_enabled) { |
| 69 build_fake_invalidators_ = test_mode_enabled; |
| 70 } |
| 71 |
| 72 P2PInvalidationService* |
| 73 InvalidationServiceFactory::BuildAndUseP2PInvalidationServiceForTest( |
| 74 content::BrowserContext* context) { |
| 75 BrowserContextKeyedService* service = |
| 76 SetTestingFactoryAndUse(context, BuildP2PInvalidationService); |
| 77 return static_cast<P2PInvalidationService*>(service); |
| 78 } |
| 79 |
53 BrowserContextKeyedService* InvalidationServiceFactory::BuildServiceInstanceFor( | 80 BrowserContextKeyedService* InvalidationServiceFactory::BuildServiceInstanceFor( |
54 content::BrowserContext* context) const { | 81 content::BrowserContext* context) const { |
55 Profile* profile = static_cast<Profile*>(context); | 82 Profile* profile = static_cast<Profile*>(context); |
| 83 |
| 84 if (build_fake_invalidators_) { |
| 85 return BuildFakeInvalidationService(context); |
| 86 } |
| 87 |
56 #if defined(OS_ANDROID) | 88 #if defined(OS_ANDROID) |
57 InvalidationServiceAndroid* service = new InvalidationServiceAndroid(profile); | 89 InvalidationServiceAndroid* service = new InvalidationServiceAndroid(profile); |
58 return service; | 90 return service; |
59 #else | 91 #else |
60 SigninManagerBase* signin_manager = | 92 SigninManagerBase* signin_manager = |
61 SigninManagerFactory::GetForProfile(profile); | 93 SigninManagerFactory::GetForProfile(profile); |
62 TokenService* token_service = TokenServiceFactory::GetForProfile(profile); | 94 TokenService* token_service = TokenServiceFactory::GetForProfile(profile); |
| 95 OAuth2TokenService* oauth2_token_service = |
| 96 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
63 | 97 |
64 TiclInvalidationService* service = new TiclInvalidationService( | 98 TiclInvalidationService* service = new TiclInvalidationService( |
65 signin_manager, token_service, profile); | 99 signin_manager, |
| 100 token_service, |
| 101 oauth2_token_service, |
| 102 profile); |
66 service->Init(); | 103 service->Init(); |
67 return service; | 104 return service; |
68 #endif | 105 #endif |
69 } | 106 } |
70 | 107 |
| 108 void InvalidationServiceFactory::RegisterUserPrefs( |
| 109 user_prefs::PrefRegistrySyncable* registry) { |
| 110 InvalidatorStorage::RegisterUserPrefs(registry); |
| 111 } |
| 112 |
71 } // namespace invalidation | 113 } // namespace invalidation |
OLD | NEW |