Commit 094349c4 authored by Ali Tofigh's avatar Ali Tofigh Committed by Commit Bot

Chrome Cleaner UI: Add user actions for webui card.

Bug: 746987
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I3397b1234aec605b93da8b8ffcddd03f121a9980
Reviewed-on: https://chromium-review.googlesource.com/588130
Commit-Queue: Ali Tofigh <alito@chromium.org>
Reviewed-by: default avatarJesse Doherty <jwd@chromium.org>
Reviewed-by: default avatarDave Schuyler <dschuyler@chromium.org>
Reviewed-by: default avatarproberge <proberge@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491204}
parent 02ca9692
......@@ -103,7 +103,7 @@
$i18n{chromeCleanupExplanation}
</span>
<a id="learn-more" href="$i18n{chromeCleanupLearnMoreUrl}"
target="_blank" hidden="[[!showLearnMore_]]">
on-tap="learnMore_" target="_blank" hidden="[[!showLearnMore_]]">
$i18n{learnMore}
</a>
</div>
......
......@@ -17,6 +17,19 @@ settings.ChromeCleanupIdleReason = {
CLEANING_SUCCEEDED: 'cleaning_succeeded',
};
/**
* The source of the dismiss action. Used when reporting metrics about how the
* card was dismissed. The numeric values must be kept in sync with the
* definition of ChromeCleanerDismissSource in
* src/chrome/browser/ui/webui/settings/chrome_cleanup_handler.cc.
* @enum {number}
*/
settings.ChromeCleanupDismissSource = {
OTHER: 0,
CLEANUP_SUCCESS_DONE_BUTTON: 1,
CLEANUP_FAILURE_DONE_BUTTON: 2,
};
/**
* @fileoverview
* 'settings-chrome-cleanup-page' is the settings page containing Chrome
......@@ -85,6 +98,7 @@ Polymer({
showFilesToRemove_: {
type: Boolean,
value: false,
observer: 'showFilesToRemoveChanged_',
},
/** @private */
......@@ -147,7 +161,6 @@ Polymer({
this.addWebUIListener(
'chrome-cleanup-upload-permission-change',
this.onUploadPermissionChange_.bind(this));
this.browserProxy_.registerChromeCleanerObserver();
},
......@@ -181,6 +194,24 @@ Polymer({
expandButton.expanded = !expandButton.expanded;
},
/**
* Notify Chrome that the details section was opened or closed.
* @private
*/
showFilesToRemoveChanged_: function() {
if (this.browserProxy_)
this.browserProxy_.notifyShowDetails(this.showFilesToRemove_);
},
/**
* Notfies Chrome that the "learn more" link was clicked.
* @private
*/
learnMore_: function() {
this.browserProxy_.notifyLearnMoreClicked();
},
/**
* @return {boolean}
* @private
......@@ -198,17 +229,23 @@ Polymer({
if (idleReason == settings.ChromeCleanupIdleReason.CLEANING_SUCCEEDED) {
this.title_ = this.i18n('chromeCleanupTitleRemoved');
this.enableActionButton_(
this.i18n('chromeCleanupDoneButtonLabel'), this.dismiss_.bind(this));
this.i18n('chromeCleanupDoneButtonLabel'),
this.dismiss_.bind(
this,
settings.ChromeCleanupDismissSource.CLEANUP_SUCCESS_DONE_BUTTON));
this.setIconDone_();
this.showLearnMore_ = false;
} else if (idleReason == settings.ChromeCleanupIdleReason.INITIAL) {
this.dismiss_();
this.dismiss_(settings.ChromeCleanupDismissSource.OTHER);
} else {
// Scanning-related idle reasons are unexpected. Show an error message for
// all reasons other than |CLEANING_SUCCEEDED| and |INITIAL|.
this.title_ = this.i18n('chromeCleanupTitleErrorCantRemove');
this.enableActionButton_(
this.i18n('chromeCleanupDoneButtonLabel'), this.dismiss_.bind(this));
this.i18n('chromeCleanupDoneButtonLabel'),
this.dismiss_.bind(
this,
settings.ChromeCleanupDismissSource.CLEANUP_FAILURE_DONE_BUTTON));
this.setIconWarning_();
this.showLearnMore_ = true;
}
......@@ -311,10 +348,11 @@ Polymer({
/**
* Dismiss the card.
* @param {number} source
* @private
*/
dismiss_: function() {
this.browserProxy_.dismissCleanupPage();
dismiss_: function(source) {
this.browserProxy_.dismissCleanupPage(source);
},
/**
......
......@@ -24,14 +24,26 @@ cr.define('settings', function() {
/**
* Hides the Cleanup page from the settings menu.
* @param {number} source
*/
dismissCleanupPage() {}
dismissCleanupPage(source) {}
/**
* Updates the cleanup logs upload permission status.
* @param {boolean} enabled
*/
setLogsUploadPermission(enabled) {}
/**
* Notfies Chrome that the state of the details section changed.
* @param {boolean} enabled
*/
notifyShowDetails(enabled) {}
/**
* Notfies Chrome that the "learn more" link was clicked.
*/
notifyLearnMoreClicked() {}
}
/**
......@@ -54,14 +66,24 @@ cr.define('settings', function() {
}
/** @override */
dismissCleanupPage() {
chrome.send('dismissCleanupPage');
dismissCleanupPage(source) {
chrome.send('dismissCleanupPage', [source]);
}
/** @override */
setLogsUploadPermission(enabled) {
chrome.send('setLogsUploadPermission', [enabled]);
}
/** @override */
notifyShowDetails(enabled) {
chrome.send('notifyShowDetails', [enabled]);
}
/** @override */
notifyLearnMoreClicked() {
chrome.send('notifyChromeCleanupLearnMoreClicked');
}
}
cr.addSingletonGetter(ChromeCleanupProxyImpl);
......
......@@ -9,6 +9,8 @@
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/synchronization/lock.h"
#include "base/values.h"
#include "chrome/browser/safe_browsing/chrome_cleaner/srt_field_trial_win.h"
......@@ -23,6 +25,15 @@ namespace settings {
namespace {
// These numeric values must be kept in sync with the definition of
// settings.ChromeCleanupDismissSource in
// chrome/browser/resources/settings/chrome_cleanup_page/chrome_cleanup_page.js.
enum ChromeCleanerDismissSource {
kOther = 0,
kCleanupSuccessDoneButton = 1,
kCleanupFailureDoneButton = 2,
};
// Returns a ListValue containing a copy of the file paths stored in |files|.
base::ListValue GetFilesAsListStorage(const std::set<base::FilePath>& files) {
base::ListValue value;
......@@ -82,6 +93,15 @@ void ChromeCleanupHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
"startCleanup", base::Bind(&ChromeCleanupHandler::HandleStartCleanup,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"notifyShowDetails",
base::Bind(&ChromeCleanupHandler::HandleNotifyShowDetails,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"notifyChromeCleanupLearnMoreClicked",
base::Bind(
&ChromeCleanupHandler::HandleNotifyChromeCleanupLearnMoreClicked,
base::Unretained(this)));
}
void ChromeCleanupHandler::OnJavascriptAllowed() {
......@@ -128,7 +148,27 @@ void ChromeCleanupHandler::OnLogsEnabledChanged(bool logs_enabled) {
}
void ChromeCleanupHandler::HandleDismiss(const base::ListValue* args) {
DCHECK_EQ(0U, args->GetSize());
CHECK_EQ(1U, args->GetSize());
int dismiss_source_int = -1;
CHECK(args->GetInteger(0, &dismiss_source_int));
ChromeCleanerDismissSource dismiss_source =
static_cast<ChromeCleanerDismissSource>(dismiss_source_int);
switch (dismiss_source) {
case kCleanupSuccessDoneButton:
base::RecordAction(base::UserMetricsAction(
"SoftwareReporter.CleanupWebui_CleanupSuccessDone"));
break;
case kCleanupFailureDoneButton:
base::RecordAction(base::UserMetricsAction(
"SoftwareReporter.CleanupWebui_CleanupFailureDone"));
break;
case kOther:
break;
default:
NOTREACHED();
}
controller_->RemoveObserver(this);
controller_->ResetIdleState();
......@@ -146,6 +186,8 @@ void ChromeCleanupHandler::HandleRegisterChromeCleanerObserver(
base::FeatureList::IsEnabled(safe_browsing::kInBrowserCleanerUIFeature));
UMA_HISTOGRAM_BOOLEAN("SoftwareReporter.CleanupCard", true);
base::RecordAction(
base::UserMetricsAction("SoftwareReporter.CleanupWebui_Shown"));
AllowJavascript();
// Send the current logs upload state.
......@@ -155,6 +197,9 @@ void ChromeCleanupHandler::HandleRegisterChromeCleanerObserver(
void ChromeCleanupHandler::HandleRestartComputer(const base::ListValue* args) {
DCHECK_EQ(0U, args->GetSize());
base::RecordAction(
base::UserMetricsAction("SoftwareReporter.CleanupWebui_RestartComputer"));
CallJavascriptFunction("cr.webUIListenerCallback",
base::Value("chrome-cleanup-on-dismiss"));
......@@ -167,6 +212,14 @@ void ChromeCleanupHandler::HandleSetLogsUploadPermission(
bool allow_logs_upload = false;
args->GetBoolean(0, &allow_logs_upload);
if (allow_logs_upload) {
base::RecordAction(base::UserMetricsAction(
"SoftwareReporter.CleanupWebui_LogsUploadEnabled"));
} else {
base::RecordAction(base::UserMetricsAction(
"SoftwareReporter.CleanupWebui_LogsUploadDisabled"));
}
controller_->SetLogsEnabled(allow_logs_upload);
}
......@@ -180,6 +233,9 @@ void ChromeCleanupHandler::HandleStartCleanup(const base::ListValue* args) {
safe_browsing::RecordCleanupStartedHistogram(
safe_browsing::CLEANUP_STARTED_FROM_PROMPT_IN_SETTINGS);
base::RecordAction(
base::UserMetricsAction("SoftwareReporter.CleanupWebui_StartCleanup"));
controller_->ReplyWithUserResponse(
profile_,
allow_logs_upload
......@@ -187,4 +243,27 @@ void ChromeCleanupHandler::HandleStartCleanup(const base::ListValue* args) {
: ChromeCleanerController::UserResponse::kAcceptedWithoutLogs);
}
void ChromeCleanupHandler::HandleNotifyShowDetails(
const base::ListValue* args) {
CHECK_EQ(1U, args->GetSize());
bool details_section_visible = false;
args->GetBoolean(0, &details_section_visible);
if (details_section_visible) {
base::RecordAction(
base::UserMetricsAction("SoftwareReporter.CleanupWebui_ShowDetails"));
} else {
base::RecordAction(
base::UserMetricsAction("SoftwareReporter.CleanupWebui_HideDetails"));
}
}
void ChromeCleanupHandler::HandleNotifyChromeCleanupLearnMoreClicked(
const base::ListValue* args) {
CHECK_EQ(0U, args->GetSize());
base::RecordAction(
base::UserMetricsAction("SoftwareReporter.CleanupWebui_LearnMore"));
}
} // namespace settings
......@@ -60,6 +60,14 @@ class ChromeCleanupHandler
// software from the user's computer.
void HandleStartCleanup(const base::ListValue* args);
// Callback for the "showDetails" message that notifies Chrome about whether
// the user expanded or closed the details section of the page.
void HandleNotifyShowDetails(const base::ListValue* args);
// Callback for the "chromeCleanupLearnMore" message that notifies Chrome that
// the "learn more" link was clicked.
void HandleNotifyChromeCleanupLearnMoreClicked(const base::ListValue* args);
// Raw pointer to a singleton. Must outlive this object.
safe_browsing::ChromeCleanerController* controller_;
......
......@@ -11,12 +11,14 @@ class TestChromeCleanupProxy extends TestBrowserProxy {
'restartComputer',
'setLogsUploadPermission',
'startCleanup',
'notifyShowDetails',
'notifyLearnMoreClicked',
]);
}
/** @override */
dismissCleanupPage() {
this.methodCalled('dismissCleanupPage');
dismissCleanupPage(source) {
this.methodCalled('dismissCleanupPage', source);
}
/** @override */
......@@ -38,6 +40,16 @@ class TestChromeCleanupProxy extends TestBrowserProxy {
startCleanup(logsUploadEnabled) {
this.methodCalled('startCleanup', logsUploadEnabled);
}
/** @override */
notifyShowDetails(enabled) {
this.methodCalled('notifyShowDetails', enabled);
}
/** @override */
notifyLearnMoreClicked() {
this.methodCalled('notifyLearnMoreClicked');
}
}
var chromeCleanupPage = null;
......
......@@ -16124,6 +16124,79 @@ should be able to be added at any place in this file.
<description>Please enter the description of this user action.</description>
</action>
<action name="SoftwareReporter.CleanupWebui_CleanupFailureDone">
<owner>alito@chromium.org</owner>
<description>
The user dismissed the Chrome Cleaner webui after a failed cleanup by
clicking on the 'Done' button.
</description>
</action>
<action name="SoftwareReporter.CleanupWebui_CleanupSuccessDone">
<owner>alito@chromium.org</owner>
<description>
The user dismissed the Chrome Cleaner webui after a successful cleanup by
clicking on the 'Done' button.
</description>
</action>
<action name="SoftwareReporter.CleanupWebui_HideDetails">
<owner>alito@chromium.org</owner>
<description>
The user closed the details section of the Chrome Cleaner webui.
</description>
</action>
<action name="SoftwareReporter.CleanupWebui_LearnMore">
<owner>alito@chromium.org</owner>
<description>
The user clicked the 'Learn more' link on the Chrome Cleaner webui.
</description>
</action>
<action name="SoftwareReporter.CleanupWebui_LogsUploadDisabled">
<owner>alito@chromium.org</owner>
<description>
The user disabled logs upload by toggling the permission checkbox in the
Chrome Cleaner webui.
</description>
</action>
<action name="SoftwareReporter.CleanupWebui_LogsUploadEnabled">
<owner>alito@chromium.org</owner>
<description>
The user enabled logs upload by toggling the permission checkbox in the
Chrome Cleaner webui.
</description>
</action>
<action name="SoftwareReporter.CleanupWebui_RestartComputer">
<owner>alito@chromium.org</owner>
<description>
The user clicked the 'Restart Computer' button in the Chrome Cleaner webui.
</description>
</action>
<action name="SoftwareReporter.CleanupWebui_ShowDetails">
<owner>alito@chromium.org</owner>
<description>
The user opened the details section of the Chrome Cleaner webui.
</description>
</action>
<action name="SoftwareReporter.CleanupWebui_Shown">
<owner>alito@chromium.org</owner>
<description>The Chrome Cleaner webui was shown.</description>
</action>
<action name="SoftwareReporter.CleanupWebui_StartCleanup">
<owner>alito@chromium.org</owner>
<description>
The cleaner accepted the cleanup operation offered on the Chrome Cleaner
webui.
</description>
</action>
<action name="SoftwareReporter.PromptDialog.LogsPermissionCheckbox_Disabled">
<owner>alito@chromium.org</owner>
<description>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment