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