Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2757)

Unified Diff: chrome/browser/page_load_metrics/page_load_metrics_util.cc

Issue 2699933003: Generalize abort tracking to page end state tracking (Closed)
Patch Set: fix comment Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
« no previous file with comments | « chrome/browser/page_load_metrics/page_load_metrics_util.h ('k') | chrome/browser/page_load_metrics/page_load_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698