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