| 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" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 const bool add_to_whitelist_; | 156 const bool add_to_whitelist_; |
| 157 SignedSettings::Delegate<bool>* d_; | 157 SignedSettings::Delegate<bool>* d_; |
| 158 em::PolicyFetchResponse to_store_; | 158 em::PolicyFetchResponse to_store_; |
| 159 scoped_refptr<SignedSettings> store_op_; | 159 scoped_refptr<SignedSettings> store_op_; |
| 160 }; | 160 }; |
| 161 | 161 |
| 162 class StorePropertyOp : public SignedSettings, | 162 class StorePropertyOp : public SignedSettings, |
| 163 public SignedSettings::Delegate<bool> { | 163 public SignedSettings::Delegate<bool> { |
| 164 public: | 164 public: |
| 165 StorePropertyOp(const std::string& name, | 165 StorePropertyOp(const std::string& name, |
| 166 const std::string& value, | 166 const base::Value& value, |
| 167 SignedSettings::Delegate<bool>* d); | 167 SignedSettings::Delegate<bool>* d); |
| 168 virtual ~StorePropertyOp(); | 168 virtual ~StorePropertyOp(); |
| 169 void Execute(); | 169 void Execute(); |
| 170 void Fail(SignedSettings::ReturnCode code); | 170 void Fail(SignedSettings::ReturnCode code); |
| 171 void Succeed(bool value); | 171 void Succeed(bool value); |
| 172 // Implementation of OwnerManager::Delegate | 172 // Implementation of OwnerManager::Delegate |
| 173 void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, | 173 void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, |
| 174 const std::vector<uint8>& payload); | 174 const std::vector<uint8>& payload); |
| 175 // Implementation of SignedSettings::Delegate | 175 // Implementation of SignedSettings::Delegate |
| 176 void OnSettingsOpCompleted(ReturnCode code, bool value); | 176 void OnSettingsOpCompleted(ReturnCode code, bool value); |
| 177 | 177 |
| 178 private: | 178 private: |
| 179 void SetInPolicy(const std::string& prop, | 179 void SetInPolicy(const std::string& prop, |
| 180 const std::string& value, | 180 const base::Value& value, |
| 181 em::PolicyData* poldata); | 181 em::PolicyData* poldata); |
| 182 // Always call d_->OnSettingOpCompleted() via this call. | 182 // Always call d_->OnSettingOpCompleted() via this call. |
| 183 // It guarantees that the callback will not be triggered until _after_ | 183 // It guarantees that the callback will not be triggered until _after_ |
| 184 // Execute() returns, which is implicitly assumed by SignedSettingsHelper | 184 // Execute() returns, which is implicitly assumed by SignedSettingsHelper |
| 185 // in some cases. | 185 // in some cases. |
| 186 void PerformCallback(SignedSettings::ReturnCode code, bool value); | 186 void PerformCallback(SignedSettings::ReturnCode code, bool value); |
| 187 | 187 |
| 188 std::string name_; | 188 std::string name_; |
| 189 std::string value_; | 189 scoped_ptr<base::Value> value_; |
| 190 SignedSettings::Delegate<bool>* d_; | 190 SignedSettings::Delegate<bool>* d_; |
| 191 em::PolicyFetchResponse to_store_; | 191 em::PolicyFetchResponse to_store_; |
| 192 scoped_refptr<SignedSettings> store_op_; | 192 scoped_refptr<SignedSettings> store_op_; |
| 193 }; | 193 }; |
| 194 | 194 |
| 195 class RetrievePropertyOp : public SignedSettings { | 195 class RetrievePropertyOp : public SignedSettings { |
| 196 public: | 196 public: |
| 197 RetrievePropertyOp(const std::string& name, | 197 RetrievePropertyOp(const std::string& name, |
| 198 SignedSettings::Delegate<std::string>* d); | 198 SignedSettings::Delegate<const base::Value*>* d); |
| 199 virtual ~RetrievePropertyOp(); | 199 virtual ~RetrievePropertyOp(); |
| 200 void Execute(); | 200 void Execute(); |
| 201 void Fail(SignedSettings::ReturnCode code); | 201 void Fail(SignedSettings::ReturnCode code); |
| 202 void Succeed(const std::string& value); | 202 void Succeed(const base::Value* value); |
| 203 // Implementation of OwnerManager::Delegate::OnKeyOpComplete() | 203 // Implementation of OwnerManager::Delegate::OnKeyOpComplete() |
| 204 void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, | 204 void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, |
| 205 const std::vector<uint8>& payload); | 205 const std::vector<uint8>& payload); |
| 206 | 206 |
| 207 private: | 207 private: |
| 208 static const char* kVeritas[]; | 208 base::Value* LookUpInPolicy(const std::string& prop); |
| 209 | |
| 210 std::string LookUpInPolicy(const std::string& prop); | |
| 211 // Always call d_->OnSettingOpCompleted() via this call. | 209 // Always call d_->OnSettingOpCompleted() via this call. |
| 212 // It guarantees that the callback will not be triggered until _after_ | 210 // It guarantees that the callback will not be triggered until _after_ |
| 213 // Execute() returns, which is implicitly assumed by SignedSettingsHelper | 211 // Execute() returns, which is implicitly assumed by SignedSettingsHelper |
| 214 // in some cases. | 212 // in some cases. |
| 215 void PerformCallback(SignedSettings::ReturnCode code, | 213 void PerformCallback(SignedSettings::ReturnCode code, |
| 216 const std::string& value); | 214 const base::Value* value); |
| 217 | 215 |
| 218 std::string name_; | 216 std::string name_; |
| 219 std::string value_; | 217 SignedSettings::Delegate<const base::Value*>* d_; |
| 220 SignedSettings::Delegate<std::string>* d_; | |
| 221 }; | 218 }; |
| 222 | 219 |
| 223 class StorePolicyOp : public SignedSettings { | 220 class StorePolicyOp : public SignedSettings { |
| 224 public: | 221 public: |
| 225 StorePolicyOp(em::PolicyFetchResponse* policy, | 222 StorePolicyOp(em::PolicyFetchResponse* policy, |
| 226 SignedSettings::Delegate<bool>* d); | 223 SignedSettings::Delegate<bool>* d); |
| 227 virtual ~StorePolicyOp(); | 224 virtual ~StorePolicyOp(); |
| 228 void Execute(); | 225 void Execute(); |
| 229 void Fail(SignedSettings::ReturnCode code); | 226 void Fail(SignedSettings::ReturnCode code); |
| 230 void Succeed(bool value); | 227 void Succeed(bool value); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 SignedSettings::Delegate<bool>* d) { | 285 SignedSettings::Delegate<bool>* d) { |
| 289 DCHECK(d != NULL); | 286 DCHECK(d != NULL); |
| 290 return new WhitelistOp(Authenticator::Canonicalize(email), | 287 return new WhitelistOp(Authenticator::Canonicalize(email), |
| 291 add_to_whitelist, | 288 add_to_whitelist, |
| 292 d); | 289 d); |
| 293 } | 290 } |
| 294 | 291 |
| 295 // static | 292 // static |
| 296 SignedSettings* SignedSettings::CreateStorePropertyOp( | 293 SignedSettings* SignedSettings::CreateStorePropertyOp( |
| 297 const std::string& name, | 294 const std::string& name, |
| 298 const std::string& value, | 295 const base::Value& value, |
| 299 SignedSettings::Delegate<bool>* d) { | 296 SignedSettings::Delegate<bool>* d) { |
| 300 DCHECK(d != NULL); | 297 DCHECK(d != NULL); |
| 301 return new StorePropertyOp(name, value, d); | 298 return new StorePropertyOp(name, value, d); |
| 302 } | 299 } |
| 303 | 300 |
| 304 // static | 301 // static |
| 305 SignedSettings* SignedSettings::CreateRetrievePropertyOp( | 302 SignedSettings* SignedSettings::CreateRetrievePropertyOp( |
| 306 const std::string& name, | 303 const std::string& name, |
| 307 SignedSettings::Delegate<std::string>* d) { | 304 SignedSettings::Delegate<const base::Value*>* d) { |
| 308 DCHECK(d != NULL); | 305 DCHECK(d != NULL); |
| 309 return new RetrievePropertyOp(name, d); | 306 return new RetrievePropertyOp(name, d); |
| 310 } | 307 } |
| 311 | 308 |
| 312 // static | 309 // static |
| 313 SignedSettings* SignedSettings::CreateStorePolicyOp( | 310 SignedSettings* SignedSettings::CreateStorePolicyOp( |
| 314 em::PolicyFetchResponse* policy, | 311 em::PolicyFetchResponse* policy, |
| 315 SignedSettings::Delegate<bool>* d) { | 312 SignedSettings::Delegate<bool>* d) { |
| 316 DCHECK(d != NULL); | 313 DCHECK(d != NULL); |
| 317 DCHECK(policy != NULL); | 314 DCHECK(policy != NULL); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 return; | 510 return; |
| 514 } | 511 } |
| 515 LOG(WARNING) << "Whitelist modification no-op: " << email; | 512 LOG(WARNING) << "Whitelist modification no-op: " << email; |
| 516 } | 513 } |
| 517 | 514 |
| 518 void WhitelistOp::PerformCallback(SignedSettings::ReturnCode code, bool value) { | 515 void WhitelistOp::PerformCallback(SignedSettings::ReturnCode code, bool value) { |
| 519 d_->OnSettingsOpCompleted(code, value); | 516 d_->OnSettingsOpCompleted(code, value); |
| 520 } | 517 } |
| 521 | 518 |
| 522 StorePropertyOp::StorePropertyOp(const std::string& name, | 519 StorePropertyOp::StorePropertyOp(const std::string& name, |
| 523 const std::string& value, | 520 const base::Value& value, |
| 524 SignedSettings::Delegate<bool>* d) | 521 SignedSettings::Delegate<bool>* d) |
| 525 : name_(name), | 522 : name_(name), |
| 526 value_(value), | 523 value_(value.DeepCopy()), |
| 527 d_(d), | 524 d_(d), |
| 528 store_op_(NULL) { | 525 store_op_(NULL) { |
| 529 } | 526 } |
| 530 | 527 |
| 531 StorePropertyOp::~StorePropertyOp() {} | 528 StorePropertyOp::~StorePropertyOp() {} |
| 532 | 529 |
| 533 void StorePropertyOp::Execute() { | 530 void StorePropertyOp::Execute() { |
| 534 if (service_->GetStatus(true) != OwnershipService::OWNERSHIP_TAKEN) { | 531 if (service_->GetStatus(true) != OwnershipService::OWNERSHIP_TAKEN) { |
| 535 if (g_browser_process && | 532 if (g_browser_process && |
| 536 g_browser_process->local_state() && | 533 g_browser_process->local_state() && |
| 537 SignedSettingsTempStorage::Store(name_, value_, | 534 SignedSettingsTempStorage::Store(name_, *value_, |
| 538 g_browser_process->local_state())) { | 535 g_browser_process->local_state())) { |
| 539 Succeed(true); | 536 Succeed(true); |
| 540 return; | 537 return; |
| 541 } | 538 } |
| 542 } | 539 } |
| 543 if (!service_->has_cached_policy()) { | 540 if (!service_->has_cached_policy()) { |
| 544 TryToFetchPolicyAndCallBack(); | 541 TryToFetchPolicyAndCallBack(); |
| 545 return; | 542 return; |
| 546 } | 543 } |
| 547 // Posts a task to the FILE thread to sign policy. | 544 // Posts a task to the FILE thread to sign policy. |
| 548 em::PolicyData to_sign; | 545 em::PolicyData to_sign; |
| 549 to_sign.CheckTypeAndMergeFrom(service_->cached_policy()); | 546 to_sign.CheckTypeAndMergeFrom(service_->cached_policy()); |
| 550 SetInPolicy(name_, value_, &to_sign); | 547 SetInPolicy(name_, *value_, &to_sign); |
| 551 to_store_.set_policy_data(to_sign.SerializeAsString()); | 548 to_store_.set_policy_data(to_sign.SerializeAsString()); |
| 552 service_->StartSigningAttempt(to_store_.policy_data(), this); | 549 service_->StartSigningAttempt(to_store_.policy_data(), this); |
| 553 } | 550 } |
| 554 | 551 |
| 555 void StorePropertyOp::Fail(SignedSettings::ReturnCode code) { | 552 void StorePropertyOp::Fail(SignedSettings::ReturnCode code) { |
| 556 BrowserThread::PostTask( | 553 BrowserThread::PostTask( |
| 557 BrowserThread::UI, FROM_HERE, | 554 BrowserThread::UI, FROM_HERE, |
| 558 base::Bind(&StorePropertyOp::PerformCallback, this, code, false)); | 555 base::Bind(&StorePropertyOp::PerformCallback, this, code, false)); |
| 559 } | 556 } |
| 560 | 557 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 591 em::PolicyData poldata; | 588 em::PolicyData poldata; |
| 592 poldata.ParseFromString(to_store_.policy_data()); | 589 poldata.ParseFromString(to_store_.policy_data()); |
| 593 service_->set_cached_policy(poldata); | 590 service_->set_cached_policy(poldata); |
| 594 Succeed(value); | 591 Succeed(value); |
| 595 return; | 592 return; |
| 596 } | 593 } |
| 597 Fail(NOT_FOUND); | 594 Fail(NOT_FOUND); |
| 598 } | 595 } |
| 599 | 596 |
| 600 void StorePropertyOp::SetInPolicy(const std::string& prop, | 597 void StorePropertyOp::SetInPolicy(const std::string& prop, |
| 601 const std::string& value, | 598 const base::Value& value, |
| 602 em::PolicyData* poldata) { | 599 em::PolicyData* poldata) { |
| 603 em::ChromeDeviceSettingsProto pol; | 600 em::ChromeDeviceSettingsProto pol; |
| 604 pol.ParseFromString(poldata->policy_value()); | 601 pol.ParseFromString(poldata->policy_value()); |
| 605 if (prop == kAccountsPrefAllowNewUser) { | 602 if (prop == kAccountsPrefAllowNewUser) { |
| 606 em::AllowNewUsersProto* allow = pol.mutable_allow_new_users(); | 603 em::AllowNewUsersProto* allow = pol.mutable_allow_new_users(); |
| 607 allow->set_allow_new_users(value == "true"); | 604 bool allow_value; |
| 608 | 605 if (value.GetAsBoolean(&allow_value)) |
| 606 allow->set_allow_new_users(allow_value); |
| 607 else |
| 608 NOTREACHED(); |
| 609 } else if (prop == kAccountsPrefAllowGuest) { | 609 } else if (prop == kAccountsPrefAllowGuest) { |
| 610 em::GuestModeEnabledProto* guest = pol.mutable_guest_mode_enabled(); | 610 em::GuestModeEnabledProto* guest = pol.mutable_guest_mode_enabled(); |
| 611 guest->set_guest_mode_enabled(value == "true"); | 611 bool guest_value; |
| 612 | 612 if (value.GetAsBoolean(&guest_value)) |
| 613 guest->set_guest_mode_enabled(guest_value); |
| 614 else |
| 615 NOTREACHED(); |
| 613 } else if (prop == kAccountsPrefShowUserNamesOnSignIn) { | 616 } else if (prop == kAccountsPrefShowUserNamesOnSignIn) { |
| 614 em::ShowUserNamesOnSigninProto* show = pol.mutable_show_user_names(); | 617 em::ShowUserNamesOnSigninProto* show = pol.mutable_show_user_names(); |
| 615 show->set_show_user_names(value == "true"); | 618 bool show_value; |
| 616 | 619 if (value.GetAsBoolean(&show_value)) |
| 620 show->set_show_user_names(show_value); |
| 621 else |
| 622 NOTREACHED(); |
| 617 } else if (prop == kSignedDataRoamingEnabled) { | 623 } else if (prop == kSignedDataRoamingEnabled) { |
| 618 em::DataRoamingEnabledProto* roam = pol.mutable_data_roaming_enabled(); | 624 em::DataRoamingEnabledProto* roam = pol.mutable_data_roaming_enabled(); |
| 619 roam->set_data_roaming_enabled(value == "true"); | 625 bool roaming_value; |
| 620 | 626 if (value.GetAsBoolean(&roaming_value)) |
| 627 roam->set_data_roaming_enabled(roaming_value); |
| 628 else |
| 629 NOTREACHED(); |
| 621 } else if (prop == kSettingProxyEverywhere) { | 630 } else if (prop == kSettingProxyEverywhere) { |
| 622 // TODO(cmasone): NOTIMPLEMENTED() once http://crosbug.com/13052 is fixed. | 631 // TODO(cmasone): NOTIMPLEMENTED() once http://crosbug.com/13052 is fixed. |
| 623 bool success = pol.mutable_device_proxy_settings()->ParseFromString(value); | 632 std::string proxy_value; |
| 624 DCHECK(success); | 633 if (value.GetAsString(&proxy_value)) { |
| 625 | 634 bool success = |
| 635 pol.mutable_device_proxy_settings()->ParseFromString(proxy_value); |
| 636 DCHECK(success); |
| 637 } else { |
| 638 NOTREACHED(); |
| 639 } |
| 626 } else if (prop == kReleaseChannel) { | 640 } else if (prop == kReleaseChannel) { |
| 627 em::ReleaseChannelProto* release_channel = pol.mutable_release_channel(); | 641 em::ReleaseChannelProto* release_channel = pol.mutable_release_channel(); |
| 628 release_channel->set_release_channel(value); | 642 std::string channel_value; |
| 629 | 643 if (value.GetAsString(&channel_value)) |
| 644 release_channel->set_release_channel(channel_value); |
| 645 else |
| 646 NOTREACHED(); |
| 630 } else if (prop == kStatsReportingPref) { | 647 } else if (prop == kStatsReportingPref) { |
| 631 em::MetricsEnabledProto* metrics = pol.mutable_metrics_enabled(); | 648 em::MetricsEnabledProto* metrics = pol.mutable_metrics_enabled(); |
| 632 metrics->set_metrics_enabled(value == "true"); | 649 bool metrics_value; |
| 633 | 650 if (value.GetAsBoolean(&metrics_value)) |
| 651 metrics->set_metrics_enabled(metrics_value); |
| 652 else |
| 653 NOTREACHED(); |
| 654 } else if (prop == kAccountsPrefUsers) { |
| 655 em::UserWhitelistProto* whitelist_proto = pol.mutable_user_whitelist(); |
| 656 whitelist_proto->clear_user_whitelist(); |
| 657 const base::ListValue& users = static_cast<const base::ListValue&>(value); |
| 658 for (base::ListValue::const_iterator i = users.begin(); |
| 659 i != users.end(); ++i) { |
| 660 std::string email; |
| 661 if ((*i)->GetAsString(&email)) |
| 662 whitelist_proto->add_user_whitelist(email.c_str()); |
| 663 } |
| 634 } else { | 664 } else { |
| 635 NOTREACHED(); | 665 NOTREACHED(); |
| 636 } | 666 } |
| 637 poldata->set_policy_value(pol.SerializeAsString()); | 667 poldata->set_policy_value(pol.SerializeAsString()); |
| 638 } | 668 } |
| 639 | 669 |
| 640 void StorePropertyOp::PerformCallback(SignedSettings::ReturnCode code, | 670 void StorePropertyOp::PerformCallback(SignedSettings::ReturnCode code, |
| 641 bool value) { | 671 bool value) { |
| 642 d_->OnSettingsOpCompleted(code, value); | 672 d_->OnSettingsOpCompleted(code, value); |
| 643 } | 673 } |
| 644 | 674 |
| 645 // static | 675 RetrievePropertyOp::RetrievePropertyOp( |
| 646 const char* RetrievePropertyOp::kVeritas[] = { "false", "true" }; | 676 const std::string& name, |
| 647 | 677 SignedSettings::Delegate<const base::Value*>* d) |
| 648 RetrievePropertyOp::RetrievePropertyOp(const std::string& name, | |
| 649 SignedSettings::Delegate<std::string>* d) | |
| 650 : name_(name), | 678 : name_(name), |
| 651 d_(d) { | 679 d_(d) { |
| 652 } | 680 } |
| 653 | 681 |
| 654 RetrievePropertyOp::~RetrievePropertyOp() {} | 682 RetrievePropertyOp::~RetrievePropertyOp() {} |
| 655 | 683 |
| 656 void RetrievePropertyOp::Execute() { | 684 void RetrievePropertyOp::Execute() { |
| 685 base::Value* value; |
| 657 // TODO(dilmah): Fix the race: | 686 // TODO(dilmah): Fix the race: |
| 658 // At the moment when device becomes owned there is lapse of time after | 687 // At the moment when device becomes owned there is lapse of time after |
| 659 // device has been owned and before temp_storage settings are finally | 688 // device has been owned and before temp_storage settings are finally |
| 660 // persisted into signed settings. | 689 // persisted into signed settings. |
| 661 // In this lapse of time Retrieve loses access to those settings. | 690 // In this lapse of time Retrieve loses access to those settings. |
| 662 if (service_->GetStatus(true) != OwnershipService::OWNERSHIP_TAKEN) { | 691 if (service_->GetStatus(true) != OwnershipService::OWNERSHIP_TAKEN) { |
| 663 if (g_browser_process && | 692 if (g_browser_process && |
| 664 g_browser_process->local_state() && | 693 g_browser_process->local_state() && |
| 665 SignedSettingsTempStorage::Retrieve( | 694 SignedSettingsTempStorage::Retrieve( |
| 666 name_, &value_, g_browser_process->local_state())) { | 695 name_, &value, g_browser_process->local_state())) { |
| 667 Succeed(value_); | 696 Succeed(value->DeepCopy()); |
| 668 return; | 697 return; |
| 669 } | 698 } |
| 670 } | 699 } |
| 671 | 700 |
| 672 if (!service_->has_cached_policy()) { | 701 if (!service_->has_cached_policy()) { |
| 673 TryToFetchPolicyAndCallBack(); | 702 TryToFetchPolicyAndCallBack(); |
| 674 return; | 703 return; |
| 675 } | 704 } |
| 676 std::string value = LookUpInPolicy(name_); | 705 value = LookUpInPolicy(name_); |
| 677 if (value.empty()) | 706 if (!value) |
| 678 Fail(NOT_FOUND); | 707 Fail(NOT_FOUND); |
| 679 else | 708 else |
| 680 Succeed(value); | 709 Succeed(value); |
| 681 } | 710 } |
| 682 | 711 |
| 683 void RetrievePropertyOp::Fail(SignedSettings::ReturnCode code) { | 712 void RetrievePropertyOp::Fail(SignedSettings::ReturnCode code) { |
| 684 BrowserThread::PostTask( | 713 BrowserThread::PostTask( |
| 685 BrowserThread::UI, FROM_HERE, | 714 BrowserThread::UI, FROM_HERE, |
| 686 base::Bind(&RetrievePropertyOp::PerformCallback, this, code, | 715 base::Bind(&RetrievePropertyOp::PerformCallback, this, |
| 687 std::string())); | 716 code, static_cast<const base::Value*>(NULL))); |
| 688 } | 717 } |
| 689 | 718 |
| 690 void RetrievePropertyOp::Succeed(const std::string& value) { | 719 void RetrievePropertyOp::Succeed(const base::Value* value) { |
| 691 BrowserThread::PostTask( | 720 BrowserThread::PostTask( |
| 692 BrowserThread::UI, FROM_HERE, | 721 BrowserThread::UI, FROM_HERE, |
| 693 base::Bind(&RetrievePropertyOp::PerformCallback, this, SUCCESS, value)); | 722 base::Bind(&RetrievePropertyOp::PerformCallback, this, |
| 723 SUCCESS, base::Owned(value))); |
| 694 } | 724 } |
| 695 | 725 |
| 696 // DEPRECATED. | 726 // DEPRECATED. |
| 697 void RetrievePropertyOp::OnKeyOpComplete( | 727 void RetrievePropertyOp::OnKeyOpComplete( |
| 698 const OwnerManager::KeyOpCode return_code, | 728 const OwnerManager::KeyOpCode return_code, |
| 699 const std::vector<uint8>& sig) { | 729 const std::vector<uint8>& sig) { |
| 700 NOTREACHED(); | 730 NOTREACHED(); |
| 701 } | 731 } |
| 702 | 732 |
| 703 std::string RetrievePropertyOp::LookUpInPolicy(const std::string& prop) { | 733 base::Value* RetrievePropertyOp::LookUpInPolicy(const std::string& prop) { |
| 704 if (prop == kDeviceOwner) { | 734 if (prop == kDeviceOwner) { |
| 705 const em::PolicyData& data = service_->cached_policy(); | 735 const em::PolicyData& data = service_->cached_policy(); |
| 706 if (data.has_username() && !data.has_request_token()) | 736 if (data.has_username() && !data.has_request_token()) |
| 707 return data.username(); | 737 return base::Value::CreateStringValue(data.username()); |
| 708 return ""; | |
| 709 } | 738 } |
| 710 VLOG(2) << "Looking up " << prop; | 739 VLOG(2) << "Looking up " << prop; |
| 711 em::ChromeDeviceSettingsProto pol; | 740 em::ChromeDeviceSettingsProto pol; |
| 712 pol.ParseFromString(service_->cached_policy().policy_value()); | 741 pol.ParseFromString(service_->cached_policy().policy_value()); |
| 713 if (prop == kAccountsPrefAllowNewUser) { | 742 if (prop == kAccountsPrefAllowNewUser) { |
| 714 if (pol.has_allow_new_users() && | 743 if (pol.has_allow_new_users() && |
| 715 pol.allow_new_users().has_allow_new_users() && | 744 pol.allow_new_users().has_allow_new_users() && |
| 716 pol.allow_new_users().allow_new_users()) { | 745 pol.allow_new_users().allow_new_users()) { |
| 717 return kVeritas[1]; // New users allowed, user_whitelist() ignored. | 746 // New users allowed, user_whitelist() ignored. |
| 747 return base::Value::CreateBooleanValue(true); |
| 718 } | 748 } |
| 719 // If we have the allow_new_users bool, and it is true, we honor that above. | 749 // If we have the allow_new_users bool, and it is true, we honor that above. |
| 720 // In all other cases (don't have it, have it and it is set to false, etc), | 750 // In all other cases (don't have it, have it and it is set to false, etc), |
| 721 // We will honor the user_whitelist() if it is there and populated. | 751 // We will honor the user_whitelist() if it is there and populated. |
| 722 // Otherwise, fail open (to do otherwise could render the device unusable). | 752 // Otherwise we default to allowing new users. |
| 723 if (!pol.has_user_whitelist()) | 753 if (!pol.has_user_whitelist()) |
| 724 return kVeritas[1]; // Default to allowing new users. | 754 return base::Value::CreateBooleanValue(true); |
| 725 return kVeritas[pol.user_whitelist().user_whitelist_size() == 0]; | 755 return base::Value::CreateBooleanValue( |
| 756 pol.user_whitelist().user_whitelist_size() == 0); |
| 726 | 757 |
| 727 } else if (prop == kAccountsPrefAllowGuest) { | 758 } else if (prop == kAccountsPrefAllowGuest) { |
| 728 if (!pol.has_guest_mode_enabled() || | 759 if (!pol.has_guest_mode_enabled() || |
| 729 !pol.guest_mode_enabled().has_guest_mode_enabled()) { | 760 !pol.guest_mode_enabled().has_guest_mode_enabled()) { |
| 730 return kVeritas[1]; // Default to allowing guests; | 761 // Default to allowing guests; |
| 762 return base::Value::CreateBooleanValue(true); |
| 731 } | 763 } |
| 732 return kVeritas[pol.guest_mode_enabled().guest_mode_enabled()]; | 764 return base::Value::CreateBooleanValue( |
| 765 pol.guest_mode_enabled().guest_mode_enabled()); |
| 733 | 766 |
| 734 } else if (prop == kAccountsPrefShowUserNamesOnSignIn) { | 767 } else if (prop == kAccountsPrefShowUserNamesOnSignIn) { |
| 735 if (!pol.has_show_user_names() || | 768 if (!pol.has_show_user_names() || |
| 736 !pol.show_user_names().has_show_user_names()) { | 769 !pol.show_user_names().has_show_user_names()) { |
| 737 return kVeritas[1]; // Default to showing pods on the login screen; | 770 // Default to showing pods on the login screen; |
| 771 return base::Value::CreateBooleanValue(true); |
| 738 } | 772 } |
| 739 return kVeritas[pol.show_user_names().show_user_names()]; | 773 return base::Value::CreateBooleanValue( |
| 774 pol.show_user_names().show_user_names()); |
| 740 | 775 |
| 741 } else if (prop == kSignedDataRoamingEnabled) { | 776 } else if (prop == kSignedDataRoamingEnabled) { |
| 742 if (!pol.has_data_roaming_enabled() || | 777 if (!pol.has_data_roaming_enabled() || |
| 743 !pol.data_roaming_enabled().has_data_roaming_enabled()) { | 778 !pol.data_roaming_enabled().has_data_roaming_enabled()) { |
| 744 return kVeritas[0]; // Default to disabling cellular data roaming; | 779 // Default to disabling cellular data roaming; |
| 780 return base::Value::CreateBooleanValue(false); |
| 745 } | 781 } |
| 746 return kVeritas[pol.data_roaming_enabled().data_roaming_enabled()]; | 782 return base::Value::CreateBooleanValue( |
| 783 pol.data_roaming_enabled().data_roaming_enabled()); |
| 747 | 784 |
| 748 } else if (prop == kSettingProxyEverywhere) { | 785 } else if (prop == kSettingProxyEverywhere) { |
| 749 // TODO(cmasone): NOTIMPLEMENTED() once http://crosbug.com/13052 is fixed. | 786 // TODO(cmasone): NOTIMPLEMENTED() once http://crosbug.com/13052 is fixed. |
| 750 std::string serialized; | 787 std::string serialized; |
| 751 if (!pol.has_device_proxy_settings() || | 788 if (pol.has_device_proxy_settings() && |
| 752 !pol.device_proxy_settings().SerializeToString(&serialized)) { | 789 pol.device_proxy_settings().SerializeToString(&serialized)) { |
| 753 return ""; // Default to invalid proxy config (will be ignored). | 790 return base::Value::CreateStringValue(serialized); |
| 754 } | 791 } |
| 755 return serialized; | |
| 756 | 792 |
| 757 } else if (prop == kReleaseChannel) { | 793 } else if (prop == kReleaseChannel) { |
| 758 if (!pol.has_release_channel() || | 794 if (!pol.has_release_channel() || |
| 759 !pol.release_channel().has_release_channel()) { | 795 !pol.release_channel().has_release_channel()) { |
| 760 return ""; // Default to an invalid channel (will be ignored). | 796 // Default to an invalid channel (will be ignored). |
| 797 return base::Value::CreateStringValue(""); |
| 761 } | 798 } |
| 762 return pol.release_channel().release_channel(); | 799 return base::Value::CreateStringValue( |
| 800 pol.release_channel().release_channel()); |
| 763 | 801 |
| 764 } else if (prop == kStatsReportingPref) { | 802 } else if (prop == kStatsReportingPref) { |
| 765 if (pol.has_metrics_enabled()) { | 803 if (pol.has_metrics_enabled()) { |
| 766 return kVeritas[pol.metrics_enabled().metrics_enabled()]; | 804 return base::Value::CreateBooleanValue( |
| 805 pol.metrics_enabled().metrics_enabled()); |
| 767 } | 806 } |
| 807 } else if (prop == kAccountsPrefUsers) { |
| 808 base::ListValue* list = new base::ListValue(); |
| 809 const em::UserWhitelistProto& whitelist_proto = pol.user_whitelist(); |
| 810 const RepeatedPtrField<string>& whitelist = |
| 811 whitelist_proto.user_whitelist(); |
| 812 for (RepeatedPtrField<string>::const_iterator it = whitelist.begin(); |
| 813 it != whitelist.end(); ++it) { |
| 814 list->Append(base::Value::CreateStringValue(*it)); |
| 815 } |
| 816 return list; |
| 768 } | 817 } |
| 769 return std::string(); | 818 return NULL; |
| 770 } | 819 } |
| 771 | 820 |
| 772 void RetrievePropertyOp::PerformCallback(SignedSettings::ReturnCode code, | 821 void RetrievePropertyOp::PerformCallback(SignedSettings::ReturnCode code, |
| 773 const std::string& value) { | 822 const base::Value* value) { |
| 774 d_->OnSettingsOpCompleted(code, value); | 823 d_->OnSettingsOpCompleted(code, value); |
| 775 } | 824 } |
| 776 | 825 |
| 777 StorePolicyOp::StorePolicyOp(em::PolicyFetchResponse* policy, | 826 StorePolicyOp::StorePolicyOp(em::PolicyFetchResponse* policy, |
| 778 SignedSettings::Delegate<bool>* d) | 827 SignedSettings::Delegate<bool>* d) |
| 779 : policy_(policy), | 828 : policy_(policy), |
| 780 d_(d) { | 829 d_(d) { |
| 781 } | 830 } |
| 782 | 831 |
| 783 StorePolicyOp::~StorePolicyOp() {} | 832 StorePolicyOp::~StorePolicyOp() {} |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 sig.assign(sig_ptr, sig_ptr + policy_.policy_data_signature().length()); | 978 sig.assign(sig_ptr, sig_ptr + policy_.policy_data_signature().length()); |
| 930 service_->StartVerifyAttempt(policy_.policy_data(), sig, this); | 979 service_->StartVerifyAttempt(policy_.policy_data(), sig, this); |
| 931 } | 980 } |
| 932 | 981 |
| 933 void RetrievePolicyOp::PerformCallback(SignedSettings::ReturnCode code, | 982 void RetrievePolicyOp::PerformCallback(SignedSettings::ReturnCode code, |
| 934 const em::PolicyFetchResponse& value) { | 983 const em::PolicyFetchResponse& value) { |
| 935 d_->OnSettingsOpCompleted(code, value); | 984 d_->OnSettingsOpCompleted(code, value); |
| 936 } | 985 } |
| 937 | 986 |
| 938 } // namespace chromeos | 987 } // namespace chromeos |
| OLD | NEW |