| Index: chrome/browser/page_load_metrics/page_load_metrics_util.cc
|
| diff --git a/chrome/browser/page_load_metrics/page_load_metrics_util.cc b/chrome/browser/page_load_metrics/page_load_metrics_util.cc
|
| index 1203a2d778bb074ecbe03490806d22ab957e0472..1449f5c5e0be59d870c31770aee9e67518a7db42 100644
|
| --- a/chrome/browser/page_load_metrics/page_load_metrics_util.cc
|
| +++ b/chrome/browser/page_load_metrics/page_load_metrics_util.cc
|
| @@ -6,11 +6,43 @@
|
|
|
| #include <algorithm>
|
|
|
| -#include "chrome/browser/page_load_metrics/page_load_metrics_observer.h"
|
| #include "chrome/common/page_load_metrics/page_load_timing.h"
|
|
|
| namespace page_load_metrics {
|
|
|
| +namespace {
|
| +
|
| +bool IsBackgroundAbort(const PageLoadExtraInfo& info) {
|
| + if (!info.started_in_foreground || !info.first_background_time)
|
| + return false;
|
| +
|
| + if (!info.page_end_time)
|
| + return true;
|
| +
|
| + return info.first_background_time <= info.page_end_time;
|
| +}
|
| +
|
| +PageAbortReason GetAbortReasonForEndReason(PageEndReason end_reason) {
|
| + switch (end_reason) {
|
| + case END_RELOAD:
|
| + return ABORT_RELOAD;
|
| + case END_FORWARD_BACK:
|
| + return ABORT_FORWARD_BACK;
|
| + case END_NEW_NAVIGATION:
|
| + return ABORT_NEW_NAVIGATION;
|
| + case END_STOP:
|
| + return ABORT_STOP;
|
| + case END_CLOSE:
|
| + return ABORT_CLOSE;
|
| + case END_OTHER:
|
| + return ABORT_OTHER;
|
| + default:
|
| + return ABORT_NONE;
|
| + }
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| bool WasStartedInForegroundOptionalEventInForeground(
|
| const base::Optional<base::TimeDelta>& event,
|
| const PageLoadExtraInfo& info) {
|
| @@ -19,4 +51,23 @@ bool WasStartedInForegroundOptionalEventInForeground(
|
| event.value() <= info.first_background_time.value());
|
| }
|
|
|
| +PageAbortInfo GetPageAbortInfo(const PageLoadExtraInfo& info) {
|
| + if (IsBackgroundAbort(info)) {
|
| + // Though most cases where a tab is backgrounded are user initiated, we
|
| + // can't be certain that we were backgrounded due to a user action. For
|
| + // example, on Android, the screen times out after a period of inactivity,
|
| + // resulting in a non-user-initiated backgrounding.
|
| + return {ABORT_BACKGROUND, UserInitiatedInfo::NotUserInitiated(),
|
| + info.first_background_time.value()};
|
| + }
|
| +
|
| + PageAbortReason abort_reason =
|
| + GetAbortReasonForEndReason(info.page_end_reason);
|
| + if (abort_reason == ABORT_NONE)
|
| + return PageAbortInfo();
|
| +
|
| + return {abort_reason, info.page_end_user_initiated_info,
|
| + info.page_end_time.value()};
|
| +}
|
| +
|
| } // namespace page_load_metrics
|
|
|