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

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: more comments. using accesor class. 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"
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"
(...skipping 17 matching lines...) Expand all
36 #include "grit/components_strings.h" 37 #include "grit/components_strings.h"
37 #include "ui/base/l10n/l10n_util.h" 38 #include "ui/base/l10n/l10n_util.h"
38 #include "url/gurl.h" 39 #include "url/gurl.h"
39 40
40 using base::UserMetricsAction; 41 using base::UserMetricsAction;
41 42
42 namespace options { 43 namespace options {
43 44
44 namespace { 45 namespace {
45 46
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 47 // 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. 48 // be set to "extension" when the preference is controlled by an extension.
60 bool CanSetExtensionControlledPrefValue( 49 bool CanSetExtensionControlledPrefValue(
61 const PrefService::Preference* preference) { 50 const PrefService::Preference* preference) {
62 #if defined(OS_WIN) 51 #if defined(OS_WIN)
63 // These have more obvious UI than the standard one for extension controlled 52 // These have more obvious UI than the standard one for extension controlled
64 // values (an extension puzzle piece) on the settings page. To avoiding 53 // values (an extension puzzle piece) on the settings page. To avoiding
65 // showing the extension puzzle piece for these settings, their "controlledBy" 54 // showing the extension puzzle piece for these settings, their "controlledBy"
66 // value should never be set to "extension". 55 // value should never be set to "extension".
67 return preference->name() != prefs::kURLsToRestoreOnStartup && 56 return preference->name() != prefs::kURLsToRestoreOnStartup &&
(...skipping 14 matching lines...) Expand all
82 CoreOptionsHandler::~CoreOptionsHandler() {} 71 CoreOptionsHandler::~CoreOptionsHandler() {}
83 72
84 void CoreOptionsHandler::InitializeHandler() { 73 void CoreOptionsHandler::InitializeHandler() {
85 Profile* profile = Profile::FromWebUI(web_ui()); 74 Profile* profile = Profile::FromWebUI(web_ui());
86 75
87 plugin_status_pref_setter_.Init( 76 plugin_status_pref_setter_.Init(
88 profile, 77 profile,
89 base::Bind(&CoreOptionsHandler::OnPreferenceChanged, 78 base::Bind(&CoreOptionsHandler::OnPreferenceChanged,
90 base::Unretained(this), 79 base::Unretained(this),
91 profile->GetPrefs())); 80 profile->GetPrefs()));
92
93 pref_change_filters_[prefs::kMetricsReportingEnabled] =
94 base::Bind(&AllowMetricsReportingChange);
95 } 81 }
96 82
97 void CoreOptionsHandler::InitializePage() { 83 void CoreOptionsHandler::InitializePage() {
98 UpdateClearPluginLSOData(); 84 UpdateClearPluginLSOData();
99 UpdatePepperFlashSettingsEnabled(); 85 UpdatePepperFlashSettingsEnabled();
100 } 86 }
101 87
102 void CoreOptionsHandler::GetLocalizedValues( 88 void CoreOptionsHandler::GetLocalizedValues(
103 base::DictionaryValue* localized_strings) { 89 base::DictionaryValue* localized_strings) {
104 GetStaticLocalizedValues(localized_strings); 90 GetStaticLocalizedValues(localized_strings);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 base::Unretained(this))); 217 base::Unretained(this)));
232 web_ui()->RegisterMessageCallback("clearPref", 218 web_ui()->RegisterMessageCallback("clearPref",
233 base::Bind(&CoreOptionsHandler::HandleClearPref, 219 base::Bind(&CoreOptionsHandler::HandleClearPref,
234 base::Unretained(this))); 220 base::Unretained(this)));
235 web_ui()->RegisterMessageCallback("coreOptionsUserMetricsAction", 221 web_ui()->RegisterMessageCallback("coreOptionsUserMetricsAction",
236 base::Bind(&CoreOptionsHandler::HandleUserMetricsAction, 222 base::Bind(&CoreOptionsHandler::HandleUserMetricsAction,
237 base::Unretained(this))); 223 base::Unretained(this)));
238 web_ui()->RegisterMessageCallback("disableExtension", 224 web_ui()->RegisterMessageCallback("disableExtension",
239 base::Bind(&CoreOptionsHandler::HandleDisableExtension, 225 base::Bind(&CoreOptionsHandler::HandleDisableExtension,
240 base::Unretained(this))); 226 base::Unretained(this)));
227 web_ui()->RegisterMessageCallback("coreOptionsMetricsReportingChange",
Alexei Svitkine (slow) 2014/09/05 15:22:48 I know the previous code was in this file, but acc
gayane -on leave until 09-2017 2014/09/05 18:30:20 That actually makes sense because other functions
228 base::Bind(&CoreOptionsHandler::HandleMetricsReportingChange,
229 base::Unretained(this)));
241 } 230 }
242 231
243 void CoreOptionsHandler::HandleInitialize(const base::ListValue* args) { 232 void CoreOptionsHandler::HandleInitialize(const base::ListValue* args) {
244 DCHECK(handlers_host_); 233 DCHECK(handlers_host_);
245 handlers_host_->InitializeHandlers(); 234 handlers_host_->InitializeHandlers();
246 } 235 }
247 236
248 void CoreOptionsHandler::OnFinishedLoading(const base::ListValue* args) { 237 void CoreOptionsHandler::OnFinishedLoading(const base::ListValue* args) {
249 DCHECK(handlers_host_); 238 DCHECK(handlers_host_);
250 handlers_host_->OnFinishedLoading(); 239 handlers_host_->OnFinishedLoading();
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 ExtensionService* extension_service = extensions::ExtensionSystem::Get( 625 ExtensionService* extension_service = extensions::ExtensionSystem::Get(
637 Profile::FromWebUI(web_ui()))->extension_service(); 626 Profile::FromWebUI(web_ui()))->extension_service();
638 DCHECK(extension_service); 627 DCHECK(extension_service);
639 extension_service->DisableExtension( 628 extension_service->DisableExtension(
640 extension_id, extensions::Extension::DISABLE_USER_ACTION); 629 extension_id, extensions::Extension::DISABLE_USER_ACTION);
641 } else { 630 } else {
642 NOTREACHED(); 631 NOTREACHED();
643 } 632 }
644 } 633 }
645 634
635 void CoreOptionsHandler::HandleMetricsReportingChange(
636 const base::ListValue* args) {
637 base::Callback<void(bool)> callback_fn = base::Bind(
638 &CoreOptionsHandler::MetricsReportingChangeCallback,
639 base::Unretained(this));
640 bool enable;
641 if (!args->GetBoolean(0, &enable)) return;
Alexei Svitkine (slow) 2014/09/05 15:22:48 Nit: Put return on the next line.
gayane -on leave until 09-2017 2014/09/05 18:30:20 Done.
642
643 InitiateMetricsReportingChange(enable, callback_fn);
644 }
645
646 void CoreOptionsHandler::MetricsReportingChangeCallback(bool success) {
647 base::DictionaryValue* dict = new base::DictionaryValue;
Alexei Svitkine (slow) 2014/09/05 15:22:48 I think you might be leaking this. Please double
gayane -on leave until 09-2017 2014/09/05 18:30:20 param removed. not needed anymore.
648 dict->SetBoolean("success", success);
649 web_ui()->CallJavascriptFunction(
650 "BrowserOptions.setMetricsReportingJSCallback", *dict);
651 }
652
646 void CoreOptionsHandler::UpdateClearPluginLSOData() { 653 void CoreOptionsHandler::UpdateClearPluginLSOData() {
647 base::FundamentalValue enabled( 654 base::FundamentalValue enabled(
648 plugin_status_pref_setter_.IsClearPluginLSODataEnabled()); 655 plugin_status_pref_setter_.IsClearPluginLSODataEnabled());
649 web_ui()->CallJavascriptFunction( 656 web_ui()->CallJavascriptFunction(
650 "OptionsPage.setClearPluginLSODataEnabled", enabled); 657 "OptionsPage.setClearPluginLSODataEnabled", enabled);
651 } 658 }
652 659
653 void CoreOptionsHandler::UpdatePepperFlashSettingsEnabled() { 660 void CoreOptionsHandler::UpdatePepperFlashSettingsEnabled() {
654 base::FundamentalValue enabled( 661 base::FundamentalValue enabled(
655 plugin_status_pref_setter_.IsPepperFlashSettingsEnabled()); 662 plugin_status_pref_setter_.IsPepperFlashSettingsEnabled());
656 web_ui()->CallJavascriptFunction( 663 web_ui()->CallJavascriptFunction(
657 "OptionsPage.setPepperFlashSettingsEnabled", enabled); 664 "OptionsPage.setPepperFlashSettingsEnabled", enabled);
658 } 665 }
659 666
660 } // namespace options 667 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698