| 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 ProcessUserMetric(value, metric); | 174 ProcessUserMetric(value, metric); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void CoreOptionsHandler::ClearPref(const std::string& pref_name, | 177 void CoreOptionsHandler::ClearPref(const std::string& pref_name, |
| 178 const std::string& metric) { | 178 const std::string& metric) { |
| 179 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); | 179 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); |
| 180 pref_service->ClearPref(pref_name.c_str()); | 180 pref_service->ClearPref(pref_name.c_str()); |
| 181 pref_service->ScheduleSavePersistentPrefs(); | 181 pref_service->ScheduleSavePersistentPrefs(); |
| 182 | 182 |
| 183 if (!metric.empty()) | 183 if (!metric.empty()) |
| 184 UserMetricsRecordAction(UserMetricsAction(metric.c_str())); | 184 UserMetrics::RecordComputedAction(metric); |
| 185 } | 185 } |
| 186 | 186 |
| 187 void CoreOptionsHandler::ProcessUserMetric(const Value* value, | 187 void CoreOptionsHandler::ProcessUserMetric(const Value* value, |
| 188 const std::string& metric) { | 188 const std::string& metric) { |
| 189 if (metric.empty()) | 189 if (metric.empty()) |
| 190 return; | 190 return; |
| 191 | 191 |
| 192 std::string metric_string = metric; | 192 std::string metric_string = metric; |
| 193 if (value->IsType(Value::TYPE_BOOLEAN)) { | 193 if (value->IsType(Value::TYPE_BOOLEAN)) { |
| 194 bool bool_value; | 194 bool bool_value; |
| 195 CHECK(value->GetAsBoolean(&bool_value)); | 195 CHECK(value->GetAsBoolean(&bool_value)); |
| 196 metric_string += bool_value ? "_Enable" : "_Disable"; | 196 metric_string += bool_value ? "_Enable" : "_Disable"; |
| 197 } | 197 } |
| 198 | 198 |
| 199 UserMetricsRecordAction(UserMetricsAction(metric_string.c_str())); | 199 UserMetrics::RecordComputedAction(metric_string); |
| 200 } | 200 } |
| 201 | 201 |
| 202 void CoreOptionsHandler::StopObservingPref(const std::string& path) { | 202 void CoreOptionsHandler::StopObservingPref(const std::string& path) { |
| 203 registrar_.Remove(path.c_str(), this); | 203 registrar_.Remove(path.c_str(), this); |
| 204 } | 204 } |
| 205 | 205 |
| 206 void CoreOptionsHandler::HandleFetchPrefs(const ListValue* args) { | 206 void CoreOptionsHandler::HandleFetchPrefs(const ListValue* args) { |
| 207 // First param is name of callback function, so, there needs to be at least | 207 // First param is name of callback function, so, there needs to be at least |
| 208 // one more element for the actual preference identifier. | 208 // one more element for the actual preference identifier. |
| 209 DCHECK_GE(static_cast<int>(args->GetSize()), 2); | 209 DCHECK_GE(static_cast<int>(args->GetSize()), 2); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 std::string metric; | 339 std::string metric; |
| 340 if (args->GetSize() > 1) | 340 if (args->GetSize() > 1) |
| 341 args->GetString(1, &metric); | 341 args->GetString(1, &metric); |
| 342 | 342 |
| 343 ClearPref(pref_name, metric); | 343 ClearPref(pref_name, metric); |
| 344 } | 344 } |
| 345 | 345 |
| 346 void CoreOptionsHandler::HandleUserMetricsAction(const ListValue* args) { | 346 void CoreOptionsHandler::HandleUserMetricsAction(const ListValue* args) { |
| 347 std::string metric = UTF16ToUTF8(ExtractStringValue(args)); | 347 std::string metric = UTF16ToUTF8(ExtractStringValue(args)); |
| 348 if (!metric.empty()) | 348 if (!metric.empty()) |
| 349 UserMetricsRecordAction(UserMetricsAction(metric.c_str())); | 349 UserMetrics::RecordComputedAction(metric); |
| 350 } | 350 } |
| 351 | 351 |
| 352 void CoreOptionsHandler::UpdateClearPluginLSOData() { | 352 void CoreOptionsHandler::UpdateClearPluginLSOData() { |
| 353 scoped_ptr<Value> enabled( | 353 scoped_ptr<Value> enabled( |
| 354 Value::CreateBooleanValue(clear_plugin_lso_data_enabled_.GetValue())); | 354 Value::CreateBooleanValue(clear_plugin_lso_data_enabled_.GetValue())); |
| 355 web_ui_->CallJavascriptFunction( | 355 web_ui_->CallJavascriptFunction( |
| 356 "OptionsPage.setClearPluginLSODataEnabled", *enabled); | 356 "OptionsPage.setClearPluginLSODataEnabled", *enabled); |
| 357 } | 357 } |
| 358 | 358 |
| 359 void CoreOptionsHandler::NotifyPrefChanged(const std::string* pref_name) { | 359 void CoreOptionsHandler::NotifyPrefChanged(const std::string* pref_name) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 377 DictionaryValue* dict = new DictionaryValue; | 377 DictionaryValue* dict = new DictionaryValue; |
| 378 dict->Set("value", pref->GetValue()->DeepCopy()); | 378 dict->Set("value", pref->GetValue()->DeepCopy()); |
| 379 dict->SetBoolean("managed", pref->IsManaged()); | 379 dict->SetBoolean("managed", pref->IsManaged()); |
| 380 result_value.Append(dict); | 380 result_value.Append(dict); |
| 381 | 381 |
| 382 web_ui_->CallJavascriptFunction(WideToASCII(callback_function), | 382 web_ui_->CallJavascriptFunction(WideToASCII(callback_function), |
| 383 result_value); | 383 result_value); |
| 384 } | 384 } |
| 385 } | 385 } |
| 386 } | 386 } |
| OLD | NEW |