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

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

Issue 506663003: Consolidates accessing and setting the UMA pref to be within metrics code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor changes and fixes Created 6 years, 3 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
OLDNEW
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h"
Alexei Svitkine (slow) 2014/09/11 15:33:43 Remove this line, since you're only now deleting c
gayane -on leave until 09-2017 2014/09/11 17:06:08 Done.
9 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
10 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "base/values.h" 15 #include "base/values.h"
15 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/chrome_notification_types.h" 17 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/extensions/extension_service.h" 18 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/extensions/extension_util.h" 19 #include "chrome/browser/extensions/extension_util.h"
19 #include "chrome/browser/metrics/metrics_reporting_state.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
23 #include "chrome/grit/chromium_strings.h" 23 #include "chrome/grit/chromium_strings.h"
24 #include "chrome/grit/generated_resources.h" 24 #include "chrome/grit/generated_resources.h"
25 #include "chrome/grit/locale_settings.h" 25 #include "chrome/grit/locale_settings.h"
26 #include "components/url_fixer/url_fixer.h" 26 #include "components/url_fixer/url_fixer.h"
27 #include "content/public/browser/notification_details.h" 27 #include "content/public/browser/notification_details.h"
28 #include "content/public/browser/notification_types.h" 28 #include "content/public/browser/notification_types.h"
29 #include "content/public/browser/user_metrics.h" 29 #include "content/public/browser/user_metrics.h"
30 #include "content/public/browser/web_ui.h" 30 #include "content/public/browser/web_ui.h"
31 #include "extensions/browser/extension_pref_value_map.h" 31 #include "extensions/browser/extension_pref_value_map.h"
32 #include "extensions/browser/extension_pref_value_map_factory.h" 32 #include "extensions/browser/extension_pref_value_map_factory.h"
33 #include "extensions/browser/extension_registry.h" 33 #include "extensions/browser/extension_registry.h"
34 #include "extensions/browser/extension_system.h" 34 #include "extensions/browser/extension_system.h"
35 #include "extensions/common/extension.h" 35 #include "extensions/common/extension.h"
36 #include "grit/components_strings.h" 36 #include "grit/components_strings.h"
37 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
38 #include "url/gurl.h" 38 #include "url/gurl.h"
39 39
40 using base::UserMetricsAction; 40 using base::UserMetricsAction;
41 41
42 namespace options { 42 namespace options {
43 43
44 namespace { 44 namespace {
45 45
46 // Only allow changes to the metrics reporting checkbox if we were succesfully
47 // able to change the service.
48 bool AllowMetricsReportingChange(const base::Value* to_value) {
49 bool enable;
50 if (!to_value->GetAsBoolean(&enable)) {
51 NOTREACHED();
52 return false;
53 }
54
55 return enable == ResolveMetricsReportingEnabled(enable);
56 }
57
58 // Whether "controlledBy" property of pref value sent to options web UI needs to 46 // Whether "controlledBy" property of pref value sent to options web UI needs to
59 // be set to "extension" when the preference is controlled by an extension. 47 // be set to "extension" when the preference is controlled by an extension.
60 bool CanSetExtensionControlledPrefValue( 48 bool CanSetExtensionControlledPrefValue(
61 const PrefService::Preference* preference) { 49 const PrefService::Preference* preference) {
62 #if defined(OS_WIN) 50 #if defined(OS_WIN)
63 // These have more obvious UI than the standard one for extension controlled 51 // These have more obvious UI than the standard one for extension controlled
64 // values (an extension puzzle piece) on the settings page. To avoiding 52 // values (an extension puzzle piece) on the settings page. To avoiding
65 // showing the extension puzzle piece for these settings, their "controlledBy" 53 // showing the extension puzzle piece for these settings, their "controlledBy"
66 // value should never be set to "extension". 54 // value should never be set to "extension".
67 return preference->name() != prefs::kURLsToRestoreOnStartup && 55 return preference->name() != prefs::kURLsToRestoreOnStartup &&
(...skipping 15 matching lines...) Expand all
83 71
84 void CoreOptionsHandler::InitializeHandler() { 72 void CoreOptionsHandler::InitializeHandler() {
85 Profile* profile = Profile::FromWebUI(web_ui()); 73 Profile* profile = Profile::FromWebUI(web_ui());
86 74
87 plugin_status_pref_setter_.Init( 75 plugin_status_pref_setter_.Init(
88 profile, 76 profile,
89 base::Bind(&CoreOptionsHandler::OnPreferenceChanged, 77 base::Bind(&CoreOptionsHandler::OnPreferenceChanged,
90 base::Unretained(this), 78 base::Unretained(this),
91 profile->GetPrefs())); 79 profile->GetPrefs()));
92 80
93 pref_change_filters_[prefs::kMetricsReportingEnabled] =
94 base::Bind(&AllowMetricsReportingChange);
95 pref_change_filters_[prefs::kBrowserGuestModeEnabled] = 81 pref_change_filters_[prefs::kBrowserGuestModeEnabled] =
96 base::Bind(&CoreOptionsHandler::IsUserUnsupervised, 82 base::Bind(&CoreOptionsHandler::IsUserUnsupervised,
97 base::Unretained(this)); 83 base::Unretained(this));
98 pref_change_filters_[prefs::kBrowserAddPersonEnabled] = 84 pref_change_filters_[prefs::kBrowserAddPersonEnabled] =
99 base::Bind(&CoreOptionsHandler::IsUserUnsupervised, 85 base::Bind(&CoreOptionsHandler::IsUserUnsupervised,
100 base::Unretained(this)); 86 base::Unretained(this));
101 } 87 }
102 88
103 void CoreOptionsHandler::InitializePage() { 89 void CoreOptionsHandler::InitializePage() {
104 UpdateClearPluginLSOData(); 90 UpdateClearPluginLSOData();
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 plugin_status_pref_setter_.IsPepperFlashSettingsEnabled()); 647 plugin_status_pref_setter_.IsPepperFlashSettingsEnabled());
662 web_ui()->CallJavascriptFunction( 648 web_ui()->CallJavascriptFunction(
663 "OptionsPage.setPepperFlashSettingsEnabled", enabled); 649 "OptionsPage.setPepperFlashSettingsEnabled", enabled);
664 } 650 }
665 651
666 bool CoreOptionsHandler::IsUserUnsupervised(const base::Value* to_value) { 652 bool CoreOptionsHandler::IsUserUnsupervised(const base::Value* to_value) {
667 return !Profile::FromWebUI(web_ui())->IsSupervised(); 653 return !Profile::FromWebUI(web_ui())->IsSupervised();
668 } 654 }
669 655
670 } // namespace options 656 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698