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

Unified Diff: components/page_load_metrics/browser/metrics_web_contents_observer.h

Issue 1357403003: Separate page load metrics for backgrounded pages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Can't record raw delta before we have nav_start. Be more lazy. Created 5 years, 3 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: components/page_load_metrics/browser/metrics_web_contents_observer.h
diff --git a/components/page_load_metrics/browser/metrics_web_contents_observer.h b/components/page_load_metrics/browser/metrics_web_contents_observer.h
index 5fa52c00a18fa2f0cc740c3c6770c23e21d0ca40..a0e2fdd64640e44ba3d9151ab0ea54b21aa4f3ef 100644
--- a/components/page_load_metrics/browser/metrics_web_contents_observer.h
+++ b/components/page_load_metrics/browser/metrics_web_contents_observer.h
@@ -5,6 +5,7 @@
#ifndef COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSERVER_H_
#define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSERVER_H_
+#include "base/containers/scoped_ptr_map.h"
#include "base/macros.h"
#include "base/time/time.h"
#include "components/page_load_metrics/common/page_load_timing.h"
@@ -23,6 +24,33 @@ class Message;
namespace page_load_metrics {
+class PageLoadTracker {
+ public:
+ PageLoadTracker(bool in_foreground);
Bryan McQuade 2015/09/29 00:32:19 nit: single-arg constructor should be explicit
Charlie Harrison 2015/09/29 14:13:07 Done.
+ ~PageLoadTracker();
+ void Commit();
+ void WebContentsHidden();
+
+ // Returns true if the timing was successfully updated.
+ bool UpdateTiming(const PageLoadTiming& timing);
+
+ private:
+ void RecordTimingHistograms();
+
+ bool has_commit_;
+
+ // Initialize |background_time_| to TimeDelta::Max() so that we can see if an
+ // event happened before a background by a simple < comparison. This will work
+ // even if the page was never backgrounded. We record separate metrics for
+ // any web contents that have been backgrounded, because metrics like
+ // layout/paint are delayed artificially when they occur in the bacground.
+ base::Time background_time_;
Bryan McQuade 2015/09/29 00:32:19 let's use a TimeTicks here, just to be clear that
Charlie Harrison 2015/09/29 14:13:07 Done.
+
+ PageLoadTiming timing_;
+
+ DISALLOW_COPY_AND_ASSIGN(PageLoadTracker);
+};
+
// MetricsWebContentsObserver logs page load UMA metrics based on
// IPC messages received from a MetricsRenderFrameObserver.
class MetricsWebContentsObserver
@@ -36,7 +64,11 @@ class MetricsWebContentsObserver
content::RenderFrameHost* render_frame_host) override;
void DidFinishNavigation(
content::NavigationHandle* navigation_handle) override;
- void RenderProcessGone(base::TerminationStatus status) override;
+ void DidStartNavigation(
Bryan McQuade 2015/09/29 00:32:19 let's move DidStartNavigation's decl above DidFini
Charlie Harrison 2015/09/29 14:13:07 Done.
+ content::NavigationHandle* navigation_handle) override;
+
+ void WasShown() override;
+ void WasHidden() override;
private:
explicit MetricsWebContentsObserver(content::WebContents* web_contents);
@@ -44,13 +76,19 @@ class MetricsWebContentsObserver
friend class MetricsWebContentsObserverTest;
void OnTimingUpdated(content::RenderFrameHost*, const PageLoadTiming& timing);
- void RecordTimingHistograms();
bool IsRelevantNavigation(content::NavigationHandle* navigation_handle);
- // Will be null before any navigations have committed. When a navigation
- // commits we will initialize this as empty.
- scoped_ptr<PageLoadTiming> current_timing_;
+ // True if the web contents is currently in the foreground.
+ bool in_foreground_;
+
+ // This map tracks all of the navigations ongoing that are not committed
+ // yet. Once a navigation is committed, it moves from the map to
+ // committed_load_. Note that a PageLoadTrackers NavigationHandle is only
+ // valid until commit time, when we remove it from the map.
+ base::ScopedPtrMap<content::NavigationHandle*, scoped_ptr<PageLoadTracker>>
+ provisional_loads_;
+ scoped_ptr<PageLoadTracker> committed_load_;
DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver);
};

Powered by Google App Engine
This is Rietveld 408576698