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/cros_settings.h" | 5 #include "chrome/browser/chromeos/cros_settings.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 | 40 |
| 41 NotificationObserverList::Iterator it(*(observer_iterator->second)); | 41 NotificationObserverList::Iterator it(*(observer_iterator->second)); |
| 42 content::NotificationObserver* observer; | 42 content::NotificationObserver* observer; |
| 43 while ((observer = it.GetNext()) != NULL) { | 43 while ((observer = it.GetNext()) != NULL) { |
| 44 observer->Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED, | 44 observer->Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED, |
| 45 content::Source<CrosSettings>(this), | 45 content::Source<CrosSettings>(this), |
| 46 content::Details<std::string>(&path_str)); | 46 content::Details<std::string>(&path_str)); |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 void CrosSettings::Set(const std::string& path, Value* in_value) { | 50 void CrosSettings::Set(const std::string& path, const base::Value& in_value) { |
| 51 DCHECK(CalledOnValidThread()); | 51 DCHECK(CalledOnValidThread()); |
| 52 CrosSettingsProvider* provider; | 52 CrosSettingsProvider* provider; |
| 53 provider = GetProvider(path); | 53 provider = GetProvider(path); |
| 54 if (provider) { | 54 if (provider) { |
| 55 provider->Set(path, in_value); | 55 provider->Set(path, in_value); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 void CrosSettings::SetBoolean(const std::string& path, bool in_value) { | 59 void CrosSettings::SetBoolean(const std::string& path, bool in_value) { |
| 60 DCHECK(CalledOnValidThread()); | 60 DCHECK(CalledOnValidThread()); |
| 61 Set(path, Value::CreateBooleanValue(in_value)); | 61 base::FundamentalValue value(in_value); |
| 62 Set(path, value); | |
| 62 } | 63 } |
| 63 | 64 |
| 64 void CrosSettings::SetInteger(const std::string& path, int in_value) { | 65 void CrosSettings::SetInteger(const std::string& path, int in_value) { |
| 65 DCHECK(CalledOnValidThread()); | 66 DCHECK(CalledOnValidThread()); |
| 66 Set(path, Value::CreateIntegerValue(in_value)); | 67 base::FundamentalValue value(in_value); |
| 68 Set(path, value); | |
| 67 } | 69 } |
| 68 | 70 |
| 69 void CrosSettings::SetDouble(const std::string& path, double in_value) { | 71 void CrosSettings::SetDouble(const std::string& path, double in_value) { |
| 70 DCHECK(CalledOnValidThread()); | 72 DCHECK(CalledOnValidThread()); |
| 71 Set(path, Value::CreateDoubleValue(in_value)); | 73 base::FundamentalValue value(in_value); |
| 74 Set(path, value); | |
| 72 } | 75 } |
| 73 | 76 |
| 74 void CrosSettings::SetString(const std::string& path, | 77 void CrosSettings::SetString(const std::string& path, |
| 75 const std::string& in_value) { | 78 const std::string& in_value) { |
| 76 DCHECK(CalledOnValidThread()); | 79 DCHECK(CalledOnValidThread()); |
| 77 Set(path, Value::CreateStringValue(in_value)); | 80 base::StringValue value(in_value); |
| 81 Set(path, value); | |
| 82 } | |
| 83 | |
| 84 void CrosSettings::AppendToList(const std::string& path, | |
| 85 const base::Value* value) { | |
| 86 DCHECK(CalledOnValidThread()); | |
| 87 const base::Value* old_value = GetPref(path); | |
| 88 scoped_ptr<base::Value> new_value( | |
| 89 old_value ? old_value->DeepCopy() : new base::ListValue()); | |
| 90 static_cast<base::ListValue*>(new_value.get())->Append(value->DeepCopy()); | |
| 91 Set(path, *new_value); | |
| 92 } | |
| 93 | |
| 94 void CrosSettings::RemoveFromList(const std::string& path, | |
| 95 const base::Value* value) { | |
| 96 DCHECK(CalledOnValidThread()); | |
| 97 const base::Value* old_value = GetPref(path); | |
| 98 scoped_ptr<base::Value> new_value( | |
| 99 old_value ? old_value->DeepCopy() : new base::ListValue()); | |
| 100 static_cast<base::ListValue*>(new_value.get())->Remove(*value, NULL); | |
| 101 Set(path, *new_value); | |
| 102 } | |
| 103 | |
| 104 bool CrosSettings::FindEmailInList(const std::string& path, | |
| 105 const std::string& email) const { | |
| 106 DCHECK(CalledOnValidThread()); | |
| 107 base::StringValue email_value(email); | |
| 108 const base::ListValue* value = | |
| 109 static_cast<const base::ListValue*>(GetPref(path)); | |
| 110 if (value) { | |
| 111 if (value->Find(email_value) != value->end()) | |
| 112 return true; | |
| 113 if (email.find('@') != std::string::npos) { | |
| 114 base::StringValue wildcarded_value( | |
| 115 std::string("*").append(email.substr(email.find('@')))); | |
|
Mattias Nissler (ping if slow)
2011/10/28 14:44:07
you call email.find twice. Create local variable?
pastarmovj
2011/11/18 13:18:42
Done.
| |
| 116 return value->Find(wildcarded_value) != value->end(); | |
| 117 } | |
| 118 } | |
| 119 return false; | |
| 78 } | 120 } |
| 79 | 121 |
| 80 bool CrosSettings::AddSettingsProvider(CrosSettingsProvider* provider) { | 122 bool CrosSettings::AddSettingsProvider(CrosSettingsProvider* provider) { |
| 81 DCHECK(CalledOnValidThread()); | 123 DCHECK(CalledOnValidThread()); |
| 82 providers_.push_back(provider); | 124 providers_.push_back(provider); |
| 83 return true; | 125 return true; |
| 84 } | 126 } |
| 85 | 127 |
| 86 bool CrosSettings::RemoveSettingsProvider(CrosSettingsProvider* provider) { | 128 bool CrosSettings::RemoveSettingsProvider(CrosSettingsProvider* provider) { |
| 87 DCHECK(CalledOnValidThread()); | 129 DCHECK(CalledOnValidThread()); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 AddSettingsProvider(new SystemSettingsProvider()); | 265 AddSettingsProvider(new SystemSettingsProvider()); |
| 224 AddSettingsProvider(new UserCrosSettingsProvider()); | 266 AddSettingsProvider(new UserCrosSettingsProvider()); |
| 225 } | 267 } |
| 226 | 268 |
| 227 CrosSettings::~CrosSettings() { | 269 CrosSettings::~CrosSettings() { |
| 228 STLDeleteElements(&providers_); | 270 STLDeleteElements(&providers_); |
| 229 STLDeleteValues(&settings_observers_); | 271 STLDeleteValues(&settings_observers_); |
| 230 } | 272 } |
| 231 | 273 |
| 232 } // namespace chromeos | 274 } // namespace chromeos |
| OLD | NEW |