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

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 rebased on a the current PART1 version. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/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/login_library.h" 17 #include "chrome/browser/chromeos/cros/login_library.h"
21 #include "chrome/browser/chromeos/cros/network_library.h" 18 #include "chrome/browser/chromeos/cros/network_library.h"
22 #include "chrome/browser/chromeos/cros_settings.h" 19 #include "chrome/browser/chromeos/cros_settings.h"
23 #include "chrome/browser/chromeos/cros_settings_names.h" 20 #include "chrome/browser/chromeos/cros_settings_names.h"
24 #include "chrome/browser/chromeos/login/ownership_service.h" 21 #include "chrome/browser/chromeos/login/ownership_service.h"
25 #include "chrome/browser/chromeos/login/ownership_status_checker.h" 22 #include "chrome/browser/chromeos/login/ownership_status_checker.h"
26 #include "chrome/browser/chromeos/login/user_manager.h" 23 #include "chrome/browser/chromeos/login/user_manager.h"
27 #include "chrome/browser/prefs/pref_service.h" 24 #include "chrome/browser/prefs/pref_service.h"
25 #include "chrome/browser/prefs/pref_value_map.h"
28 #include "chrome/browser/prefs/scoped_user_pref_update.h" 26 #include "chrome/browser/prefs/scoped_user_pref_update.h"
29 #include "chrome/browser/ui/options/options_util.h" 27 #include "chrome/browser/ui/options/options_util.h"
30 #include "chrome/common/chrome_notification_types.h" 28 #include "chrome/common/chrome_notification_types.h"
31 #include "chrome/installer/util/google_update_settings.h" 29 #include "chrome/installer/util/google_update_settings.h"
32 #include "content/browser/browser_thread.h" 30 #include "content/browser/browser_thread.h"
33 31
34 namespace chromeos { 32 namespace chromeos {
35 33
36 namespace { 34 namespace {
37 35
(...skipping 31 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 NotificationService::AllSources()); 70 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 NotificationSource& source, 88 const NotificationSource& source,
91 const NotificationDetails& details) OVERRIDE { 89 const 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 NotificationRegistrar registrar_; 115 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 {
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_;
Mattias Nissler (ping if slow) 2011/10/13 14:49:52 DISALLOW_COPY_AND_ASSIGN?
pastarmovj 2011/10/26 15:44:59 Done.
136 };
137
126 bool IsControlledBooleanSetting(const std::string& pref_path) { 138 bool IsControlledBooleanSetting(const std::string& pref_path) {
127 // TODO(nkostylev): Using std::find for 4 value array generates this warning 139 // 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. 140 // in chroot stl_algo.h:231: error: array subscript is above array bounds.
129 // GCC 4.4.3 141 // GCC 4.4.3
130 return (pref_path == kAccountsPrefAllowNewUser) || 142 return (pref_path == kAccountsPrefAllowNewUser) ||
131 (pref_path == kAccountsPrefAllowGuest) || 143 (pref_path == kAccountsPrefAllowGuest) ||
132 (pref_path == kAccountsPrefShowUserNamesOnSignIn) || 144 (pref_path == kAccountsPrefShowUserNamesOnSignIn) ||
133 (pref_path == kSignedDataRoamingEnabled) || 145 (pref_path == kSignedDataRoamingEnabled) ||
134 (pref_path == kStatsReportingPref); 146 (pref_path == kStatsReportingPref);
135 } 147 }
136 148
137 bool IsControlledStringSetting(const std::string& pref_path) { 149 bool IsControlledStringSetting(const std::string& pref_path) {
138 return std::find(kStringSettings, 150 return std::find(kStringSettings,
139 kStringSettings + arraysize(kStringSettings), 151 kStringSettings + arraysize(kStringSettings),
140 pref_path) != 152 pref_path) !=
141 kStringSettings + arraysize(kStringSettings); 153 kStringSettings + arraysize(kStringSettings);
142 } 154 }
143 155
144 bool IsControlledListSetting(const std::string& pref_path) { 156 bool IsControlledListSetting(const std::string& pref_path) {
145 return std::find(kListSettings, 157 return std::find(kListSettings,
146 kListSettings + arraysize(kListSettings), 158 kListSettings + arraysize(kListSettings),
147 pref_path) != 159 pref_path) !=
148 kListSettings + arraysize(kListSettings); 160 kListSettings + arraysize(kListSettings);
149 } 161 }
150 162
163 bool IsControlledSetting(const std::string& pref_path) {
164 return (IsControlledBooleanSetting(pref_path) ||
165 IsControlledStringSetting(pref_path) ||
166 IsControlledListSetting(pref_path));
167 }
168
151 void RegisterSetting(PrefService* local_state, const std::string& pref_path) { 169 void RegisterSetting(PrefService* local_state, const std::string& pref_path) {
152 local_state->RegisterBooleanPref((pref_path + kTrustedSuffix).c_str(), 170 local_state->RegisterBooleanPref((pref_path + kTrustedSuffix).c_str(),
153 false, 171 false,
154 PrefService::UNSYNCABLE_PREF); 172 PrefService::UNSYNCABLE_PREF);
155 if (IsControlledBooleanSetting(pref_path)) { 173 if (IsControlledBooleanSetting(pref_path)) {
156 if (pref_path == kSignedDataRoamingEnabled || 174 if (pref_path == kSignedDataRoamingEnabled ||
157 pref_path == kStatsReportingPref) 175 pref_path == kStatsReportingPref)
158 local_state->RegisterBooleanPref(pref_path.c_str(), 176 local_state->RegisterBooleanPref(pref_path.c_str(),
159 false, 177 false,
160 PrefService::UNSYNCABLE_PREF); 178 PrefService::UNSYNCABLE_PREF);
(...skipping 10 matching lines...) Expand all
171 local_state->RegisterListPref(pref_path.c_str(), 189 local_state->RegisterListPref(pref_path.c_str(),
172 PrefService::UNSYNCABLE_PREF); 190 PrefService::UNSYNCABLE_PREF);
173 } 191 }
174 } 192 }
175 193
176 enum UseValue { 194 enum UseValue {
177 USE_VALUE_SUPPLIED, 195 USE_VALUE_SUPPLIED,
178 USE_VALUE_DEFAULT 196 USE_VALUE_DEFAULT
179 }; 197 };
180 198
181 void UpdateCacheBool(const std::string& name, 199 void UpdateCache(const std::string& name,
182 bool value, 200 const base::Value& value,
183 UseValue use_value) { 201 UseValue use_value) {
184 PrefService* prefs = g_browser_process->local_state(); 202 PrefService* prefs = g_browser_process->local_state();
185 if (use_value == USE_VALUE_DEFAULT) 203 if (use_value == USE_VALUE_DEFAULT)
186 prefs->ClearPref(name.c_str()); 204 prefs->ClearPref(name.c_str());
187 else 205 else
188 prefs->SetBoolean(name.c_str(), value); 206 prefs->Set(name.c_str(), value);
189 prefs->ScheduleSavePersistentPrefs(); 207 prefs->ScheduleSavePersistentPrefs();
190 } 208 }
191 209
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 { 210 class UserCrosSettingsTrust : public SignedSettingsHelper::Callback {
228 public: 211 public:
229 static UserCrosSettingsTrust* GetInstance() { 212 static UserCrosSettingsTrust* GetInstance() {
230 return Singleton<UserCrosSettingsTrust>::get(); 213 return Singleton<UserCrosSettingsTrust>::get();
231 } 214 }
232 215
233 // Working horse for UserCrosSettingsProvider::RequestTrusted* family. 216 // Working horse for UserCrosSettingsProvider::RequestTrusted* family.
234 bool RequestTrustedEntity(const std::string& name) { 217 bool RequestTrustedEntity(const std::string& name) {
235 OwnershipService::Status ownership_status = 218 OwnershipService::Status ownership_status =
236 ownership_service_->GetStatus(false); 219 ownership_service_->GetStatus(false);
(...skipping 21 matching lines...) Expand all
258 callbacks_[name].push_back(callback); 241 callbacks_[name].push_back(callback);
259 return false; 242 return false;
260 } 243 }
261 } 244 }
262 245
263 void Reload() { 246 void Reload() {
264 for (size_t i = 0; i < arraysize(kBooleanSettings); ++i) 247 for (size_t i = 0; i < arraysize(kBooleanSettings); ++i)
265 StartFetchingSetting(kBooleanSettings[i]); 248 StartFetchingSetting(kBooleanSettings[i]);
266 for (size_t i = 0; i < arraysize(kStringSettings); ++i) 249 for (size_t i = 0; i < arraysize(kStringSettings); ++i)
267 StartFetchingSetting(kStringSettings[i]); 250 StartFetchingSetting(kStringSettings[i]);
251 for (size_t i = 0; i < arraysize(kListSettings); ++i)
252 StartFetchingSetting(kListSettings[i]);
268 } 253 }
269 254
270 void Set(const std::string& path, Value* in_value) { 255 void Set(const std::string& path, const base::Value& in_value) {
271 PrefService* prefs = g_browser_process->local_state(); 256 PrefService* prefs = g_browser_process->local_state();
272 DCHECK(!prefs->IsManagedPreference(path.c_str())); 257 DCHECK(!prefs->IsManagedPreference(path.c_str()));
273 258
274 if (!UserManager::Get()->current_user_is_owner()) { 259 if (!UserManager::Get()->current_user_is_owner()) {
275 LOG(WARNING) << "Changing settings from non-owner, setting=" << path; 260 LOG(WARNING) << "Changing settings from non-owner, setting=" << path;
276 261
277 // Revert UI change. 262 // Revert UI change.
278 CrosSettings::Get()->FireObservers(path.c_str()); 263 CrosSettings::Get()->FireObservers(path.c_str());
279 return; 264 return;
280 } 265 }
266 if (IsControlledSetting(path)) {
267 if (IsControlledBooleanSetting(path)) {
268 bool bool_value = false;
269 if (in_value.GetAsBoolean(&bool_value)) {
270 OnBooleanPropertyChange(path, bool_value);
271 }
272 }
273 SignedSettingsHelper::Get()->StartStorePropertyOp(
274 path, in_value, this);
275 UpdateCache(path, in_value, USE_VALUE_SUPPLIED);
281 276
282 if (IsControlledBooleanSetting(path)) { 277 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 { 278 } else {
309 LOG(WARNING) << "Try to set unhandled cros setting " << path; 279 LOG(WARNING) << "Try to set unhandled cros setting " << path;
310 } 280 }
311 } 281 }
312 282
313 private: 283 private:
314 // upper bound for number of retries to fetch a signed setting. 284 // upper bound for number of retries to fetch a signed setting.
315 static const int kNumRetriesLimit = 9; 285 static const int kNumRetriesLimit = 9;
316 286
317 UserCrosSettingsTrust() 287 UserCrosSettingsTrust()
(...skipping 26 matching lines...) Expand all
344 } 314 }
345 cros->SetCellularDataRoamingAllowed(new_value); 315 cros->SetCellularDataRoamingAllowed(new_value);
346 } else if (path == kStatsReportingPref) { 316 } else if (path == kStatsReportingPref) {
347 // TODO(pastarmovj): Remove this once we don't need to regenerate the 317 // TODO(pastarmovj): Remove this once we don't need to regenerate the
348 // consent file for the GUID anymore. 318 // consent file for the GUID anymore.
349 OptionsUtil::ResolveMetricsReportingEnabled(new_value); 319 OptionsUtil::ResolveMetricsReportingEnabled(new_value);
350 } 320 }
351 } 321 }
352 322
353 // Called right after signed value was checked. 323 // Called right after signed value was checked.
354 void OnBooleanPropertyRetrieve(const std::string& path, 324 void OnPropertyRetrieve(const std::string& path,
355 bool value, 325 const base::Value& value,
356 UseValue use_value) { 326 UseValue use_value) {
357 if (path == kSignedDataRoamingEnabled) { 327 if (path == kSignedDataRoamingEnabled) {
358 if (!CrosLibrary::Get()->EnsureLoaded()) 328 if (!CrosLibrary::Get()->EnsureLoaded())
359 return; 329 return;
360 330
361 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); 331 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
362 const NetworkDevice* cellular = cros->FindCellularDevice(); 332 const NetworkDevice* cellular = cros->FindCellularDevice();
363 if (cellular) { 333 if (cellular) {
364 bool device_value = cellular->data_roaming_allowed(); 334 bool device_value = cellular->data_roaming_allowed();
365 if (!device_value && cros->IsCellularAlwaysInRoaming()) { 335 if (!device_value && cros->IsCellularAlwaysInRoaming()) {
366 // If operator requires roaming always enabled, ignore supplied value 336 // If operator requires roaming always enabled, ignore supplied value
367 // and set data roaming allowed in true always. 337 // and set data roaming allowed in true always.
368 cros->SetCellularDataRoamingAllowed(true); 338 cros->SetCellularDataRoamingAllowed(true);
369 } else { 339 } else {
370 bool new_value = (use_value == USE_VALUE_SUPPLIED) ? value : false; 340 bool prop_val;
341 value.GetAsBoolean(&prop_val);
342 bool new_value = (use_value == USE_VALUE_SUPPLIED) ? prop_val : false;
371 if (device_value != new_value) 343 if (device_value != new_value)
372 cros->SetCellularDataRoamingAllowed(new_value); 344 cros->SetCellularDataRoamingAllowed(new_value);
373 } 345 }
374 } 346 }
375 } else if (path == kStatsReportingPref) { 347 } else if (path == kStatsReportingPref) {
376 bool stats_consent = (use_value == USE_VALUE_SUPPLIED) ? value : false; 348 bool prop_val;
349 value.GetAsBoolean(&prop_val);
350 bool stats_consent = (use_value == USE_VALUE_SUPPLIED) ? prop_val : false;
377 // TODO(pastarmovj): Remove this once migration is not needed anymore. 351 // 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. 352 // If the value is not set we should try to migrate legacy consent file.
379 if (use_value == USE_VALUE_DEFAULT) { 353 if (use_value == USE_VALUE_DEFAULT) {
380 // Loading consent file state causes us to do blocking IO on UI thread. 354 // Loading consent file state causes us to do blocking IO on UI thread.
381 // Temporarily allow it until we fix http://crbug.com/62626 355 // Temporarily allow it until we fix http://crbug.com/62626
382 base::ThreadRestrictions::ScopedAllowIO allow_io; 356 base::ThreadRestrictions::ScopedAllowIO allow_io;
383 stats_consent = GoogleUpdateSettings::GetCollectStatsConsent(); 357 stats_consent = GoogleUpdateSettings::GetCollectStatsConsent();
384 // Make sure the values will get eventually written to the policy file. 358 // Make sure the values will get eventually written to the policy file.
385 migration_helper_.AddMigrationValue( 359 migration_helper_.AddMigrationValue(
386 path, stats_consent ? "true" : "false"); 360 path, base::Value::CreateBooleanValue(stats_consent));
387 migration_helper_.MigrateValues(); 361 migration_helper_.MigrateValues();
388 UpdateCacheBool(path, stats_consent, USE_VALUE_SUPPLIED); 362 base::FundamentalValue base_value(stats_consent);
363 UpdateCache(path, base_value, USE_VALUE_SUPPLIED);
389 LOG(WARNING) << "No metrics policy set will revert to checking " 364 LOG(WARNING) << "No metrics policy set will revert to checking "
390 << "consent file which is " 365 << "consent file which is "
391 << (stats_consent ? "on." : "off."); 366 << (stats_consent ? "on." : "off.");
392 } 367 }
393 // TODO(pastarmovj): Remove this once we don't need to regenerate the 368 // TODO(pastarmovj): Remove this once we don't need to regenerate the
394 // consent file for the GUID anymore. 369 // consent file for the GUID anymore.
395 VLOG(1) << "Metrics policy is being set to : " << stats_consent 370 VLOG(1) << "Metrics policy is being set to : " << stats_consent
396 << "(reason : " << use_value << ")"; 371 << "(reason : " << use_value << ")";
397 OptionsUtil::ResolveMetricsReportingEnabled(stats_consent); 372 OptionsUtil::ResolveMetricsReportingEnabled(stats_consent);
398 } 373 }
399 } 374 }
400 375
401 void StartFetchingSetting(const std::string& name) { 376 void StartFetchingSetting(const std::string& name) {
402 DCHECK(g_browser_process); 377 DCHECK(g_browser_process);
403 PrefService* prefs = g_browser_process->local_state(); 378 PrefService* prefs = g_browser_process->local_state();
404 if (!prefs) 379 if (!prefs)
405 return; 380 return;
406 // Do not trust before fetching complete. 381 // Do not trust before fetching complete.
407 prefs->ClearPref((name + kTrustedSuffix).c_str()); 382 prefs->ClearPref((name + kTrustedSuffix).c_str());
408 prefs->ScheduleSavePersistentPrefs(); 383 prefs->ScheduleSavePersistentPrefs();
409 if (CrosLibrary::Get()->EnsureLoaded()) { 384 if (CrosLibrary::Get()->EnsureLoaded()) {
410 SignedSettingsHelper::Get()->StartRetrieveProperty(name, this); 385 SignedSettingsHelper::Get()->StartRetrieveProperty(name, this);
411 } 386 }
412 } 387 }
413 388
414 // Implementation of SignedSettingsHelper::Callback. 389 // Implementation of SignedSettingsHelper::Callback.
415 virtual void OnRetrievePropertyCompleted(SignedSettings::ReturnCode code, 390 virtual void OnRetrievePropertyCompleted(SignedSettings::ReturnCode code,
416 const std::string& name, 391 const std::string& name,
417 const std::string& value) { 392 const base::Value& value) {
418 if (!IsControlledBooleanSetting(name) && !IsControlledStringSetting(name)) { 393 if (!IsControlledSetting(name)) {
419 NOTREACHED(); 394 NOTREACHED();
420 return; 395 return;
421 } 396 }
422 397
423 bool is_owned = ownership_service_->GetStatus(true) == 398 bool is_owned = ownership_service_->GetStatus(true) ==
424 OwnershipService::OWNERSHIP_TAKEN; 399 OwnershipService::OWNERSHIP_TAKEN;
425 PrefService* prefs = g_browser_process->local_state(); 400 PrefService* prefs = g_browser_process->local_state();
426 switch (code) { 401 switch (code) {
427 case SignedSettings::SUCCESS: 402 case SignedSettings::SUCCESS:
428 case SignedSettings::NOT_FOUND: 403 case SignedSettings::NOT_FOUND:
429 case SignedSettings::KEY_UNAVAILABLE: { 404 case SignedSettings::KEY_UNAVAILABLE: {
430 bool fallback_to_default = !is_owned 405 bool fallback_to_default = !is_owned
431 || (code == SignedSettings::NOT_FOUND); 406 || (code == SignedSettings::NOT_FOUND);
432 DCHECK(fallback_to_default || code == SignedSettings::SUCCESS); 407 DCHECK(fallback_to_default || code == SignedSettings::SUCCESS);
433 if (fallback_to_default) 408 if (fallback_to_default)
434 VLOG(1) << "Going default for cros setting " << name; 409 VLOG(1) << "Going default for cros setting " << name;
435 else 410 else
436 VLOG(1) << "Retrieved cros setting " << name << "=" << value; 411 VLOG(1) << "Retrieved cros setting " << name;
437 if (IsControlledBooleanSetting(name)) { 412 UpdateCache(
438 UpdateCacheBool(name, (value == kTrueIncantation), 413 name, value,
439 fallback_to_default ? USE_VALUE_DEFAULT : USE_VALUE_SUPPLIED); 414 fallback_to_default ? USE_VALUE_DEFAULT : USE_VALUE_SUPPLIED);
440 OnBooleanPropertyRetrieve(name, (value == kTrueIncantation), 415 OnPropertyRetrieve(
441 fallback_to_default ? USE_VALUE_DEFAULT : USE_VALUE_SUPPLIED); 416 name, value,
442 } else if (IsControlledStringSetting(name)) { 417 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; 418 break;
447 } 419 }
448 case SignedSettings::OPERATION_FAILED: 420 case SignedSettings::OPERATION_FAILED:
449 default: { 421 default: {
450 DCHECK(code == SignedSettings::OPERATION_FAILED); 422 DCHECK(code == SignedSettings::OPERATION_FAILED);
451 DCHECK(is_owned); 423 DCHECK(is_owned);
452 LOG(ERROR) << "On owned device: failed to retrieve cros " 424 LOG(ERROR) << "On owned device: failed to retrieve cros "
453 "setting, name=" << name; 425 "setting, name=" << name;
454 if (retries_left_ > 0) { 426 if (retries_left_ > 0) {
455 retries_left_ -= 1; 427 retries_left_ -= 1;
456 StartFetchingSetting(name); 428 StartFetchingSetting(name);
457 return; 429 return;
458 } 430 }
459 LOG(ERROR) << "No retries left"; 431 LOG(ERROR) << "No retries left";
460 if (IsControlledBooleanSetting(name)) { 432 if (IsControlledBooleanSetting(name)) {
461 // For boolean settings we can just set safe (false) values 433 // For boolean settings we can just set safe (false) values
462 // and continue as trusted. 434 // and continue as trusted.
463 OnBooleanPropertyRetrieve(name, false, USE_VALUE_SUPPLIED); 435 scoped_ptr<base::Value> false_value(
464 UpdateCacheBool(name, false, USE_VALUE_SUPPLIED); 436 base::Value::CreateBooleanValue(false));
437 OnPropertyRetrieve(name, *false_value, USE_VALUE_SUPPLIED);
438 UpdateCache(name, *false_value, USE_VALUE_SUPPLIED);
465 } else { 439 } else {
466 prefs->ClearPref((name + kTrustedSuffix).c_str()); 440 prefs->ClearPref((name + kTrustedSuffix).c_str());
467 return; 441 return;
468 } 442 }
469 break; 443 break;
470 } 444 }
471 } 445 }
472 prefs->SetBoolean((name + kTrustedSuffix).c_str(), true); 446 prefs->SetBoolean((name + kTrustedSuffix).c_str(), true);
473 { 447 {
474 std::vector<base::Closure>& callbacks_vector = callbacks_[name]; 448 std::vector<base::Closure>& callbacks_vector = callbacks_[name];
475 for (size_t i = 0; i < callbacks_vector.size(); ++i) 449 for (size_t i = 0; i < callbacks_vector.size(); ++i)
476 MessageLoop::current()->PostTask(FROM_HERE, callbacks_vector[i]); 450 MessageLoop::current()->PostTask(FROM_HERE, callbacks_vector[i]);
477 callbacks_vector.clear(); 451 callbacks_vector.clear();
478 } 452 }
479 if (code == SignedSettings::SUCCESS) 453 if (code == SignedSettings::SUCCESS)
480 CrosSettings::Get()->FireObservers(name.c_str()); 454 CrosSettings::Get()->FireObservers(name.c_str());
481 } 455 }
482 456
483 // Implementation of SignedSettingsHelper::Callback. 457 // Implementation of SignedSettingsHelper::Callback.
484 virtual void OnStorePropertyCompleted(SignedSettings::ReturnCode code, 458 virtual void OnStorePropertyCompleted(SignedSettings::ReturnCode code,
485 const std::string& name, 459 const std::string& name,
486 const std::string& value) { 460 const base::Value& value) {
487 VLOG(1) << "Store cros setting " << name << "=" << value << ", code=" 461 VLOG(1) << "Store cros setting " << name << ", code=" << code;
488 << code;
489 462
490 // Reload the setting if store op fails. 463 // Reload the setting if store op fails.
491 if (code != SignedSettings::SUCCESS) 464 if (code != SignedSettings::SUCCESS)
492 SignedSettingsHelper::Get()->StartRetrieveProperty(name, this); 465 SignedSettingsHelper::Get()->StartRetrieveProperty(name, this);
493 } 466 }
494 467
495 // Implementation of SignedSettingsHelper::Callback. 468 // Implementation of SignedSettingsHelper::Callback.
496 virtual void OnWhitelistCompleted(SignedSettings::ReturnCode code, 469 virtual void OnWhitelistCompleted(SignedSettings::ReturnCode code,
497 const std::string& email) { 470 const std::string& email) {
498 VLOG(1) << "Add " << email << " to whitelist, code=" << code; 471 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]); 520 RegisterSetting(local_state, kStringSettings[i]);
548 for (size_t i = 0; i < arraysize(kListSettings); ++i) 521 for (size_t i = 0; i < arraysize(kListSettings); ++i)
549 RegisterSetting(local_state, kListSettings[i]); 522 RegisterSetting(local_state, kListSettings[i]);
550 } 523 }
551 524
552 void UserCrosSettingsProvider::Reload() { 525 void UserCrosSettingsProvider::Reload() {
553 UserCrosSettingsTrust::GetInstance()->Reload(); 526 UserCrosSettingsTrust::GetInstance()->Reload();
554 } 527 }
555 528
556 void UserCrosSettingsProvider::DoSet(const std::string& path, 529 void UserCrosSettingsProvider::DoSet(const std::string& path,
557 Value* in_value) { 530 const base::Value& in_value) {
558 UserCrosSettingsTrust::GetInstance()->Set(path, in_value); 531 UserCrosSettingsTrust::GetInstance()->Set(path, in_value);
559 } 532 }
560 533
561 const base::Value* UserCrosSettingsProvider::Get( 534 const base::Value* UserCrosSettingsProvider::Get(
562 const std::string& path) const { 535 const std::string& path) const {
563 if (HandlesSetting(path)) { 536 if (HandlesSetting(path)) {
564 PrefService* prefs = g_browser_process->local_state(); 537 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()); 538 const PrefService::Preference* pref = prefs->FindPreference(path.c_str());
572 return pref->GetValue(); 539 return pref->GetValue();
573 } 540 }
574 return NULL; 541 return NULL;
575 } 542 }
576 543
577 bool UserCrosSettingsProvider::GetTrusted(const std::string& path, 544 bool UserCrosSettingsProvider::GetTrusted(const std::string& path,
578 const base::Closure& callback) const { 545 const base::Closure& callback) const {
579 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( 546 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity(
580 path, callback); 547 path, callback);
(...skipping 24 matching lines...) Expand all
605 572
606 PrefService* prefs = g_browser_process->local_state(); 573 PrefService* prefs = g_browser_process->local_state();
607 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers); 574 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers);
608 StringValue email_value(email); 575 StringValue email_value(email);
609 if (cached_whitelist_update->Remove(email_value, NULL)) 576 if (cached_whitelist_update->Remove(email_value, NULL))
610 prefs->ScheduleSavePersistentPrefs(); 577 prefs->ScheduleSavePersistentPrefs();
611 } 578 }
612 579
613 // static 580 // static
614 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { 581 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) {
615 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); 582 base::StringValue email_value(email);
583 UpdateCache(kDeviceOwner, email_value, USE_VALUE_SUPPLIED);
616 } 584 }
617 585
618 } // namespace chromeos 586 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698