Skip to content

Commit

Permalink
[blink] Record beforeunload metrics using //base/metrics helpers.
Browse files Browse the repository at this point in the history
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: Nate Chapin <japhet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822195}
  • Loading branch information
zetafunction authored and Commit Bot committed Oct 29, 2020
1 parent cd9219a commit e1b75a4
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions third_party/blink/renderer/core/dom/document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

#include "base/auto_reset.h"
#include "base/macros.h"
#include "base/metrics/histogram_functions.h"
#include "base/optional.h"
#include "base/time/time.h"
#include "cc/input/overscroll_behavior.h"
Expand Down Expand Up @@ -3995,6 +3996,23 @@ bool Document::CheckCompletedInternal() {
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 is_reload,
bool& did_allow_navigation) {
Expand Down Expand Up @@ -4033,24 +4051,14 @@ bool Document::DispatchBeforeUnloadEvent(ChromeClient* chrome_client,
if (!before_unload_event.defaultPrevented())
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()) {
beforeunload_dialog_histogram.Count(kNoDialogNoText);
RecordBeforeUnloadUse(BeforeUnloadUse::kNoDialogNoText);
}
if (!GetFrame() || before_unload_event.returnValue().IsNull())
return true;

if (!GetFrame()->HasStickyUserActivation()) {
beforeunload_dialog_histogram.Count(kNoDialogNoUserGesture);
RecordBeforeUnloadUse(BeforeUnloadUse::kNoDialogNoUserGesture);
String message =
"Blocked attempt to show a 'beforeunload' confirmation panel for a "
"frame that never had a user gesture since its load. "
Expand All @@ -4060,8 +4068,8 @@ bool Document::DispatchBeforeUnloadEvent(ChromeClient* chrome_client,
}

if (did_allow_navigation) {
beforeunload_dialog_histogram.Count(
kNoDialogMultipleConfirmationForNavigation);
RecordBeforeUnloadUse(
BeforeUnloadUse::kNoDialogMultipleConfirmationForNavigation);
String message =
"Blocked attempt to show multiple 'beforeunload' confirmation panels "
"for a single navigation.";
Expand All @@ -4072,14 +4080,13 @@ bool Document::DispatchBeforeUnloadEvent(ChromeClient* chrome_client,
// If |chrome_client| is null simply indicate that the navigation should
// not proceed.
if (!chrome_client) {
beforeunload_dialog_histogram.Count(kNoDialogAutoCancelTrue);
RecordBeforeUnloadUse(BeforeUnloadUse::kNoDialogAutoCancelTrue);
did_allow_navigation = false;
return false;
}

String text = before_unload_event.returnValue();
beforeunload_dialog_histogram.Count(
BeforeUnloadDialogHistogramEnum::kShowDialog);
RecordBeforeUnloadUse(BeforeUnloadUse::kShowDialog);
const base::TimeTicks beforeunload_confirmpanel_start =
base::TimeTicks::Now();
did_allow_navigation =
Expand Down

0 comments on commit e1b75a4

Please sign in to comment.