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

Side by Side Diff: chrome/browser/chromeos/cros_settings.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 the nits and rebased on ToT (which now has PART1 in). Created 9 years 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/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 28 matching lines...) Expand all
39 39
40 NotificationObserverList::Iterator it(*(observer_iterator->second)); 40 NotificationObserverList::Iterator it(*(observer_iterator->second));
41 content::NotificationObserver* observer; 41 content::NotificationObserver* observer;
42 while ((observer = it.GetNext()) != NULL) { 42 while ((observer = it.GetNext()) != NULL) {
43 observer->Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED, 43 observer->Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED,
44 content::Source<CrosSettings>(this), 44 content::Source<CrosSettings>(this),
45 content::Details<std::string>(&path_str)); 45 content::Details<std::string>(&path_str));
46 } 46 }
47 } 47 }
48 48
49 void CrosSettings::Set(const std::string& path, Value* in_value) { 49 void CrosSettings::Set(const std::string& path, const base::Value& in_value) {
50 DCHECK(CalledOnValidThread()); 50 DCHECK(CalledOnValidThread());
51 CrosSettingsProvider* provider; 51 CrosSettingsProvider* provider;
52 provider = GetProvider(path); 52 provider = GetProvider(path);
53 if (provider) { 53 if (provider) {
54 provider->Set(path, in_value); 54 provider->Set(path, in_value);
55 } 55 }
56 } 56 }
57 57
58 void CrosSettings::SetBoolean(const std::string& path, bool in_value) { 58 void CrosSettings::SetBoolean(const std::string& path, bool in_value) {
59 DCHECK(CalledOnValidThread()); 59 DCHECK(CalledOnValidThread());
60 Set(path, Value::CreateBooleanValue(in_value)); 60 base::FundamentalValue value(in_value);
61 Set(path, value);
61 } 62 }
62 63
63 void CrosSettings::SetInteger(const std::string& path, int in_value) { 64 void CrosSettings::SetInteger(const std::string& path, int in_value) {
64 DCHECK(CalledOnValidThread()); 65 DCHECK(CalledOnValidThread());
65 Set(path, Value::CreateIntegerValue(in_value)); 66 base::FundamentalValue value(in_value);
67 Set(path, value);
66 } 68 }
67 69
68 void CrosSettings::SetDouble(const std::string& path, double in_value) { 70 void CrosSettings::SetDouble(const std::string& path, double in_value) {
69 DCHECK(CalledOnValidThread()); 71 DCHECK(CalledOnValidThread());
70 Set(path, Value::CreateDoubleValue(in_value)); 72 base::FundamentalValue value(in_value);
73 Set(path, value);
71 } 74 }
72 75
73 void CrosSettings::SetString(const std::string& path, 76 void CrosSettings::SetString(const std::string& path,
74 const std::string& in_value) { 77 const std::string& in_value) {
75 DCHECK(CalledOnValidThread()); 78 DCHECK(CalledOnValidThread());
76 Set(path, Value::CreateStringValue(in_value)); 79 base::StringValue value(in_value);
80 Set(path, value);
81 }
82
83 void CrosSettings::AppendToList(const std::string& path,
84 const base::Value* value) {
85 DCHECK(CalledOnValidThread());
86 const base::Value* old_value = GetPref(path);
87 scoped_ptr<base::Value> new_value(
88 old_value ? old_value->DeepCopy() : new base::ListValue());
89 static_cast<base::ListValue*>(new_value.get())->Append(value->DeepCopy());
90 Set(path, *new_value);
91 }
92
93 void CrosSettings::RemoveFromList(const std::string& path,
94 const base::Value* value) {
95 DCHECK(CalledOnValidThread());
96 const base::Value* old_value = GetPref(path);
97 scoped_ptr<base::Value> new_value(
98 old_value ? old_value->DeepCopy() : new base::ListValue());
99 static_cast<base::ListValue*>(new_value.get())->Remove(*value, NULL);
100 Set(path, *new_value);
101 }
102
103 bool CrosSettings::FindEmailInList(const std::string& path,
104 const std::string& email) const {
105 DCHECK(CalledOnValidThread());
106 base::StringValue email_value(email);
107 const base::ListValue* value =
108 static_cast<const base::ListValue*>(GetPref(path));
109 if (value) {
110 if (value->Find(email_value) != value->end())
111 return true;
112 std::string::size_type at_pos = email.find('@');
113 if (at_pos != std::string::npos) {
114 base::StringValue wildcarded_value(
115 std::string("*").append(email.substr(at_pos)));
116 return value->Find(wildcarded_value) != value->end();
117 }
118 }
119 return false;
77 } 120 }
78 121
79 bool CrosSettings::AddSettingsProvider(CrosSettingsProvider* provider) { 122 bool CrosSettings::AddSettingsProvider(CrosSettingsProvider* provider) {
80 DCHECK(CalledOnValidThread()); 123 DCHECK(CalledOnValidThread());
81 providers_.push_back(provider); 124 providers_.push_back(provider);
82 return true; 125 return true;
83 } 126 }
84 127
85 bool CrosSettings::RemoveSettingsProvider(CrosSettingsProvider* provider) { 128 bool CrosSettings::RemoveSettingsProvider(CrosSettingsProvider* provider) {
86 DCHECK(CalledOnValidThread()); 129 DCHECK(CalledOnValidThread());
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 AddSettingsProvider(new SystemSettingsProvider()); 263 AddSettingsProvider(new SystemSettingsProvider());
221 AddSettingsProvider(new UserCrosSettingsProvider()); 264 AddSettingsProvider(new UserCrosSettingsProvider());
222 } 265 }
223 266
224 CrosSettings::~CrosSettings() { 267 CrosSettings::~CrosSettings() {
225 STLDeleteElements(&providers_); 268 STLDeleteElements(&providers_);
226 STLDeleteValues(&settings_observers_); 269 STLDeleteValues(&settings_observers_);
227 } 270 }
228 271
229 } // namespace chromeos 272 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros_settings.h ('k') | chrome/browser/chromeos/cros_settings_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698