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