Index: components/page_load_metrics/browser/page_load_metrics_observer.h |
diff --git a/components/page_load_metrics/browser/page_load_metrics_observer.h b/components/page_load_metrics/browser/page_load_metrics_observer.h |
index 08a35dddc2fc226a29ea57a2e5b701983cda9031..dddfb823179542be103f0cad7af6189d2699f13a 100644 |
--- a/components/page_load_metrics/browser/page_load_metrics_observer.h |
+++ b/components/page_load_metrics/browser/page_load_metrics_observer.h |
@@ -5,6 +5,7 @@ |
#ifndef COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_OBSERVER_H_ |
#define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_OBSERVER_H_ |
+#include "base/macros.h" |
#include "components/page_load_metrics/common/page_load_timing.h" |
#include "content/public/browser/navigation_handle.h" |
@@ -13,7 +14,8 @@ namespace page_load_metrics { |
struct PageLoadExtraInfo { |
PageLoadExtraInfo(const base::TimeDelta& first_background_time, |
const base::TimeDelta& first_foreground_time, |
- bool started_in_foreground); |
+ bool started_in_foreground, |
+ bool has_commit); |
// Returns the time to first background if the page load started in the |
// foreground. If the page has not been backgrounded, or the page started in |
@@ -27,22 +29,25 @@ struct PageLoadExtraInfo { |
// True if the page load started in the foreground. |
const bool started_in_foreground; |
+ |
+ // True if the page load committed and received its first bytes of data. |
+ const bool has_commit; |
}; |
-// Interface for PageLoadMetrics observers. Note that it might be possible for |
-// OnCommit to be fired without a subsequent OnComplete (i.e. if an error |
-// occurs or we don't have any metrics to log). PageLoadMetricsObservers are |
-// required to stop observing (call PageLoadMetricsObservable::RemoveObserver) |
-// some time before the OnPageLoadMetricsGoingAway trigger finishes. If this |
-// class is destroyed before the PageLoadMetricsObservable, it should call |
-// RemoveObserver in its destructor. |
+// Interface for PageLoadMetrics observers. All instances of this class are |
+// owned by the PageLoadTracker tracking a page load. They will be deleted after |
+// calling OnComplete. |
class PageLoadMetricsObserver { |
public: |
virtual ~PageLoadMetricsObserver() {} |
+ // The page load started, with the given navigation handle. |
+ virtual void OnStart(content::NavigationHandle* navigation_handle) {} |
+ |
// OnRedirect is triggered when a page load redirects to another URL. |
// The navigation handle holds relevant data for the navigation, but will |
- // be destroyed soon after this call. Don't hold a reference to it. |
+ // be destroyed soon after this call. Don't hold a reference to it. This can |
+ // be called multiple times. |
virtual void OnRedirect(content::NavigationHandle* navigation_handle) {} |
// OnCommit is triggered when a page load commits, i.e. when we receive the |
@@ -52,26 +57,13 @@ class PageLoadMetricsObserver { |
virtual void OnCommit(content::NavigationHandle* navigation_handle) {} |
// OnComplete is triggered when we are ready to record metrics for this page |
- // load. This will happen some time after commit, and will be triggered as |
- // long as we've received some data about the page load. The |
- // PageLoadTiming struct contains timing data and the PageLoadExtraInfo struct |
- // contains other useful information about the tab backgrounding/foregrounding |
- // over the course of the page load. |
+ // load. This will happen some time after commit. The PageLoadTiming struct |
+ // contains timing data and the PageLoadExtraInfo struct contains other useful |
+ // data collected over the course of the page load. If the load did not |
+ // receive any timing information, |timing.IsEmpty()| will be true. |
+ // After this call, the object will be deleted. |
virtual void OnComplete(const PageLoadTiming& timing, |
const PageLoadExtraInfo& extra_info) {} |
- |
- // This is called when the WebContents we are observing is tearing down. No |
- // further callbacks will be triggered. |
- virtual void OnPageLoadMetricsGoingAway() {} |
-}; |
- |
-// Class which handles notifying observers when loads commit and complete. It |
-// must call OnPageLoadMetricsGoingAway in the destructor. |
-class PageLoadMetricsObservable { |
- public: |
- virtual ~PageLoadMetricsObservable() {} |
- virtual void AddObserver(PageLoadMetricsObserver* observer) = 0; |
- virtual void RemoveObserver(PageLoadMetricsObserver* observer) = 0; |
}; |
} // namespace page_load_metrics |