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

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: Observe on creation 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
14 class PageLoadMetricsObservable;
15
13 struct PageLoadExtraInfo { 16 struct PageLoadExtraInfo {
14 PageLoadExtraInfo(const base::TimeDelta& first_background_time, 17 PageLoadExtraInfo(const base::TimeDelta& first_background_time,
15 const base::TimeDelta& first_foreground_time, 18 const base::TimeDelta& first_foreground_time,
16 bool started_in_foreground); 19 bool started_in_foreground,
20 bool has_commit);
17 21
18 // Returns the time to first background if the page load started in the 22 // 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 23 // foreground. If the page has not been backgrounded, or the page started in
20 // the background, this will be base::TimeDelta(). 24 // the background, this will be base::TimeDelta().
21 const base::TimeDelta first_background_time; 25 const base::TimeDelta first_background_time;
22 26
23 // Returns the time to first foreground if the page load started in the 27 // 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 28 // background. If the page has not been foregrounded, or the page started in
25 // the foreground, this will be base::TimeDelta(). 29 // the foreground, this will be base::TimeDelta().
26 const base::TimeDelta first_foreground_time; 30 const base::TimeDelta first_foreground_time;
27 31
28 // True if the page load started in the foreground. 32 // True if the page load started in the foreground.
29 const bool started_in_foreground; 33 const bool started_in_foreground;
34
35 // True if the page load committed and received its first bytes of data.
36 const bool has_commit;
30 }; 37 };
31 38
32 // Interface for PageLoadMetrics observers. Note that it might be possible for 39 // Interface for PageLoadMetrics observers.
33 // OnCommit to be fired without a subsequent OnComplete (i.e. if an error
34 // occurs or we don't have any metrics to log). PageLoadMetricsObservers are
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:
42 // This constructor will add the object as an observable to the passed in
Randy Smith (Not in Mondays) 2015/11/28 22:03:14 nit: "observable" -> "observer"?
Charlie Harrison 2015/11/30 16:39:29 Done.
43 // observable.
44 explicit PageLoadMetricsObserver(PageLoadMetricsObservable* observable);
45
41 virtual ~PageLoadMetricsObserver() {} 46 virtual ~PageLoadMetricsObserver() {}
42 47
48 // The page load started, with the given navigation handle.
49 virtual void OnStart(content::NavigationHandle* navigation_handle) {}
50
43 // OnRedirect is triggered when a page load redirects to another URL. 51 // OnRedirect is triggered when a page load redirects to another URL.
44 // The navigation handle holds relevant data for the navigation, but will 52 // 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. 53 // be destroyed soon after this call. Don't hold a reference to it. This can
54 // be called multiple times.
46 virtual void OnRedirect(content::NavigationHandle* navigation_handle) {} 55 virtual void OnRedirect(content::NavigationHandle* navigation_handle) {}
47 56
48 // OnCommit is triggered when a page load commits, i.e. when we receive the 57 // 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 58 // 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 59 // the navigation, but will be destroyed soon after this call. Don't hold a
51 // reference to it. 60 // reference to it.
52 virtual void OnCommit(content::NavigationHandle* navigation_handle) {} 61 virtual void OnCommit(content::NavigationHandle* navigation_handle) {}
53 62
54 // OnComplete is triggered when we are ready to record metrics for this page 63 // 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 64 // load. This will happen some time after commit, the PageLoadTiming struct
Randy Smith (Not in Mondays) 2015/11/28 22:03:14 nit: I think this is better as two separate senten
Charlie Harrison 2015/11/30 16:39:29 Done.
56 // long as we've received some data about the page load. The 65 // contains timing data and the PageLoadExtraInfo struct contains other useful
57 // PageLoadTiming struct contains timing data and the PageLoadExtraInfo struct 66 // data collected over the course of the page load. If the load did not
58 // contains other useful information about the tab backgrounding/foregrounding 67 // receive any timing information, |timing.IsEmpty()| will be true.
59 // over the course of the page load. 68 // OnPageLoadMetricsGoingAway will be called after OnComplete.
60 virtual void OnComplete(const PageLoadTiming& timing, 69 virtual void OnComplete(const PageLoadTiming& timing,
61 const PageLoadExtraInfo& extra_info) {} 70 const PageLoadExtraInfo& extra_info) {}
62 71
63 // This is called when the WebContents we are observing is tearing down. No 72 // This is called when the metrics we are observing is tearing down. No
Randy Smith (Not in Mondays) 2015/11/28 22:03:14 nit: "the metrics ... is" reads funny in English.
Charlie Harrison 2015/11/30 16:39:29 Done.
64 // further callbacks will be triggered. 73 // further callbacks will be triggered. If your object has longer lifetime
Randy Smith (Not in Mondays) 2015/11/28 22:03:14 nit: "Your" is problematic for the same reason as
Charlie Harrison 2015/11/30 16:39:29 Done.
65 virtual void OnPageLoadMetricsGoingAway() {} 74 // than the observable, override this method and call RemoveObserver() by this
Randy Smith (Not in Mondays) 2015/11/28 22:03:14 nit: "*it should* override this method and call Re
Charlie Harrison 2015/11/30 16:39:29 Done.
75 // point.
76 virtual void OnPageLoadMetricsGoingAway();
77
78 // Call this if the object will start observing after its construction time.
79 void Observe(PageLoadMetricsObservable* observable);
Randy Smith (Not in Mondays) 2015/11/28 22:03:14 I don't see this ever being called; why does it ex
Charlie Harrison 2015/11/30 16:39:29 This exists for consumers who want to observe with
Randy Smith (Not in Mondays) 2015/12/01 22:34:03 Yeah, if you would. I'm afraid I'm one of those
80
81 PageLoadMetricsObservable* GetObservable() { return observable_; }
82
83 private:
84 PageLoadMetricsObservable* observable_;
85 DISALLOW_COPY_AND_ASSIGN(PageLoadMetricsObserver);
66 }; 86 };
67 87
68 // Class which handles notifying observers when loads commit and complete. It 88 // Class which handles notifying observers when loads commit and complete.
69 // must call OnPageLoadMetricsGoingAway in the destructor.
70 class PageLoadMetricsObservable { 89 class PageLoadMetricsObservable {
71 public: 90 public:
72 virtual ~PageLoadMetricsObservable() {} 91 virtual ~PageLoadMetricsObservable() {}
73 virtual void AddObserver(PageLoadMetricsObserver* observer) = 0; 92 virtual void AddObserver(PageLoadMetricsObserver* observer) = 0;
74 virtual void RemoveObserver(PageLoadMetricsObserver* observer) = 0; 93 virtual void RemoveObserver(PageLoadMetricsObserver* observer) = 0;
75 }; 94 };
76 95
77 } // namespace page_load_metrics 96 } // namespace page_load_metrics
78 97
79 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_OBSERVER_H_ 98 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698