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