Commit e1b75a41 authored by Daniel Cheng's avatar Daniel Cheng Committed by Commit Bot

[blink] Record beforeunload metrics using //base/metrics helpers.

This also converts the recorded enum to be a scoped enum, which allows:

- clang to enforce kMaxValue correctness
- autodeduction of the max value by UMA_HISTOGRAM_ENUMERATION.

Bug: 742517, 1047547
Change-Id: Ib8acb900fd919945e220bae7f674ea57df062c86
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2506245
Auto-Submit: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Nate Chapin <japhet@chromium.org>
Reviewed-by: default avatarNate Chapin <japhet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822195}
parent cd9219ae
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "base/auto_reset.h" #include "base/auto_reset.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/metrics/histogram_functions.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "cc/input/overscroll_behavior.h" #include "cc/input/overscroll_behavior.h"
...@@ -3995,6 +3996,23 @@ bool Document::CheckCompletedInternal() { ...@@ -3995,6 +3996,23 @@ bool Document::CheckCompletedInternal() {
return true; return true;
} }
namespace {
enum class BeforeUnloadUse {
kNoDialogNoText,
kNoDialogNoUserGesture,
kNoDialogMultipleConfirmationForNavigation,
kShowDialog,
kNoDialogAutoCancelTrue,
kMaxValue = kNoDialogAutoCancelTrue,
};
void RecordBeforeUnloadUse(BeforeUnloadUse metric) {
base::UmaHistogramEnumeration("Document.BeforeUnloadDialog", metric);
}
} // namespace
bool Document::DispatchBeforeUnloadEvent(ChromeClient* chrome_client, bool Document::DispatchBeforeUnloadEvent(ChromeClient* chrome_client,
bool is_reload, bool is_reload,
bool& did_allow_navigation) { bool& did_allow_navigation) {
...@@ -4033,24 +4051,14 @@ bool Document::DispatchBeforeUnloadEvent(ChromeClient* chrome_client, ...@@ -4033,24 +4051,14 @@ bool Document::DispatchBeforeUnloadEvent(ChromeClient* chrome_client,
if (!before_unload_event.defaultPrevented()) if (!before_unload_event.defaultPrevented())
DefaultEventHandler(before_unload_event); DefaultEventHandler(before_unload_event);
enum BeforeUnloadDialogHistogramEnum {
kNoDialogNoText,
kNoDialogNoUserGesture,
kNoDialogMultipleConfirmationForNavigation,
kShowDialog,
kNoDialogAutoCancelTrue,
kDialogEnumMax
};
DEFINE_STATIC_LOCAL(EnumerationHistogram, beforeunload_dialog_histogram,
("Document.BeforeUnloadDialog", kDialogEnumMax));
if (before_unload_event.returnValue().IsNull()) { if (before_unload_event.returnValue().IsNull()) {
beforeunload_dialog_histogram.Count(kNoDialogNoText); RecordBeforeUnloadUse(BeforeUnloadUse::kNoDialogNoText);
} }
if (!GetFrame() || before_unload_event.returnValue().IsNull()) if (!GetFrame() || before_unload_event.returnValue().IsNull())
return true; return true;
if (!GetFrame()->HasStickyUserActivation()) { if (!GetFrame()->HasStickyUserActivation()) {
beforeunload_dialog_histogram.Count(kNoDialogNoUserGesture); RecordBeforeUnloadUse(BeforeUnloadUse::kNoDialogNoUserGesture);
String message = String message =
"Blocked attempt to show a 'beforeunload' confirmation panel for a " "Blocked attempt to show a 'beforeunload' confirmation panel for a "
"frame that never had a user gesture since its load. " "frame that never had a user gesture since its load. "
...@@ -4060,8 +4068,8 @@ bool Document::DispatchBeforeUnloadEvent(ChromeClient* chrome_client, ...@@ -4060,8 +4068,8 @@ bool Document::DispatchBeforeUnloadEvent(ChromeClient* chrome_client,
} }
if (did_allow_navigation) { if (did_allow_navigation) {
beforeunload_dialog_histogram.Count( RecordBeforeUnloadUse(
kNoDialogMultipleConfirmationForNavigation); BeforeUnloadUse::kNoDialogMultipleConfirmationForNavigation);
String message = String message =
"Blocked attempt to show multiple 'beforeunload' confirmation panels " "Blocked attempt to show multiple 'beforeunload' confirmation panels "
"for a single navigation."; "for a single navigation.";
...@@ -4072,14 +4080,13 @@ bool Document::DispatchBeforeUnloadEvent(ChromeClient* chrome_client, ...@@ -4072,14 +4080,13 @@ bool Document::DispatchBeforeUnloadEvent(ChromeClient* chrome_client,
// If |chrome_client| is null simply indicate that the navigation should // If |chrome_client| is null simply indicate that the navigation should
// not proceed. // not proceed.
if (!chrome_client) { if (!chrome_client) {
beforeunload_dialog_histogram.Count(kNoDialogAutoCancelTrue); RecordBeforeUnloadUse(BeforeUnloadUse::kNoDialogAutoCancelTrue);
did_allow_navigation = false; did_allow_navigation = false;
return false; return false;
} }
String text = before_unload_event.returnValue(); String text = before_unload_event.returnValue();
beforeunload_dialog_histogram.Count( RecordBeforeUnloadUse(BeforeUnloadUse::kShowDialog);
BeforeUnloadDialogHistogramEnum::kShowDialog);
const base::TimeTicks beforeunload_confirmpanel_start = const base::TimeTicks beforeunload_confirmpanel_start =
base::TimeTicks::Now(); base::TimeTicks::Now();
did_allow_navigation = did_allow_navigation =
......
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