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

Side by Side Diff: chrome/browser/ui/webui/options/core_options_handler.cc

Issue 7661009: base: Add Is* functions to Value class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tony review Created 9 years, 4 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/ui/webui/options/core_options_handler.h" 5 #include "chrome/browser/ui/webui/options/core_options_handler.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 if (!metric.empty()) 197 if (!metric.empty())
198 UserMetrics::RecordComputedAction(metric); 198 UserMetrics::RecordComputedAction(metric);
199 } 199 }
200 200
201 void CoreOptionsHandler::ProcessUserMetric(const Value* value, 201 void CoreOptionsHandler::ProcessUserMetric(const Value* value,
202 const std::string& metric) { 202 const std::string& metric) {
203 if (metric.empty()) 203 if (metric.empty())
204 return; 204 return;
205 205
206 std::string metric_string = metric; 206 std::string metric_string = metric;
207 if (value->IsType(Value::TYPE_BOOLEAN)) { 207 if (value->IsBoolean()) {
208 bool bool_value; 208 bool bool_value;
209 CHECK(value->GetAsBoolean(&bool_value)); 209 CHECK(value->GetAsBoolean(&bool_value));
210 metric_string += bool_value ? "_Enable" : "_Disable"; 210 metric_string += bool_value ? "_Enable" : "_Disable";
211 } 211 }
212 212
213 UserMetrics::RecordComputedAction(metric_string); 213 UserMetrics::RecordComputedAction(metric_string);
214 } 214 }
215 215
216 void CoreOptionsHandler::StopObservingPref(const std::string& path) { 216 void CoreOptionsHandler::StopObservingPref(const std::string& path) {
217 registrar_.Remove(path.c_str(), this); 217 registrar_.Remove(path.c_str(), this);
218 } 218 }
219 219
220 void CoreOptionsHandler::HandleFetchPrefs(const ListValue* args) { 220 void CoreOptionsHandler::HandleFetchPrefs(const ListValue* args) {
221 // First param is name of callback function, so, there needs to be at least 221 // First param is name of callback function, so, there needs to be at least
222 // one more element for the actual preference identifier. 222 // one more element for the actual preference identifier.
223 DCHECK_GE(static_cast<int>(args->GetSize()), 2); 223 DCHECK_GE(static_cast<int>(args->GetSize()), 2);
224 224
225 // Get callback JS function name. 225 // Get callback JS function name.
226 Value* callback; 226 Value* callback;
227 if (!args->Get(0, &callback) || !callback->IsType(Value::TYPE_STRING)) 227 if (!args->Get(0, &callback) || !callback->IsString())
228 return; 228 return;
229 229
230 string16 callback_function; 230 string16 callback_function;
231 if (!callback->GetAsString(&callback_function)) 231 if (!callback->GetAsString(&callback_function))
232 return; 232 return;
233 233
234 // Get the list of name for prefs to build the response dictionary. 234 // Get the list of name for prefs to build the response dictionary.
235 DictionaryValue result_value; 235 DictionaryValue result_value;
236 Value* list_member; 236 Value* list_member;
237 237
238 for (size_t i = 1; i < args->GetSize(); i++) { 238 for (size_t i = 1; i < args->GetSize(); i++) {
239 if (!args->Get(i, &list_member)) 239 if (!args->Get(i, &list_member))
240 break; 240 break;
241 241
242 if (!list_member->IsType(Value::TYPE_STRING)) 242 if (!list_member->IsString())
243 continue; 243 continue;
244 244
245 std::string pref_name; 245 std::string pref_name;
246 if (!list_member->GetAsString(&pref_name)) 246 if (!list_member->GetAsString(&pref_name))
247 continue; 247 continue;
248 248
249 result_value.Set(pref_name.c_str(), FetchPref(pref_name)); 249 result_value.Set(pref_name.c_str(), FetchPref(pref_name));
250 } 250 }
251 web_ui_->CallJavascriptFunction(UTF16ToASCII(callback_function), 251 web_ui_->CallJavascriptFunction(UTF16ToASCII(callback_function),
252 result_value); 252 result_value);
(...skipping 10 matching lines...) Expand all
263 return; 263 return;
264 264
265 // Get all other parameters - pref identifiers. 265 // Get all other parameters - pref identifiers.
266 for (size_t i = 1; i < args->GetSize(); i++) { 266 for (size_t i = 1; i < args->GetSize(); i++) {
267 Value* list_member; 267 Value* list_member;
268 if (!args->Get(i, &list_member)) 268 if (!args->Get(i, &list_member))
269 break; 269 break;
270 270
271 // Just ignore bad pref identifiers for now. 271 // Just ignore bad pref identifiers for now.
272 std::string pref_name; 272 std::string pref_name;
273 if (!list_member->IsType(Value::TYPE_STRING) || 273 if (!list_member->IsString() || !list_member->GetAsString(&pref_name))
274 !list_member->GetAsString(&pref_name))
275 continue; 274 continue;
276 275
277 if (pref_callback_map_.find(pref_name) == pref_callback_map_.end()) 276 if (pref_callback_map_.find(pref_name) == pref_callback_map_.end())
278 ObservePref(pref_name); 277 ObservePref(pref_name);
279 278
280 pref_callback_map_.insert( 279 pref_callback_map_.insert(
281 PreferenceCallbackMap::value_type(pref_name, 280 PreferenceCallbackMap::value_type(pref_name,
282 UTF16ToWideHack(callback_func_name))); 281 UTF16ToWideHack(callback_func_name)));
283 } 282 }
284 } 283 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 const std::wstring& callback_function = iter->second; 390 const std::wstring& callback_function = iter->second;
392 ListValue result_value; 391 ListValue result_value;
393 result_value.Append(Value::CreateStringValue(pref_name->c_str())); 392 result_value.Append(Value::CreateStringValue(pref_name->c_str()));
394 393
395 result_value.Append(CreateValueForPref(pref)); 394 result_value.Append(CreateValueForPref(pref));
396 395
397 web_ui_->CallJavascriptFunction(WideToASCII(callback_function), 396 web_ui_->CallJavascriptFunction(WideToASCII(callback_function),
398 result_value); 397 result_value);
399 } 398 }
400 } 399 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/chromeos/system_settings_provider.cc ('k') | chrome/browser/ui/webui/print_preview_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698