Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/chromeos/policy/device_cloud_policy_invalidator.h" | 5 #include "chrome/browser/chromeos/policy/affiliated_invalidation_service_provide r.h" |
| 6 | 6 |
| 7 #include <string> | |
| 8 #include <vector> | 7 #include <vector> |
| 9 | 8 |
| 10 #include "base/logging.h" | 9 #include "base/logging.h" |
| 11 #include "base/message_loop/message_loop_proxy.h" | |
| 12 #include "base/time/clock.h" | |
| 13 #include "base/time/default_clock.h" | |
| 14 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/browser_process_platform_part_chromeos.h" | 11 #include "chrome/browser/browser_process_platform_part_chromeos.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
| 17 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 13 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 18 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" | |
| 19 #include "chrome/browser/chromeos/policy/ticl_device_settings_provider.h" | 14 #include "chrome/browser/chromeos/policy/ticl_device_settings_provider.h" |
| 20 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 15 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 21 #include "chrome/browser/chromeos/settings/device_identity_provider.h" | 16 #include "chrome/browser/chromeos/settings/device_identity_provider.h" |
| 22 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " | 17 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " |
| 23 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" | 18 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" |
| 24 #include "chrome/browser/policy/cloud/cloud_policy_invalidator.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
| 26 #include "chrome/common/chrome_content_client.h" | 21 #include "chrome/common/chrome_content_client.h" |
| 27 #include "components/invalidation/invalidation_handler.h" | 22 #include "components/invalidation/invalidation_handler.h" |
| 28 #include "components/invalidation/invalidation_service.h" | 23 #include "components/invalidation/invalidation_service.h" |
| 29 #include "components/invalidation/invalidation_state_tracker.h" | 24 #include "components/invalidation/invalidation_state_tracker.h" |
| 30 #include "components/invalidation/invalidator_state.h" | 25 #include "components/invalidation/invalidator_state.h" |
| 31 #include "components/invalidation/invalidator_storage.h" | 26 #include "components/invalidation/invalidator_storage.h" |
| 32 #include "components/invalidation/profile_invalidation_provider.h" | 27 #include "components/invalidation/profile_invalidation_provider.h" |
| 33 #include "components/invalidation/ticl_invalidation_service.h" | 28 #include "components/invalidation/ticl_invalidation_service.h" |
| 34 #include "components/invalidation/ticl_settings_provider.h" | 29 #include "components/invalidation/ticl_settings_provider.h" |
| 35 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 30 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 36 #include "components/user_manager/user.h" | 31 #include "components/user_manager/user.h" |
| 37 #include "content/public/browser/notification_details.h" | 32 #include "content/public/browser/notification_details.h" |
| 38 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
| 39 #include "google_apis/gaia/identity_provider.h" | 34 #include "google_apis/gaia/identity_provider.h" |
| 40 #include "net/url_request/url_request_context_getter.h" | |
| 41 #include "policy/proto/device_management_backend.pb.h" | |
| 42 | |
| 43 class Profile; | |
| 44 | 35 |
| 45 namespace policy { | 36 namespace policy { |
| 46 | 37 |
| 47 class DeviceCloudPolicyInvalidator::InvalidationServiceObserver | 38 AffiliatedInvalidationServiceProvider::Consumer::~Consumer() { |
| 39 } | |
| 40 | |
| 41 class AffiliatedInvalidationServiceProvider::InvalidationServiceObserver | |
| 48 : public syncer::InvalidationHandler { | 42 : public syncer::InvalidationHandler { |
| 49 public: | 43 public: |
| 50 explicit InvalidationServiceObserver( | 44 explicit InvalidationServiceObserver( |
| 51 DeviceCloudPolicyInvalidator* parent, | 45 AffiliatedInvalidationServiceProvider* parent, |
| 52 invalidation::InvalidationService* invalidation_service); | 46 invalidation::InvalidationService* invalidation_service); |
| 53 ~InvalidationServiceObserver() override; | 47 virtual ~InvalidationServiceObserver(); |
| 54 | 48 |
| 55 invalidation::InvalidationService* GetInvalidationService(); | 49 invalidation::InvalidationService* GetInvalidationService(); |
| 56 bool IsServiceConnected() const; | 50 bool IsServiceConnected() const; |
| 57 | 51 |
| 58 // public syncer::InvalidationHandler: | 52 // public syncer::InvalidationHandler: |
| 59 void OnInvalidatorStateChange(syncer::InvalidatorState state) override; | 53 virtual void OnInvalidatorStateChange( |
| 60 void OnIncomingInvalidation( | 54 syncer::InvalidatorState state) override; |
| 55 virtual void OnIncomingInvalidation( | |
| 61 const syncer::ObjectIdInvalidationMap& invalidation_map) override; | 56 const syncer::ObjectIdInvalidationMap& invalidation_map) override; |
| 62 std::string GetOwnerName() const override; | 57 virtual std::string GetOwnerName() const override; |
| 63 | 58 |
| 64 private: | 59 private: |
| 65 DeviceCloudPolicyInvalidator* parent_; | 60 AffiliatedInvalidationServiceProvider* parent_; |
| 66 invalidation::InvalidationService* invalidation_service_; | 61 invalidation::InvalidationService* invalidation_service_; |
| 67 bool is_service_connected_; | 62 bool is_service_connected_; |
| 63 bool is_observer_ready_; | |
| 68 | 64 |
| 69 DISALLOW_COPY_AND_ASSIGN(InvalidationServiceObserver); | 65 DISALLOW_COPY_AND_ASSIGN(InvalidationServiceObserver); |
| 70 }; | 66 }; |
| 71 | 67 |
| 72 DeviceCloudPolicyInvalidator::InvalidationServiceObserver:: | 68 AffiliatedInvalidationServiceProvider::InvalidationServiceObserver:: |
| 73 InvalidationServiceObserver( | 69 InvalidationServiceObserver( |
| 74 DeviceCloudPolicyInvalidator* parent, | 70 AffiliatedInvalidationServiceProvider* parent, |
| 75 invalidation::InvalidationService* invalidation_service) | 71 invalidation::InvalidationService* invalidation_service) |
| 76 : parent_(parent), | 72 : parent_(parent), |
| 77 invalidation_service_(invalidation_service), | 73 invalidation_service_(invalidation_service), |
| 78 is_service_connected_(invalidation_service->GetInvalidatorState() == | 74 is_service_connected_(false), |
| 79 syncer::INVALIDATIONS_ENABLED) { | 75 is_observer_ready_(false) { |
| 80 invalidation_service_->RegisterInvalidationHandler(this); | 76 invalidation_service_->RegisterInvalidationHandler(this); |
| 77 is_service_connected_ = invalidation_service->GetInvalidatorState() == | |
| 78 syncer::INVALIDATIONS_ENABLED; | |
| 79 is_observer_ready_ = true; | |
| 81 } | 80 } |
| 82 | 81 |
| 83 DeviceCloudPolicyInvalidator::InvalidationServiceObserver:: | 82 AffiliatedInvalidationServiceProvider::InvalidationServiceObserver:: |
| 84 ~InvalidationServiceObserver() { | 83 ~InvalidationServiceObserver() { |
| 84 is_observer_ready_ = false; | |
| 85 invalidation_service_->UnregisterInvalidationHandler(this); | 85 invalidation_service_->UnregisterInvalidationHandler(this); |
| 86 } | 86 } |
| 87 | 87 |
| 88 invalidation::InvalidationService* | 88 invalidation::InvalidationService* |
| 89 DeviceCloudPolicyInvalidator::InvalidationServiceObserver:: | 89 AffiliatedInvalidationServiceProvider::InvalidationServiceObserver:: |
| 90 GetInvalidationService() { | 90 GetInvalidationService() { |
| 91 return invalidation_service_; | 91 return invalidation_service_; |
| 92 } | 92 } |
| 93 | 93 |
| 94 bool DeviceCloudPolicyInvalidator::InvalidationServiceObserver:: | 94 bool AffiliatedInvalidationServiceProvider::InvalidationServiceObserver:: |
| 95 IsServiceConnected() const { | 95 IsServiceConnected() const { |
| 96 return is_service_connected_; | 96 return is_service_connected_; |
| 97 } | 97 } |
| 98 | 98 |
| 99 void DeviceCloudPolicyInvalidator::InvalidationServiceObserver:: | 99 void AffiliatedInvalidationServiceProvider::InvalidationServiceObserver:: |
| 100 OnInvalidatorStateChange(syncer::InvalidatorState state) { | 100 OnInvalidatorStateChange(syncer::InvalidatorState state) { |
| 101 if (!is_observer_ready_) | |
| 102 return; | |
| 103 | |
| 101 const bool is_service_connected = (state == syncer::INVALIDATIONS_ENABLED); | 104 const bool is_service_connected = (state == syncer::INVALIDATIONS_ENABLED); |
| 102 if (is_service_connected == is_service_connected_) | 105 if (is_service_connected == is_service_connected_) |
| 103 return; | 106 return; |
| 104 | 107 |
| 105 is_service_connected_ = is_service_connected; | 108 is_service_connected_ = is_service_connected; |
| 106 if (is_service_connected_) | 109 if (is_service_connected_) |
| 107 parent_->OnInvalidationServiceConnected(invalidation_service_); | 110 parent_->OnInvalidationServiceConnected(invalidation_service_); |
| 108 else | 111 else |
| 109 parent_->OnInvalidationServiceDisconnected(invalidation_service_); | 112 parent_->OnInvalidationServiceDisconnected(invalidation_service_); |
| 110 } | 113 } |
| 111 | 114 |
| 112 void DeviceCloudPolicyInvalidator::InvalidationServiceObserver:: | 115 void AffiliatedInvalidationServiceProvider::InvalidationServiceObserver:: |
| 113 OnIncomingInvalidation( | 116 OnIncomingInvalidation( |
| 114 const syncer::ObjectIdInvalidationMap& invalidation_map) { | 117 const syncer::ObjectIdInvalidationMap& invalidation_map) { |
| 115 } | 118 } |
| 116 | 119 |
| 117 std::string DeviceCloudPolicyInvalidator::InvalidationServiceObserver:: | 120 std::string AffiliatedInvalidationServiceProvider::InvalidationServiceObserver:: |
| 118 GetOwnerName() const { | 121 GetOwnerName() const { |
| 119 return "DevicePolicy"; | 122 return "AffiliatedInvalidationService"; |
| 120 } | 123 } |
| 121 | 124 |
| 122 DeviceCloudPolicyInvalidator::DeviceCloudPolicyInvalidator() | 125 AffiliatedInvalidationServiceProvider::AffiliatedInvalidationServiceProvider() |
| 123 : invalidation_service_(NULL), | 126 : invalidation_service_(nullptr), |
| 124 highest_handled_invalidation_version_(0) { | 127 consumer_count_(0), |
| 125 // The DeviceCloudPolicyInvalidator should be created before any user | 128 is_shut_down_(false) { |
| 129 // The AffiliatedInvalidationServiceProvider should be created before any user | |
| 126 // Profiles. | 130 // Profiles. |
| 127 DCHECK(g_browser_process->profile_manager()->GetLoadedProfiles().empty()); | 131 DCHECK(g_browser_process->profile_manager()->GetLoadedProfiles().empty()); |
| 128 | 132 |
| 129 // Subscribe to notification about new user profiles becoming available. | 133 // Subscribe to notification about new user profiles becoming available. |
| 130 registrar_.Add(this, | 134 registrar_.Add(this, |
| 131 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 135 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 132 content::NotificationService::AllSources()); | 136 content::NotificationService::AllSources()); |
| 133 | |
| 134 TryToCreateInvalidator(); | |
| 135 } | 137 } |
| 136 | 138 |
| 137 DeviceCloudPolicyInvalidator::~DeviceCloudPolicyInvalidator() { | 139 AffiliatedInvalidationServiceProvider:: |
| 138 DestroyInvalidator(); | 140 ~AffiliatedInvalidationServiceProvider() { |
| 141 // Verify that the provider was shut down first. | |
| 142 DCHECK(is_shut_down_); | |
|
Mattias Nissler (ping if slow)
2015/01/28 09:02:23
I'm not sure this DCHECK is a good idea. What if t
bartfab (slow)
2015/01/28 09:28:31
The provider is created when BrowserPolicyConnecto
| |
| 139 } | 143 } |
| 140 | 144 |
| 141 void DeviceCloudPolicyInvalidator::Observe( | 145 void AffiliatedInvalidationServiceProvider::Observe( |
| 142 int type, | 146 int type, |
| 143 const content::NotificationSource& source, | 147 const content::NotificationSource& source, |
| 144 const content::NotificationDetails& details) { | 148 const content::NotificationDetails& details) { |
| 145 DCHECK_EQ(chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, type); | 149 DCHECK_EQ(chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, type); |
| 150 DCHECK(!is_shut_down_); | |
| 146 Profile* profile = content::Details<Profile>(details).ptr(); | 151 Profile* profile = content::Details<Profile>(details).ptr(); |
| 147 invalidation::ProfileInvalidationProvider* invalidation_provider = | 152 invalidation::ProfileInvalidationProvider* invalidation_provider = |
| 148 invalidation::ProfileInvalidationProviderFactory::GetForProfile(profile); | 153 invalidation::ProfileInvalidationProviderFactory::GetForProfile(profile); |
| 149 if (!invalidation_provider) { | 154 if (!invalidation_provider) { |
| 150 // If the Profile does not support invalidation (e.g. guest, incognito), | 155 // If the Profile does not support invalidation (e.g. guest, incognito), |
| 151 // ignore it. | 156 // ignore it. |
| 152 return; | 157 return; |
| 153 } | 158 } |
| 154 user_manager::User* user = | 159 user_manager::User* user = |
| 155 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); | 160 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); |
| 156 if (!user || | 161 if (!user || |
| 157 g_browser_process->platform_part()->browser_policy_connector_chromeos()-> | 162 g_browser_process->platform_part()->browser_policy_connector_chromeos()-> |
| 158 GetUserAffiliation(user->email()) != USER_AFFILIATION_MANAGED) { | 163 GetUserAffiliation(user->email()) != USER_AFFILIATION_MANAGED) { |
| 159 // If the Profile belongs to a user who is not affiliated with the domain | 164 // If the Profile belongs to a user who is not affiliated with the device's |
| 160 // the device is enrolled into, ignore it. | 165 // enrollment domain, ignore it. |
| 161 return; | 166 return; |
| 162 } | 167 } |
| 168 | |
| 163 // Create a state observer for the user's invalidation service. | 169 // Create a state observer for the user's invalidation service. |
| 170 invalidation::InvalidationService* invalidation_service = | |
| 171 invalidation_provider->GetInvalidationService(); | |
| 164 profile_invalidation_service_observers_.push_back( | 172 profile_invalidation_service_observers_.push_back( |
| 165 new InvalidationServiceObserver( | 173 new InvalidationServiceObserver(this, invalidation_service)); |
| 166 this, | |
| 167 invalidation_provider->GetInvalidationService())); | |
| 168 | 174 |
| 169 TryToCreateInvalidator(); | 175 if (profile_invalidation_service_observers_.back()->IsServiceConnected()) { |
| 176 // If the invalidation service is connected, check whether to switch to it. | |
| 177 OnInvalidationServiceConnected(invalidation_service); | |
| 178 } | |
| 170 } | 179 } |
| 171 | 180 |
| 172 void DeviceCloudPolicyInvalidator::OnInvalidationServiceConnected( | 181 void AffiliatedInvalidationServiceProvider::RegisterConsumer( |
| 182 Consumer* consumer) { | |
| 183 if (consumers_.HasObserver(consumer) || is_shut_down_) | |
| 184 return; | |
| 185 | |
| 186 consumers_.AddObserver(consumer); | |
| 187 ++consumer_count_; | |
| 188 | |
| 189 if (invalidation_service_) | |
| 190 consumer->OnInvalidationServiceSet(invalidation_service_); | |
| 191 else if (consumer_count_ == 1) | |
| 192 FindConnectedInvalidationService(); | |
| 193 } | |
| 194 | |
| 195 void AffiliatedInvalidationServiceProvider::UnregisterConsumer( | |
| 196 Consumer* consumer) { | |
| 197 if (!consumers_.HasObserver(consumer)) | |
| 198 return; | |
| 199 | |
| 200 consumers_.RemoveObserver(consumer); | |
| 201 --consumer_count_; | |
| 202 | |
| 203 if (invalidation_service_ && consumer_count_ == 0) { | |
| 204 invalidation_service_ = nullptr; | |
| 205 DestroyDeviceInvalidationService(); | |
| 206 } | |
| 207 } | |
| 208 | |
| 209 void AffiliatedInvalidationServiceProvider::Shutdown() { | |
| 210 is_shut_down_ = true; | |
| 211 | |
| 212 registrar_.RemoveAll(); | |
| 213 profile_invalidation_service_observers_.clear(); | |
| 214 DestroyDeviceInvalidationService(); | |
| 215 | |
| 216 if (invalidation_service_) { | |
| 217 invalidation_service_ = nullptr; | |
| 218 // Explicitly notify consumers that the invalidation service they were using | |
| 219 // is no longer available. | |
| 220 SetInvalidationService(nullptr); | |
| 221 } | |
| 222 } | |
| 223 | |
| 224 invalidation::TiclInvalidationService* | |
| 225 AffiliatedInvalidationServiceProvider:: | |
| 226 GetDeviceInvalidationServiceForTest() const { | |
| 227 return device_invalidation_service_.get(); | |
| 228 } | |
| 229 | |
| 230 void AffiliatedInvalidationServiceProvider::OnInvalidationServiceConnected( | |
| 173 invalidation::InvalidationService* invalidation_service) { | 231 invalidation::InvalidationService* invalidation_service) { |
| 232 DCHECK(!is_shut_down_); | |
| 233 | |
| 234 if (consumer_count_ == 0) { | |
| 235 // If there are no consumers, no invalidation service is required. | |
| 236 return; | |
| 237 } | |
| 238 | |
| 174 if (!device_invalidation_service_) { | 239 if (!device_invalidation_service_) { |
| 175 // The lack of a device-global invalidation service implies that a | 240 // The lack of a device-global invalidation service implies that another |
| 176 // |CloudPolicyInvalidator| backed by another connected service exists | 241 // connected invalidation service is being made available to consumers |
| 177 // already. There is no need to switch from that to the service which just | 242 // already. There is no need to switch from that to the service which just |
| 178 // connected. | 243 // connected. |
| 179 return; | 244 return; |
| 180 } | 245 } |
| 181 | 246 |
| 182 if (invalidation_service != device_invalidation_service_.get()) { | 247 if (invalidation_service != device_invalidation_service_.get()) { |
| 183 // If an invalidation service other than the device-global one connected, | 248 // If an invalidation service other than the device-global one connected, |
| 184 // destroy the device-global service and the |CloudPolicyInvalidator| backed | 249 // destroy the device-global service. |
| 185 // by it, if any. | 250 invalidation_service_ = nullptr; |
| 186 DestroyInvalidator(); | |
| 187 DestroyDeviceInvalidationService(); | 251 DestroyDeviceInvalidationService(); |
| 188 } | 252 } |
| 189 | 253 |
| 190 // Create a |CloudPolicyInvalidator| backed by the invalidation service which | 254 // Make the invalidation service that just connected available to consumers. |
| 191 // just connected. | 255 SetInvalidationService(invalidation_service); |
| 192 CreateInvalidator(invalidation_service); | |
| 193 } | 256 } |
| 194 | 257 |
| 195 void DeviceCloudPolicyInvalidator::OnInvalidationServiceDisconnected( | 258 void AffiliatedInvalidationServiceProvider::OnInvalidationServiceDisconnected( |
| 196 invalidation::InvalidationService* invalidation_service) { | 259 invalidation::InvalidationService* invalidation_service) { |
| 260 DCHECK(!is_shut_down_); | |
| 261 | |
| 197 if (invalidation_service != invalidation_service_) { | 262 if (invalidation_service != invalidation_service_) { |
| 198 // If the invalidation service which disconnected is not backing the current | 263 // If the invalidation service which disconnected was not being made |
| 199 // |CloudPolicyInvalidator|, return. | 264 // available to consumers, return. |
| 200 return; | 265 return; |
| 201 } | 266 } |
| 202 | 267 |
| 203 // Destroy the |CloudPolicyInvalidator| backed by the invalidation service | 268 // The invalidation service which disconnected was being made available to |
| 204 // which just disconnected. | 269 // consumers. Stop making it available. |
| 205 DestroyInvalidator(); | 270 DCHECK(consumer_count_); |
| 271 invalidation_service_ = nullptr; | |
| 206 | 272 |
| 207 // Try to create a |CloudPolicyInvalidator| backed by another invalidation | 273 // Try to make another invalidation service available to consumers. |
| 208 // service. | 274 FindConnectedInvalidationService(); |
| 209 TryToCreateInvalidator(); | 275 |
| 276 // If no other connected invalidation service was found, explicitly notify | |
| 277 // consumers that the invalidation service they were using is no longer | |
| 278 // available. | |
| 279 if (!invalidation_service_) | |
| 280 SetInvalidationService(nullptr); | |
| 210 } | 281 } |
| 211 | 282 |
| 212 void DeviceCloudPolicyInvalidator::TryToCreateInvalidator() { | 283 void AffiliatedInvalidationServiceProvider::FindConnectedInvalidationService() { |
| 213 if (invalidator_) { | 284 DCHECK(!invalidation_service_); |
| 214 // If a |CloudPolicyInvalidator| exists already, return. | 285 DCHECK(consumer_count_); |
| 215 return; | 286 DCHECK(!is_shut_down_); |
| 216 } | |
| 217 | 287 |
| 218 for (ScopedVector<InvalidationServiceObserver>::const_iterator it = | 288 for (ScopedVector<InvalidationServiceObserver>::const_iterator it = |
| 219 profile_invalidation_service_observers_.begin(); | 289 profile_invalidation_service_observers_.begin(); |
| 220 it != profile_invalidation_service_observers_.end(); ++it) { | 290 it != profile_invalidation_service_observers_.end(); ++it) { |
| 221 if ((*it)->IsServiceConnected()) { | 291 if ((*it)->IsServiceConnected()) { |
| 222 // If a connected invalidation service belonging to an affiliated | 292 // If a connected invalidation service belonging to an affiliated |
| 223 // logged-in user is found, create a |CloudPolicyInvalidator| backed by | 293 // logged-in user is found, make it available to consumers. |
| 224 // that service and destroy the device-global service, if any. | |
| 225 DestroyDeviceInvalidationService(); | 294 DestroyDeviceInvalidationService(); |
| 226 CreateInvalidator((*it)->GetInvalidationService()); | 295 SetInvalidationService((*it)->GetInvalidationService()); |
| 227 return; | 296 return; |
| 228 } | 297 } |
| 229 } | 298 } |
| 230 | 299 |
| 231 if (!device_invalidation_service_) { | 300 if (!device_invalidation_service_) { |
| 232 // If no other connected invalidation service was found, ensure that a | 301 // If no other connected invalidation service was found and no device-global |
| 233 // device-global service is running. | 302 // invalidation service exists, create one. |
| 234 device_invalidation_service_.reset( | 303 device_invalidation_service_.reset( |
| 235 new invalidation::TiclInvalidationService( | 304 new invalidation::TiclInvalidationService( |
| 236 GetUserAgent(), | 305 GetUserAgent(), |
| 237 scoped_ptr<IdentityProvider>(new chromeos::DeviceIdentityProvider( | 306 scoped_ptr<IdentityProvider>(new chromeos::DeviceIdentityProvider( |
| 238 chromeos::DeviceOAuth2TokenServiceFactory::Get())), | 307 chromeos::DeviceOAuth2TokenServiceFactory::Get())), |
| 239 scoped_ptr<invalidation::TiclSettingsProvider>( | 308 scoped_ptr<invalidation::TiclSettingsProvider>( |
| 240 new TiclDeviceSettingsProvider), | 309 new TiclDeviceSettingsProvider), |
| 241 g_browser_process->gcm_driver(), | 310 g_browser_process->gcm_driver(), |
| 242 g_browser_process->system_request_context())); | 311 g_browser_process->system_request_context())); |
| 243 device_invalidation_service_->Init( | 312 device_invalidation_service_->Init( |
| 244 scoped_ptr<syncer::InvalidationStateTracker>( | 313 scoped_ptr<syncer::InvalidationStateTracker>( |
| 245 new invalidation::InvalidatorStorage( | 314 new invalidation::InvalidatorStorage( |
| 246 g_browser_process->local_state()))); | 315 g_browser_process->local_state()))); |
| 247 device_invalidation_service_observer_.reset( | 316 device_invalidation_service_observer_.reset( |
| 248 new InvalidationServiceObserver( | 317 new InvalidationServiceObserver( |
| 249 this, | 318 this, |
| 250 device_invalidation_service_.get())); | 319 device_invalidation_service_.get())); |
| 251 } | 320 } |
| 252 | 321 |
| 253 if (device_invalidation_service_observer_->IsServiceConnected()) { | 322 if (device_invalidation_service_observer_->IsServiceConnected()) { |
| 254 // If the device-global invalidation service is connected, create a | 323 // If the device-global invalidation service is connected already, make it |
| 255 // |CloudPolicyInvalidator| backed by it. Otherwise, a | 324 // available to consumers immediately. Otherwise, the invalidation service |
| 256 // |CloudPolicyInvalidator| will be created later when a connected service | 325 // will be made available to clients when it successfully connects. |
| 257 // becomes available. | 326 OnInvalidationServiceConnected(device_invalidation_service_.get()); |
| 258 CreateInvalidator(device_invalidation_service_.get()); | |
| 259 } | 327 } |
| 260 } | 328 } |
| 261 | 329 |
| 262 void DeviceCloudPolicyInvalidator::CreateInvalidator( | 330 void AffiliatedInvalidationServiceProvider::SetInvalidationService( |
| 263 invalidation::InvalidationService* invalidation_service) { | 331 invalidation::InvalidationService* invalidation_service) { |
| 332 DCHECK(!invalidation_service_); | |
| 264 invalidation_service_ = invalidation_service; | 333 invalidation_service_ = invalidation_service; |
| 265 DCHECK(!invalidator_); | 334 FOR_EACH_OBSERVER(Consumer, |
| 266 invalidator_.reset(new CloudPolicyInvalidator( | 335 consumers_, |
| 267 enterprise_management::DeviceRegisterRequest::DEVICE, | 336 OnInvalidationServiceSet(invalidation_service_)); |
| 268 g_browser_process->platform_part()->browser_policy_connector_chromeos()-> | |
| 269 GetDeviceCloudPolicyManager()->core(), | |
| 270 base::MessageLoopProxy::current(), | |
| 271 scoped_ptr<base::Clock>(new base::DefaultClock()), | |
| 272 highest_handled_invalidation_version_)); | |
| 273 invalidator_->Initialize(invalidation_service); | |
| 274 } | 337 } |
| 275 | 338 |
| 276 void DeviceCloudPolicyInvalidator::DestroyInvalidator() { | 339 void AffiliatedInvalidationServiceProvider::DestroyDeviceInvalidationService() { |
| 277 if (invalidator_) { | |
| 278 highest_handled_invalidation_version_ = | |
| 279 invalidator_->highest_handled_invalidation_version(); | |
| 280 invalidator_->Shutdown(); | |
| 281 } | |
| 282 invalidator_.reset(); | |
| 283 invalidation_service_ = NULL; | |
| 284 } | |
| 285 | |
| 286 void DeviceCloudPolicyInvalidator::DestroyDeviceInvalidationService() { | |
| 287 device_invalidation_service_observer_.reset(); | 340 device_invalidation_service_observer_.reset(); |
| 288 device_invalidation_service_.reset(); | 341 device_invalidation_service_.reset(); |
| 289 } | 342 } |
| 290 | 343 |
| 291 } // namespace policy | 344 } // namespace policy |
| OLD | NEW |