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

Side by Side Diff: chrome/browser/chromeos/settings/device_settings_provider.cc

Issue 11975009: Prevent a DCHECK when starting a chromeos=1 build with --stub-cros-settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: IsDeviceSettings() Created 7 years, 11 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/settings/device_settings_provider.h" 5 #include "chrome/browser/chromeos/settings/device_settings_provider.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 kSettingProxyEverywhere, 60 kSettingProxyEverywhere,
61 kSignedDataRoamingEnabled, 61 kSignedDataRoamingEnabled,
62 kStartUpUrls, 62 kStartUpUrls,
63 kStatsReportingPref, 63 kStatsReportingPref,
64 kSystemTimezonePolicy, 64 kSystemTimezonePolicy,
65 }; 65 };
66 66
67 // Legacy policy file location. Used to detect migration from pre v12 ChromeOS. 67 // Legacy policy file location. Used to detect migration from pre v12 ChromeOS.
68 const char kLegacyPolicyFile[] = "/var/lib/whitelist/preferences"; 68 const char kLegacyPolicyFile[] = "/var/lib/whitelist/preferences";
69 69
70 bool IsControlledSetting(const std::string& pref_path) {
71 const char** end = kKnownSettings + arraysize(kKnownSettings);
72 return std::find(kKnownSettings, end, pref_path) != end;
73 }
74
75 bool HasOldMetricsFile() { 70 bool HasOldMetricsFile() {
76 // TODO(pastarmovj): Remove this once migration is not needed anymore. 71 // TODO(pastarmovj): Remove this once migration is not needed anymore.
77 // If the value is not set we should try to migrate legacy consent file. 72 // If the value is not set we should try to migrate legacy consent file.
78 // Loading consent file state causes us to do blocking IO on UI thread. 73 // Loading consent file state causes us to do blocking IO on UI thread.
79 // Temporarily allow it until we fix http://crbug.com/62626 74 // Temporarily allow it until we fix http://crbug.com/62626
80 base::ThreadRestrictions::ScopedAllowIO allow_io; 75 base::ThreadRestrictions::ScopedAllowIO allow_io;
81 return GoogleUpdateSettings::GetCollectStatsConsent(); 76 return GoogleUpdateSettings::GetCollectStatsConsent();
82 } 77 }
83 78
84 } // namespace 79 } // namespace
(...skipping 11 matching lines...) Expand all
96 if (!UpdateFromService()) { 91 if (!UpdateFromService()) {
97 // Make sure we have at least the cache data immediately. 92 // Make sure we have at least the cache data immediately.
98 RetrieveCachedData(); 93 RetrieveCachedData();
99 } 94 }
100 } 95 }
101 96
102 DeviceSettingsProvider::~DeviceSettingsProvider() { 97 DeviceSettingsProvider::~DeviceSettingsProvider() {
103 device_settings_service_->RemoveObserver(this); 98 device_settings_service_->RemoveObserver(this);
104 } 99 }
105 100
101 // static
102 bool DeviceSettingsProvider::IsDeviceSetting(const std::string& name) {
103 const char** end = kKnownSettings + arraysize(kKnownSettings);
104 return std::find(kKnownSettings, end, name) != end;
105 }
106
106 void DeviceSettingsProvider::DoSet(const std::string& path, 107 void DeviceSettingsProvider::DoSet(const std::string& path,
107 const base::Value& in_value) { 108 const base::Value& in_value) {
108 // Make sure that either the current user is the device owner or the 109 // Make sure that either the current user is the device owner or the
109 // device doesn't have an owner yet. 110 // device doesn't have an owner yet.
110 if (!(device_settings_service_->HasPrivateOwnerKey() || 111 if (!(device_settings_service_->HasPrivateOwnerKey() ||
111 ownership_status_ == DeviceSettingsService::OWNERSHIP_NONE)) { 112 ownership_status_ == DeviceSettingsService::OWNERSHIP_NONE)) {
112 LOG(WARNING) << "Changing settings from non-owner, setting=" << path; 113 LOG(WARNING) << "Changing settings from non-owner, setting=" << path;
113 114
114 // Revert UI change. 115 // Revert UI change.
115 NotifyObservers(path); 116 NotifyObservers(path);
116 return; 117 return;
117 } 118 }
118 119
119 if (IsControlledSetting(path)) { 120 if (IsDeviceSetting(path)) {
120 pending_changes_.push_back(PendingQueueElement(path, in_value.DeepCopy())); 121 pending_changes_.push_back(PendingQueueElement(path, in_value.DeepCopy()));
121 if (!store_callback_factory_.HasWeakPtrs()) 122 if (!store_callback_factory_.HasWeakPtrs())
122 SetInPolicy(); 123 SetInPolicy();
123 } else { 124 } else {
124 NOTREACHED() << "Try to set unhandled cros setting " << path; 125 NOTREACHED() << "Try to set unhandled cros setting " << path;
125 } 126 }
126 } 127 }
127 128
128 void DeviceSettingsProvider::OwnershipStatusChanged() { 129 void DeviceSettingsProvider::OwnershipStatusChanged() {
129 DeviceSettingsService::OwnershipStatus new_ownership_status = 130 DeviceSettingsService::OwnershipStatus new_ownership_status =
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 device_settings_.mutable_allow_new_users()->set_allow_new_users(true); 651 device_settings_.mutable_allow_new_users()->set_allow_new_users(true);
651 device_settings_.mutable_guest_mode_enabled()->set_guest_mode_enabled(true); 652 device_settings_.mutable_guest_mode_enabled()->set_guest_mode_enabled(true);
652 em::PolicyData empty_policy_data; 653 em::PolicyData empty_policy_data;
653 UpdateValuesCache(empty_policy_data, device_settings_, TRUSTED); 654 UpdateValuesCache(empty_policy_data, device_settings_, TRUSTED);
654 values_cache_.SetBoolean(kPolicyMissingMitigationMode, true); 655 values_cache_.SetBoolean(kPolicyMissingMitigationMode, true);
655 656
656 return true; 657 return true;
657 } 658 }
658 659
659 const base::Value* DeviceSettingsProvider::Get(const std::string& path) const { 660 const base::Value* DeviceSettingsProvider::Get(const std::string& path) const {
660 if (IsControlledSetting(path)) { 661 if (IsDeviceSetting(path)) {
661 const base::Value* value; 662 const base::Value* value;
662 if (values_cache_.GetValue(path, &value)) 663 if (values_cache_.GetValue(path, &value))
663 return value; 664 return value;
664 } else { 665 } else {
665 NOTREACHED() << "Trying to get non cros setting."; 666 NOTREACHED() << "Trying to get non cros setting.";
666 } 667 }
667 668
668 return NULL; 669 return NULL;
669 } 670 }
670 671
671 DeviceSettingsProvider::TrustedStatus 672 DeviceSettingsProvider::TrustedStatus
672 DeviceSettingsProvider::PrepareTrustedValues(const base::Closure& cb) { 673 DeviceSettingsProvider::PrepareTrustedValues(const base::Closure& cb) {
673 TrustedStatus status = RequestTrustedEntity(); 674 TrustedStatus status = RequestTrustedEntity();
674 if (status == TEMPORARILY_UNTRUSTED && !cb.is_null()) 675 if (status == TEMPORARILY_UNTRUSTED && !cb.is_null())
675 callbacks_.push_back(cb); 676 callbacks_.push_back(cb);
676 return status; 677 return status;
677 } 678 }
678 679
679 bool DeviceSettingsProvider::HandlesSetting(const std::string& path) const { 680 bool DeviceSettingsProvider::HandlesSetting(const std::string& path) const {
680 return IsControlledSetting(path); 681 return IsDeviceSetting(path);
681 } 682 }
682 683
683 DeviceSettingsProvider::TrustedStatus 684 DeviceSettingsProvider::TrustedStatus
684 DeviceSettingsProvider::RequestTrustedEntity() { 685 DeviceSettingsProvider::RequestTrustedEntity() {
685 if (ownership_status_ == DeviceSettingsService::OWNERSHIP_NONE) 686 if (ownership_status_ == DeviceSettingsService::OWNERSHIP_NONE)
686 return TRUSTED; 687 return TRUSTED;
687 return trusted_status_; 688 return trusted_status_;
688 } 689 }
689 690
690 void DeviceSettingsProvider::UpdateAndProceedStoring() { 691 void DeviceSettingsProvider::UpdateAndProceedStoring() {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 void DeviceSettingsProvider::AttemptMigration() { 773 void DeviceSettingsProvider::AttemptMigration() {
773 if (device_settings_service_->HasPrivateOwnerKey()) { 774 if (device_settings_service_->HasPrivateOwnerKey()) {
774 PrefValueMap::const_iterator i; 775 PrefValueMap::const_iterator i;
775 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) 776 for (i = migration_values_.begin(); i != migration_values_.end(); ++i)
776 DoSet(i->first, *i->second); 777 DoSet(i->first, *i->second);
777 migration_values_.Clear(); 778 migration_values_.Clear();
778 } 779 }
779 } 780 }
780 781
781 } // namespace chromeos 782 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698