| 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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 }; | 189 }; |
| 190 | 190 |
| 191 void UpdateCacheBool(const std::string& name, | 191 void UpdateCacheBool(const std::string& name, |
| 192 bool value, | 192 bool value, |
| 193 UseValue use_value) { | 193 UseValue use_value) { |
| 194 PrefService* prefs = g_browser_process->local_state(); | 194 PrefService* prefs = g_browser_process->local_state(); |
| 195 if (use_value == USE_VALUE_DEFAULT) | 195 if (use_value == USE_VALUE_DEFAULT) |
| 196 prefs->ClearPref(name.c_str()); | 196 prefs->ClearPref(name.c_str()); |
| 197 else | 197 else |
| 198 prefs->SetBoolean(name.c_str(), value); | 198 prefs->SetBoolean(name.c_str(), value); |
| 199 prefs->ScheduleSavePersistentPrefs(); | |
| 200 } | 199 } |
| 201 | 200 |
| 202 void UpdateCacheString(const std::string& name, | 201 void UpdateCacheString(const std::string& name, |
| 203 const std::string& value, | 202 const std::string& value, |
| 204 UseValue use_value) { | 203 UseValue use_value) { |
| 205 PrefService* prefs = g_browser_process->local_state(); | 204 PrefService* prefs = g_browser_process->local_state(); |
| 206 if (use_value == USE_VALUE_DEFAULT) | 205 if (use_value == USE_VALUE_DEFAULT) |
| 207 prefs->ClearPref(name.c_str()); | 206 prefs->ClearPref(name.c_str()); |
| 208 else | 207 else |
| 209 prefs->SetString(name.c_str(), value); | 208 prefs->SetString(name.c_str(), value); |
| 210 prefs->ScheduleSavePersistentPrefs(); | |
| 211 } | 209 } |
| 212 | 210 |
| 213 bool GetUserWhitelist(ListValue* user_list) { | 211 bool GetUserWhitelist(ListValue* user_list) { |
| 214 PrefService* prefs = g_browser_process->local_state(); | 212 PrefService* prefs = g_browser_process->local_state(); |
| 215 DCHECK(!prefs->IsManagedPreference(kAccountsPrefUsers)); | 213 DCHECK(!prefs->IsManagedPreference(kAccountsPrefUsers)); |
| 216 | 214 |
| 217 std::vector<std::string> whitelist; | 215 std::vector<std::string> whitelist; |
| 218 if (!SignedSettings::EnumerateWhitelist(&whitelist)) { | 216 if (!SignedSettings::EnumerateWhitelist(&whitelist)) { |
| 219 LOG(WARNING) << "Failed to retrieve user whitelist."; | 217 LOG(WARNING) << "Failed to retrieve user whitelist."; |
| 220 return false; | 218 return false; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 233 DictionaryValue* user = new DictionaryValue; | 231 DictionaryValue* user = new DictionaryValue; |
| 234 user->SetString("email", email); | 232 user->SetString("email", email); |
| 235 user->SetString("name", ""); | 233 user->SetString("name", ""); |
| 236 user->SetBoolean("owner", is_owner && email == self.email()); | 234 user->SetBoolean("owner", is_owner && email == self.email()); |
| 237 user_list->Append(user); | 235 user_list->Append(user); |
| 238 } | 236 } |
| 239 | 237 |
| 240 cached_whitelist_update->Append(Value::CreateStringValue(email)); | 238 cached_whitelist_update->Append(Value::CreateStringValue(email)); |
| 241 } | 239 } |
| 242 | 240 |
| 243 prefs->ScheduleSavePersistentPrefs(); | |
| 244 return true; | 241 return true; |
| 245 } | 242 } |
| 246 | 243 |
| 247 class UserCrosSettingsTrust : public SignedSettingsHelper::Callback { | 244 class UserCrosSettingsTrust : public SignedSettingsHelper::Callback { |
| 248 public: | 245 public: |
| 249 static UserCrosSettingsTrust* GetInstance() { | 246 static UserCrosSettingsTrust* GetInstance() { |
| 250 return Singleton<UserCrosSettingsTrust>::get(); | 247 return Singleton<UserCrosSettingsTrust>::get(); |
| 251 } | 248 } |
| 252 | 249 |
| 253 // Working horse for UserCrosSettingsProvider::RequestTrusted* family. | 250 // Working horse for UserCrosSettingsProvider::RequestTrusted* family. |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 } | 415 } |
| 419 } | 416 } |
| 420 | 417 |
| 421 void StartFetchingSetting(const std::string& name) { | 418 void StartFetchingSetting(const std::string& name) { |
| 422 DCHECK(g_browser_process); | 419 DCHECK(g_browser_process); |
| 423 PrefService* prefs = g_browser_process->local_state(); | 420 PrefService* prefs = g_browser_process->local_state(); |
| 424 if (!prefs) | 421 if (!prefs) |
| 425 return; | 422 return; |
| 426 // Do not trust before fetching complete. | 423 // Do not trust before fetching complete. |
| 427 prefs->ClearPref((name + kTrustedSuffix).c_str()); | 424 prefs->ClearPref((name + kTrustedSuffix).c_str()); |
| 428 prefs->ScheduleSavePersistentPrefs(); | |
| 429 if (CrosLibrary::Get()->EnsureLoaded()) { | 425 if (CrosLibrary::Get()->EnsureLoaded()) { |
| 430 SignedSettingsHelper::Get()->StartRetrieveProperty(name, this); | 426 SignedSettingsHelper::Get()->StartRetrieveProperty(name, this); |
| 431 } | 427 } |
| 432 } | 428 } |
| 433 | 429 |
| 434 // Implementation of SignedSettingsHelper::Callback. | 430 // Implementation of SignedSettingsHelper::Callback. |
| 435 virtual void OnRetrievePropertyCompleted(SignedSettings::ReturnCode code, | 431 virtual void OnRetrievePropertyCompleted(SignedSettings::ReturnCode code, |
| 436 const std::string& name, | 432 const std::string& name, |
| 437 const std::string& value) { | 433 const std::string& value) { |
| 438 if (!IsControlledBooleanSetting(name) && !IsControlledStringSetting(name)) { | 434 if (!IsControlledBooleanSetting(name) && !IsControlledStringSetting(name)) { |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 ::StartsWithASCII(path, "cros.metrics.", true) || | 720 ::StartsWithASCII(path, "cros.metrics.", true) || |
| 725 path == kReleaseChannel; | 721 path == kReleaseChannel; |
| 726 } | 722 } |
| 727 | 723 |
| 728 void UserCrosSettingsProvider::WhitelistUser(const std::string& email) { | 724 void UserCrosSettingsProvider::WhitelistUser(const std::string& email) { |
| 729 SignedSettingsHelper::Get()->StartWhitelistOp( | 725 SignedSettingsHelper::Get()->StartWhitelistOp( |
| 730 email, true, UserCrosSettingsTrust::GetInstance()); | 726 email, true, UserCrosSettingsTrust::GetInstance()); |
| 731 PrefService* prefs = g_browser_process->local_state(); | 727 PrefService* prefs = g_browser_process->local_state(); |
| 732 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers); | 728 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers); |
| 733 cached_whitelist_update->Append(Value::CreateStringValue(email)); | 729 cached_whitelist_update->Append(Value::CreateStringValue(email)); |
| 734 prefs->ScheduleSavePersistentPrefs(); | |
| 735 } | 730 } |
| 736 | 731 |
| 737 void UserCrosSettingsProvider::UnwhitelistUser(const std::string& email) { | 732 void UserCrosSettingsProvider::UnwhitelistUser(const std::string& email) { |
| 738 SignedSettingsHelper::Get()->StartWhitelistOp( | 733 SignedSettingsHelper::Get()->StartWhitelistOp( |
| 739 email, false, UserCrosSettingsTrust::GetInstance()); | 734 email, false, UserCrosSettingsTrust::GetInstance()); |
| 740 | 735 |
| 741 PrefService* prefs = g_browser_process->local_state(); | 736 PrefService* prefs = g_browser_process->local_state(); |
| 742 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers); | 737 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers); |
| 743 StringValue email_value(email); | 738 StringValue email_value(email); |
| 744 if (cached_whitelist_update->Remove(email_value, NULL)) | 739 cached_whitelist_update->Remove(email_value, NULL); |
| 745 prefs->ScheduleSavePersistentPrefs(); | |
| 746 } | 740 } |
| 747 | 741 |
| 748 // static | 742 // static |
| 749 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { | 743 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { |
| 750 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); | 744 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); |
| 751 } | 745 } |
| 752 | 746 |
| 753 } // namespace chromeos | 747 } // namespace chromeos |
| OLD | NEW |