Commit 70f9ea00 authored by avi's avatar avi Committed by Commit bot

Add UMA metrics to measure the dismissal cause of dialogs.

BUG=629964

Review-Url: https://codereview.chromium.org/2535043002
Cr-Commit-Position: refs/heads/master@{#435016}
parent b976d1f4
......@@ -56,14 +56,29 @@ bool IsWebContentsForemost(content::WebContents* web_contents) {
// JavaScriptDialogTabHelper::OnDialogClosed(), which, after doing the callback,
// again calls ClearDialogInfo() to remove observers.
enum class JavaScriptDialogTabHelper::DismissalCause {
// This is used for a UMA histogram. Please never alter existing values, only
// append new ones.
TAB_HELPER_DESTROYED = 0,
SUBSEQUENT_DIALOG_SHOWN = 1,
HANDLE_DIALOG_CALLED = 2,
CANCEL_DIALOGS_CALLED = 3,
TAB_HIDDEN = 4,
BROWSER_SWITCHED = 5,
DIALOG_BUTTON_CLICKED = 6,
MAX,
};
JavaScriptDialogTabHelper::JavaScriptDialogTabHelper(
content::WebContents* web_contents)
: content::WebContentsObserver(web_contents) {
}
JavaScriptDialogTabHelper::~JavaScriptDialogTabHelper() {
if (dialog_)
CloseDialog(true /*suppress_callback*/, false, base::string16());
if (dialog_) {
CloseDialog(true /*suppress_callback*/, false, base::string16(),
DismissalCause::TAB_HELPER_DESTROYED);
}
}
void JavaScriptDialogTabHelper::SetDialogShownCallbackForTesting(
......@@ -131,12 +146,14 @@ void JavaScriptDialogTabHelper::RunJavaScriptDialog(
if (dialog_) {
// There's already a dialog up; clear it out.
CloseDialog(false, false, base::string16());
CloseDialog(false, false, base::string16(),
DismissalCause::SUBSEQUENT_DIALOG_SHOWN);
}
base::string16 title =
AppModalDialogManager()->GetTitle(alerting_web_contents, origin_url);
dialog_callback_ = callback;
message_type_ = message_type;
dialog_ = JavaScriptDialog::Create(
parent_web_contents, alerting_web_contents, title, message_type,
message_text, default_prompt_text,
......@@ -213,7 +230,8 @@ bool JavaScriptDialogTabHelper::HandleJavaScriptDialog(
const base::string16* prompt_override) {
if (dialog_) {
CloseDialog(false /*suppress_callback*/, accept,
prompt_override ? *prompt_override : base::string16());
prompt_override ? *prompt_override : base::string16(),
DismissalCause::HANDLE_DIALOG_CALLED);
return true;
}
......@@ -227,7 +245,8 @@ void JavaScriptDialogTabHelper::CancelDialogs(
bool suppress_callbacks,
bool reset_state) {
if (dialog_)
CloseDialog(suppress_callbacks, false, base::string16());
CloseDialog(suppress_callbacks, false, base::string16(),
DismissalCause::CANCEL_DIALOGS_CALLED);
// Cancel any app-modal dialogs being run by the app-modal dialog system.
return AppModalDialogManager()->CancelDialogs(
......@@ -235,19 +254,44 @@ void JavaScriptDialogTabHelper::CancelDialogs(
}
void JavaScriptDialogTabHelper::WasHidden() {
if (dialog_)
CloseDialog(false, false, base::string16());
if (dialog_) {
CloseDialog(false, false, base::string16(), DismissalCause::TAB_HIDDEN);
}
}
void JavaScriptDialogTabHelper::OnBrowserSetLastActive(Browser* browser) {
if (dialog_ && !IsWebContentsForemost(web_contents()))
CloseDialog(false, false, base::string16());
if (dialog_ && !IsWebContentsForemost(web_contents())) {
CloseDialog(false, false, base::string16(),
DismissalCause::BROWSER_SWITCHED);
}
}
void JavaScriptDialogTabHelper::LogDialogDismissalCause(
JavaScriptDialogTabHelper::DismissalCause cause) {
switch (message_type_) {
case content::JAVASCRIPT_MESSAGE_TYPE_ALERT:
UMA_HISTOGRAM_ENUMERATION("JSDialogs.DismissalCause.Alert",
static_cast<int>(cause),
static_cast<int>(DismissalCause::MAX));
break;
case content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM:
UMA_HISTOGRAM_ENUMERATION("JSDialogs.DismissalCause.Confirm",
static_cast<int>(cause),
static_cast<int>(DismissalCause::MAX));
break;
case content::JAVASCRIPT_MESSAGE_TYPE_PROMPT:
UMA_HISTOGRAM_ENUMERATION("JSDialogs.DismissalCause.Prompt",
static_cast<int>(cause),
static_cast<int>(DismissalCause::MAX));
break;
}
}
void JavaScriptDialogTabHelper::OnDialogClosed(
DialogClosedCallback callback,
bool success,
const base::string16& user_input) {
LogDialogDismissalCause(DismissalCause::DIALOG_BUTTON_CLICKED);
callback.Run(success, user_input);
ClearDialogInfo();
......@@ -255,8 +299,10 @@ void JavaScriptDialogTabHelper::OnDialogClosed(
void JavaScriptDialogTabHelper::CloseDialog(bool suppress_callback,
bool success,
const base::string16& user_input) {
const base::string16& user_input,
DismissalCause cause) {
DCHECK(dialog_);
LogDialogDismissalCause(cause);
dialog_->CloseDialogWithoutCallback();
if (!suppress_callback)
......
......@@ -64,6 +64,9 @@ class JavaScriptDialogTabHelper
private:
friend class content::WebContentsUserData<JavaScriptDialogTabHelper>;
enum class DismissalCause;
void LogDialogDismissalCause(DismissalCause cause);
// Wrapper around a DialogClosedCallback so that we can intercept it before
// passing it onto the original callback.
......@@ -73,13 +76,18 @@ class JavaScriptDialogTabHelper
void CloseDialog(bool suppress_callback,
bool success,
const base::string16& user_input);
const base::string16& user_input,
DismissalCause cause);
void ClearDialogInfo();
// The dialog being displayed on the observed WebContents.
base::WeakPtr<JavaScriptDialog> dialog_;
// The type of dialog being displayed. Only valid when |dialog_| is non-null.
content::JavaScriptMessageType message_type_ =
content::JavaScriptMessageType::JAVASCRIPT_MESSAGE_TYPE_ALERT;
// The callback provided for when the dialog is closed. Usually the dialog
// itself calls it, but in the cases where the dialog is closed not by the
// user's input but by a call to |CloseDialog|, this class will call it.
......
......@@ -22249,6 +22249,12 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary>
</histogram>
<histogram name="JSDialogs.DismissalCause"
enum="JavaScriptDialogDismissalCause">
<owner>avi@chromium.org</owner>
<summary>The cause of dismissal of JavaScript dialogs.</summary>
</histogram>
<histogram
name="JSDialogs.FineTiming.TimeBetweenDialogClosedAndNextDialogCreated"
units="ms">
......@@ -90482,6 +90488,22 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
<int value="7" label="VideoCaptureStream"/>
</enum>
<enum name="JavaScriptDialogDismissalCause" type="int">
<int value="0" label="Tab closed">The tab owning the dialog was closed</int>
<int value="1" label="New dialog">
A new dialog was shown, closing the existing dialog
</int>
<int value="2" label="HandleDialog">HandleJavaScriptDialog was called</int>
<int value="3" label="CancelDialog">CancelDialogs was called</int>
<int value="4" label="Tab hidden">The tab owning the dialog was hidden</int>
<int value="5" label="Browser switched">
The browser owning the dialog was deactivated
</int>
<int value="6" label="Button click">
The user clicked on the OK or Cancel button
</int>
</enum>
<enum name="JumplisticonsfolderCategory" type="int">
<int value="0" label="Del Succeed - Mov Succeed - Create Succeed"/>
<int value="1" label="Del Fail - Mov Succeed - Create Succeed"/>
......@@ -108648,6 +108670,7 @@ value.
<suffix name="Alert"/>
<suffix name="Confirm"/>
<suffix name="Prompt"/>
<affected-histogram name="JSDialogs.DismissalCause"/>
<affected-histogram name="JSDialogs.IsForemost"/>
<affected-histogram name="JSDialogs.SiteEngagementOfDialogs"/>
</histogram_suffixes>
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