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