| OLD | NEW |
| 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 "chrome/browser/ui/webui/options/core_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/core_options_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
| 15 #include "base/metrics/user_metrics.h" |
| 15 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 16 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/values.h" | 19 #include "base/values.h" |
| 19 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 20 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/chrome_notification_types.h" | 22 #include "chrome/browser/chrome_notification_types.h" |
| 22 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
| 23 #include "chrome/browser/extensions/extension_util.h" | 24 #include "chrome/browser/extensions/extension_util.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 28 #include "chrome/grit/chromium_strings.h" | 29 #include "chrome/grit/chromium_strings.h" |
| 29 #include "chrome/grit/generated_resources.h" | 30 #include "chrome/grit/generated_resources.h" |
| 30 #include "chrome/grit/locale_settings.h" | 31 #include "chrome/grit/locale_settings.h" |
| 31 #include "components/proxy_config/proxy_config_pref_names.h" | 32 #include "components/proxy_config/proxy_config_pref_names.h" |
| 32 #include "components/strings/grit/components_strings.h" | 33 #include "components/strings/grit/components_strings.h" |
| 33 #include "components/url_formatter/url_fixer.h" | 34 #include "components/url_formatter/url_fixer.h" |
| 34 #include "content/public/browser/notification_details.h" | 35 #include "content/public/browser/notification_details.h" |
| 35 #include "content/public/browser/notification_types.h" | 36 #include "content/public/browser/notification_types.h" |
| 36 #include "content/public/browser/user_metrics.h" | |
| 37 #include "content/public/browser/web_ui.h" | 37 #include "content/public/browser/web_ui.h" |
| 38 #include "extensions/browser/extension_pref_value_map.h" | 38 #include "extensions/browser/extension_pref_value_map.h" |
| 39 #include "extensions/browser/extension_pref_value_map_factory.h" | 39 #include "extensions/browser/extension_pref_value_map_factory.h" |
| 40 #include "extensions/browser/extension_registry.h" | 40 #include "extensions/browser/extension_registry.h" |
| 41 #include "extensions/browser/extension_system.h" | 41 #include "extensions/browser/extension_system.h" |
| 42 #include "extensions/common/extension.h" | 42 #include "extensions/common/extension.h" |
| 43 #include "ui/base/l10n/l10n_util.h" | 43 #include "ui/base/l10n/l10n_util.h" |
| 44 #include "url/gurl.h" | 44 #include "url/gurl.h" |
| 45 | 45 |
| 46 using base::UserMetricsAction; | 46 using base::UserMetricsAction; |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 | 315 |
| 316 ProcessUserMetric(value, metric); | 316 ProcessUserMetric(value, metric); |
| 317 } | 317 } |
| 318 | 318 |
| 319 void CoreOptionsHandler::ClearPref(const std::string& pref_name, | 319 void CoreOptionsHandler::ClearPref(const std::string& pref_name, |
| 320 const std::string& metric) { | 320 const std::string& metric) { |
| 321 PrefService* pref_service = FindServiceForPref(pref_name); | 321 PrefService* pref_service = FindServiceForPref(pref_name); |
| 322 pref_service->ClearPref(pref_name); | 322 pref_service->ClearPref(pref_name); |
| 323 | 323 |
| 324 if (!metric.empty()) | 324 if (!metric.empty()) |
| 325 content::RecordComputedAction(metric); | 325 base::RecordComputedAction(metric); |
| 326 } | 326 } |
| 327 | 327 |
| 328 void CoreOptionsHandler::ProcessUserMetric(const base::Value* value, | 328 void CoreOptionsHandler::ProcessUserMetric(const base::Value* value, |
| 329 const std::string& metric) { | 329 const std::string& metric) { |
| 330 if (metric.empty()) | 330 if (metric.empty()) |
| 331 return; | 331 return; |
| 332 | 332 |
| 333 std::string metric_string = metric; | 333 std::string metric_string = metric; |
| 334 if (value->IsType(base::Value::Type::BOOLEAN)) { | 334 if (value->IsType(base::Value::Type::BOOLEAN)) { |
| 335 bool bool_value; | 335 bool bool_value; |
| 336 CHECK(value->GetAsBoolean(&bool_value)); | 336 CHECK(value->GetAsBoolean(&bool_value)); |
| 337 metric_string += bool_value ? "_Enable" : "_Disable"; | 337 metric_string += bool_value ? "_Enable" : "_Disable"; |
| 338 } | 338 } |
| 339 | 339 |
| 340 content::RecordComputedAction(metric_string); | 340 base::RecordComputedAction(metric_string); |
| 341 } | 341 } |
| 342 | 342 |
| 343 void CoreOptionsHandler::NotifyPrefChanged( | 343 void CoreOptionsHandler::NotifyPrefChanged( |
| 344 const std::string& pref_name, | 344 const std::string& pref_name, |
| 345 const std::string& controlling_pref_name) { | 345 const std::string& controlling_pref_name) { |
| 346 std::unique_ptr<base::Value> value( | 346 std::unique_ptr<base::Value> value( |
| 347 CreateValueForPref(pref_name, controlling_pref_name)); | 347 CreateValueForPref(pref_name, controlling_pref_name)); |
| 348 DispatchPrefChangeNotification(pref_name, std::move(value)); | 348 DispatchPrefChangeNotification(pref_name, std::move(value)); |
| 349 } | 349 } |
| 350 | 350 |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 if (!args->GetString(1, &metric)) | 620 if (!args->GetString(1, &metric)) |
| 621 NOTREACHED(); | 621 NOTREACHED(); |
| 622 } | 622 } |
| 623 | 623 |
| 624 ClearPref(pref_name, metric); | 624 ClearPref(pref_name, metric); |
| 625 } | 625 } |
| 626 | 626 |
| 627 void CoreOptionsHandler::HandleUserMetricsAction(const base::ListValue* args) { | 627 void CoreOptionsHandler::HandleUserMetricsAction(const base::ListValue* args) { |
| 628 std::string metric = base::UTF16ToUTF8(ExtractStringValue(args)); | 628 std::string metric = base::UTF16ToUTF8(ExtractStringValue(args)); |
| 629 if (!metric.empty()) | 629 if (!metric.empty()) |
| 630 content::RecordComputedAction(metric); | 630 base::RecordComputedAction(metric); |
| 631 } | 631 } |
| 632 | 632 |
| 633 void CoreOptionsHandler::HandleDisableExtension(const base::ListValue* args) { | 633 void CoreOptionsHandler::HandleDisableExtension(const base::ListValue* args) { |
| 634 std::string extension_id; | 634 std::string extension_id; |
| 635 if (args->GetString(0, &extension_id)) { | 635 if (args->GetString(0, &extension_id)) { |
| 636 ExtensionService* extension_service = extensions::ExtensionSystem::Get( | 636 ExtensionService* extension_service = extensions::ExtensionSystem::Get( |
| 637 Profile::FromWebUI(web_ui()))->extension_service(); | 637 Profile::FromWebUI(web_ui()))->extension_service(); |
| 638 DCHECK(extension_service); | 638 DCHECK(extension_service); |
| 639 extension_service->DisableExtension( | 639 extension_service->DisableExtension( |
| 640 extension_id, extensions::Extension::DISABLE_USER_ACTION); | 640 extension_id, extensions::Extension::DISABLE_USER_ACTION); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 654 plugin_status_pref_setter_.IsPepperFlashSettingsEnabled()); | 654 plugin_status_pref_setter_.IsPepperFlashSettingsEnabled()); |
| 655 web_ui()->CallJavascriptFunctionUnsafe( | 655 web_ui()->CallJavascriptFunctionUnsafe( |
| 656 "options.OptionsPage.setPepperFlashSettingsEnabled", enabled); | 656 "options.OptionsPage.setPepperFlashSettingsEnabled", enabled); |
| 657 } | 657 } |
| 658 | 658 |
| 659 bool CoreOptionsHandler::IsUserUnsupervised(const base::Value* to_value) { | 659 bool CoreOptionsHandler::IsUserUnsupervised(const base::Value* to_value) { |
| 660 return !Profile::FromWebUI(web_ui())->IsSupervised(); | 660 return !Profile::FromWebUI(web_ui())->IsSupervised(); |
| 661 } | 661 } |
| 662 | 662 |
| 663 } // namespace options | 663 } // namespace options |
| OLD | NEW |