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