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