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