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

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

Powered by Google App Engine
This is Rietveld 408576698