| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/string16.h" | 11 #include "base/string16.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/google/google_util.h" | 16 #include "chrome/browser/google/google_util.h" |
| 17 #include "chrome/browser/net/url_fixer_upper.h" | 17 #include "chrome/browser/net/url_fixer_upper.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 22 #include "content/browser/user_metrics.h" | |
| 23 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
| 24 #include "content/public/browser/notification_types.h" | 23 #include "content/public/browser/notification_types.h" |
| 24 #include "content/public/browser/user_metrics.h" |
| 25 #include "googleurl/src/gurl.h" | 25 #include "googleurl/src/gurl.h" |
| 26 #include "grit/chromium_strings.h" | 26 #include "grit/chromium_strings.h" |
| 27 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 28 #include "grit/locale_settings.h" | 28 #include "grit/locale_settings.h" |
| 29 #include "grit/theme_resources.h" | 29 #include "grit/theme_resources.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 31 | 31 |
| 32 using content::UserMetricsAction; |
| 33 |
| 32 CoreOptionsHandler::CoreOptionsHandler() | 34 CoreOptionsHandler::CoreOptionsHandler() |
| 33 : handlers_host_(NULL) { | 35 : handlers_host_(NULL) { |
| 34 } | 36 } |
| 35 | 37 |
| 36 CoreOptionsHandler::~CoreOptionsHandler() {} | 38 CoreOptionsHandler::~CoreOptionsHandler() {} |
| 37 | 39 |
| 38 void CoreOptionsHandler::Initialize() { | 40 void CoreOptionsHandler::Initialize() { |
| 39 clear_plugin_lso_data_enabled_.Init(prefs::kClearPluginLSODataEnabled, | 41 clear_plugin_lso_data_enabled_.Init(prefs::kClearPluginLSODataEnabled, |
| 40 Profile::FromWebUI(web_ui_), | 42 Profile::FromWebUI(web_ui_), |
| 41 this); | 43 this); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 ProcessUserMetric(value, metric); | 213 ProcessUserMetric(value, metric); |
| 212 } | 214 } |
| 213 | 215 |
| 214 void CoreOptionsHandler::ClearPref(const std::string& pref_name, | 216 void CoreOptionsHandler::ClearPref(const std::string& pref_name, |
| 215 const std::string& metric) { | 217 const std::string& metric) { |
| 216 PrefService* pref_service = Profile::FromWebUI(web_ui_)->GetPrefs(); | 218 PrefService* pref_service = Profile::FromWebUI(web_ui_)->GetPrefs(); |
| 217 pref_service->ClearPref(pref_name.c_str()); | 219 pref_service->ClearPref(pref_name.c_str()); |
| 218 pref_service->ScheduleSavePersistentPrefs(); | 220 pref_service->ScheduleSavePersistentPrefs(); |
| 219 | 221 |
| 220 if (!metric.empty()) | 222 if (!metric.empty()) |
| 221 UserMetrics::RecordComputedAction(metric); | 223 content::RecordComputedAction(metric); |
| 222 } | 224 } |
| 223 | 225 |
| 224 void CoreOptionsHandler::ProcessUserMetric(const base::Value* value, | 226 void CoreOptionsHandler::ProcessUserMetric(const base::Value* value, |
| 225 const std::string& metric) { | 227 const std::string& metric) { |
| 226 if (metric.empty()) | 228 if (metric.empty()) |
| 227 return; | 229 return; |
| 228 | 230 |
| 229 std::string metric_string = metric; | 231 std::string metric_string = metric; |
| 230 if (value->IsType(base::Value::TYPE_BOOLEAN)) { | 232 if (value->IsType(base::Value::TYPE_BOOLEAN)) { |
| 231 bool bool_value; | 233 bool bool_value; |
| 232 CHECK(value->GetAsBoolean(&bool_value)); | 234 CHECK(value->GetAsBoolean(&bool_value)); |
| 233 metric_string += bool_value ? "_Enable" : "_Disable"; | 235 metric_string += bool_value ? "_Enable" : "_Disable"; |
| 234 } | 236 } |
| 235 | 237 |
| 236 UserMetrics::RecordComputedAction(metric_string); | 238 content::RecordComputedAction(metric_string); |
| 237 } | 239 } |
| 238 | 240 |
| 239 void CoreOptionsHandler::NotifyPrefChanged( | 241 void CoreOptionsHandler::NotifyPrefChanged( |
| 240 const std::string& pref_name, | 242 const std::string& pref_name, |
| 241 const std::string& controlling_pref_name) { | 243 const std::string& controlling_pref_name) { |
| 242 const PrefService* pref_service = Profile::FromWebUI(web_ui_)->GetPrefs(); | 244 const PrefService* pref_service = Profile::FromWebUI(web_ui_)->GetPrefs(); |
| 243 const PrefService::Preference* pref = | 245 const PrefService::Preference* pref = |
| 244 pref_service->FindPreference(pref_name.c_str()); | 246 pref_service->FindPreference(pref_name.c_str()); |
| 245 if (!pref) | 247 if (!pref) |
| 246 return; | 248 return; |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 std::string metric; | 447 std::string metric; |
| 446 if (args->GetSize() > 1) | 448 if (args->GetSize() > 1) |
| 447 args->GetString(1, &metric); | 449 args->GetString(1, &metric); |
| 448 | 450 |
| 449 ClearPref(pref_name, metric); | 451 ClearPref(pref_name, metric); |
| 450 } | 452 } |
| 451 | 453 |
| 452 void CoreOptionsHandler::HandleUserMetricsAction(const ListValue* args) { | 454 void CoreOptionsHandler::HandleUserMetricsAction(const ListValue* args) { |
| 453 std::string metric = UTF16ToUTF8(ExtractStringValue(args)); | 455 std::string metric = UTF16ToUTF8(ExtractStringValue(args)); |
| 454 if (!metric.empty()) | 456 if (!metric.empty()) |
| 455 UserMetrics::RecordComputedAction(metric); | 457 content::RecordComputedAction(metric); |
| 456 } | 458 } |
| 457 | 459 |
| 458 void CoreOptionsHandler::UpdateClearPluginLSOData() { | 460 void CoreOptionsHandler::UpdateClearPluginLSOData() { |
| 459 scoped_ptr<base::Value> enabled( | 461 scoped_ptr<base::Value> enabled( |
| 460 base::Value::CreateBooleanValue( | 462 base::Value::CreateBooleanValue( |
| 461 clear_plugin_lso_data_enabled_.GetValue())); | 463 clear_plugin_lso_data_enabled_.GetValue())); |
| 462 web_ui_->CallJavascriptFunction( | 464 web_ui_->CallJavascriptFunction( |
| 463 "OptionsPage.setClearPluginLSODataEnabled", *enabled); | 465 "OptionsPage.setClearPluginLSODataEnabled", *enabled); |
| 464 } | 466 } |
| OLD | NEW |