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

Side by Side Diff: components/page_load_metrics/browser/page_load_metrics_observer.h

Issue 1473153002: PageLoadMetricsObservers observe individual page loads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Randy/Bryan review: needed to revert ~MWCO destructor for lifecycle reasons Created 5 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_OBSERVER_H_ 5 #ifndef COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_OBSERVER_H_
6 #define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_OBSERVER_H_ 6 #define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_OBSERVER_H_
7 7
8 #include "base/macros.h"
8 #include "components/page_load_metrics/common/page_load_timing.h" 9 #include "components/page_load_metrics/common/page_load_timing.h"
9 #include "content/public/browser/navigation_handle.h" 10 #include "content/public/browser/navigation_handle.h"
10 11
11 namespace page_load_metrics { 12 namespace page_load_metrics {
12 13
13 struct PageLoadExtraInfo { 14 struct PageLoadExtraInfo {
14 PageLoadExtraInfo(const base::TimeDelta& first_background_time, 15 PageLoadExtraInfo(const base::TimeDelta& first_background_time,
15 const base::TimeDelta& first_foreground_time, 16 const base::TimeDelta& first_foreground_time,
16 bool started_in_foreground); 17 bool started_in_foreground,
18 bool has_commit);
17 19
18 // Returns the time to first background if the page load started in the 20 // Returns the time to first background if the page load started in the
19 // foreground. If the page has not been backgrounded, or the page started in 21 // foreground. If the page has not been backgrounded, or the page started in
20 // the background, this will be base::TimeDelta(). 22 // the background, this will be base::TimeDelta().
21 const base::TimeDelta first_background_time; 23 const base::TimeDelta first_background_time;
22 24
23 // Returns the time to first foreground if the page load started in the 25 // Returns the time to first foreground if the page load started in the
24 // background. If the page has not been foregrounded, or the page started in 26 // background. If the page has not been foregrounded, or the page started in
25 // the foreground, this will be base::TimeDelta(). 27 // the foreground, this will be base::TimeDelta().
26 const base::TimeDelta first_foreground_time; 28 const base::TimeDelta first_foreground_time;
27 29
28 // True if the page load started in the foreground. 30 // True if the page load started in the foreground.
29 const bool started_in_foreground; 31 const bool started_in_foreground;
32
33 // True if the page load committed and received its first bytes of data.
34 const bool has_commit;
30 }; 35 };
31 36
32 // Interface for PageLoadMetrics observers. Note that it might be possible for 37 // Interface for PageLoadMetrics observers. All instances of this class are
33 // OnCommit to be fired without a subsequent OnComplete (i.e. if an error 38 // owned by the PageLoadTracker tracking a page load. They will be deleted after
34 // occurs or we don't have any metrics to log). PageLoadMetricsObservers are 39 // calling OnComplete.
35 // required to stop observing (call PageLoadMetricsObservable::RemoveObserver)
36 // some time before the OnPageLoadMetricsGoingAway trigger finishes. If this
37 // class is destroyed before the PageLoadMetricsObservable, it should call
38 // RemoveObserver in its destructor.
39 class PageLoadMetricsObserver { 40 class PageLoadMetricsObserver {
40 public: 41 public:
41 virtual ~PageLoadMetricsObserver() {} 42 virtual ~PageLoadMetricsObserver() {}
42 43
44 // The page load started, with the given navigation handle.
45 virtual void OnStart(content::NavigationHandle* navigation_handle) {}
46
43 // OnRedirect is triggered when a page load redirects to another URL. 47 // OnRedirect is triggered when a page load redirects to another URL.
44 // The navigation handle holds relevant data for the navigation, but will 48 // The navigation handle holds relevant data for the navigation, but will
45 // be destroyed soon after this call. Don't hold a reference to it. 49 // be destroyed soon after this call. Don't hold a reference to it. This can
50 // be called multiple times.
46 virtual void OnRedirect(content::NavigationHandle* navigation_handle) {} 51 virtual void OnRedirect(content::NavigationHandle* navigation_handle) {}
47 52
48 // OnCommit is triggered when a page load commits, i.e. when we receive the 53 // OnCommit is triggered when a page load commits, i.e. when we receive the
49 // first data for the request. The navigation handle holds relevant data for 54 // first data for the request. The navigation handle holds relevant data for
50 // the navigation, but will be destroyed soon after this call. Don't hold a 55 // the navigation, but will be destroyed soon after this call. Don't hold a
51 // reference to it. 56 // reference to it.
52 virtual void OnCommit(content::NavigationHandle* navigation_handle) {} 57 virtual void OnCommit(content::NavigationHandle* navigation_handle) {}
53 58
54 // OnComplete is triggered when we are ready to record metrics for this page 59 // OnComplete is triggered when we are ready to record metrics for this page
55 // load. This will happen some time after commit, and will be triggered as 60 // load. This will happen some time after commit. The PageLoadTiming struct
56 // long as we've received some data about the page load. The 61 // contains timing data and the PageLoadExtraInfo struct contains other useful
57 // PageLoadTiming struct contains timing data and the PageLoadExtraInfo struct 62 // data collected over the course of the page load. If the load did not
58 // contains other useful information about the tab backgrounding/foregrounding 63 // receive any timing information, |timing.IsEmpty()| will be true.
59 // over the course of the page load. 64 // After this call, the object will be deleted.
60 virtual void OnComplete(const PageLoadTiming& timing, 65 virtual void OnComplete(const PageLoadTiming& timing,
61 const PageLoadExtraInfo& extra_info) {} 66 const PageLoadExtraInfo& extra_info) {}
62
63 // This is called when the WebContents we are observing is tearing down. No
64 // further callbacks will be triggered.
65 virtual void OnPageLoadMetricsGoingAway() {}
66 };
67
68 // Class which handles notifying observers when loads commit and complete. It
69 // must call OnPageLoadMetricsGoingAway in the destructor.
70 class PageLoadMetricsObservable {
71 public:
72 virtual ~PageLoadMetricsObservable() {}
73 virtual void AddObserver(PageLoadMetricsObserver* observer) = 0;
74 virtual void RemoveObserver(PageLoadMetricsObserver* observer) = 0;
75 }; 67 };
76 68
77 } // namespace page_load_metrics 69 } // namespace page_load_metrics
78 70
79 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_OBSERVER_H_ 71 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698