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

Side by Side Diff: base/prefs/public/pref_member.cc

Issue 12286020: Replace FilePath with base::FilePath. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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
« no previous file with comments | « base/prefs/public/pref_member.h ('k') | base/process_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/prefs/public/pref_member.h" 5 #include "base/prefs/public/pref_member.h"
6 6
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/prefs/public/pref_service_base.h" 10 #include "base/prefs/public/pref_service_base.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 is_managed_(false) { 97 is_managed_(false) {
98 } 98 }
99 PrefMemberBase::Internal::~Internal() { } 99 PrefMemberBase::Internal::~Internal() { }
100 100
101 bool PrefMemberBase::Internal::IsOnCorrectThread() const { 101 bool PrefMemberBase::Internal::IsOnCorrectThread() const {
102 // In unit tests, there may not be a message loop. 102 // In unit tests, there may not be a message loop.
103 return thread_loop_ == NULL || thread_loop_->BelongsToCurrentThread(); 103 return thread_loop_ == NULL || thread_loop_->BelongsToCurrentThread();
104 } 104 }
105 105
106 void PrefMemberBase::Internal::UpdateValue( 106 void PrefMemberBase::Internal::UpdateValue(
107 Value* v, 107 base::Value* v,
108 bool is_managed, 108 bool is_managed,
109 bool is_user_modifiable, 109 bool is_user_modifiable,
110 const base::Closure& callback) const { 110 const base::Closure& callback) const {
111 scoped_ptr<Value> value(v); 111 scoped_ptr<base::Value> value(v);
112 base::ScopedClosureRunner closure_runner(callback); 112 base::ScopedClosureRunner closure_runner(callback);
113 if (IsOnCorrectThread()) { 113 if (IsOnCorrectThread()) {
114 bool rv = UpdateValueInternal(*value); 114 bool rv = UpdateValueInternal(*value);
115 DCHECK(rv); 115 DCHECK(rv);
116 is_managed_ = is_managed; 116 is_managed_ = is_managed;
117 is_user_modifiable_ = is_user_modifiable; 117 is_user_modifiable_ = is_user_modifiable;
118 } else { 118 } else {
119 bool may_run = thread_loop_->PostTask( 119 bool may_run = thread_loop_->PostTask(
120 FROM_HERE, 120 FROM_HERE,
121 base::Bind(&PrefMemberBase::Internal::UpdateValue, this, 121 base::Bind(&PrefMemberBase::Internal::UpdateValue, this,
122 value.release(), is_managed, is_user_modifiable, 122 value.release(), is_managed, is_user_modifiable,
123 closure_runner.Release())); 123 closure_runner.Release()));
124 DCHECK(may_run); 124 DCHECK(may_run);
125 } 125 }
126 } 126 }
127 127
128 void PrefMemberBase::Internal::MoveToThread( 128 void PrefMemberBase::Internal::MoveToThread(
129 const scoped_refptr<MessageLoopProxy>& message_loop) { 129 const scoped_refptr<MessageLoopProxy>& message_loop) {
130 CheckOnCorrectThread(); 130 CheckOnCorrectThread();
131 thread_loop_ = message_loop; 131 thread_loop_ = message_loop;
132 } 132 }
133 133
134 bool PrefMemberVectorStringUpdate(const Value& value, 134 bool PrefMemberVectorStringUpdate(const base::Value& value,
135 std::vector<std::string>* string_vector) { 135 std::vector<std::string>* string_vector) {
136 if (!value.IsType(Value::TYPE_LIST)) 136 if (!value.IsType(base::Value::TYPE_LIST))
137 return false; 137 return false;
138 const ListValue* list = static_cast<const ListValue*>(&value); 138 const ListValue* list = static_cast<const ListValue*>(&value);
139 139
140 std::vector<std::string> local_vector; 140 std::vector<std::string> local_vector;
141 for (ListValue::const_iterator it = list->begin(); it != list->end(); ++it) { 141 for (ListValue::const_iterator it = list->begin(); it != list->end(); ++it) {
142 std::string string_value; 142 std::string string_value;
143 if (!(*it)->GetAsString(&string_value)) 143 if (!(*it)->GetAsString(&string_value))
144 return false; 144 return false;
145 145
146 local_vector.push_back(string_value); 146 local_vector.push_back(string_value);
147 } 147 }
148 148
149 string_vector->swap(local_vector); 149 string_vector->swap(local_vector);
150 return true; 150 return true;
151 } 151 }
152 152
153 } // namespace subtle 153 } // namespace subtle
154 154
155 template <> 155 template <>
156 void PrefMember<bool>::UpdatePref(const bool& value) { 156 void PrefMember<bool>::UpdatePref(const bool& value) {
157 prefs()->SetBoolean(pref_name().c_str(), value); 157 prefs()->SetBoolean(pref_name().c_str(), value);
158 } 158 }
159 159
160 template <> 160 template <>
161 bool PrefMember<bool>::Internal::UpdateValueInternal(const Value& value) const { 161 bool PrefMember<bool>::Internal::UpdateValueInternal(
162 const base::Value& value) const {
162 return value.GetAsBoolean(&value_); 163 return value.GetAsBoolean(&value_);
163 } 164 }
164 165
165 template <> 166 template <>
166 void PrefMember<int>::UpdatePref(const int& value) { 167 void PrefMember<int>::UpdatePref(const int& value) {
167 prefs()->SetInteger(pref_name().c_str(), value); 168 prefs()->SetInteger(pref_name().c_str(), value);
168 } 169 }
169 170
170 template <> 171 template <>
171 bool PrefMember<int>::Internal::UpdateValueInternal(const Value& value) const { 172 bool PrefMember<int>::Internal::UpdateValueInternal(
173 const base::Value& value) const {
172 return value.GetAsInteger(&value_); 174 return value.GetAsInteger(&value_);
173 } 175 }
174 176
175 template <> 177 template <>
176 void PrefMember<double>::UpdatePref(const double& value) { 178 void PrefMember<double>::UpdatePref(const double& value) {
177 prefs()->SetDouble(pref_name().c_str(), value); 179 prefs()->SetDouble(pref_name().c_str(), value);
178 } 180 }
179 181
180 template <> 182 template <>
181 bool PrefMember<double>::Internal::UpdateValueInternal(const Value& value) 183 bool PrefMember<double>::Internal::UpdateValueInternal(const base::Value& value)
182 const { 184 const {
183 return value.GetAsDouble(&value_); 185 return value.GetAsDouble(&value_);
184 } 186 }
185 187
186 template <> 188 template <>
187 void PrefMember<std::string>::UpdatePref(const std::string& value) { 189 void PrefMember<std::string>::UpdatePref(const std::string& value) {
188 prefs()->SetString(pref_name().c_str(), value); 190 prefs()->SetString(pref_name().c_str(), value);
189 } 191 }
190 192
191 template <> 193 template <>
192 bool PrefMember<std::string>::Internal::UpdateValueInternal(const Value& value) 194 bool PrefMember<std::string>::Internal::UpdateValueInternal(
195 const base::Value& value)
193 const { 196 const {
194 return value.GetAsString(&value_); 197 return value.GetAsString(&value_);
195 } 198 }
196 199
197 template <> 200 template <>
198 void PrefMember<FilePath>::UpdatePref(const FilePath& value) { 201 void PrefMember<base::FilePath>::UpdatePref(const base::FilePath& value) {
199 prefs()->SetFilePath(pref_name().c_str(), value); 202 prefs()->SetFilePath(pref_name().c_str(), value);
200 } 203 }
201 204
202 template <> 205 template <>
203 bool PrefMember<FilePath>::Internal::UpdateValueInternal(const Value& value) 206 bool PrefMember<base::FilePath>::Internal::UpdateValueInternal(
207 const base::Value& value)
204 const { 208 const {
205 return base::GetValueAsFilePath(value, &value_); 209 return base::GetValueAsFilePath(value, &value_);
206 } 210 }
207 211
208 template <> 212 template <>
209 void PrefMember<std::vector<std::string> >::UpdatePref( 213 void PrefMember<std::vector<std::string> >::UpdatePref(
210 const std::vector<std::string>& value) { 214 const std::vector<std::string>& value) {
211 ListValue list_value; 215 ListValue list_value;
212 list_value.AppendStrings(value); 216 list_value.AppendStrings(value);
213 prefs()->Set(pref_name().c_str(), list_value); 217 prefs()->Set(pref_name().c_str(), list_value);
214 } 218 }
215 219
216 template <> 220 template <>
217 bool PrefMember<std::vector<std::string> >::Internal::UpdateValueInternal( 221 bool PrefMember<std::vector<std::string> >::Internal::UpdateValueInternal(
218 const Value& value) const { 222 const base::Value& value) const {
219 return subtle::PrefMemberVectorStringUpdate(value, &value_); 223 return subtle::PrefMemberVectorStringUpdate(value, &value_);
220 } 224 }
OLDNEW
« no previous file with comments | « base/prefs/public/pref_member.h ('k') | base/process_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698