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 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); | |
Denis Lagno
2011/10/13 13:43:10
nit: why not pass const reference to temporary obj
Mattias Nissler (ping if slow)
2011/10/13 14:49:52
clang won't like it.
pastarmovj
2011/10/26 15:44:59
Exactly, sad but true fact :(
| |
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); | |
Denis Lagno
2011/10/13 13:43:10
ditto
| |
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); | |
Denis Lagno
2011/10/13 13:43:10
ditto
| |
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); | |
Denis Lagno
2011/10/13 13:43:10
ditto
| |
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); | |
78 } | 102 } |
79 | 103 |
80 bool CrosSettings::AddSettingsProvider(CrosSettingsProvider* provider) { | 104 bool CrosSettings::AddSettingsProvider(CrosSettingsProvider* provider) { |
81 DCHECK(CalledOnValidThread()); | 105 DCHECK(CalledOnValidThread()); |
82 providers_.push_back(provider); | 106 providers_.push_back(provider); |
83 return true; | 107 return true; |
84 } | 108 } |
85 | 109 |
86 bool CrosSettings::RemoveSettingsProvider(CrosSettingsProvider* provider) { | 110 bool CrosSettings::RemoveSettingsProvider(CrosSettingsProvider* provider) { |
87 DCHECK(CalledOnValidThread()); | 111 DCHECK(CalledOnValidThread()); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 AddSettingsProvider(new SystemSettingsProvider()); | 249 AddSettingsProvider(new SystemSettingsProvider()); |
226 AddSettingsProvider(new UserCrosSettingsProvider()); | 250 AddSettingsProvider(new UserCrosSettingsProvider()); |
227 } | 251 } |
228 | 252 |
229 CrosSettings::~CrosSettings() { | 253 CrosSettings::~CrosSettings() { |
230 STLDeleteElements(&providers_); | 254 STLDeleteElements(&providers_); |
231 STLDeleteValues(&settings_observers_); | 255 STLDeleteValues(&settings_observers_); |
232 } | 256 } |
233 | 257 |
234 } // namespace chromeos | 258 } // namespace chromeos |
OLD | NEW |