OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/invalidation_service_factory.h" |
| 6 |
| 7 #include "chrome/browser/android_invalidation_service.h" |
| 8 #include "chrome/browser/invalidation_service.h" |
| 9 #include "chrome/browser/p2p_invalidation_service.h" |
| 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/profiles/profile_dependency_manager.h" |
| 12 #include "chrome/browser/signin/signin_manager_factory.h" |
| 13 #include "chrome/browser/signin/token_service_factory.h" |
| 14 |
| 15 // static |
| 16 InvalidationService* InvalidationServiceFactory::GetForProfile( |
| 17 Profile* profile) { |
| 18 return static_cast<InvalidationService*>( |
| 19 GetInstance()->GetServiceForProfile(profile, true)); |
| 20 } |
| 21 |
| 22 // static |
| 23 InvalidationServiceFactory* InvalidationServiceFactory::GetInstance() { |
| 24 return Singleton<InvalidationServiceFactory>::get(); |
| 25 } |
| 26 |
| 27 InvalidationServiceFactory::InvalidationServiceFactory() |
| 28 : ProfileKeyedServiceFactory("InvalidationService", |
| 29 ProfileDependencyManager::GetInstance()) { |
| 30 #ifndef OS_ANDROID |
| 31 DependsOn(SigninManagerFactory::GetInstance()); |
| 32 DependsOn(TokenServiceFactory::GetInstance()); |
| 33 #endif |
| 34 } |
| 35 |
| 36 InvalidationServiceFactory::~InvalidationServiceFactory() {} |
| 37 |
| 38 ProfileKeyedService* InvalidationServiceFactory::BuildServiceInstanceFor( |
| 39 Profile* profile) const { |
| 40 #ifndef OS_ANDROID |
| 41 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile); |
| 42 TokenService* token_service = TokenServiceFactory::GetForProfile(profile); |
| 43 |
| 44 InvalidationService* service = new InvalidationService( |
| 45 signin_manager, token_service); |
| 46 service->Init(profile); |
| 47 return service; |
| 48 #else |
| 49 AndroidInvalidationService* service = new AndroidInvalidationService(); |
| 50 service->Init(profile); |
| 51 return service; |
| 52 #endif |
| 53 } |
| 54 |
| 55 // static |
| 56 ProfileKeyedService* InvalidationServiceFactory::BuildTestServiceInstanceFor( |
| 57 Profile* profile) { |
| 58 // This looks unsafe because it is unsafe. Fortunately, this class has |
| 59 // sufficiently close relations to the InvalidationService to know that it |
| 60 // will never access those NULL pointers because Init() was never called. |
| 61 return new InvalidationService(NULL, NULL); |
| 62 } |
| 63 |
| 64 // static |
| 65 ProfileKeyedService* |
| 66 InvalidationServiceFactory::BuildP2PInvalidationServiceFor(Profile* profile) { |
| 67 P2PInvalidationService* service = new P2PInvalidationService(); |
| 68 service->Init(profile); |
| 69 return service; |
| 70 } |
| 71 |
OLD | NEW |