| 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/chromeos/login/signed_settings.h" | 5 #include "chrome/browser/chromeos/login/signed_settings.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/stringprintf.h" | |
| 13 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
| 14 #include "base/values.h" | |
| 15 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/chromeos/cros/cros_library.h" | 14 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 17 #include "chrome/browser/chromeos/cros_settings_names.h" | |
| 18 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 15 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
| 19 #include "chrome/browser/chromeos/dbus/session_manager_client.h" | 16 #include "chrome/browser/chromeos/dbus/session_manager_client.h" |
| 20 #include "chrome/browser/chromeos/login/authenticator.h" | 17 #include "chrome/browser/chromeos/login/authenticator.h" |
| 21 #include "chrome/browser/chromeos/login/ownership_service.h" | 18 #include "chrome/browser/chromeos/login/ownership_service.h" |
| 22 #include "chrome/browser/chromeos/login/signed_settings_temp_storage.h" | |
| 23 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" | 19 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" |
| 24 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 20 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
| 25 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 26 | 22 |
| 27 namespace chromeos { | 23 namespace chromeos { |
| 28 using content::BrowserThread; | 24 using content::BrowserThread; |
| 29 using google::protobuf::RepeatedPtrField; | 25 using google::protobuf::RepeatedPtrField; |
| 30 using std::string; | 26 using std::string; |
| 31 | 27 |
| 32 // static | 28 const char kDevicePolicyType[] = "google/chromeos/device"; |
| 33 const char SignedSettings::kDevicePolicyType[] = "google/chromeos/device"; | |
| 34 | |
| 35 SignedSettings::Relay::Relay(SignedSettings* s) : settings_(s) { | |
| 36 } | |
| 37 | |
| 38 SignedSettings::Relay::~Relay() {} | |
| 39 | |
| 40 void SignedSettings::Relay::OnSettingsOpCompleted( | |
| 41 SignedSettings::ReturnCode code, | |
| 42 const em::PolicyFetchResponse& value) { | |
| 43 if (code == SignedSettings::SUCCESS) { | |
| 44 settings_->Execute(); | |
| 45 return; | |
| 46 } | |
| 47 settings_->Fail(code); | |
| 48 } | |
| 49 | 29 |
| 50 SignedSettings::SignedSettings() | 30 SignedSettings::SignedSettings() |
| 51 : service_(OwnershipService::GetSharedInstance()), | 31 : service_(OwnershipService::GetSharedInstance()) { |
| 52 relay_(NULL), | |
| 53 polfetcher_(NULL) { | |
| 54 } | 32 } |
| 55 | 33 |
| 56 SignedSettings::~SignedSettings() {} | 34 SignedSettings::~SignedSettings() {} |
| 57 | 35 |
| 58 void SignedSettings::TryToFetchPolicyAndCallBack() { | |
| 59 relay_.reset(new Relay(this)); | |
| 60 polfetcher_ = SignedSettings::CreateRetrievePolicyOp(relay_.get()); | |
| 61 polfetcher_->set_service(service_); | |
| 62 polfetcher_->Execute(); | |
| 63 } | |
| 64 | |
| 65 // static | 36 // static |
| 66 bool SignedSettings::PolicyIsSane(const em::PolicyFetchResponse& value, | 37 bool SignedSettings::PolicyIsSane(const em::PolicyFetchResponse& value, |
| 67 em::PolicyData* poldata) { | 38 em::PolicyData* poldata) { |
| 68 if (value.has_policy_data()) { | 39 if (value.has_policy_data()) { |
| 69 poldata->ParseFromString(value.policy_data()); | 40 poldata->ParseFromString(value.policy_data()); |
| 70 if (poldata->has_policy_type() && | 41 if (poldata->has_policy_type() && |
| 71 poldata->policy_type() == kDevicePolicyType && | 42 poldata->policy_type() == kDevicePolicyType && |
| 72 poldata->has_policy_value()) { | 43 poldata->has_policy_value()) { |
| 73 return true; | 44 return true; |
| 74 } | 45 } |
| 75 } | 46 } |
| 76 return false; | 47 return false; |
| 77 } | 48 } |
| 78 | 49 |
| 79 // static | 50 // static |
| 80 SignedSettings::ReturnCode SignedSettings::MapKeyOpCode( | 51 SignedSettings::ReturnCode SignedSettings::MapKeyOpCode( |
| 81 OwnerManager::KeyOpCode return_code) { | 52 OwnerManager::KeyOpCode return_code) { |
| 82 return (return_code == OwnerManager::KEY_UNAVAILABLE ? | 53 return (return_code == OwnerManager::KEY_UNAVAILABLE ? |
| 83 KEY_UNAVAILABLE : BAD_SIGNATURE); | 54 KEY_UNAVAILABLE : BAD_SIGNATURE); |
| 84 } | 55 } |
| 85 | 56 |
| 86 class StorePropertyOp : public SignedSettings, | |
| 87 public SignedSettings::Delegate<bool> { | |
| 88 public: | |
| 89 StorePropertyOp(const std::string& name, | |
| 90 const base::Value& value, | |
| 91 SignedSettings::Delegate<bool>* d); | |
| 92 virtual ~StorePropertyOp(); | |
| 93 void Execute(); | |
| 94 void Fail(SignedSettings::ReturnCode code); | |
| 95 void Succeed(bool value); | |
| 96 // Implementation of OwnerManager::Delegate | |
| 97 void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, | |
| 98 const std::vector<uint8>& payload); | |
| 99 // Implementation of SignedSettings::Delegate | |
| 100 void OnSettingsOpCompleted(ReturnCode code, bool value); | |
| 101 | |
| 102 private: | |
| 103 void SetInPolicy(const std::string& prop, | |
| 104 const base::Value& value, | |
| 105 em::PolicyData* poldata); | |
| 106 // Always call d_->OnSettingOpCompleted() via this call. | |
| 107 // It guarantees that the callback will not be triggered until _after_ | |
| 108 // Execute() returns, which is implicitly assumed by SignedSettingsHelper | |
| 109 // in some cases. | |
| 110 void PerformCallback(SignedSettings::ReturnCode code, bool value); | |
| 111 | |
| 112 std::string name_; | |
| 113 scoped_ptr<base::Value> value_; | |
| 114 SignedSettings::Delegate<bool>* d_; | |
| 115 em::PolicyFetchResponse to_store_; | |
| 116 scoped_refptr<SignedSettings> store_op_; | |
| 117 }; | |
| 118 | |
| 119 class RetrievePropertyOp : public SignedSettings { | |
| 120 public: | |
| 121 RetrievePropertyOp(const std::string& name, | |
| 122 SignedSettings::Delegate<const base::Value*>* d); | |
| 123 virtual ~RetrievePropertyOp(); | |
| 124 void Execute(); | |
| 125 void Fail(SignedSettings::ReturnCode code); | |
| 126 void Succeed(const base::Value* value); | |
| 127 // Implementation of OwnerManager::Delegate::OnKeyOpComplete() | |
| 128 void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, | |
| 129 const std::vector<uint8>& payload); | |
| 130 | |
| 131 private: | |
| 132 base::Value* LookUpInPolicy(const std::string& prop); | |
| 133 // Always call d_->OnSettingOpCompleted() via this call. | |
| 134 // It guarantees that the callback will not be triggered until _after_ | |
| 135 // Execute() returns, which is implicitly assumed by SignedSettingsHelper | |
| 136 // in some cases. | |
| 137 void PerformCallback(SignedSettings::ReturnCode code, | |
| 138 const base::Value* value); | |
| 139 | |
| 140 std::string name_; | |
| 141 SignedSettings::Delegate<const base::Value*>* d_; | |
| 142 }; | |
| 143 | |
| 144 class StorePolicyOp : public SignedSettings { | 57 class StorePolicyOp : public SignedSettings { |
| 145 public: | 58 public: |
| 146 StorePolicyOp(em::PolicyFetchResponse* policy, | 59 StorePolicyOp(em::PolicyFetchResponse* policy, |
| 147 SignedSettings::Delegate<bool>* d); | 60 SignedSettings::Delegate<bool>* d); |
| 148 virtual ~StorePolicyOp(); | 61 virtual ~StorePolicyOp(); |
| 149 void Execute(); | 62 void Execute(); |
| 150 void Fail(SignedSettings::ReturnCode code); | 63 void Fail(SignedSettings::ReturnCode code); |
| 151 void Succeed(bool value); | 64 void Succeed(bool value); |
| 152 // Implementation of OwnerManager::Delegate | 65 // Implementation of OwnerManager::Delegate |
| 153 void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, | 66 void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 void PerformCallback(SignedSettings::ReturnCode code, | 101 void PerformCallback(SignedSettings::ReturnCode code, |
| 189 const em::PolicyFetchResponse& value); | 102 const em::PolicyFetchResponse& value); |
| 190 | 103 |
| 191 void ProcessPolicy(const std::string& serialized_proto); | 104 void ProcessPolicy(const std::string& serialized_proto); |
| 192 | 105 |
| 193 em::PolicyFetchResponse policy_; | 106 em::PolicyFetchResponse policy_; |
| 194 SignedSettings::Delegate<const em::PolicyFetchResponse&>* d_; | 107 SignedSettings::Delegate<const em::PolicyFetchResponse&>* d_; |
| 195 }; | 108 }; |
| 196 | 109 |
| 197 // static | 110 // static |
| 198 SignedSettings* SignedSettings::CreateStorePropertyOp( | |
| 199 const std::string& name, | |
| 200 const base::Value& value, | |
| 201 SignedSettings::Delegate<bool>* d) { | |
| 202 DCHECK(d != NULL); | |
| 203 return new StorePropertyOp(name, value, d); | |
| 204 } | |
| 205 | |
| 206 // static | |
| 207 SignedSettings* SignedSettings::CreateRetrievePropertyOp( | |
| 208 const std::string& name, | |
| 209 SignedSettings::Delegate<const base::Value*>* d) { | |
| 210 DCHECK(d != NULL); | |
| 211 return new RetrievePropertyOp(name, d); | |
| 212 } | |
| 213 | |
| 214 // static | |
| 215 SignedSettings* SignedSettings::CreateStorePolicyOp( | 111 SignedSettings* SignedSettings::CreateStorePolicyOp( |
| 216 em::PolicyFetchResponse* policy, | 112 em::PolicyFetchResponse* policy, |
| 217 SignedSettings::Delegate<bool>* d) { | 113 SignedSettings::Delegate<bool>* d) { |
| 218 DCHECK(d != NULL); | 114 DCHECK(d != NULL); |
| 219 DCHECK(policy != NULL); | 115 DCHECK(policy != NULL); |
| 220 return new StorePolicyOp(policy, d); | 116 return new StorePolicyOp(policy, d); |
| 221 } | 117 } |
| 222 | 118 |
| 223 // static | 119 // static |
| 224 SignedSettings* SignedSettings::CreateRetrievePolicyOp( | 120 SignedSettings* SignedSettings::CreateRetrievePolicyOp( |
| 225 SignedSettings::Delegate<const em::PolicyFetchResponse&>* d) { | 121 SignedSettings::Delegate<const em::PolicyFetchResponse&>* d) { |
| 226 DCHECK(d != NULL); | 122 DCHECK(d != NULL); |
| 227 return new RetrievePolicyOp(d); | 123 return new RetrievePolicyOp(d); |
| 228 } | 124 } |
| 229 | 125 |
| 230 StorePropertyOp::StorePropertyOp(const std::string& name, | |
| 231 const base::Value& value, | |
| 232 SignedSettings::Delegate<bool>* d) | |
| 233 : name_(name), | |
| 234 value_(value.DeepCopy()), | |
| 235 d_(d), | |
| 236 store_op_(NULL) { | |
| 237 } | |
| 238 | |
| 239 StorePropertyOp::~StorePropertyOp() {} | |
| 240 | |
| 241 void StorePropertyOp::Execute() { | |
| 242 if (service_->GetStatus(true) != OwnershipService::OWNERSHIP_TAKEN) { | |
| 243 if (g_browser_process && | |
| 244 g_browser_process->local_state() && | |
| 245 SignedSettingsTempStorage::Store(name_, *value_, | |
| 246 g_browser_process->local_state())) { | |
| 247 Succeed(true); | |
| 248 return; | |
| 249 } | |
| 250 } | |
| 251 if (!service_->has_cached_policy()) { | |
| 252 TryToFetchPolicyAndCallBack(); | |
| 253 return; | |
| 254 } | |
| 255 // Posts a task to the FILE thread to sign policy. | |
| 256 em::PolicyData to_sign; | |
| 257 to_sign.CheckTypeAndMergeFrom(service_->cached_policy()); | |
| 258 SetInPolicy(name_, *value_, &to_sign); | |
| 259 to_store_.set_policy_data(to_sign.SerializeAsString()); | |
| 260 service_->StartSigningAttempt(to_store_.policy_data(), this); | |
| 261 } | |
| 262 | |
| 263 void StorePropertyOp::Fail(SignedSettings::ReturnCode code) { | |
| 264 BrowserThread::PostTask( | |
| 265 BrowserThread::UI, FROM_HERE, | |
| 266 base::Bind(&StorePropertyOp::PerformCallback, this, code, false)); | |
| 267 } | |
| 268 | |
| 269 void StorePropertyOp::Succeed(bool value) { | |
| 270 BrowserThread::PostTask( | |
| 271 BrowserThread::UI, FROM_HERE, | |
| 272 base::Bind(&StorePropertyOp::PerformCallback, this, SUCCESS, value)); | |
| 273 } | |
| 274 | |
| 275 void StorePropertyOp::OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, | |
| 276 const std::vector<uint8>& sig) { | |
| 277 // Ensure we're on the UI thread, due to the need to send DBus traffic. | |
| 278 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
| 279 BrowserThread::PostTask( | |
| 280 BrowserThread::UI, FROM_HERE, | |
| 281 base::Bind(&StorePropertyOp::OnKeyOpComplete, this, return_code, sig)); | |
| 282 return; | |
| 283 } | |
| 284 VLOG(2) << "StorePropertyOp::OnKeyOpComplete return_code = " << return_code; | |
| 285 // Now, sure we're on the UI thread. | |
| 286 if (return_code == OwnerManager::SUCCESS) { | |
| 287 to_store_.set_policy_data_signature( | |
| 288 std::string(reinterpret_cast<const char*>(&sig[0]), sig.size())); | |
| 289 store_op_ = CreateStorePolicyOp(&to_store_, this); | |
| 290 // d_->OnSettingsOpCompleted() will be called by this call. | |
| 291 store_op_->Execute(); | |
| 292 } else { | |
| 293 Fail(SignedSettings::MapKeyOpCode(return_code)); | |
| 294 } | |
| 295 } | |
| 296 | |
| 297 void StorePropertyOp::OnSettingsOpCompleted(ReturnCode code, bool value) { | |
| 298 if (value && to_store_.has_policy_data()) { | |
| 299 em::PolicyData poldata; | |
| 300 poldata.ParseFromString(to_store_.policy_data()); | |
| 301 service_->set_cached_policy(poldata); | |
| 302 Succeed(value); | |
| 303 return; | |
| 304 } | |
| 305 Fail(NOT_FOUND); | |
| 306 } | |
| 307 | |
| 308 void StorePropertyOp::SetInPolicy(const std::string& prop, | |
| 309 const base::Value& value, | |
| 310 em::PolicyData* poldata) { | |
| 311 em::ChromeDeviceSettingsProto pol; | |
| 312 pol.ParseFromString(poldata->policy_value()); | |
| 313 if (prop == kAccountsPrefAllowNewUser) { | |
| 314 em::AllowNewUsersProto* allow = pol.mutable_allow_new_users(); | |
| 315 bool allow_value; | |
| 316 if (value.GetAsBoolean(&allow_value)) | |
| 317 allow->set_allow_new_users(allow_value); | |
| 318 else | |
| 319 NOTREACHED(); | |
| 320 } else if (prop == kAccountsPrefAllowGuest) { | |
| 321 em::GuestModeEnabledProto* guest = pol.mutable_guest_mode_enabled(); | |
| 322 bool guest_value; | |
| 323 if (value.GetAsBoolean(&guest_value)) | |
| 324 guest->set_guest_mode_enabled(guest_value); | |
| 325 else | |
| 326 NOTREACHED(); | |
| 327 } else if (prop == kAccountsPrefShowUserNamesOnSignIn) { | |
| 328 em::ShowUserNamesOnSigninProto* show = pol.mutable_show_user_names(); | |
| 329 bool show_value; | |
| 330 if (value.GetAsBoolean(&show_value)) | |
| 331 show->set_show_user_names(show_value); | |
| 332 else | |
| 333 NOTREACHED(); | |
| 334 } else if (prop == kSignedDataRoamingEnabled) { | |
| 335 em::DataRoamingEnabledProto* roam = pol.mutable_data_roaming_enabled(); | |
| 336 bool roaming_value; | |
| 337 if (value.GetAsBoolean(&roaming_value)) | |
| 338 roam->set_data_roaming_enabled(roaming_value); | |
| 339 else | |
| 340 NOTREACHED(); | |
| 341 } else if (prop == kSettingProxyEverywhere) { | |
| 342 // TODO(cmasone): NOTIMPLEMENTED() once http://crosbug.com/13052 is fixed. | |
| 343 std::string proxy_value; | |
| 344 if (value.GetAsString(&proxy_value)) { | |
| 345 bool success = | |
| 346 pol.mutable_device_proxy_settings()->ParseFromString(proxy_value); | |
| 347 DCHECK(success); | |
| 348 } else { | |
| 349 NOTREACHED(); | |
| 350 } | |
| 351 } else if (prop == kReleaseChannel) { | |
| 352 em::ReleaseChannelProto* release_channel = pol.mutable_release_channel(); | |
| 353 std::string channel_value; | |
| 354 if (value.GetAsString(&channel_value)) | |
| 355 release_channel->set_release_channel(channel_value); | |
| 356 else | |
| 357 NOTREACHED(); | |
| 358 } else if (prop == kStatsReportingPref) { | |
| 359 em::MetricsEnabledProto* metrics = pol.mutable_metrics_enabled(); | |
| 360 bool metrics_value; | |
| 361 if (value.GetAsBoolean(&metrics_value)) | |
| 362 metrics->set_metrics_enabled(metrics_value); | |
| 363 else | |
| 364 NOTREACHED(); | |
| 365 } else if (prop == kAccountsPrefUsers) { | |
| 366 em::UserWhitelistProto* whitelist_proto = pol.mutable_user_whitelist(); | |
| 367 whitelist_proto->clear_user_whitelist(); | |
| 368 const base::ListValue& users = static_cast<const base::ListValue&>(value); | |
| 369 for (base::ListValue::const_iterator i = users.begin(); | |
| 370 i != users.end(); ++i) { | |
| 371 std::string email; | |
| 372 if ((*i)->GetAsString(&email)) | |
| 373 whitelist_proto->add_user_whitelist(email.c_str()); | |
| 374 } | |
| 375 } else if (prop == kDeviceOwner) { | |
| 376 // We don't serialize this one to the policy blob. | |
| 377 } else { | |
| 378 NOTREACHED(); | |
| 379 } | |
| 380 poldata->set_policy_value(pol.SerializeAsString()); | |
| 381 } | |
| 382 | |
| 383 void StorePropertyOp::PerformCallback(SignedSettings::ReturnCode code, | |
| 384 bool value) { | |
| 385 d_->OnSettingsOpCompleted(code, value); | |
| 386 } | |
| 387 | |
| 388 RetrievePropertyOp::RetrievePropertyOp( | |
| 389 const std::string& name, | |
| 390 SignedSettings::Delegate<const base::Value*>* d) | |
| 391 : name_(name), | |
| 392 d_(d) { | |
| 393 } | |
| 394 | |
| 395 RetrievePropertyOp::~RetrievePropertyOp() {} | |
| 396 | |
| 397 void RetrievePropertyOp::Execute() { | |
| 398 base::Value* value; | |
| 399 // TODO(dilmah): Fix the race: | |
| 400 // At the moment when device becomes owned there is lapse of time after | |
| 401 // device has been owned and before temp_storage settings are finally | |
| 402 // persisted into signed settings. | |
| 403 // In this lapse of time Retrieve loses access to those settings. | |
| 404 if (service_->GetStatus(true) != OwnershipService::OWNERSHIP_TAKEN) { | |
| 405 if (g_browser_process && | |
| 406 g_browser_process->local_state() && | |
| 407 SignedSettingsTempStorage::Retrieve( | |
| 408 name_, &value, g_browser_process->local_state())) { | |
| 409 Succeed(value->DeepCopy()); | |
| 410 return; | |
| 411 } | |
| 412 } | |
| 413 | |
| 414 if (!service_->has_cached_policy()) { | |
| 415 TryToFetchPolicyAndCallBack(); | |
| 416 return; | |
| 417 } | |
| 418 value = LookUpInPolicy(name_); | |
| 419 if (!value) | |
| 420 Fail(NOT_FOUND); | |
| 421 else | |
| 422 Succeed(value); | |
| 423 } | |
| 424 | |
| 425 void RetrievePropertyOp::Fail(SignedSettings::ReturnCode code) { | |
| 426 BrowserThread::PostTask( | |
| 427 BrowserThread::UI, FROM_HERE, | |
| 428 base::Bind(&RetrievePropertyOp::PerformCallback, this, | |
| 429 code, static_cast<const base::Value*>(NULL))); | |
| 430 } | |
| 431 | |
| 432 void RetrievePropertyOp::Succeed(const base::Value* value) { | |
| 433 BrowserThread::PostTask( | |
| 434 BrowserThread::UI, FROM_HERE, | |
| 435 base::Bind(&RetrievePropertyOp::PerformCallback, this, | |
| 436 SUCCESS, base::Owned(value))); | |
| 437 } | |
| 438 | |
| 439 // DEPRECATED. | |
| 440 void RetrievePropertyOp::OnKeyOpComplete( | |
| 441 const OwnerManager::KeyOpCode return_code, | |
| 442 const std::vector<uint8>& sig) { | |
| 443 NOTREACHED(); | |
| 444 } | |
| 445 | |
| 446 base::Value* RetrievePropertyOp::LookUpInPolicy(const std::string& prop) { | |
| 447 if (prop == kDeviceOwner) { | |
| 448 const em::PolicyData& data = service_->cached_policy(); | |
| 449 if (data.has_username() && !data.has_request_token()) | |
| 450 return base::Value::CreateStringValue(data.username()); | |
| 451 } | |
| 452 VLOG(2) << "Looking up " << prop; | |
| 453 em::ChromeDeviceSettingsProto pol; | |
| 454 pol.ParseFromString(service_->cached_policy().policy_value()); | |
| 455 if (prop == kAccountsPrefAllowNewUser) { | |
| 456 if (pol.has_allow_new_users() && | |
| 457 pol.allow_new_users().has_allow_new_users() && | |
| 458 pol.allow_new_users().allow_new_users()) { | |
| 459 // New users allowed, user_whitelist() ignored. | |
| 460 return base::Value::CreateBooleanValue(true); | |
| 461 } | |
| 462 // If we have the allow_new_users bool, and it is true, we honor that above. | |
| 463 // In all other cases (don't have it, have it and it is set to false, etc), | |
| 464 // We will honor the user_whitelist() if it is there and populated. | |
| 465 // Otherwise we default to allowing new users. | |
| 466 if (!pol.has_user_whitelist()) | |
| 467 return base::Value::CreateBooleanValue(true); | |
| 468 return base::Value::CreateBooleanValue( | |
| 469 pol.user_whitelist().user_whitelist_size() == 0); | |
| 470 | |
| 471 } else if (prop == kAccountsPrefAllowGuest) { | |
| 472 if (!pol.has_guest_mode_enabled() || | |
| 473 !pol.guest_mode_enabled().has_guest_mode_enabled()) { | |
| 474 // Default to allowing guests; | |
| 475 return base::Value::CreateBooleanValue(true); | |
| 476 } | |
| 477 return base::Value::CreateBooleanValue( | |
| 478 pol.guest_mode_enabled().guest_mode_enabled()); | |
| 479 | |
| 480 } else if (prop == kAccountsPrefShowUserNamesOnSignIn) { | |
| 481 if (!pol.has_show_user_names() || | |
| 482 !pol.show_user_names().has_show_user_names()) { | |
| 483 // Default to showing pods on the login screen; | |
| 484 return base::Value::CreateBooleanValue(true); | |
| 485 } | |
| 486 return base::Value::CreateBooleanValue( | |
| 487 pol.show_user_names().show_user_names()); | |
| 488 | |
| 489 } else if (prop == kSignedDataRoamingEnabled) { | |
| 490 if (!pol.has_data_roaming_enabled() || | |
| 491 !pol.data_roaming_enabled().has_data_roaming_enabled()) { | |
| 492 // Default to disabling cellular data roaming; | |
| 493 return base::Value::CreateBooleanValue(false); | |
| 494 } | |
| 495 return base::Value::CreateBooleanValue( | |
| 496 pol.data_roaming_enabled().data_roaming_enabled()); | |
| 497 | |
| 498 } else if (prop == kSettingProxyEverywhere) { | |
| 499 // TODO(cmasone): NOTIMPLEMENTED() once http://crosbug.com/13052 is fixed. | |
| 500 std::string serialized; | |
| 501 if (pol.has_device_proxy_settings() && | |
| 502 pol.device_proxy_settings().SerializeToString(&serialized)) { | |
| 503 return base::Value::CreateStringValue(serialized); | |
| 504 } | |
| 505 | |
| 506 } else if (prop == kReleaseChannel) { | |
| 507 if (!pol.has_release_channel() || | |
| 508 !pol.release_channel().has_release_channel()) { | |
| 509 // Default to an invalid channel (will be ignored). | |
| 510 return base::Value::CreateStringValue(""); | |
| 511 } | |
| 512 return base::Value::CreateStringValue( | |
| 513 pol.release_channel().release_channel()); | |
| 514 | |
| 515 } else if (prop == kStatsReportingPref) { | |
| 516 if (pol.has_metrics_enabled()) { | |
| 517 return base::Value::CreateBooleanValue( | |
| 518 pol.metrics_enabled().metrics_enabled()); | |
| 519 } | |
| 520 } else if (prop == kAccountsPrefUsers) { | |
| 521 base::ListValue* list = new base::ListValue(); | |
| 522 const em::UserWhitelistProto& whitelist_proto = pol.user_whitelist(); | |
| 523 const RepeatedPtrField<string>& whitelist = | |
| 524 whitelist_proto.user_whitelist(); | |
| 525 for (RepeatedPtrField<string>::const_iterator it = whitelist.begin(); | |
| 526 it != whitelist.end(); ++it) { | |
| 527 list->Append(base::Value::CreateStringValue(*it)); | |
| 528 } | |
| 529 return list; | |
| 530 } | |
| 531 return NULL; | |
| 532 } | |
| 533 | |
| 534 void RetrievePropertyOp::PerformCallback(SignedSettings::ReturnCode code, | |
| 535 const base::Value* value) { | |
| 536 d_->OnSettingsOpCompleted(code, value); | |
| 537 } | |
| 538 | 126 |
| 539 StorePolicyOp::StorePolicyOp(em::PolicyFetchResponse* policy, | 127 StorePolicyOp::StorePolicyOp(em::PolicyFetchResponse* policy, |
| 540 SignedSettings::Delegate<bool>* d) | 128 SignedSettings::Delegate<bool>* d) |
| 541 : policy_(policy), | 129 : policy_(policy), |
| 542 d_(d) { | 130 d_(d) { |
| 543 } | 131 } |
| 544 | 132 |
| 545 StorePolicyOp::~StorePolicyOp() {} | 133 StorePolicyOp::~StorePolicyOp() {} |
| 546 | 134 |
| 547 void StorePolicyOp::OnBoolComplete(bool success) { | 135 void StorePolicyOp::OnBoolComplete(bool success) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 565 BrowserThread::PostTask( | 153 BrowserThread::PostTask( |
| 566 BrowserThread::UI, FROM_HERE, | 154 BrowserThread::UI, FROM_HERE, |
| 567 base::Bind(&StorePolicyOp::PerformCallback, this, code, false)); | 155 base::Bind(&StorePolicyOp::PerformCallback, this, code, false)); |
| 568 } | 156 } |
| 569 | 157 |
| 570 void StorePolicyOp::Succeed(bool ignored) { | 158 void StorePolicyOp::Succeed(bool ignored) { |
| 571 SignedSettings::ReturnCode code = SUCCESS; | 159 SignedSettings::ReturnCode code = SUCCESS; |
| 572 bool to_ret = true; | 160 bool to_ret = true; |
| 573 em::PolicyData poldata; | 161 em::PolicyData poldata; |
| 574 if (SignedSettings::PolicyIsSane(*policy_, &poldata)) { | 162 if (SignedSettings::PolicyIsSane(*policy_, &poldata)) { |
| 575 service_->set_cached_policy(poldata); | |
| 576 } else { | 163 } else { |
| 577 code = NOT_FOUND; | 164 code = NOT_FOUND; |
| 578 to_ret = false; | 165 to_ret = false; |
| 579 } | 166 } |
| 580 BrowserThread::PostTask( | 167 BrowserThread::PostTask( |
| 581 BrowserThread::UI, FROM_HERE, | 168 BrowserThread::UI, FROM_HERE, |
| 582 base::Bind(&StorePolicyOp::PerformCallback, this, code, to_ret)); | 169 base::Bind(&StorePolicyOp::PerformCallback, this, code, to_ret)); |
| 583 } | 170 } |
| 584 | 171 |
| 585 void StorePolicyOp::OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, | 172 void StorePolicyOp::OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 VLOG(2) << "RetrievePolicyOp::Execute() failed with " << code; | 222 VLOG(2) << "RetrievePolicyOp::Execute() failed with " << code; |
| 636 BrowserThread::PostTask( | 223 BrowserThread::PostTask( |
| 637 BrowserThread::UI, FROM_HERE, | 224 BrowserThread::UI, FROM_HERE, |
| 638 base::Bind(&RetrievePolicyOp::PerformCallback, this, code, | 225 base::Bind(&RetrievePolicyOp::PerformCallback, this, code, |
| 639 em::PolicyFetchResponse())); | 226 em::PolicyFetchResponse())); |
| 640 } | 227 } |
| 641 | 228 |
| 642 void RetrievePolicyOp::Succeed(const em::PolicyFetchResponse& value) { | 229 void RetrievePolicyOp::Succeed(const em::PolicyFetchResponse& value) { |
| 643 em::PolicyData poldata; | 230 em::PolicyData poldata; |
| 644 if (SignedSettings::PolicyIsSane(value, &poldata)) { | 231 if (SignedSettings::PolicyIsSane(value, &poldata)) { |
| 645 service_->set_cached_policy(poldata); | |
| 646 BrowserThread::PostTask( | 232 BrowserThread::PostTask( |
| 647 BrowserThread::UI, FROM_HERE, | 233 BrowserThread::UI, FROM_HERE, |
| 648 base::Bind(&RetrievePolicyOp::PerformCallback, this, SUCCESS, value)); | 234 base::Bind(&RetrievePolicyOp::PerformCallback, this, SUCCESS, value)); |
| 649 } else { | 235 } else { |
| 650 Fail(NOT_FOUND); | 236 Fail(NOT_FOUND); |
| 651 } | 237 } |
| 652 } | 238 } |
| 653 | 239 |
| 654 void RetrievePolicyOp::OnKeyOpComplete( | 240 void RetrievePolicyOp::OnKeyOpComplete( |
| 655 const OwnerManager::KeyOpCode return_code, | 241 const OwnerManager::KeyOpCode return_code, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 sig.assign(sig_ptr, sig_ptr + policy_.policy_data_signature().length()); | 277 sig.assign(sig_ptr, sig_ptr + policy_.policy_data_signature().length()); |
| 692 service_->StartVerifyAttempt(policy_.policy_data(), sig, this); | 278 service_->StartVerifyAttempt(policy_.policy_data(), sig, this); |
| 693 } | 279 } |
| 694 | 280 |
| 695 void RetrievePolicyOp::PerformCallback(SignedSettings::ReturnCode code, | 281 void RetrievePolicyOp::PerformCallback(SignedSettings::ReturnCode code, |
| 696 const em::PolicyFetchResponse& value) { | 282 const em::PolicyFetchResponse& value) { |
| 697 d_->OnSettingsOpCompleted(code, value); | 283 d_->OnSettingsOpCompleted(code, value); |
| 698 } | 284 } |
| 699 | 285 |
| 700 } // namespace chromeos | 286 } // namespace chromeos |
| OLD | NEW |