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

Side by Side Diff: chrome/browser/chromeos/user_cros_settings_provider.cc

Issue 8091002: PART2: Make SignedSettings use proper Value types instead of string all around the place. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments and fixed an issue with user whitelist checks. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/user_cros_settings_provider.h" 5 #include "chrome/browser/chromeos/user_cros_settings_provider.h"
6 6
7 #include <map>
8 #include <set>
9
10 #include "base/bind.h" 7 #include "base/bind.h"
11 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
12 #include "base/callback.h" 9 #include "base/callback.h"
13 #include "base/hash_tables.h" 10 #include "base/hash_tables.h"
14 #include "base/logging.h" 11 #include "base/logging.h"
15 #include "base/memory/singleton.h" 12 #include "base/memory/singleton.h"
16 #include "base/string_util.h" 13 #include "base/string_util.h"
17 #include "base/values.h" 14 #include "base/values.h"
18 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/chromeos/cros/cros_library.h" 16 #include "chrome/browser/chromeos/cros/cros_library.h"
20 #include "chrome/browser/chromeos/cros/network_library.h" 17 #include "chrome/browser/chromeos/cros/network_library.h"
21 #include "chrome/browser/chromeos/cros_settings.h" 18 #include "chrome/browser/chromeos/cros_settings.h"
22 #include "chrome/browser/chromeos/cros_settings_names.h" 19 #include "chrome/browser/chromeos/cros_settings_names.h"
23 #include "chrome/browser/chromeos/login/ownership_service.h" 20 #include "chrome/browser/chromeos/login/ownership_service.h"
24 #include "chrome/browser/chromeos/login/ownership_status_checker.h" 21 #include "chrome/browser/chromeos/login/ownership_status_checker.h"
25 #include "chrome/browser/chromeos/login/user_manager.h" 22 #include "chrome/browser/chromeos/login/user_manager.h"
26 #include "chrome/browser/prefs/pref_service.h" 23 #include "chrome/browser/prefs/pref_service.h"
24 #include "chrome/browser/prefs/pref_value_map.h"
27 #include "chrome/browser/prefs/scoped_user_pref_update.h" 25 #include "chrome/browser/prefs/scoped_user_pref_update.h"
28 #include "chrome/browser/ui/options/options_util.h" 26 #include "chrome/browser/ui/options/options_util.h"
29 #include "chrome/common/chrome_notification_types.h" 27 #include "chrome/common/chrome_notification_types.h"
30 #include "chrome/installer/util/google_update_settings.h" 28 #include "chrome/installer/util/google_update_settings.h"
31 #include "content/browser/browser_thread.h" 29 #include "content/browser/browser_thread.h"
32 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
33 31
34 namespace chromeos { 32 namespace chromeos {
35 33
36 namespace { 34 namespace {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 public: 67 public:
70 explicit MigrationHelper() : callback_(NULL) { 68 explicit MigrationHelper() : callback_(NULL) {
71 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_CHECKED, 69 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_CHECKED,
72 content::NotificationService::AllSources()); 70 content::NotificationService::AllSources());
73 } 71 }
74 72
75 void set_callback(SignedSettingsHelper::Callback* callback) { 73 void set_callback(SignedSettingsHelper::Callback* callback) {
76 callback_ = callback; 74 callback_ = callback;
77 } 75 }
78 76
79 void AddMigrationValue(const std::string& path, const std::string& value) { 77 void AddMigrationValue(const std::string& path, base::Value* value) {
80 migration_values_[path] = value; 78 migration_values_.SetValue(path, value);
81 } 79 }
82 80
83 void MigrateValues(void) { 81 void MigrateValues(void) {
84 ownership_checker_.reset(new OwnershipStatusChecker( 82 ownership_checker_.reset(new OwnershipStatusChecker(
85 base::Bind(&MigrationHelper::DoMigrateValues, base::Unretained(this)))); 83 base::Bind(&MigrationHelper::DoMigrateValues, base::Unretained(this))));
86 } 84 }
87 85
88 // NotificationObserver overrides: 86 // NotificationObserver overrides:
89 virtual void Observe(int type, 87 virtual void Observe(int type,
90 const content::NotificationSource& source, 88 const content::NotificationSource& source,
91 const content::NotificationDetails& details) OVERRIDE { 89 const content::NotificationDetails& details) OVERRIDE {
92 if (type == chrome::NOTIFICATION_OWNERSHIP_CHECKED) 90 if (type == chrome::NOTIFICATION_OWNERSHIP_CHECKED)
93 MigrateValues(); 91 MigrateValues();
94 } 92 }
95 93
96 private: 94 private:
97 void DoMigrateValues(OwnershipService::Status status, 95 void DoMigrateValues(OwnershipService::Status status,
98 bool current_user_is_owner) { 96 bool current_user_is_owner) {
99 ownership_checker_.reset(NULL); 97 ownership_checker_.reset(NULL);
100 98
101 // We can call StartStorePropertyOp in two cases - either if the owner is 99 // We can call StartStorePropertyOp in two cases - either if the owner is
102 // currently logged in and the policy can be updated immediately or if there 100 // currently logged in and the policy can be updated immediately or if there
103 // is no owner yet in which case the value will be temporarily stored in the 101 // is no owner yet in which case the value will be temporarily stored in the
104 // SignedSettingsTempStorage until the device is owned. If none of these 102 // SignedSettingsTempStorage until the device is owned. If none of these
105 // cases is met then we will wait for user change notification and retry. 103 // cases is met then we will wait for user change notification and retry.
106 if (current_user_is_owner || status != OwnershipService::OWNERSHIP_TAKEN) { 104 if (current_user_is_owner || status != OwnershipService::OWNERSHIP_TAKEN) {
107 std::map<std::string, std::string>::const_iterator i; 105 PrefValueMap::const_iterator i;
108 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) { 106 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) {
109 // Queue all values for storing. 107 // Queue all values for storing.
110 SignedSettingsHelper::Get()->StartStorePropertyOp(i->first, i->second, 108 SignedSettingsHelper::Get()->StartStorePropertyOp(i->first, *i->second,
111 callback_); 109 callback_);
112 } 110 }
113 migration_values_.clear(); 111 migration_values_.Clear();
114 } 112 }
115 } 113 }
116 114
117 content::NotificationRegistrar registrar_; 115 content::NotificationRegistrar registrar_;
118 scoped_ptr<OwnershipStatusChecker> ownership_checker_; 116 scoped_ptr<OwnershipStatusChecker> ownership_checker_;
119 SignedSettingsHelper::Callback* callback_; 117 SignedSettingsHelper::Callback* callback_;
120 118 PrefValueMap migration_values_;
121 std::map<std::string, std::string> migration_values_;
122 119
123 DISALLOW_COPY_AND_ASSIGN(MigrationHelper); 120 DISALLOW_COPY_AND_ASSIGN(MigrationHelper);
124 }; 121 };
125 122
123 // A task that exports the Op completion to a Closure callback.
124 class TrustedEntryFetcher : public Task {
Mattias Nissler (ping if slow) 2011/10/28 14:44:07 Seems unused.
pastarmovj 2011/11/18 13:18:42 Yep obsolete since the base::Bind refactor of Task
125 public:
126 explicit TrustedEntryFetcher(const base::Closure& callback)
127 : callback_(callback) {
128 }
129
130 void Run() {
131 callback_.Run();
132 }
133
134 private:
135 base::Closure callback_;
136
137 DISALLOW_COPY_AND_ASSIGN(TrustedEntryFetcher);
138 };
139
126 bool IsControlledBooleanSetting(const std::string& pref_path) { 140 bool IsControlledBooleanSetting(const std::string& pref_path) {
127 // TODO(nkostylev): Using std::find for 4 value array generates this warning 141 // TODO(nkostylev): Using std::find for 4 value array generates this warning
128 // in chroot stl_algo.h:231: error: array subscript is above array bounds. 142 // in chroot stl_algo.h:231: error: array subscript is above array bounds.
129 // GCC 4.4.3 143 // GCC 4.4.3
130 return (pref_path == kAccountsPrefAllowNewUser) || 144 return (pref_path == kAccountsPrefAllowNewUser) ||
131 (pref_path == kAccountsPrefAllowGuest) || 145 (pref_path == kAccountsPrefAllowGuest) ||
132 (pref_path == kAccountsPrefShowUserNamesOnSignIn) || 146 (pref_path == kAccountsPrefShowUserNamesOnSignIn) ||
133 (pref_path == kSignedDataRoamingEnabled) || 147 (pref_path == kSignedDataRoamingEnabled) ||
134 (pref_path == kStatsReportingPref); 148 (pref_path == kStatsReportingPref);
135 } 149 }
136 150
137 bool IsControlledStringSetting(const std::string& pref_path) { 151 bool IsControlledStringSetting(const std::string& pref_path) {
138 return std::find(kStringSettings, 152 return std::find(kStringSettings,
139 kStringSettings + arraysize(kStringSettings), 153 kStringSettings + arraysize(kStringSettings),
140 pref_path) != 154 pref_path) !=
141 kStringSettings + arraysize(kStringSettings); 155 kStringSettings + arraysize(kStringSettings);
142 } 156 }
143 157
144 bool IsControlledListSetting(const std::string& pref_path) { 158 bool IsControlledListSetting(const std::string& pref_path) {
145 return std::find(kListSettings, 159 return std::find(kListSettings,
146 kListSettings + arraysize(kListSettings), 160 kListSettings + arraysize(kListSettings),
147 pref_path) != 161 pref_path) !=
148 kListSettings + arraysize(kListSettings); 162 kListSettings + arraysize(kListSettings);
149 } 163 }
150 164
165 bool IsControlledSetting(const std::string& pref_path) {
166 return (IsControlledBooleanSetting(pref_path) ||
167 IsControlledStringSetting(pref_path) ||
168 IsControlledListSetting(pref_path));
169 }
170
151 void RegisterSetting(PrefService* local_state, const std::string& pref_path) { 171 void RegisterSetting(PrefService* local_state, const std::string& pref_path) {
152 local_state->RegisterBooleanPref((pref_path + kTrustedSuffix).c_str(), 172 local_state->RegisterBooleanPref((pref_path + kTrustedSuffix).c_str(),
153 false, 173 false,
154 PrefService::UNSYNCABLE_PREF); 174 PrefService::UNSYNCABLE_PREF);
155 if (IsControlledBooleanSetting(pref_path)) { 175 if (IsControlledBooleanSetting(pref_path)) {
156 if (pref_path == kSignedDataRoamingEnabled || 176 if (pref_path == kSignedDataRoamingEnabled ||
157 pref_path == kStatsReportingPref) 177 pref_path == kStatsReportingPref)
158 local_state->RegisterBooleanPref(pref_path.c_str(), 178 local_state->RegisterBooleanPref(pref_path.c_str(),
159 false, 179 false,
160 PrefService::UNSYNCABLE_PREF); 180 PrefService::UNSYNCABLE_PREF);
(...skipping 10 matching lines...) Expand all
171 local_state->RegisterListPref(pref_path.c_str(), 191 local_state->RegisterListPref(pref_path.c_str(),
172 PrefService::UNSYNCABLE_PREF); 192 PrefService::UNSYNCABLE_PREF);
173 } 193 }
174 } 194 }
175 195
176 enum UseValue { 196 enum UseValue {
177 USE_VALUE_SUPPLIED, 197 USE_VALUE_SUPPLIED,
178 USE_VALUE_DEFAULT 198 USE_VALUE_DEFAULT
179 }; 199 };
180 200
181 void UpdateCacheBool(const std::string& name, 201 void UpdateCache(const std::string& name,
182 bool value, 202 const base::Value* value,
183 UseValue use_value) { 203 UseValue use_value) {
184 PrefService* prefs = g_browser_process->local_state(); 204 PrefService* prefs = g_browser_process->local_state();
185 if (use_value == USE_VALUE_DEFAULT) 205 if (use_value == USE_VALUE_DEFAULT)
186 prefs->ClearPref(name.c_str()); 206 prefs->ClearPref(name.c_str());
187 else 207 else
188 prefs->SetBoolean(name.c_str(), value); 208 prefs->Set(name.c_str(), *value);
189 prefs->ScheduleSavePersistentPrefs(); 209 prefs->ScheduleSavePersistentPrefs();
190 } 210 }
191 211
192 void UpdateCacheString(const std::string& name,
193 const std::string& value,
194 UseValue use_value) {
195 PrefService* prefs = g_browser_process->local_state();
196 if (use_value == USE_VALUE_DEFAULT)
197 prefs->ClearPref(name.c_str());
198 else
199 prefs->SetString(name.c_str(), value);
200 prefs->ScheduleSavePersistentPrefs();
201 }
202
203 // Helper function to parse the whitelist from the policy cache into the local
204 // state.
205 // TODO(pastarmovj): This function will disappear in step two of the refactoring
206 // as per design doc. (Contact pastarmovj@chromium.org for a link to it.)
207 bool GetUserWhitelist(ListValue* user_list) {
208 PrefService* prefs = g_browser_process->local_state();
209 DCHECK(!prefs->IsManagedPreference(kAccountsPrefUsers));
210
211 std::vector<std::string> whitelist;
212 if (!SignedSettings::EnumerateWhitelist(&whitelist)) {
213 LOG(WARNING) << "Failed to retrieve user whitelist.";
214 return false;
215 }
216
217 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers);
218 cached_whitelist_update->Clear();
219
220 for (size_t i = 0; i < whitelist.size(); ++i)
221 cached_whitelist_update->Append(Value::CreateStringValue(whitelist[i]));
222
223 prefs->ScheduleSavePersistentPrefs();
224 return true;
225 }
226
227 class UserCrosSettingsTrust : public SignedSettingsHelper::Callback { 212 class UserCrosSettingsTrust : public SignedSettingsHelper::Callback {
228 public: 213 public:
229 static UserCrosSettingsTrust* GetInstance() { 214 static UserCrosSettingsTrust* GetInstance() {
230 return Singleton<UserCrosSettingsTrust>::get(); 215 return Singleton<UserCrosSettingsTrust>::get();
231 } 216 }
232 217
233 // Working horse for UserCrosSettingsProvider::RequestTrusted* family. 218 // Working horse for UserCrosSettingsProvider::RequestTrusted* family.
234 bool RequestTrustedEntity(const std::string& name) { 219 bool RequestTrustedEntity(const std::string& name) {
235 OwnershipService::Status ownership_status = 220 OwnershipService::Status ownership_status =
236 ownership_service_->GetStatus(false); 221 ownership_service_->GetStatus(false);
(...skipping 21 matching lines...) Expand all
258 callbacks_[name].push_back(callback); 243 callbacks_[name].push_back(callback);
259 return false; 244 return false;
260 } 245 }
261 } 246 }
262 247
263 void Reload() { 248 void Reload() {
264 for (size_t i = 0; i < arraysize(kBooleanSettings); ++i) 249 for (size_t i = 0; i < arraysize(kBooleanSettings); ++i)
265 StartFetchingSetting(kBooleanSettings[i]); 250 StartFetchingSetting(kBooleanSettings[i]);
266 for (size_t i = 0; i < arraysize(kStringSettings); ++i) 251 for (size_t i = 0; i < arraysize(kStringSettings); ++i)
267 StartFetchingSetting(kStringSettings[i]); 252 StartFetchingSetting(kStringSettings[i]);
253 for (size_t i = 0; i < arraysize(kListSettings); ++i)
254 StartFetchingSetting(kListSettings[i]);
268 } 255 }
269 256
270 void Set(const std::string& path, Value* in_value) { 257 void Set(const std::string& path, const base::Value& in_value) {
271 PrefService* prefs = g_browser_process->local_state(); 258 PrefService* prefs = g_browser_process->local_state();
272 DCHECK(!prefs->IsManagedPreference(path.c_str())); 259 DCHECK(!prefs->IsManagedPreference(path.c_str()));
273 260
274 if (!UserManager::Get()->current_user_is_owner()) { 261 if (!UserManager::Get()->current_user_is_owner()) {
275 LOG(WARNING) << "Changing settings from non-owner, setting=" << path; 262 LOG(WARNING) << "Changing settings from non-owner, setting=" << path;
276 263
277 // Revert UI change. 264 // Revert UI change.
278 CrosSettings::Get()->FireObservers(path.c_str()); 265 CrosSettings::Get()->FireObservers(path.c_str());
279 return; 266 return;
280 } 267 }
268 if (IsControlledSetting(path)) {
269 if (IsControlledBooleanSetting(path)) {
270 bool bool_value = false;
271 if (in_value.GetAsBoolean(&bool_value)) {
272 OnBooleanPropertyChange(path, bool_value);
273 }
274 }
275 SignedSettingsHelper::Get()->StartStorePropertyOp(
276 path, in_value, this);
277 UpdateCache(path, &in_value, USE_VALUE_SUPPLIED);
281 278
282 if (IsControlledBooleanSetting(path)) { 279 LOG(ERROR) << "Set cros setting " << path;
283 bool bool_value = false;
284 if (in_value->GetAsBoolean(&bool_value)) {
285 OnBooleanPropertyChange(path, bool_value);
286 std::string value = bool_value ? kTrueIncantation : kFalseIncantation;
287 SignedSettingsHelper::Get()->StartStorePropertyOp(path, value, this);
288 UpdateCacheBool(path, bool_value, USE_VALUE_SUPPLIED);
289
290 VLOG(1) << "Set cros setting " << path << "=" << value;
291 }
292 } else if (IsControlledStringSetting(path)) {
293 std::string value;
294 if (in_value->GetAsString(&value)) {
295 SignedSettingsHelper::Get()->StartStorePropertyOp(path, value, this);
296 UpdateCacheString(path, value, USE_VALUE_SUPPLIED);
297
298 VLOG(1) << "Set cros setting " << path << "=" << value;
299 } else {
300 NOTREACHED() << "Unable to convert string value.";
301 }
302 } else if (path == kDeviceOwner) {
303 VLOG(1) << "Setting owner is not supported. Please use "
304 "'UpdateCachedOwner' instead.";
305 } else if (path == kAccountsPrefUsers) {
306 VLOG(1) << "Setting user whitelist is not implemented. Please use "
307 "whitelist/unwhitelist instead.";
308 } else { 280 } else {
309 LOG(WARNING) << "Try to set unhandled cros setting " << path; 281 LOG(WARNING) << "Try to set unhandled cros setting " << path;
310 } 282 }
311 } 283 }
312 284
313 private: 285 private:
314 // upper bound for number of retries to fetch a signed setting. 286 // upper bound for number of retries to fetch a signed setting.
315 static const int kNumRetriesLimit = 9; 287 static const int kNumRetriesLimit = 9;
316 288
317 UserCrosSettingsTrust() 289 UserCrosSettingsTrust()
(...skipping 26 matching lines...) Expand all
344 } 316 }
345 cros->SetCellularDataRoamingAllowed(new_value); 317 cros->SetCellularDataRoamingAllowed(new_value);
346 } else if (path == kStatsReportingPref) { 318 } else if (path == kStatsReportingPref) {
347 // TODO(pastarmovj): Remove this once we don't need to regenerate the 319 // TODO(pastarmovj): Remove this once we don't need to regenerate the
348 // consent file for the GUID anymore. 320 // consent file for the GUID anymore.
349 OptionsUtil::ResolveMetricsReportingEnabled(new_value); 321 OptionsUtil::ResolveMetricsReportingEnabled(new_value);
350 } 322 }
351 } 323 }
352 324
353 // Called right after signed value was checked. 325 // Called right after signed value was checked.
354 void OnBooleanPropertyRetrieve(const std::string& path, 326 void OnPropertyRetrieve(const std::string& path,
355 bool value, 327 const base::Value* value,
356 UseValue use_value) { 328 UseValue use_value) {
357 if (path == kSignedDataRoamingEnabled) { 329 if (path == kSignedDataRoamingEnabled) {
358 if (!CrosLibrary::Get()->EnsureLoaded()) 330 if (!CrosLibrary::Get()->EnsureLoaded())
359 return; 331 return;
360 332
361 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); 333 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
362 const NetworkDevice* cellular = cros->FindCellularDevice(); 334 const NetworkDevice* cellular = cros->FindCellularDevice();
363 if (cellular) { 335 if (cellular) {
364 bool device_value = cellular->data_roaming_allowed(); 336 bool device_value = cellular->data_roaming_allowed();
365 if (!device_value && cros->IsCellularAlwaysInRoaming()) { 337 if (!device_value && cros->IsCellularAlwaysInRoaming()) {
366 // If operator requires roaming always enabled, ignore supplied value 338 // If operator requires roaming always enabled, ignore supplied value
367 // and set data roaming allowed in true always. 339 // and set data roaming allowed in true always.
368 cros->SetCellularDataRoamingAllowed(true); 340 cros->SetCellularDataRoamingAllowed(true);
369 } else { 341 } else {
370 bool new_value = (use_value == USE_VALUE_SUPPLIED) ? value : false; 342 bool new_value = false;
343 if (use_value == USE_VALUE_SUPPLIED)
344 value->GetAsBoolean(&new_value);
371 if (device_value != new_value) 345 if (device_value != new_value)
372 cros->SetCellularDataRoamingAllowed(new_value); 346 cros->SetCellularDataRoamingAllowed(new_value);
373 } 347 }
374 } 348 }
375 } else if (path == kStatsReportingPref) { 349 } else if (path == kStatsReportingPref) {
376 bool stats_consent = (use_value == USE_VALUE_SUPPLIED) ? value : false; 350 bool stats_consent = false;
351 if (use_value == USE_VALUE_SUPPLIED)
352 value->GetAsBoolean(&stats_consent);
377 // TODO(pastarmovj): Remove this once migration is not needed anymore. 353 // TODO(pastarmovj): Remove this once migration is not needed anymore.
378 // If the value is not set we should try to migrate legacy consent file. 354 // If the value is not set we should try to migrate legacy consent file.
379 if (use_value == USE_VALUE_DEFAULT) { 355 if (use_value == USE_VALUE_DEFAULT) {
380 // Loading consent file state causes us to do blocking IO on UI thread. 356 // Loading consent file state causes us to do blocking IO on UI thread.
381 // Temporarily allow it until we fix http://crbug.com/62626 357 // Temporarily allow it until we fix http://crbug.com/62626
382 base::ThreadRestrictions::ScopedAllowIO allow_io; 358 base::ThreadRestrictions::ScopedAllowIO allow_io;
383 stats_consent = GoogleUpdateSettings::GetCollectStatsConsent(); 359 stats_consent = GoogleUpdateSettings::GetCollectStatsConsent();
384 // Make sure the values will get eventually written to the policy file. 360 // Make sure the values will get eventually written to the policy file.
385 migration_helper_.AddMigrationValue( 361 migration_helper_.AddMigrationValue(
386 path, stats_consent ? "true" : "false"); 362 path, base::Value::CreateBooleanValue(stats_consent));
387 migration_helper_.MigrateValues(); 363 migration_helper_.MigrateValues();
388 UpdateCacheBool(path, stats_consent, USE_VALUE_SUPPLIED); 364 base::FundamentalValue base_value(stats_consent);
365 UpdateCache(path, &base_value, USE_VALUE_SUPPLIED);
389 LOG(WARNING) << "No metrics policy set will revert to checking " 366 LOG(WARNING) << "No metrics policy set will revert to checking "
390 << "consent file which is " 367 << "consent file which is "
391 << (stats_consent ? "on." : "off."); 368 << (stats_consent ? "on." : "off.");
392 } 369 }
393 // TODO(pastarmovj): Remove this once we don't need to regenerate the 370 // TODO(pastarmovj): Remove this once we don't need to regenerate the
394 // consent file for the GUID anymore. 371 // consent file for the GUID anymore.
395 VLOG(1) << "Metrics policy is being set to : " << stats_consent 372 VLOG(1) << "Metrics policy is being set to : " << stats_consent
396 << "(reason : " << use_value << ")"; 373 << "(reason : " << use_value << ")";
397 OptionsUtil::ResolveMetricsReportingEnabled(stats_consent); 374 OptionsUtil::ResolveMetricsReportingEnabled(stats_consent);
398 } 375 }
399 } 376 }
400 377
401 void StartFetchingSetting(const std::string& name) { 378 void StartFetchingSetting(const std::string& name) {
402 DCHECK(g_browser_process); 379 DCHECK(g_browser_process);
403 PrefService* prefs = g_browser_process->local_state(); 380 PrefService* prefs = g_browser_process->local_state();
404 if (!prefs) 381 if (!prefs)
405 return; 382 return;
406 // Do not trust before fetching complete. 383 // Do not trust before fetching complete.
407 prefs->ClearPref((name + kTrustedSuffix).c_str()); 384 prefs->ClearPref((name + kTrustedSuffix).c_str());
408 prefs->ScheduleSavePersistentPrefs(); 385 prefs->ScheduleSavePersistentPrefs();
409 if (CrosLibrary::Get()->EnsureLoaded()) { 386 if (CrosLibrary::Get()->EnsureLoaded()) {
410 SignedSettingsHelper::Get()->StartRetrieveProperty(name, this); 387 SignedSettingsHelper::Get()->StartRetrieveProperty(name, this);
411 } 388 }
412 } 389 }
413 390
414 // Implementation of SignedSettingsHelper::Callback. 391 // Implementation of SignedSettingsHelper::Callback.
415 virtual void OnRetrievePropertyCompleted(SignedSettings::ReturnCode code, 392 virtual void OnRetrievePropertyCompleted(SignedSettings::ReturnCode code,
416 const std::string& name, 393 const std::string& name,
417 const std::string& value) { 394 const base::Value* value) {
418 if (!IsControlledBooleanSetting(name) && !IsControlledStringSetting(name)) { 395 if (!IsControlledSetting(name)) {
419 NOTREACHED(); 396 NOTREACHED();
420 return; 397 return;
421 } 398 }
422 399
423 bool is_owned = ownership_service_->GetStatus(true) == 400 bool is_owned = ownership_service_->GetStatus(true) ==
424 OwnershipService::OWNERSHIP_TAKEN; 401 OwnershipService::OWNERSHIP_TAKEN;
425 PrefService* prefs = g_browser_process->local_state(); 402 PrefService* prefs = g_browser_process->local_state();
426 switch (code) { 403 switch (code) {
427 case SignedSettings::SUCCESS: 404 case SignedSettings::SUCCESS:
428 case SignedSettings::NOT_FOUND: 405 case SignedSettings::NOT_FOUND:
429 case SignedSettings::KEY_UNAVAILABLE: { 406 case SignedSettings::KEY_UNAVAILABLE: {
430 bool fallback_to_default = !is_owned 407 bool fallback_to_default = !is_owned
431 || (code == SignedSettings::NOT_FOUND); 408 || (code == SignedSettings::NOT_FOUND);
432 DCHECK(fallback_to_default || code == SignedSettings::SUCCESS); 409 DCHECK(fallback_to_default || code == SignedSettings::SUCCESS);
433 if (fallback_to_default) 410 if (fallback_to_default)
434 VLOG(1) << "Going default for cros setting " << name; 411 VLOG(1) << "Going default for cros setting " << name;
435 else 412 else
436 VLOG(1) << "Retrieved cros setting " << name << "=" << value; 413 VLOG(1) << "Retrieved cros setting " << name;
437 if (IsControlledBooleanSetting(name)) { 414 UpdateCache(
438 UpdateCacheBool(name, (value == kTrueIncantation), 415 name, value,
439 fallback_to_default ? USE_VALUE_DEFAULT : USE_VALUE_SUPPLIED); 416 fallback_to_default ? USE_VALUE_DEFAULT : USE_VALUE_SUPPLIED);
440 OnBooleanPropertyRetrieve(name, (value == kTrueIncantation), 417 OnPropertyRetrieve(
441 fallback_to_default ? USE_VALUE_DEFAULT : USE_VALUE_SUPPLIED); 418 name, value,
442 } else if (IsControlledStringSetting(name)) { 419 fallback_to_default ? USE_VALUE_DEFAULT : USE_VALUE_SUPPLIED);
443 UpdateCacheString(name, value,
444 fallback_to_default ? USE_VALUE_DEFAULT : USE_VALUE_SUPPLIED);
445 }
446 break; 420 break;
447 } 421 }
448 case SignedSettings::OPERATION_FAILED: 422 case SignedSettings::OPERATION_FAILED:
449 default: { 423 default: {
450 DCHECK(code == SignedSettings::OPERATION_FAILED); 424 DCHECK(code == SignedSettings::OPERATION_FAILED);
451 DCHECK(is_owned); 425 DCHECK(is_owned);
452 LOG(ERROR) << "On owned device: failed to retrieve cros " 426 LOG(ERROR) << "On owned device: failed to retrieve cros "
453 "setting, name=" << name; 427 "setting, name=" << name;
454 if (retries_left_ > 0) { 428 if (retries_left_ > 0) {
455 retries_left_ -= 1; 429 retries_left_ -= 1;
456 StartFetchingSetting(name); 430 StartFetchingSetting(name);
457 return; 431 return;
458 } 432 }
459 LOG(ERROR) << "No retries left"; 433 LOG(ERROR) << "No retries left";
460 if (IsControlledBooleanSetting(name)) { 434 if (IsControlledBooleanSetting(name)) {
461 // For boolean settings we can just set safe (false) values 435 // For boolean settings we can just set safe (false) values
462 // and continue as trusted. 436 // and continue as trusted.
463 OnBooleanPropertyRetrieve(name, false, USE_VALUE_SUPPLIED); 437 scoped_ptr<base::Value> false_value(
464 UpdateCacheBool(name, false, USE_VALUE_SUPPLIED); 438 base::Value::CreateBooleanValue(false));
439 OnPropertyRetrieve(name, false_value.get(), USE_VALUE_SUPPLIED);
440 UpdateCache(name, false_value.get(), USE_VALUE_SUPPLIED);
465 } else { 441 } else {
466 prefs->ClearPref((name + kTrustedSuffix).c_str()); 442 prefs->ClearPref((name + kTrustedSuffix).c_str());
467 return; 443 return;
468 } 444 }
469 break; 445 break;
470 } 446 }
471 } 447 }
472 prefs->SetBoolean((name + kTrustedSuffix).c_str(), true); 448 prefs->SetBoolean((name + kTrustedSuffix).c_str(), true);
473 { 449 {
474 std::vector<base::Closure>& callbacks_vector = callbacks_[name]; 450 std::vector<base::Closure>& callbacks_vector = callbacks_[name];
475 for (size_t i = 0; i < callbacks_vector.size(); ++i) 451 for (size_t i = 0; i < callbacks_vector.size(); ++i)
476 MessageLoop::current()->PostTask(FROM_HERE, callbacks_vector[i]); 452 MessageLoop::current()->PostTask(FROM_HERE, callbacks_vector[i]);
477 callbacks_vector.clear(); 453 callbacks_vector.clear();
478 } 454 }
479 if (code == SignedSettings::SUCCESS) 455 if (code == SignedSettings::SUCCESS)
480 CrosSettings::Get()->FireObservers(name.c_str()); 456 CrosSettings::Get()->FireObservers(name.c_str());
481 } 457 }
482 458
483 // Implementation of SignedSettingsHelper::Callback. 459 // Implementation of SignedSettingsHelper::Callback.
484 virtual void OnStorePropertyCompleted(SignedSettings::ReturnCode code, 460 virtual void OnStorePropertyCompleted(SignedSettings::ReturnCode code,
485 const std::string& name, 461 const std::string& name,
486 const std::string& value) { 462 const base::Value& value) {
487 VLOG(1) << "Store cros setting " << name << "=" << value << ", code=" 463 VLOG(1) << "Store cros setting " << name << ", code=" << code;
488 << code;
489 464
490 // Reload the setting if store op fails. 465 // Reload the setting if store op fails.
491 if (code != SignedSettings::SUCCESS) 466 if (code != SignedSettings::SUCCESS)
492 SignedSettingsHelper::Get()->StartRetrieveProperty(name, this); 467 SignedSettingsHelper::Get()->StartRetrieveProperty(name, this);
493 } 468 }
494 469
495 // Implementation of SignedSettingsHelper::Callback. 470 // Implementation of SignedSettingsHelper::Callback.
496 virtual void OnWhitelistCompleted(SignedSettings::ReturnCode code, 471 virtual void OnWhitelistCompleted(SignedSettings::ReturnCode code,
497 const std::string& email) { 472 const std::string& email) {
498 VLOG(1) << "Add " << email << " to whitelist, code=" << code; 473 VLOG(1) << "Add " << email << " to whitelist, code=" << code;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 RegisterSetting(local_state, kStringSettings[i]); 522 RegisterSetting(local_state, kStringSettings[i]);
548 for (size_t i = 0; i < arraysize(kListSettings); ++i) 523 for (size_t i = 0; i < arraysize(kListSettings); ++i)
549 RegisterSetting(local_state, kListSettings[i]); 524 RegisterSetting(local_state, kListSettings[i]);
550 } 525 }
551 526
552 void UserCrosSettingsProvider::Reload() { 527 void UserCrosSettingsProvider::Reload() {
553 UserCrosSettingsTrust::GetInstance()->Reload(); 528 UserCrosSettingsTrust::GetInstance()->Reload();
554 } 529 }
555 530
556 void UserCrosSettingsProvider::DoSet(const std::string& path, 531 void UserCrosSettingsProvider::DoSet(const std::string& path,
557 Value* in_value) { 532 const base::Value& in_value) {
558 UserCrosSettingsTrust::GetInstance()->Set(path, in_value); 533 UserCrosSettingsTrust::GetInstance()->Set(path, in_value);
559 } 534 }
560 535
561 const base::Value* UserCrosSettingsProvider::Get( 536 const base::Value* UserCrosSettingsProvider::Get(
562 const std::string& path) const { 537 const std::string& path) const {
563 if (HandlesSetting(path)) { 538 if (HandlesSetting(path)) {
564 PrefService* prefs = g_browser_process->local_state(); 539 const PrefService* prefs = g_browser_process->local_state();
565 // TODO(pastarmovj): Temporary hack until we refactor the user whitelisting
566 // handling to completely coincide with the rest of the settings.
567 if (path == kAccountsPrefUsers &&
568 prefs->GetList(kAccountsPrefUsers) == NULL) {
569 GetUserWhitelist(NULL);
570 }
571 const PrefService::Preference* pref = prefs->FindPreference(path.c_str()); 540 const PrefService::Preference* pref = prefs->FindPreference(path.c_str());
572 return pref->GetValue(); 541 return pref->GetValue();
573 } 542 }
574 return NULL; 543 return NULL;
575 } 544 }
576 545
577 bool UserCrosSettingsProvider::GetTrusted(const std::string& path, 546 bool UserCrosSettingsProvider::GetTrusted(const std::string& path,
578 const base::Closure& callback) const { 547 const base::Closure& callback) const {
579 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( 548 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity(
580 path, callback); 549 path, callback);
(...skipping 24 matching lines...) Expand all
605 574
606 PrefService* prefs = g_browser_process->local_state(); 575 PrefService* prefs = g_browser_process->local_state();
607 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers); 576 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers);
608 StringValue email_value(email); 577 StringValue email_value(email);
609 if (cached_whitelist_update->Remove(email_value, NULL)) 578 if (cached_whitelist_update->Remove(email_value, NULL))
610 prefs->ScheduleSavePersistentPrefs(); 579 prefs->ScheduleSavePersistentPrefs();
611 } 580 }
612 581
613 // static 582 // static
614 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { 583 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) {
615 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); 584 base::StringValue email_value(email);
585 UpdateCache(kDeviceOwner, &email_value, USE_VALUE_SUPPLIED);
616 } 586 }
617 587
618 } // namespace chromeos 588 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698