| 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/device_cloud_policy_invalidator.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
| 12 #include "base/time/clock.h" | 12 #include "base/time/clock.h" |
| 13 #include "base/time/default_clock.h" | 13 #include "base/time/default_clock.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/browser_process_platform_part_chromeos.h" | 15 #include "chrome/browser/browser_process_platform_part_chromeos.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
| 17 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 17 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 18 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_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" | 19 #include "chrome/browser/chromeos/policy/ticl_device_settings_provider.h" |
| 20 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 20 #include "chrome/browser/chromeos/settings/device_identity_provider.h" | 21 #include "chrome/browser/chromeos/settings/device_identity_provider.h" |
| 21 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h
" | 22 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h
" |
| 22 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" | 23 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" |
| 23 #include "chrome/browser/policy/cloud/cloud_policy_invalidator.h" | 24 #include "chrome/browser/policy/cloud/cloud_policy_invalidator.h" |
| 24 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
| 25 #include "chrome/common/chrome_content_client.h" | 26 #include "chrome/common/chrome_content_client.h" |
| 26 #include "components/invalidation/invalidation_handler.h" | 27 #include "components/invalidation/invalidation_handler.h" |
| 27 #include "components/invalidation/invalidation_service.h" | 28 #include "components/invalidation/invalidation_service.h" |
| 28 #include "components/invalidation/invalidation_state_tracker.h" | 29 #include "components/invalidation/invalidation_state_tracker.h" |
| 29 #include "components/invalidation/invalidator_state.h" | 30 #include "components/invalidation/invalidator_state.h" |
| 30 #include "components/invalidation/invalidator_storage.h" | 31 #include "components/invalidation/invalidator_storage.h" |
| 31 #include "components/invalidation/profile_invalidation_provider.h" | 32 #include "components/invalidation/profile_invalidation_provider.h" |
| 32 #include "components/invalidation/ticl_invalidation_service.h" | 33 #include "components/invalidation/ticl_invalidation_service.h" |
| 33 #include "components/invalidation/ticl_settings_provider.h" | 34 #include "components/invalidation/ticl_settings_provider.h" |
| 35 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 36 #include "components/user_manager/user.h" |
| 34 #include "content/public/browser/notification_details.h" | 37 #include "content/public/browser/notification_details.h" |
| 35 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
| 36 #include "google_apis/gaia/identity_provider.h" | 39 #include "google_apis/gaia/identity_provider.h" |
| 37 #include "net/url_request/url_request_context_getter.h" | 40 #include "net/url_request/url_request_context_getter.h" |
| 38 #include "policy/proto/device_management_backend.pb.h" | 41 #include "policy/proto/device_management_backend.pb.h" |
| 39 | 42 |
| 40 class Profile; | 43 class Profile; |
| 41 | 44 |
| 42 namespace policy { | 45 namespace policy { |
| 43 | 46 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 137 |
| 135 DeviceCloudPolicyInvalidator::~DeviceCloudPolicyInvalidator() { | 138 DeviceCloudPolicyInvalidator::~DeviceCloudPolicyInvalidator() { |
| 136 DestroyInvalidator(); | 139 DestroyInvalidator(); |
| 137 } | 140 } |
| 138 | 141 |
| 139 void DeviceCloudPolicyInvalidator::Observe( | 142 void DeviceCloudPolicyInvalidator::Observe( |
| 140 int type, | 143 int type, |
| 141 const content::NotificationSource& source, | 144 const content::NotificationSource& source, |
| 142 const content::NotificationDetails& details) { | 145 const content::NotificationDetails& details) { |
| 143 DCHECK_EQ(chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, type); | 146 DCHECK_EQ(chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, type); |
| 147 Profile* profile = content::Details<Profile>(details).ptr(); |
| 144 invalidation::ProfileInvalidationProvider* invalidation_provider = | 148 invalidation::ProfileInvalidationProvider* invalidation_provider = |
| 145 invalidation::ProfileInvalidationProviderFactory::GetForProfile( | 149 invalidation::ProfileInvalidationProviderFactory::GetForProfile(profile); |
| 146 content::Details<Profile>(details).ptr()); | |
| 147 if (!invalidation_provider) { | 150 if (!invalidation_provider) { |
| 148 // If the Profile does not support invalidation (e.g. guest, incognito), | 151 // If the Profile does not support invalidation (e.g. guest, incognito), |
| 149 // ignore it. | 152 // ignore it. |
| 150 return; | 153 return; |
| 151 } | 154 } |
| 152 | 155 user_manager::User* user = |
| 156 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); |
| 157 if (!user || |
| 158 g_browser_process->platform_part()->browser_policy_connector_chromeos()-> |
| 159 GetUserAffiliation(user->email()) != USER_AFFILIATION_MANAGED) { |
| 160 // If the Profile belongs to a user who is not affiliated with the domain |
| 161 // the device is enrolled into, ignore it. |
| 162 return; |
| 163 } |
| 153 // Create a state observer for the user's invalidation service. | 164 // Create a state observer for the user's invalidation service. |
| 154 profile_invalidation_service_observers_.push_back( | 165 profile_invalidation_service_observers_.push_back( |
| 155 new InvalidationServiceObserver( | 166 new InvalidationServiceObserver( |
| 156 this, | 167 this, |
| 157 invalidation_provider->GetInvalidationService())); | 168 invalidation_provider->GetInvalidationService())); |
| 158 | 169 |
| 159 TryToCreateInvalidator(); | 170 TryToCreateInvalidator(); |
| 160 } | 171 } |
| 161 | 172 |
| 162 void DeviceCloudPolicyInvalidator::OnInvalidationServiceConnected( | 173 void DeviceCloudPolicyInvalidator::OnInvalidationServiceConnected( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 void DeviceCloudPolicyInvalidator::TryToCreateInvalidator() { | 213 void DeviceCloudPolicyInvalidator::TryToCreateInvalidator() { |
| 203 if (invalidator_) { | 214 if (invalidator_) { |
| 204 // If a |CloudPolicyInvalidator| exists already, return. | 215 // If a |CloudPolicyInvalidator| exists already, return. |
| 205 return; | 216 return; |
| 206 } | 217 } |
| 207 | 218 |
| 208 for (ScopedVector<InvalidationServiceObserver>::const_iterator it = | 219 for (ScopedVector<InvalidationServiceObserver>::const_iterator it = |
| 209 profile_invalidation_service_observers_.begin(); | 220 profile_invalidation_service_observers_.begin(); |
| 210 it != profile_invalidation_service_observers_.end(); ++it) { | 221 it != profile_invalidation_service_observers_.end(); ++it) { |
| 211 if ((*it)->IsServiceConnected()) { | 222 if ((*it)->IsServiceConnected()) { |
| 212 // If a connected invalidation service belonging to a logged-in user is | 223 // If a connected invalidation service belonging to an affiliated |
| 213 // found, create a |CloudPolicyInvalidator| backed by that service and | 224 // logged-in user is found, create a |CloudPolicyInvalidator| backed by |
| 214 // destroy the device-global service, if any. | 225 // that service and destroy the device-global service, if any. |
| 215 DestroyDeviceInvalidationService(); | 226 DestroyDeviceInvalidationService(); |
| 216 CreateInvalidator((*it)->GetInvalidationService()); | 227 CreateInvalidator((*it)->GetInvalidationService()); |
| 217 return; | 228 return; |
| 218 } | 229 } |
| 219 } | 230 } |
| 220 | 231 |
| 221 if (!device_invalidation_service_) { | 232 if (!device_invalidation_service_) { |
| 222 // If no other connected invalidation service was found, ensure that a | 233 // If no other connected invalidation service was found, ensure that a |
| 223 // device-global service is running. | 234 // device-global service is running. |
| 224 device_invalidation_service_.reset( | 235 device_invalidation_service_.reset( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 invalidator_.reset(); | 283 invalidator_.reset(); |
| 273 invalidation_service_ = NULL; | 284 invalidation_service_ = NULL; |
| 274 } | 285 } |
| 275 | 286 |
| 276 void DeviceCloudPolicyInvalidator::DestroyDeviceInvalidationService() { | 287 void DeviceCloudPolicyInvalidator::DestroyDeviceInvalidationService() { |
| 277 device_invalidation_service_observer_.reset(); | 288 device_invalidation_service_observer_.reset(); |
| 278 device_invalidation_service_.reset(); | 289 device_invalidation_service_.reset(); |
| 279 } | 290 } |
| 280 | 291 |
| 281 } // namespace policy | 292 } // namespace policy |
| OLD | NEW |