Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(398)

Side by Side Diff: chrome/browser/chromeos/login/signed_settings.cc

Issue 8091002: PART2: Make SignedSettings use proper Value types instead of string all around the place. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments and fixed an issue with user whitelist checks. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 const bool add_to_whitelist_; 155 const bool add_to_whitelist_;
156 SignedSettings::Delegate<bool>* d_; 156 SignedSettings::Delegate<bool>* d_;
157 em::PolicyFetchResponse to_store_; 157 em::PolicyFetchResponse to_store_;
158 scoped_refptr<SignedSettings> store_op_; 158 scoped_refptr<SignedSettings> store_op_;
159 }; 159 };
160 160
161 class StorePropertyOp : public SignedSettings, 161 class StorePropertyOp : public SignedSettings,
162 public SignedSettings::Delegate<bool> { 162 public SignedSettings::Delegate<bool> {
163 public: 163 public:
164 StorePropertyOp(const std::string& name, 164 StorePropertyOp(const std::string& name,
165 const std::string& value, 165 const base::Value& value,
166 SignedSettings::Delegate<bool>* d); 166 SignedSettings::Delegate<bool>* d);
167 virtual ~StorePropertyOp(); 167 virtual ~StorePropertyOp();
168 void Execute(); 168 void Execute();
169 void Fail(SignedSettings::ReturnCode code); 169 void Fail(SignedSettings::ReturnCode code);
170 void Succeed(bool value); 170 void Succeed(bool value);
171 // Implementation of OwnerManager::Delegate 171 // Implementation of OwnerManager::Delegate
172 void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, 172 void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code,
173 const std::vector<uint8>& payload); 173 const std::vector<uint8>& payload);
174 // Implementation of SignedSettings::Delegate 174 // Implementation of SignedSettings::Delegate
175 void OnSettingsOpCompleted(ReturnCode code, bool value); 175 void OnSettingsOpCompleted(ReturnCode code, bool value);
176 176
177 private: 177 private:
178 void SetInPolicy(const std::string& prop, 178 void SetInPolicy(const std::string& prop,
179 const std::string& value, 179 const base::Value& value,
180 em::PolicyData* poldata); 180 em::PolicyData* poldata);
181 // Always call d_->OnSettingOpCompleted() via this call. 181 // Always call d_->OnSettingOpCompleted() via this call.
182 // It guarantees that the callback will not be triggered until _after_ 182 // It guarantees that the callback will not be triggered until _after_
183 // Execute() returns, which is implicitly assumed by SignedSettingsHelper 183 // Execute() returns, which is implicitly assumed by SignedSettingsHelper
184 // in some cases. 184 // in some cases.
185 void PerformCallback(SignedSettings::ReturnCode code, bool value); 185 void PerformCallback(SignedSettings::ReturnCode code, bool value);
186 186
187 std::string name_; 187 std::string name_;
188 std::string value_; 188 scoped_ptr<base::Value> value_;
189 SignedSettings::Delegate<bool>* d_; 189 SignedSettings::Delegate<bool>* d_;
190 em::PolicyFetchResponse to_store_; 190 em::PolicyFetchResponse to_store_;
191 scoped_refptr<SignedSettings> store_op_; 191 scoped_refptr<SignedSettings> store_op_;
192 }; 192 };
193 193
194 class RetrievePropertyOp : public SignedSettings { 194 class RetrievePropertyOp : public SignedSettings {
195 public: 195 public:
196 RetrievePropertyOp(const std::string& name, 196 RetrievePropertyOp(const std::string& name,
197 SignedSettings::Delegate<std::string>* d); 197 SignedSettings::Delegate<const base::Value*>* d);
198 virtual ~RetrievePropertyOp(); 198 virtual ~RetrievePropertyOp();
199 void Execute(); 199 void Execute();
200 void Fail(SignedSettings::ReturnCode code); 200 void Fail(SignedSettings::ReturnCode code);
201 void Succeed(const std::string& value); 201 void Succeed(const base::Value* value);
202 // Implementation of OwnerManager::Delegate::OnKeyOpComplete() 202 // Implementation of OwnerManager::Delegate::OnKeyOpComplete()
203 void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, 203 void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code,
204 const std::vector<uint8>& payload); 204 const std::vector<uint8>& payload);
205 205
206 private: 206 private:
207 static const char* kVeritas[]; 207 base::Value* LookUpInPolicy(const std::string& prop);
208
209 std::string LookUpInPolicy(const std::string& prop);
210 // Always call d_->OnSettingOpCompleted() via this call. 208 // Always call d_->OnSettingOpCompleted() via this call.
211 // It guarantees that the callback will not be triggered until _after_ 209 // It guarantees that the callback will not be triggered until _after_
212 // Execute() returns, which is implicitly assumed by SignedSettingsHelper 210 // Execute() returns, which is implicitly assumed by SignedSettingsHelper
213 // in some cases. 211 // in some cases.
214 void PerformCallback(SignedSettings::ReturnCode code, 212 void PerformCallback(SignedSettings::ReturnCode code,
215 const std::string& value); 213 const base::Value* value);
216 214
217 std::string name_; 215 std::string name_;
218 std::string value_; 216 SignedSettings::Delegate<const base::Value*>* d_;
219 SignedSettings::Delegate<std::string>* d_;
220 }; 217 };
221 218
222 class StorePolicyOp : public SignedSettings { 219 class StorePolicyOp : public SignedSettings {
223 public: 220 public:
224 StorePolicyOp(em::PolicyFetchResponse* policy, 221 StorePolicyOp(em::PolicyFetchResponse* policy,
225 SignedSettings::Delegate<bool>* d); 222 SignedSettings::Delegate<bool>* d);
226 virtual ~StorePolicyOp(); 223 virtual ~StorePolicyOp();
227 void Execute(); 224 void Execute();
228 void Fail(SignedSettings::ReturnCode code); 225 void Fail(SignedSettings::ReturnCode code);
229 void Succeed(bool value); 226 void Succeed(bool value);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 SignedSettings::Delegate<bool>* d) { 284 SignedSettings::Delegate<bool>* d) {
288 DCHECK(d != NULL); 285 DCHECK(d != NULL);
289 return new WhitelistOp(Authenticator::Canonicalize(email), 286 return new WhitelistOp(Authenticator::Canonicalize(email),
290 add_to_whitelist, 287 add_to_whitelist,
291 d); 288 d);
292 } 289 }
293 290
294 // static 291 // static
295 SignedSettings* SignedSettings::CreateStorePropertyOp( 292 SignedSettings* SignedSettings::CreateStorePropertyOp(
296 const std::string& name, 293 const std::string& name,
297 const std::string& value, 294 const base::Value& value,
298 SignedSettings::Delegate<bool>* d) { 295 SignedSettings::Delegate<bool>* d) {
299 DCHECK(d != NULL); 296 DCHECK(d != NULL);
300 return new StorePropertyOp(name, value, d); 297 return new StorePropertyOp(name, value, d);
301 } 298 }
302 299
303 // static 300 // static
304 SignedSettings* SignedSettings::CreateRetrievePropertyOp( 301 SignedSettings* SignedSettings::CreateRetrievePropertyOp(
305 const std::string& name, 302 const std::string& name,
306 SignedSettings::Delegate<std::string>* d) { 303 SignedSettings::Delegate<const base::Value*>* d) {
307 DCHECK(d != NULL); 304 DCHECK(d != NULL);
308 return new RetrievePropertyOp(name, d); 305 return new RetrievePropertyOp(name, d);
309 } 306 }
310 307
311 // static 308 // static
312 SignedSettings* SignedSettings::CreateStorePolicyOp( 309 SignedSettings* SignedSettings::CreateStorePolicyOp(
313 em::PolicyFetchResponse* policy, 310 em::PolicyFetchResponse* policy,
314 SignedSettings::Delegate<bool>* d) { 311 SignedSettings::Delegate<bool>* d) {
315 DCHECK(d != NULL); 312 DCHECK(d != NULL);
316 DCHECK(policy != NULL); 313 DCHECK(policy != NULL);
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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() {
657 CHECK(chromeos::CrosLibrary::Get()->EnsureLoaded()); 685 CHECK(chromeos::CrosLibrary::Get()->EnsureLoaded());
686 base::Value* value;
658 // TODO(dilmah): Fix the race: 687 // TODO(dilmah): Fix the race:
659 // At the moment when device becomes owned there is lapse of time after 688 // At the moment when device becomes owned there is lapse of time after
660 // device has been owned and before temp_storage settings are finally 689 // device has been owned and before temp_storage settings are finally
661 // persisted into signed settings. 690 // persisted into signed settings.
662 // In this lapse of time Retrieve loses access to those settings. 691 // In this lapse of time Retrieve loses access to those settings.
663 if (service_->GetStatus(true) != OwnershipService::OWNERSHIP_TAKEN) { 692 if (service_->GetStatus(true) != OwnershipService::OWNERSHIP_TAKEN) {
664 if (g_browser_process && 693 if (g_browser_process &&
665 g_browser_process->local_state() && 694 g_browser_process->local_state() &&
666 SignedSettingsTempStorage::Retrieve( 695 SignedSettingsTempStorage::Retrieve(
667 name_, &value_, g_browser_process->local_state())) { 696 name_, &value, g_browser_process->local_state())) {
668 Succeed(value_); 697 Succeed(value->DeepCopy());
669 return; 698 return;
670 } 699 }
671 } 700 }
672 701
673 if (!service_->has_cached_policy()) { 702 if (!service_->has_cached_policy()) {
674 TryToFetchPolicyAndCallBack(); 703 TryToFetchPolicyAndCallBack();
675 return; 704 return;
676 } 705 }
677 std::string value = LookUpInPolicy(name_); 706 value = LookUpInPolicy(name_);
678 if (value.empty()) 707 if (!value)
679 Fail(NOT_FOUND); 708 Fail(NOT_FOUND);
680 else 709 else
681 Succeed(value); 710 Succeed(value);
682 } 711 }
683 712
684 void RetrievePropertyOp::Fail(SignedSettings::ReturnCode code) { 713 void RetrievePropertyOp::Fail(SignedSettings::ReturnCode code) {
685 BrowserThread::PostTask( 714 BrowserThread::PostTask(
686 BrowserThread::UI, FROM_HERE, 715 BrowserThread::UI, FROM_HERE,
687 base::Bind(&RetrievePropertyOp::PerformCallback, this, code, 716 base::Bind(&RetrievePropertyOp::PerformCallback, this,
688 std::string())); 717 code, static_cast<const base::Value*>(NULL)));
689 } 718 }
690 719
691 void RetrievePropertyOp::Succeed(const std::string& value) { 720 void RetrievePropertyOp::Succeed(const base::Value* value) {
692 BrowserThread::PostTask( 721 BrowserThread::PostTask(
693 BrowserThread::UI, FROM_HERE, 722 BrowserThread::UI, FROM_HERE,
694 base::Bind(&RetrievePropertyOp::PerformCallback, this, SUCCESS, value)); 723 base::Bind(&RetrievePropertyOp::PerformCallback, this,
724 SUCCESS, base::Owned(value)));
695 } 725 }
696 726
697 // DEPRECATED. 727 // DEPRECATED.
698 void RetrievePropertyOp::OnKeyOpComplete( 728 void RetrievePropertyOp::OnKeyOpComplete(
699 const OwnerManager::KeyOpCode return_code, 729 const OwnerManager::KeyOpCode return_code,
700 const std::vector<uint8>& sig) { 730 const std::vector<uint8>& sig) {
701 NOTREACHED(); 731 NOTREACHED();
702 } 732 }
703 733
704 std::string RetrievePropertyOp::LookUpInPolicy(const std::string& prop) { 734 base::Value* RetrievePropertyOp::LookUpInPolicy(const std::string& prop) {
705 if (prop == kDeviceOwner) { 735 if (prop == kDeviceOwner) {
706 const em::PolicyData& data = service_->cached_policy(); 736 const em::PolicyData& data = service_->cached_policy();
707 if (data.has_username() && !data.has_request_token()) 737 if (data.has_username() && !data.has_request_token())
708 return data.username(); 738 return base::Value::CreateStringValue(data.username());
709 return "";
710 } 739 }
711 VLOG(2) << "Looking up " << prop; 740 VLOG(2) << "Looking up " << prop;
712 em::ChromeDeviceSettingsProto pol; 741 em::ChromeDeviceSettingsProto pol;
713 pol.ParseFromString(service_->cached_policy().policy_value()); 742 pol.ParseFromString(service_->cached_policy().policy_value());
714 if (prop == kAccountsPrefAllowNewUser) { 743 if (prop == kAccountsPrefAllowNewUser) {
715 if (pol.has_allow_new_users() && 744 if (pol.has_allow_new_users() &&
716 pol.allow_new_users().has_allow_new_users() && 745 pol.allow_new_users().has_allow_new_users() &&
717 pol.allow_new_users().allow_new_users()) { 746 pol.allow_new_users().allow_new_users()) {
718 return kVeritas[1]; // New users allowed, user_whitelist() ignored. 747 // New users allowed, user_whitelist() ignored.
748 return base::Value::CreateBooleanValue(true);
719 } 749 }
720 // If we have the allow_new_users bool, and it is true, we honor that above. 750 // If we have the allow_new_users bool, and it is true, we honor that above.
721 // In all other cases (don't have it, have it and it is set to false, etc), 751 // In all other cases (don't have it, have it and it is set to false, etc),
722 // We will honor the user_whitelist() if it is there and populated. 752 // We will honor the user_whitelist() if it is there and populated.
723 // Otherwise, fail open (to do otherwise could render the device unusable). 753 // Otherwise we default to allowing new users.
724 if (!pol.has_user_whitelist()) 754 if (!pol.has_user_whitelist())
725 return kVeritas[1]; // Default to allowing new users. 755 return base::Value::CreateBooleanValue(true);
726 return kVeritas[pol.user_whitelist().user_whitelist_size() == 0]; 756 return base::Value::CreateBooleanValue(
757 pol.user_whitelist().user_whitelist_size() == 0);
727 758
728 } else if (prop == kAccountsPrefAllowGuest) { 759 } else if (prop == kAccountsPrefAllowGuest) {
729 if (!pol.has_guest_mode_enabled() || 760 if (!pol.has_guest_mode_enabled() ||
730 !pol.guest_mode_enabled().has_guest_mode_enabled()) { 761 !pol.guest_mode_enabled().has_guest_mode_enabled()) {
731 return kVeritas[1]; // Default to allowing guests; 762 // Default to allowing guests;
763 return base::Value::CreateBooleanValue(true);
732 } 764 }
733 return kVeritas[pol.guest_mode_enabled().guest_mode_enabled()]; 765 return base::Value::CreateBooleanValue(
766 pol.guest_mode_enabled().guest_mode_enabled());
734 767
735 } else if (prop == kAccountsPrefShowUserNamesOnSignIn) { 768 } else if (prop == kAccountsPrefShowUserNamesOnSignIn) {
736 if (!pol.has_show_user_names() || 769 if (!pol.has_show_user_names() ||
737 !pol.show_user_names().has_show_user_names()) { 770 !pol.show_user_names().has_show_user_names()) {
738 return kVeritas[1]; // Default to showing pods on the login screen; 771 // Default to showing pods on the login screen;
772 return base::Value::CreateBooleanValue(true);
739 } 773 }
740 return kVeritas[pol.show_user_names().show_user_names()]; 774 return base::Value::CreateBooleanValue(
775 pol.show_user_names().show_user_names());
741 776
742 } else if (prop == kSignedDataRoamingEnabled) { 777 } else if (prop == kSignedDataRoamingEnabled) {
743 if (!pol.has_data_roaming_enabled() || 778 if (!pol.has_data_roaming_enabled() ||
744 !pol.data_roaming_enabled().has_data_roaming_enabled()) { 779 !pol.data_roaming_enabled().has_data_roaming_enabled()) {
745 return kVeritas[0]; // Default to disabling cellular data roaming; 780 // Default to disabling cellular data roaming;
781 return base::Value::CreateBooleanValue(false);
746 } 782 }
747 return kVeritas[pol.data_roaming_enabled().data_roaming_enabled()]; 783 return base::Value::CreateBooleanValue(
784 pol.data_roaming_enabled().data_roaming_enabled());
748 785
749 } else if (prop == kSettingProxyEverywhere) { 786 } else if (prop == kSettingProxyEverywhere) {
750 // TODO(cmasone): NOTIMPLEMENTED() once http://crosbug.com/13052 is fixed. 787 // TODO(cmasone): NOTIMPLEMENTED() once http://crosbug.com/13052 is fixed.
751 std::string serialized; 788 std::string serialized;
752 if (!pol.has_device_proxy_settings() || 789 if (pol.has_device_proxy_settings() &&
753 !pol.device_proxy_settings().SerializeToString(&serialized)) { 790 pol.device_proxy_settings().SerializeToString(&serialized)) {
754 return ""; // Default to invalid proxy config (will be ignored). 791 return base::Value::CreateStringValue(serialized);
755 } 792 }
756 return serialized;
757 793
758 } else if (prop == kReleaseChannel) { 794 } else if (prop == kReleaseChannel) {
759 if (!pol.has_release_channel() || 795 if (!pol.has_release_channel() ||
760 !pol.release_channel().has_release_channel()) { 796 !pol.release_channel().has_release_channel()) {
761 return ""; // Default to an invalid channel (will be ignored). 797 // Default to an invalid channel (will be ignored).
798 return base::Value::CreateStringValue("");
762 } 799 }
763 return pol.release_channel().release_channel(); 800 return base::Value::CreateStringValue(
801 pol.release_channel().release_channel());
764 802
765 } else if (prop == kStatsReportingPref) { 803 } else if (prop == kStatsReportingPref) {
766 if (pol.has_metrics_enabled()) { 804 if (pol.has_metrics_enabled()) {
767 return kVeritas[pol.metrics_enabled().metrics_enabled()]; 805 return base::Value::CreateBooleanValue(
806 pol.metrics_enabled().metrics_enabled());
768 } 807 }
808 } else if (prop == kAccountsPrefUsers) {
809 base::ListValue* list = new base::ListValue();
810 const em::UserWhitelistProto& whitelist_proto = pol.user_whitelist();
811 const RepeatedPtrField<string>& whitelist =
812 whitelist_proto.user_whitelist();
813 for (RepeatedPtrField<string>::const_iterator it = whitelist.begin();
814 it != whitelist.end(); ++it) {
815 list->Append(base::Value::CreateStringValue(*it));
816 }
817 return list;
769 } 818 }
770 return std::string(); 819 return NULL;
771 } 820 }
772 821
773 void RetrievePropertyOp::PerformCallback(SignedSettings::ReturnCode code, 822 void RetrievePropertyOp::PerformCallback(SignedSettings::ReturnCode code,
774 const std::string& value) { 823 const base::Value* value) {
775 d_->OnSettingsOpCompleted(code, value); 824 d_->OnSettingsOpCompleted(code, value);
776 } 825 }
777 826
778 StorePolicyOp::StorePolicyOp(em::PolicyFetchResponse* policy, 827 StorePolicyOp::StorePolicyOp(em::PolicyFetchResponse* policy,
779 SignedSettings::Delegate<bool>* d) 828 SignedSettings::Delegate<bool>* d)
780 : policy_(policy), 829 : policy_(policy),
781 d_(d) { 830 d_(d) {
782 } 831 }
783 832
784 StorePolicyOp::~StorePolicyOp() {} 833 StorePolicyOp::~StorePolicyOp() {}
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 sig.assign(sig_ptr, sig_ptr + policy_.policy_data_signature().length()); 979 sig.assign(sig_ptr, sig_ptr + policy_.policy_data_signature().length());
931 service_->StartVerifyAttempt(policy_.policy_data(), sig, this); 980 service_->StartVerifyAttempt(policy_.policy_data(), sig, this);
932 } 981 }
933 982
934 void RetrievePolicyOp::PerformCallback(SignedSettings::ReturnCode code, 983 void RetrievePolicyOp::PerformCallback(SignedSettings::ReturnCode code,
935 const em::PolicyFetchResponse& value) { 984 const em::PolicyFetchResponse& value) {
936 d_->OnSettingsOpCompleted(code, value); 985 d_->OnSettingsOpCompleted(code, value);
937 } 986 }
938 987
939 } // namespace chromeos 988 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698