Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/policy/browser_policy_connector.h" | 5 #include "chrome/browser/policy/browser_policy_connector.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "chrome/browser/net/gaia/token_service.h" | 9 #include "chrome/browser/net/gaia/token_service.h" |
| 10 #include "chrome/browser/policy/cloud_policy_data.h" | |
| 10 #include "chrome/browser/policy/cloud_policy_provider.h" | 11 #include "chrome/browser/policy/cloud_policy_provider.h" |
| 11 #include "chrome/browser/policy/cloud_policy_provider_impl.h" | 12 #include "chrome/browser/policy/cloud_policy_provider_impl.h" |
| 12 #include "chrome/browser/policy/cloud_policy_subsystem.h" | 13 #include "chrome/browser/policy/cloud_policy_subsystem.h" |
| 13 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 14 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| 14 #include "chrome/browser/policy/configuration_policy_provider.h" | 15 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 15 #include "chrome/browser/policy/dummy_cloud_policy_provider.h" | 16 #include "chrome/browser/policy/dummy_cloud_policy_provider.h" |
| 16 #include "chrome/browser/policy/dummy_configuration_policy_provider.h" | 17 #include "chrome/browser/policy/dummy_configuration_policy_provider.h" |
| 17 #include "chrome/browser/policy/user_policy_cache.h" | 18 #include "chrome/browser/policy/user_policy_cache.h" |
| 18 #include "chrome/browser/policy/user_policy_identity_strategy.h" | 19 #include "chrome/browser/policy/user_policy_token_cache.h" |
| 19 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
| 20 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/net/gaia/gaia_constants.h" | 22 #include "chrome/common/net/gaia/gaia_constants.h" |
| 22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 23 #include "content/common/notification_details.h" | 24 #include "content/common/notification_details.h" |
| 24 #include "content/common/notification_source.h" | 25 #include "content/common/notification_source.h" |
| 25 | 26 |
| 26 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
| 27 #include "chrome/browser/policy/configuration_policy_provider_win.h" | 28 #include "chrome/browser/policy/configuration_policy_provider_win.h" |
| 28 #elif defined(OS_MACOSX) | 29 #elif defined(OS_MACOSX) |
| 29 #include "chrome/browser/policy/configuration_policy_provider_mac.h" | 30 #include "chrome/browser/policy/configuration_policy_provider_mac.h" |
| 30 #elif defined(OS_POSIX) | 31 #elif defined(OS_POSIX) |
| 31 #include "chrome/browser/policy/config_dir_policy_provider.h" | 32 #include "chrome/browser/policy/config_dir_policy_provider.h" |
| 32 #endif | 33 #endif |
| 33 | 34 |
| 34 #if defined(OS_CHROMEOS) | 35 #if defined(OS_CHROMEOS) |
| 35 #include "chrome/browser/chromeos/cros/cros_library.h" | 36 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 36 #include "chrome/browser/policy/device_policy_cache.h" | 37 #include "chrome/browser/policy/device_policy_cache.h" |
| 37 #include "chrome/browser/policy/device_policy_identity_strategy.h" | |
| 38 #include "content/common/notification_service.h" | 38 #include "content/common/notification_service.h" |
|
Joao da Silva
2011/07/06 16:45:14
Nit: notification_service.h not used
gfeher
2011/07/07 13:51:00
Done.
| |
| 39 #endif | 39 #endif |
| 40 | 40 |
| 41 namespace policy { | 41 namespace policy { |
| 42 | 42 |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 // Subdirectory in the user's profile for storing user policies. | 45 // Subdirectory in the user's profile for storing user policies. |
| 46 const FilePath::CharType kPolicyDir[] = FILE_PATH_LITERAL("Device Management"); | 46 const FilePath::CharType kPolicyDir[] = FILE_PATH_LITERAL("Device Management"); |
| 47 // File in the above directory for stroing user policy dmtokens. | 47 // File in the above directory for stroing user policy dmtokens. |
| 48 const FilePath::CharType kTokenCacheFile[] = FILE_PATH_LITERAL("Token"); | 48 const FilePath::CharType kTokenCacheFile[] = FILE_PATH_LITERAL("Token"); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 managed_cloud_provider_(managed_cloud_provider), | 100 managed_cloud_provider_(managed_cloud_provider), |
| 101 recommended_cloud_provider_(recommended_cloud_provider), | 101 recommended_cloud_provider_(recommended_cloud_provider), |
| 102 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {} | 102 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {} |
| 103 | 103 |
| 104 BrowserPolicyConnector::~BrowserPolicyConnector() { | 104 BrowserPolicyConnector::~BrowserPolicyConnector() { |
| 105 // Shutdown device cloud policy. | 105 // Shutdown device cloud policy. |
| 106 #if defined(OS_CHROMEOS) | 106 #if defined(OS_CHROMEOS) |
| 107 if (device_cloud_policy_subsystem_.get()) | 107 if (device_cloud_policy_subsystem_.get()) |
| 108 device_cloud_policy_subsystem_->Shutdown(); | 108 device_cloud_policy_subsystem_->Shutdown(); |
| 109 device_cloud_policy_subsystem_.reset(); | 109 device_cloud_policy_subsystem_.reset(); |
| 110 device_identity_strategy_.reset(); | 110 device_policy_data_.reset(); |
| 111 #endif | 111 #endif |
| 112 | 112 |
| 113 // Shutdown user cloud policy. | 113 // Shutdown user cloud policy. |
| 114 if (user_cloud_policy_subsystem_.get()) | 114 if (user_cloud_policy_subsystem_.get()) |
| 115 user_cloud_policy_subsystem_->Shutdown(); | 115 user_cloud_policy_subsystem_->Shutdown(); |
| 116 user_cloud_policy_subsystem_.reset(); | 116 user_cloud_policy_subsystem_.reset(); |
| 117 user_identity_strategy_.reset(); | 117 user_policy_data_.reset(); |
| 118 user_policy_token_cache_ = NULL; | |
| 118 } | 119 } |
| 119 | 120 |
| 120 ConfigurationPolicyProvider* | 121 ConfigurationPolicyProvider* |
| 121 BrowserPolicyConnector::GetManagedPlatformProvider() const { | 122 BrowserPolicyConnector::GetManagedPlatformProvider() const { |
| 122 return managed_platform_provider_.get(); | 123 return managed_platform_provider_.get(); |
| 123 } | 124 } |
| 124 | 125 |
| 125 ConfigurationPolicyProvider* | 126 ConfigurationPolicyProvider* |
| 126 BrowserPolicyConnector::GetManagedCloudProvider() const { | 127 BrowserPolicyConnector::GetManagedCloudProvider() const { |
| 127 return managed_cloud_provider_.get(); | 128 return managed_cloud_provider_.get(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 } | 175 } |
| 175 #else | 176 #else |
| 176 return new DummyConfigurationPolicyProvider(policy_list); | 177 return new DummyConfigurationPolicyProvider(policy_list); |
| 177 #endif | 178 #endif |
| 178 } | 179 } |
| 179 | 180 |
| 180 void BrowserPolicyConnector::SetDeviceCredentials( | 181 void BrowserPolicyConnector::SetDeviceCredentials( |
| 181 const std::string& owner_email, | 182 const std::string& owner_email, |
| 182 const std::string& gaia_token) { | 183 const std::string& gaia_token) { |
| 183 #if defined(OS_CHROMEOS) | 184 #if defined(OS_CHROMEOS) |
| 184 if (device_identity_strategy_.get()) | 185 if (device_policy_data_.get()) { |
| 185 device_identity_strategy_->SetAuthCredentials(owner_email, gaia_token); | 186 device_policy_data_->set_user_name(owner_email); |
| 187 device_policy_data_->SetGaiaToken(gaia_token); | |
| 188 } | |
| 186 #endif | 189 #endif |
| 187 } | 190 } |
| 188 | 191 |
| 189 bool BrowserPolicyConnector::IsEnterpriseManaged() { | 192 bool BrowserPolicyConnector::IsEnterpriseManaged() { |
| 190 #if defined(OS_CHROMEOS) | 193 #if defined(OS_CHROMEOS) |
| 191 return install_attributes_.get() && install_attributes_->IsEnterpriseDevice(); | 194 return install_attributes_.get() && install_attributes_->IsEnterpriseDevice(); |
| 192 #else | 195 #else |
| 193 return false; | 196 return false; |
| 194 #endif | 197 #endif |
| 195 } | 198 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 215 | 218 |
| 216 void BrowserPolicyConnector::DeviceStopAutoRetry() { | 219 void BrowserPolicyConnector::DeviceStopAutoRetry() { |
| 217 #if defined(OS_CHROMEOS) | 220 #if defined(OS_CHROMEOS) |
| 218 if (device_cloud_policy_subsystem_.get()) | 221 if (device_cloud_policy_subsystem_.get()) |
| 219 device_cloud_policy_subsystem_->StopAutoRetry(); | 222 device_cloud_policy_subsystem_->StopAutoRetry(); |
| 220 #endif | 223 #endif |
| 221 } | 224 } |
| 222 | 225 |
| 223 void BrowserPolicyConnector::FetchDevicePolicy() { | 226 void BrowserPolicyConnector::FetchDevicePolicy() { |
| 224 #if defined(OS_CHROMEOS) | 227 #if defined(OS_CHROMEOS) |
| 225 if (device_identity_strategy_.get()) | 228 if (device_policy_data_.get()) { |
| 226 return device_identity_strategy_->FetchPolicy(); | 229 DCHECK(!device_policy_data_->device_token().empty()); |
| 230 device_policy_data_->NotifyDeviceTokenChanged(); | |
| 231 } | |
| 227 #endif | 232 #endif |
| 228 } | 233 } |
| 229 | 234 |
| 230 void BrowserPolicyConnector::InitializeUserPolicy(const std::string& user_name, | 235 void BrowserPolicyConnector::InitializeUserPolicy(const std::string& user_name, |
| 231 const FilePath& policy_dir, | 236 const FilePath& policy_dir, |
| 232 TokenService* token_service) { | 237 TokenService* token_service) { |
| 233 DCHECK(token_service); | 238 DCHECK(token_service); |
| 234 | 239 |
| 235 // Throw away the old backend. | 240 // Throw away the old backend. |
| 236 user_cloud_policy_subsystem_.reset(); | 241 user_cloud_policy_subsystem_.reset(); |
| 237 user_identity_strategy_.reset(); | 242 user_policy_data_.reset(); |
| 243 user_policy_token_cache_ = NULL; | |
| 238 registrar_.RemoveAll(); | 244 registrar_.RemoveAll(); |
| 239 | 245 |
| 240 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 246 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 241 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { | 247 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { |
| 242 token_service_ = token_service; | 248 token_service_ = token_service; |
| 243 registrar_.Add(this, | 249 registrar_.Add(this, |
| 244 NotificationType::TOKEN_AVAILABLE, | 250 NotificationType::TOKEN_AVAILABLE, |
| 245 Source<TokenService>(token_service_)); | 251 Source<TokenService>(token_service_)); |
| 246 | 252 |
| 247 FilePath policy_cache_dir = policy_dir.Append(kPolicyDir); | 253 FilePath policy_cache_dir = policy_dir.Append(kPolicyDir); |
| 248 UserPolicyCache* user_policy_cache = | 254 UserPolicyCache* user_policy_cache = |
| 249 new UserPolicyCache(policy_cache_dir.Append(kPolicyCacheFile)); | 255 new UserPolicyCache(policy_cache_dir.Append(kPolicyCacheFile)); |
| 256 user_policy_data_.reset(CloudPolicyData::CreateForUserPolicies()); | |
| 257 user_policy_token_cache_ = new UserPolicyTokenCache( | |
| 258 user_policy_data_.get(), policy_cache_dir.Append(kTokenCacheFile)); | |
| 250 | 259 |
| 251 // Prepending user caches meaning they will take precedence of device policy | 260 // Prepending user caches meaning they will take precedence of device policy |
| 252 // caches. | 261 // caches. |
| 253 managed_cloud_provider_->PrependCache(user_policy_cache); | 262 managed_cloud_provider_->PrependCache(user_policy_cache); |
| 254 recommended_cloud_provider_->PrependCache(user_policy_cache); | 263 recommended_cloud_provider_->PrependCache(user_policy_cache); |
| 255 user_identity_strategy_.reset( | |
| 256 new UserPolicyIdentityStrategy( | |
| 257 user_name, | |
| 258 policy_cache_dir.Append(kTokenCacheFile))); | |
| 259 user_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( | 264 user_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
| 260 user_identity_strategy_.get(), | 265 user_policy_data_.get(), |
| 261 user_policy_cache)); | 266 user_policy_cache)); |
| 262 | 267 |
| 263 // Initiate the DM-Token load. | 268 // Initiate the DM-Token load. |
| 264 user_identity_strategy_->LoadTokenCache(); | 269 user_policy_token_cache_->Load(); |
| 265 | 270 |
| 271 user_policy_data_->set_user_name(user_name); | |
| 266 if (token_service_->HasTokenForService( | 272 if (token_service_->HasTokenForService( |
| 267 GaiaConstants::kDeviceManagementService)) { | 273 GaiaConstants::kDeviceManagementService)) { |
| 268 user_identity_strategy_->SetAuthToken( | 274 user_policy_data_->SetGaiaToken(token_service_->GetTokenForService( |
| 269 token_service_->GetTokenForService( | |
| 270 GaiaConstants::kDeviceManagementService)); | 275 GaiaConstants::kDeviceManagementService)); |
| 271 } | 276 } |
| 272 | 277 |
| 273 user_cloud_policy_subsystem_->CompleteInitialization( | 278 user_cloud_policy_subsystem_->CompleteInitialization( |
| 274 prefs::kUserPolicyRefreshRate, | 279 prefs::kUserPolicyRefreshRate, |
| 275 kServiceInitializationStartupDelay); | 280 kServiceInitializationStartupDelay); |
| 276 } | 281 } |
| 277 } | 282 } |
| 278 | 283 |
| 279 void BrowserPolicyConnector::ScheduleServiceInitialization( | 284 void BrowserPolicyConnector::ScheduleServiceInitialization( |
| 280 int64 delay_milliseconds) { | 285 int64 delay_milliseconds) { |
| 281 if (user_cloud_policy_subsystem_.get()) { | 286 if (user_cloud_policy_subsystem_.get()) { |
| 282 user_cloud_policy_subsystem_-> | 287 user_cloud_policy_subsystem_-> |
| 283 ScheduleServiceInitialization(delay_milliseconds); | 288 ScheduleServiceInitialization(delay_milliseconds); |
| 284 } | 289 } |
| 285 #if defined(OS_CHROMEOS) | 290 #if defined(OS_CHROMEOS) |
| 286 if (device_cloud_policy_subsystem_.get()) { | 291 if (device_cloud_policy_subsystem_.get()) { |
| 287 device_cloud_policy_subsystem_-> | 292 device_cloud_policy_subsystem_-> |
| 288 ScheduleServiceInitialization(delay_milliseconds); | 293 ScheduleServiceInitialization(delay_milliseconds); |
| 289 } | 294 } |
| 290 #endif | 295 #endif |
| 291 } | 296 } |
| 292 | 297 |
| 293 void BrowserPolicyConnector::InitializeDevicePolicy() { | 298 void BrowserPolicyConnector::InitializeDevicePolicy() { |
| 294 #if defined(OS_CHROMEOS) | 299 #if defined(OS_CHROMEOS) |
| 295 // Throw away the old backend. | 300 // Throw away the old backend. |
| 296 device_cloud_policy_subsystem_.reset(); | 301 device_cloud_policy_subsystem_.reset(); |
| 297 device_identity_strategy_.reset(); | 302 device_policy_data_.reset(); |
| 298 | 303 |
| 299 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 304 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 300 if (command_line->HasSwitch(switches::kEnableDevicePolicy)) { | 305 if (command_line->HasSwitch(switches::kEnableDevicePolicy)) { |
| 301 device_identity_strategy_.reset(new DevicePolicyIdentityStrategy()); | 306 device_policy_data_.reset(CloudPolicyData::CreateForDevicePolicies()); |
| 302 install_attributes_.reset(new EnterpriseInstallAttributes( | 307 install_attributes_.reset(new EnterpriseInstallAttributes( |
| 303 chromeos::CrosLibrary::Get()->GetCryptohomeLibrary())); | 308 chromeos::CrosLibrary::Get()->GetCryptohomeLibrary())); |
| 304 DevicePolicyCache* device_policy_cache = | 309 DevicePolicyCache* device_policy_cache = |
| 305 new DevicePolicyCache(device_identity_strategy_.get(), | 310 new DevicePolicyCache(device_policy_data_.get(), |
| 306 install_attributes_.get()); | 311 install_attributes_.get()); |
| 307 | 312 |
| 308 managed_cloud_provider_->AppendCache(device_policy_cache); | 313 managed_cloud_provider_->AppendCache(device_policy_cache); |
| 309 recommended_cloud_provider_->AppendCache(device_policy_cache); | 314 recommended_cloud_provider_->AppendCache(device_policy_cache); |
| 310 | 315 |
| 311 device_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( | 316 device_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
| 312 device_identity_strategy_.get(), | 317 device_policy_data_.get(), |
| 313 device_policy_cache)); | 318 device_policy_cache)); |
| 314 | 319 |
| 315 // Initialize the subsystem once the message loops are spinning. | 320 // Initialize the subsystem once the message loops are spinning. |
| 316 MessageLoop::current()->PostTask( | 321 MessageLoop::current()->PostTask( |
| 317 FROM_HERE, | 322 FROM_HERE, |
| 318 method_factory_.NewRunnableMethod( | 323 method_factory_.NewRunnableMethod( |
| 319 &BrowserPolicyConnector::InitializeDevicePolicySubsystem)); | 324 &BrowserPolicyConnector::InitializeDevicePolicySubsystem)); |
| 320 } | 325 } |
| 321 #endif | 326 #endif |
| 322 } | 327 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 335 const NotificationSource& source, | 340 const NotificationSource& source, |
| 336 const NotificationDetails& details) { | 341 const NotificationDetails& details) { |
| 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 342 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 338 if (type == NotificationType::TOKEN_AVAILABLE) { | 343 if (type == NotificationType::TOKEN_AVAILABLE) { |
| 339 const TokenService* token_source = | 344 const TokenService* token_source = |
| 340 Source<const TokenService>(source).ptr(); | 345 Source<const TokenService>(source).ptr(); |
| 341 DCHECK_EQ(token_service_, token_source); | 346 DCHECK_EQ(token_service_, token_source); |
| 342 const TokenService::TokenAvailableDetails* token_details = | 347 const TokenService::TokenAvailableDetails* token_details = |
| 343 Details<const TokenService::TokenAvailableDetails>(details).ptr(); | 348 Details<const TokenService::TokenAvailableDetails>(details).ptr(); |
| 344 if (token_details->service() == GaiaConstants::kDeviceManagementService) { | 349 if (token_details->service() == GaiaConstants::kDeviceManagementService) { |
| 345 if (user_identity_strategy_.get()) { | 350 if (user_policy_data_.get()) { |
| 346 user_identity_strategy_->SetAuthToken(token_details->token()); | 351 user_policy_data_->SetGaiaToken(token_details->token()); |
| 347 } | 352 } |
| 348 } | 353 } |
| 349 } else { | 354 } else { |
| 350 NOTREACHED(); | 355 NOTREACHED(); |
| 351 } | 356 } |
| 352 } | 357 } |
| 353 | 358 |
| 354 } // namespace | 359 } // namespace |
| OLD | NEW |