Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: chrome/browser/invalidation/profile_invalidation_provider_factory.cc

Issue 327243003: Introduce ProfileInvalidationProvider wrapper for InvalidationService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/profile_invalidation_provider_factory.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/prefs/pref_registry.h" 8 #include "base/prefs/pref_registry.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/invalidation/fake_invalidation_service.h"
11 #include "chrome/browser/invalidation/invalidation_service_android.h"
12 #include "chrome/browser/invalidation/ticl_invalidation_service.h" 10 #include "chrome/browser/invalidation/ticl_invalidation_service.h"
13 #include "chrome/browser/invalidation/ticl_profile_settings_provider.h" 11 #include "chrome/browser/invalidation/ticl_profile_settings_provider.h"
14 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/services/gcm/gcm_profile_service.h" 13 #include "chrome/browser/services/gcm/gcm_profile_service.h"
16 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" 14 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
17 #include "chrome/browser/signin/profile_identity_provider.h" 15 #include "chrome/browser/signin/profile_identity_provider.h"
18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
19 #include "chrome/browser/signin/signin_manager_factory.h" 17 #include "chrome/browser/signin/signin_manager_factory.h"
20 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 18 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
21 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
22 #include "components/invalidation/invalidation_service.h" 20 #include "components/invalidation/invalidation_service.h"
23 #include "components/invalidation/invalidator_storage.h" 21 #include "components/invalidation/invalidator_storage.h"
22 #include "components/invalidation/profile_invalidation_provider.h"
24 #include "components/invalidation/ticl_settings_provider.h" 23 #include "components/invalidation/ticl_settings_provider.h"
25 #include "components/keyed_service/content/browser_context_dependency_manager.h" 24 #include "components/keyed_service/content/browser_context_dependency_manager.h"
26 #include "components/pref_registry/pref_registry_syncable.h" 25 #include "components/pref_registry/pref_registry_syncable.h"
27 #include "components/signin/core/browser/profile_oauth2_token_service.h" 26 #include "components/signin/core/browser/profile_oauth2_token_service.h"
28 #include "components/signin/core/browser/signin_manager.h" 27 #include "components/signin/core/browser/signin_manager.h"
29 #include "net/url_request/url_request_context_getter.h" 28 #include "net/url_request/url_request_context_getter.h"
30 #include "sync/notifier/invalidation_state_tracker.h" 29 #include "sync/notifier/invalidation_state_tracker.h"
31 30
32 #if defined(OS_ANDROID) 31 #if defined(OS_ANDROID)
33 #include "chrome/browser/invalidation/invalidation_controller_android.h" 32 #include "chrome/browser/invalidation/invalidation_controller_android.h"
33 #include "chrome/browser/invalidation/invalidation_service_android.h"
34 #endif // defined(OS_ANDROID) 34 #endif // defined(OS_ANDROID)
35 35
36 #if defined(OS_CHROMEOS) 36 #if defined(OS_CHROMEOS)
37 #include "base/files/file_path.h" 37 #include "base/files/file_path.h"
38 #include "chrome/browser/chromeos/login/users/user_manager.h" 38 #include "chrome/browser/chromeos/login/users/user_manager.h"
39 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 39 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
40 #include "chrome/browser/chromeos/profiles/profile_helper.h" 40 #include "chrome/browser/chromeos/profiles/profile_helper.h"
41 #include "chrome/browser/chromeos/settings/device_identity_provider.h" 41 #include "chrome/browser/chromeos/settings/device_identity_provider.h"
42 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " 42 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h "
43 #endif 43 #endif
44 44
45 namespace invalidation { 45 namespace invalidation {
46 46
47 // static 47 // static
48 InvalidationService* InvalidationServiceFactory::GetForProfile( 48 ProfileInvalidationProvider* ProfileInvalidationProviderFactory::GetForProfile(
49 Profile* profile) { 49 Profile* profile) {
50 #if defined(OS_CHROMEOS) 50 #if defined(OS_CHROMEOS)
51 // Using ProfileHelper::GetSigninProfile() here would lead to an infinite loop 51 // Using ProfileHelper::GetSigninProfile() here would lead to an infinite loop
52 // when this method is called during the creation of the sign-in profile 52 // when this method is called during the creation of the sign-in profile
53 // itself. Using ProfileHelper::GetSigninProfileDir() is safe because it does 53 // itself. Using ProfileHelper::GetSigninProfileDir() is safe because it does
54 // not try to access the sign-in profile. 54 // not try to access the sign-in profile.
55 if (profile->GetPath() == chromeos::ProfileHelper::GetSigninProfileDir()|| 55 if (profile->GetPath() == chromeos::ProfileHelper::GetSigninProfileDir()||
56 (chromeos::UserManager::IsInitialized() && 56 (chromeos::UserManager::IsInitialized() &&
57 chromeos::UserManager::Get()->IsLoggedInAsGuest())) { 57 chromeos::UserManager::Get()->IsLoggedInAsGuest())) {
58 // The Chrome OS login and Chrome OS guest profiles do not have GAIA 58 // The Chrome OS login and Chrome OS guest profiles do not have GAIA
59 // credentials and do not support invalidation. 59 // credentials and do not support invalidation.
60 return NULL; 60 return NULL;
61 } 61 }
62 #endif 62 #endif
63 return static_cast<InvalidationService*>( 63 return static_cast<ProfileInvalidationProvider*>(
64 GetInstance()->GetServiceForBrowserContext(profile, true)); 64 GetInstance()->GetServiceForBrowserContext(profile, true));
65 } 65 }
66 66
67 // static 67 // static
68 InvalidationServiceFactory* InvalidationServiceFactory::GetInstance() { 68 ProfileInvalidationProviderFactory*
69 return Singleton<InvalidationServiceFactory>::get(); 69 ProfileInvalidationProviderFactory::GetInstance() {
70 return Singleton<ProfileInvalidationProviderFactory>::get();
70 } 71 }
71 72
72 InvalidationServiceFactory::InvalidationServiceFactory() 73 ProfileInvalidationProviderFactory::ProfileInvalidationProviderFactory()
73 : BrowserContextKeyedServiceFactory( 74 : BrowserContextKeyedServiceFactory(
74 "InvalidationService", 75 "InvalidationService",
75 BrowserContextDependencyManager::GetInstance()), 76 BrowserContextDependencyManager::GetInstance()),
76 testing_factory_(NULL) { 77 testing_factory_(NULL) {
77 #if !defined(OS_ANDROID) 78 #if !defined(OS_ANDROID)
78 DependsOn(SigninManagerFactory::GetInstance()); 79 DependsOn(SigninManagerFactory::GetInstance());
79 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); 80 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
80 DependsOn(gcm::GCMProfileServiceFactory::GetInstance()); 81 DependsOn(gcm::GCMProfileServiceFactory::GetInstance());
81 DependsOn(LoginUIServiceFactory::GetInstance()); 82 DependsOn(LoginUIServiceFactory::GetInstance());
82 #endif 83 #endif
83 } 84 }
84 85
85 InvalidationServiceFactory::~InvalidationServiceFactory() {} 86 ProfileInvalidationProviderFactory::~ProfileInvalidationProviderFactory() {
87 }
86 88
87 void InvalidationServiceFactory::RegisterTestingFactory( 89 void ProfileInvalidationProviderFactory::RegisterTestingFactory(
88 TestingFactoryFunction testing_factory) { 90 TestingFactoryFunction testing_factory) {
89 testing_factory_ = testing_factory; 91 testing_factory_ = testing_factory;
90 } 92 }
91 93
92 KeyedService* InvalidationServiceFactory::BuildServiceInstanceFor( 94 KeyedService* ProfileInvalidationProviderFactory::BuildServiceInstanceFor(
93 content::BrowserContext* context) const { 95 content::BrowserContext* context) const {
94 Profile* profile = static_cast<Profile*>(context); 96 Profile* profile = static_cast<Profile*>(context);
95 97
96 if (testing_factory_) 98 if (testing_factory_)
97 return testing_factory_(context); 99 return testing_factory_(context);
98 100
99 #if defined(OS_ANDROID) 101 #if defined(OS_ANDROID)
100 return new InvalidationServiceAndroid(profile, 102 return new ProfileInvalidationProvider(scoped_ptr<InvalidationService>(
101 new InvalidationControllerAndroid()); 103 new InvalidationServiceAndroid(profile,
104 new InvalidationControllerAndroid())));
102 #else 105 #else
103 106
104 scoped_ptr<IdentityProvider> identity_provider; 107 scoped_ptr<IdentityProvider> identity_provider;
105 108
106 #if defined(OS_CHROMEOS) 109 #if defined(OS_CHROMEOS)
107 policy::BrowserPolicyConnectorChromeOS* connector = 110 policy::BrowserPolicyConnectorChromeOS* connector =
108 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 111 g_browser_process->platform_part()->browser_policy_connector_chromeos();
109 if (chromeos::UserManager::IsInitialized() && 112 if (chromeos::UserManager::IsInitialized() &&
110 chromeos::UserManager::Get()->IsLoggedInAsKioskApp() && 113 chromeos::UserManager::Get()->IsLoggedInAsKioskApp() &&
111 connector->IsEnterpriseManaged()) { 114 connector->IsEnterpriseManaged()) {
112 identity_provider.reset(new chromeos::DeviceIdentityProvider( 115 identity_provider.reset(new chromeos::DeviceIdentityProvider(
113 chromeos::DeviceOAuth2TokenServiceFactory::Get())); 116 chromeos::DeviceOAuth2TokenServiceFactory::Get()));
114 } 117 }
115 #endif 118 #endif
116 119
117 if (!identity_provider) { 120 if (!identity_provider) {
118 identity_provider.reset(new ProfileIdentityProvider( 121 identity_provider.reset(new ProfileIdentityProvider(
119 SigninManagerFactory::GetForProfile(profile), 122 SigninManagerFactory::GetForProfile(profile),
120 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), 123 ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
121 LoginUIServiceFactory::GetForProfile(profile))); 124 LoginUIServiceFactory::GetForProfile(profile)));
122 } 125 }
123 126
124 TiclInvalidationService* service = new TiclInvalidationService( 127 scoped_ptr<TiclInvalidationService> service(new TiclInvalidationService(
125 identity_provider.Pass(), 128 identity_provider.Pass(),
126 scoped_ptr<TiclSettingsProvider>( 129 scoped_ptr<TiclSettingsProvider>(
127 new TiclProfileSettingsProvider(profile)), 130 new TiclProfileSettingsProvider(profile)),
128 gcm::GCMProfileServiceFactory::GetForProfile(profile)->driver(), 131 gcm::GCMProfileServiceFactory::GetForProfile(profile)->driver(),
129 profile->GetRequestContext()); 132 profile->GetRequestContext()));
130 service->Init(scoped_ptr<syncer::InvalidationStateTracker>( 133 service->Init(scoped_ptr<syncer::InvalidationStateTracker>(
131 new InvalidatorStorage(profile->GetPrefs()))); 134 new InvalidatorStorage(profile->GetPrefs())));
132 return service; 135
136 return new ProfileInvalidationProvider(service.PassAs<InvalidationService>());
133 #endif 137 #endif
134 } 138 }
135 139
136 void InvalidationServiceFactory::RegisterProfilePrefs( 140 void ProfileInvalidationProviderFactory::RegisterProfilePrefs(
137 user_prefs::PrefRegistrySyncable* registry) { 141 user_prefs::PrefRegistrySyncable* registry) {
138 registry->RegisterBooleanPref( 142 registry->RegisterBooleanPref(
139 prefs::kInvalidationServiceUseGCMChannel, 143 prefs::kInvalidationServiceUseGCMChannel,
140 false, 144 false,
141 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 145 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
142 InvalidatorStorage::RegisterProfilePrefs(registry); 146 InvalidatorStorage::RegisterProfilePrefs(registry);
143 } 147 }
144 148
145 } // namespace invalidation 149 } // namespace invalidation
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698