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