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/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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 ProcessUserMetric(value, metric); | 188 ProcessUserMetric(value, metric); |
189 } | 189 } |
190 | 190 |
191 void CoreOptionsHandler::ClearPref(const std::string& pref_name, | 191 void CoreOptionsHandler::ClearPref(const std::string& pref_name, |
192 const std::string& metric) { | 192 const std::string& metric) { |
193 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); | 193 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); |
194 pref_service->ClearPref(pref_name.c_str()); | 194 pref_service->ClearPref(pref_name.c_str()); |
195 pref_service->ScheduleSavePersistentPrefs(); | 195 pref_service->ScheduleSavePersistentPrefs(); |
196 | 196 |
197 if (!metric.empty()) | 197 if (!metric.empty()) |
198 UserMetricsRecordAction(UserMetricsAction(metric.c_str())); | 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->IsType(Value::TYPE_BOOLEAN)) { |
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 UserMetricsRecordAction(UserMetricsAction(metric_string.c_str())); | 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); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 std::string metric; | 353 std::string metric; |
354 if (args->GetSize() > 1) | 354 if (args->GetSize() > 1) |
355 args->GetString(1, &metric); | 355 args->GetString(1, &metric); |
356 | 356 |
357 ClearPref(pref_name, metric); | 357 ClearPref(pref_name, metric); |
358 } | 358 } |
359 | 359 |
360 void CoreOptionsHandler::HandleUserMetricsAction(const ListValue* args) { | 360 void CoreOptionsHandler::HandleUserMetricsAction(const ListValue* args) { |
361 std::string metric = UTF16ToUTF8(ExtractStringValue(args)); | 361 std::string metric = UTF16ToUTF8(ExtractStringValue(args)); |
362 if (!metric.empty()) | 362 if (!metric.empty()) |
363 UserMetricsRecordAction(UserMetricsAction(metric.c_str())); | 363 UserMetrics::RecordComputedAction(metric); |
364 } | 364 } |
365 | 365 |
366 void CoreOptionsHandler::UpdateClearPluginLSOData() { | 366 void CoreOptionsHandler::UpdateClearPluginLSOData() { |
367 scoped_ptr<Value> enabled( | 367 scoped_ptr<Value> enabled( |
368 Value::CreateBooleanValue(clear_plugin_lso_data_enabled_.GetValue())); | 368 Value::CreateBooleanValue(clear_plugin_lso_data_enabled_.GetValue())); |
369 web_ui_->CallJavascriptFunction( | 369 web_ui_->CallJavascriptFunction( |
370 "OptionsPage.setClearPluginLSODataEnabled", *enabled); | 370 "OptionsPage.setClearPluginLSODataEnabled", *enabled); |
371 } | 371 } |
372 | 372 |
373 void CoreOptionsHandler::NotifyPrefChanged(const std::string* pref_name) { | 373 void CoreOptionsHandler::NotifyPrefChanged(const std::string* pref_name) { |
(...skipping 17 matching lines...) Expand all Loading... |
391 const std::wstring& callback_function = iter->second; | 391 const std::wstring& callback_function = iter->second; |
392 ListValue result_value; | 392 ListValue result_value; |
393 result_value.Append(Value::CreateStringValue(pref_name->c_str())); | 393 result_value.Append(Value::CreateStringValue(pref_name->c_str())); |
394 | 394 |
395 result_value.Append(CreateValueForPref(pref)); | 395 result_value.Append(CreateValueForPref(pref)); |
396 | 396 |
397 web_ui_->CallJavascriptFunction(WideToASCII(callback_function), | 397 web_ui_->CallJavascriptFunction(WideToASCII(callback_function), |
398 result_value); | 398 result_value); |
399 } | 399 } |
400 } | 400 } |
OLD | NEW |