OLD | NEW |
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 "base/macros.h" |
9 #include "base/optional.h" | 9 #include "base/optional.h" |
10 #include "components/page_load_metrics/common/page_load_timing.h" | 10 #include "components/page_load_metrics/common/page_load_timing.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 // aborted, |abort_type| will be |ABORT_NONE|. | 85 // aborted, |abort_type| will be |ABORT_NONE|. |
86 const UserAbortType abort_type; | 86 const UserAbortType abort_type; |
87 const base::Optional<base::TimeDelta> time_to_abort; | 87 const base::Optional<base::TimeDelta> time_to_abort; |
88 | 88 |
89 // Extra information supplied to the page load metrics system from the | 89 // Extra information supplied to the page load metrics system from the |
90 // renderer. | 90 // renderer. |
91 const PageLoadMetadata metadata; | 91 const PageLoadMetadata metadata; |
92 }; | 92 }; |
93 | 93 |
94 // Interface for PageLoadMetrics observers. All instances of this class are | 94 // Interface for PageLoadMetrics observers. All instances of this class are |
95 // owned by the PageLoadTracker tracking a page load. They will be deleted after | 95 // owned by the PageLoadTracker tracking a page load. |
96 // calling OnComplete. | |
97 class PageLoadMetricsObserver { | 96 class PageLoadMetricsObserver { |
98 public: | 97 public: |
99 virtual ~PageLoadMetricsObserver() {} | 98 virtual ~PageLoadMetricsObserver() {} |
100 | 99 |
101 // The page load started, with the given navigation handle. Note that OnStart | 100 // The page load started, with the given navigation handle. Note that OnStart |
102 // is called for same-page navigations. Implementers of OnStart that only want | 101 // is called for same-page navigations. Implementers of OnStart that only want |
103 // to process non-same-page navigations should also check to see that the page | 102 // to process non-same-page navigations should also check to see that the page |
104 // load committed via OnCommit or committed_url in | 103 // load committed via OnCommit or committed_url in |
105 // PageLoadExtraInfo. currently_committed_url contains the URL of the | 104 // PageLoadExtraInfo. currently_committed_url contains the URL of the |
106 // committed page load at the time the navigation for navigation_handle was | 105 // committed page load at the time the navigation for navigation_handle was |
(...skipping 15 matching lines...) Expand all Loading... |
122 // reference to it. | 121 // reference to it. |
123 // Note that this does not get called for same page navigations. | 122 // Note that this does not get called for same page navigations. |
124 virtual void OnCommit(content::NavigationHandle* navigation_handle) {} | 123 virtual void OnCommit(content::NavigationHandle* navigation_handle) {} |
125 | 124 |
126 // OnFailedProvisionalLoad is triggered when a provisional load failed and did | 125 // OnFailedProvisionalLoad is triggered when a provisional load failed and did |
127 // not commit. Note that provisional loads that result in downloads or 204s | 126 // not commit. Note that provisional loads that result in downloads or 204s |
128 // are aborted by the system, and thus considered failed provisional loads. | 127 // are aborted by the system, and thus considered failed provisional loads. |
129 virtual void OnFailedProvisionalLoad( | 128 virtual void OnFailedProvisionalLoad( |
130 content::NavigationHandle* navigation_handle) {} | 129 content::NavigationHandle* navigation_handle) {} |
131 | 130 |
132 // OnTimingUpdate is triggered when an updated PageLoadTiming is | |
133 // available. This method may be called multiple times over the course of the | |
134 // page load. Note that this is currently an experimental API which may be | |
135 // removed in the future. Please email loading-dev@chromium.org if you intend | |
136 // to override this method. | |
137 virtual void OnTimingUpdate(const PageLoadTiming& timing, | |
138 const PageLoadExtraInfo& extra_info) {} | |
139 | |
140 // OnHidden is triggered when a page leaves the foreground. It does not fire | 131 // OnHidden is triggered when a page leaves the foreground. It does not fire |
141 // when a foreground page is permanently closed; for that, listen to | 132 // when a foreground page is permanently closed; for that, listen to |
142 // OnComplete instead. | 133 // OnComplete instead. |
143 virtual void OnHidden() {} | 134 virtual void OnHidden() {} |
144 | 135 |
145 // OnShown is triggered when a page is brought to the foreground. It does not | 136 // OnShown is triggered when a page is brought to the foreground. It does not |
146 // fire when the page first loads; for that, listen for OnStart instead. | 137 // fire when the page first loads; for that, listen for OnStart instead. |
147 virtual void OnShown() {} | 138 virtual void OnShown() {} |
148 | 139 |
149 // OnComplete is triggered when we are ready to record metrics for this page | 140 // The callbacks below are only invoked after a navigation commits, for |
150 // load. This will happen some time after commit. The PageLoadTiming struct | 141 // tracked page loads. Page loads that don't meet the criteria for being |
151 // contains timing data and the PageLoadExtraInfo struct contains other useful | 142 // tracked at the time a navigation commits will not receive any of the |
152 // data collected over the course of the page load. If the load did not | 143 // callbacks below. |
153 // receive any timing information, |timing.IsEmpty()| will be true. | 144 |
154 // After this call, the object will be deleted. | 145 // OnTimingUpdate is triggered when an updated PageLoadTiming is |
155 virtual void OnComplete(const PageLoadTiming& timing, | 146 // available. This method may be called multiple times over the course of the |
156 const PageLoadExtraInfo& extra_info) {} | 147 // page load. This method is currently only intended for use in testing. Most |
| 148 // implementers should implement one of the On* callbacks, such as |
| 149 // OnFirstContentfulPaint or OnDomContentLoadedEventStart. Please email |
| 150 // loading-dev@chromium.org if you intend to override this method. |
| 151 virtual void OnTimingUpdate(const PageLoadTiming& timing, |
| 152 const PageLoadExtraInfo& extra_info) {} |
157 | 153 |
158 // OnUserInput is triggered when a new user input is passed in to | 154 // OnUserInput is triggered when a new user input is passed in to |
159 // web_contents. Contains a TimeDelta from navigation start. | 155 // web_contents. Contains a TimeDelta from navigation start. |
160 virtual void OnUserInput(const blink::WebInputEvent& event) {} | 156 virtual void OnUserInput(const blink::WebInputEvent& event) {} |
161 | 157 |
162 // The following methods are invoked at most once, when the timing for the | 158 // The following methods are invoked at most once, when the timing for the |
163 // associated event first becomes available. | 159 // associated event first becomes available. |
164 virtual void OnDomContentLoadedEventStart( | 160 virtual void OnDomContentLoadedEventStart( |
165 const PageLoadTiming& timing, | 161 const PageLoadTiming& timing, |
166 const PageLoadExtraInfo& extra_info) {} | 162 const PageLoadExtraInfo& extra_info) {} |
(...skipping 11 matching lines...) Expand all Loading... |
178 const PageLoadExtraInfo& extra_info) {} | 174 const PageLoadExtraInfo& extra_info) {} |
179 virtual void OnParseStart(const PageLoadTiming& timing, | 175 virtual void OnParseStart(const PageLoadTiming& timing, |
180 const PageLoadExtraInfo& extra_info) {} | 176 const PageLoadExtraInfo& extra_info) {} |
181 virtual void OnParseStop(const PageLoadTiming& timing, | 177 virtual void OnParseStop(const PageLoadTiming& timing, |
182 const PageLoadExtraInfo& extra_info) {} | 178 const PageLoadExtraInfo& extra_info) {} |
183 | 179 |
184 // Observer method to be invoked when there is a change in PageLoadMetadata's | 180 // Observer method to be invoked when there is a change in PageLoadMetadata's |
185 // behavior_flags. | 181 // behavior_flags. |
186 virtual void OnLoadingBehaviorObserved( | 182 virtual void OnLoadingBehaviorObserved( |
187 const page_load_metrics::PageLoadExtraInfo& extra_info) {} | 183 const page_load_metrics::PageLoadExtraInfo& extra_info) {} |
| 184 |
| 185 // OnComplete is invoked for tracked page loads, immediately before the |
| 186 // observer is deleted. The PageLoadTiming struct contains timing data and |
| 187 // the PageLoadExtraInfo struct contains other useful data collected over the |
| 188 // course of the page load. Most observers should not need to implement this |
| 189 // method, and should implement the On* timing callbacks instead. |
| 190 virtual void OnComplete(const PageLoadTiming& timing, |
| 191 const PageLoadExtraInfo& extra_info) {} |
188 }; | 192 }; |
189 | 193 |
190 } // namespace page_load_metrics | 194 } // namespace page_load_metrics |
191 | 195 |
192 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_OBSERVER_H_ | 196 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_OBSERVER_H_ |
OLD | NEW |