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

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: Rebased on ToT and made clang happy. Created 9 years, 2 months 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 29 matching lines...) Expand all
40 40
41 NotificationObserverList::Iterator it(*(observer_iterator->second)); 41 NotificationObserverList::Iterator it(*(observer_iterator->second));
42 NotificationObserver* observer; 42 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 Source<CrosSettings>(this), 45 Source<CrosSettings>(this),
46 Details<std::string>(&path_str)); 46 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(new base::ListValue());
Mattias Nissler (ping if slow) 2011/10/07 11:02:57 Allocating an object and throwing it away immediat
pastarmovj 2011/10/13 11:25:06 Done.
89 if (old_value)
90 new_value.reset(old_value->DeepCopy());
91 static_cast<base::ListValue*>(new_value.get())->Append(value.DeepCopy());
92 Set(path, *new_value);
93 }
94
95 void CrosSettings::RemoveFromList(const std::string& path,
96 const base::Value& value) {
97 DCHECK(CalledOnValidThread());
98 const base::Value* old_value = GetPref(path);
99 scoped_ptr<base::Value> new_value(new base::ListValue());
Mattias Nissler (ping if slow) 2011/10/07 11:02:57 ditto.
pastarmovj 2011/10/13 11:25:06 Done.
100 if (old_value)
101 new_value.reset(old_value->DeepCopy());
102 static_cast<base::ListValue*>(new_value.get())->Remove(value, NULL);
103 Set(path, *new_value);
78 } 104 }
79 105
80 bool CrosSettings::AddSettingsProvider(CrosSettingsProvider* provider) { 106 bool CrosSettings::AddSettingsProvider(CrosSettingsProvider* provider) {
81 DCHECK(CalledOnValidThread()); 107 DCHECK(CalledOnValidThread());
82 providers_.push_back(provider); 108 providers_.push_back(provider);
83 return true; 109 return true;
84 } 110 }
85 111
86 bool CrosSettings::RemoveSettingsProvider(CrosSettingsProvider* provider) { 112 bool CrosSettings::RemoveSettingsProvider(CrosSettingsProvider* provider) {
87 DCHECK(CalledOnValidThread()); 113 DCHECK(CalledOnValidThread());
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 AddSettingsProvider(new SystemSettingsProvider()); 251 AddSettingsProvider(new SystemSettingsProvider());
226 AddSettingsProvider(new UserCrosSettingsProvider()); 252 AddSettingsProvider(new UserCrosSettingsProvider());
227 } 253 }
228 254
229 CrosSettings::~CrosSettings() { 255 CrosSettings::~CrosSettings() {
230 STLDeleteElements(&providers_); 256 STLDeleteElements(&providers_);
231 STLDeleteValues(&settings_observers_); 257 STLDeleteValues(&settings_observers_);
232 } 258 }
233 259
234 } // namespace chromeos 260 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698