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