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_WEB_CONTENTS_OBSE RVER_H_ | 5 #ifndef COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSE RVER_H_ |
6 #define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSE RVER_H_ | 6 #define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSE RVER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 // This event captures all the other ways a provisional load can fail. | 110 // This event captures all the other ways a provisional load can fail. |
111 PROVISIONAL_LOAD_ERR_FAILED_NON_ABORT, | 111 PROVISIONAL_LOAD_ERR_FAILED_NON_ABORT, |
112 | 112 |
113 // Counts the number of successful commits. | 113 // Counts the number of successful commits. |
114 PROVISIONAL_LOAD_COMMITTED, | 114 PROVISIONAL_LOAD_COMMITTED, |
115 | 115 |
116 // Add values before this final count. | 116 // Add values before this final count. |
117 PROVISIONAL_LOAD_LAST_ENTRY | 117 PROVISIONAL_LOAD_LAST_ENTRY |
118 }; | 118 }; |
119 | 119 |
120 // CommittedLoadEvents are events that occur on committed loads that we track. | 120 // CommittedRelevantLoadEvents are events that occur on committed loads that we |
Randy Smith (Not in Mondays)
2015/11/28 22:03:13
nit: There's a preference in the net stack for avo
Charlie Harrison
2015/11/30 16:39:29
Yupp. I'm trying to break the habit :P
Randy Smith (Not in Mondays)
2015/12/01 22:34:03
But you didn't change the comment; is the habit st
Charlie Harrison
2015/12/01 22:54:24
Oops :O fixed.
| |
121 // track. | |
121 // Note that we capture events only for committed loads that: | 122 // Note that we capture events only for committed loads that: |
122 // - Are http/https. | 123 // - Are http/https. |
123 // - Not same-page navigations. | 124 // - Not same-page navigations. |
124 // - Are not navigations to an error page. | 125 // - Are not navigations to an error page. |
125 // We only know these things about a navigation post-commit. | 126 // We only know these things about a navigation post-commit. |
126 // | 127 // |
127 // If you add elements to this enum, make sure you update the enum | 128 // If you add elements to this enum, make sure you update the enum |
128 // value in histograms.xml. Only add elements to the end to prevent | 129 // value in histograms.xml. Only add elements to the end to prevent |
129 // inconsistencies between versions. | 130 // inconsistencies between versions. |
130 enum CommittedLoadEvent { | 131 enum CommittedRelevantLoadEvent { |
131 // When a load that eventually commits started. Note we can't log this until | 132 // When a load that eventually commits started. Note we can't log this until |
132 // commit time, but it represents when the actual page load started. Thus, we | 133 // commit time, but it represents when the actual page load started. Thus, we |
133 // only separate this into .Background when a page load starts backgrounded. | 134 // only separate this into .Background when a page load starts backgrounded. |
134 COMMITTED_LOAD_STARTED, | 135 RELEVANT_LOAD_STARTED, |
135 | 136 |
136 // These two events are disjoint. Sum them to find the total number of | 137 // These two events are disjoint. Sum them to find the total number of |
137 // committed loads that we end up tracking. | 138 // committed loads that we end up tracking. |
138 COMMITTED_LOAD_FAILED_BEFORE_FIRST_LAYOUT, | 139 RELEVANT_LOAD_FAILED_BEFORE_FIRST_LAYOUT, |
139 COMMITTED_LOAD_SUCCESSFUL_FIRST_LAYOUT, | 140 RELEVANT_LOAD_SUCCESSFUL_FIRST_LAYOUT, |
140 | 141 |
141 // TODO(csharrison) once first paint metrics are in place, add new events. | 142 // TODO(csharrison) once first paint metrics are in place, add new events. |
142 | 143 |
143 // Add values before this final count. | 144 // Add values before this final count. |
144 COMMITTED_LOAD_LAST_ENTRY | 145 RELEVANT_LOAD_LAST_ENTRY |
145 }; | 146 }; |
146 | 147 |
147 // These errors are internal to the page_load_metrics subsystem and do not | 148 // These errors are internal to the page_load_metrics subsystem and do not |
148 // reflect actual errors that occur during a page load. | 149 // reflect actual errors that occur during a page load. |
149 // | 150 // |
150 // If you add elements to this enum, make sure you update the enum | 151 // If you add elements to this enum, make sure you update the enum |
151 // value in histograms.xml. Only add elements to the end to prevent | 152 // value in histograms.xml. Only add elements to the end to prevent |
152 // inconsistencies between versions. | 153 // inconsistencies between versions. |
153 enum InternalErrorLoadEvent { | 154 enum InternalErrorLoadEvent { |
154 // A timing IPC was sent from the renderer that did not line up with previous | 155 // A timing IPC was sent from the renderer that did not line up with previous |
155 // data we've received (i.e. navigation start is different or the timing | 156 // data we've received (i.e. navigation start is different or the timing |
156 // struct is somehow invalid). This error can only occur once the IPC is | 157 // struct is somehow invalid). This error can only occur once the IPC is |
157 // vetted in other ways (see other errors). | 158 // vetted in other ways (see other errors). |
158 ERR_BAD_TIMING_IPC, | 159 ERR_BAD_TIMING_IPC, |
159 | 160 |
160 // The following IPCs are not mutually exclusive. | 161 // The following IPCs are not mutually exclusive. |
161 // | 162 // |
162 // We received an IPC when we weren't tracking a committed load. This will | 163 // We received an IPC when we weren't tracking a committed load. This will |
163 // often happen if we get an IPC from a bad URL scheme (that is, the renderer | 164 // often happen if we get an IPC from a bad URL scheme (that is, the renderer |
164 // sent us an IPC from a navigation we don't care about). | 165 // sent us an IPC from a navigation we don't care about). |
165 ERR_IPC_WITH_NO_COMMITTED_LOAD, | 166 ERR_IPC_WITH_NO_RELEVANT_LOAD, |
166 | 167 |
167 // Received a notification from a frame that has been navigated away from. | 168 // Received a notification from a frame that has been navigated away from. |
168 ERR_IPC_FROM_WRONG_FRAME, | 169 ERR_IPC_FROM_WRONG_FRAME, |
169 | 170 |
170 // We received an IPC even through the last committed url from the browser | 171 // We received an IPC even through the last committed url from the browser |
171 // was not http/s. This can happen with the renderer sending IPCs for the | 172 // was not http/s. This can happen with the renderer sending IPCs for the |
172 // new tab page. This will often come paired with | 173 // new tab page. This will often come paired with |
173 // ERR_IPC_WITH_NO_COMMITTED_LOAD. | 174 // ERR_IPC_WITH_NO_RELEVANT_LOAD. |
174 ERR_IPC_FROM_BAD_URL_SCHEME, | 175 ERR_IPC_FROM_BAD_URL_SCHEME, |
175 | 176 |
176 // If we track a navigation, but the renderer sends us no IPCs. This could | 177 // If we track a navigation, but the renderer sends us no IPCs. This could |
177 // occur if the browser filters loads less aggressively than the renderer. | 178 // occur if the browser filters loads less aggressively than the renderer. |
178 ERR_NO_IPCS_RECEIVED, | 179 ERR_NO_IPCS_RECEIVED, |
179 | 180 |
180 // Add values before this final count. | 181 // Add values before this final count. |
181 ERR_LAST_ENTRY | 182 ERR_LAST_ENTRY |
182 }; | 183 }; |
183 | 184 |
184 // This class serves as a functional interface to various chrome// features. | 185 // This class serves as a functional interface to various chrome// features. |
185 // Impl version is defined in chrome/browser/page_load_metrics. | 186 // Impl version is defined in chrome/browser/page_load_metrics. |
186 class PageLoadMetricsEmbedderInterface { | 187 class PageLoadMetricsEmbedderInterface { |
187 public: | 188 public: |
188 virtual ~PageLoadMetricsEmbedderInterface() {} | 189 virtual ~PageLoadMetricsEmbedderInterface() {} |
189 virtual rappor::RapporService* GetRapporService() = 0; | 190 virtual rappor::RapporService* GetRapporService() = 0; |
190 virtual bool IsPrerendering(content::WebContents* web_contents) = 0; | 191 virtual bool IsPrerendering(content::WebContents* web_contents) = 0; |
192 virtual void RegisterObservers(PageLoadMetricsObservable* metrics) = 0; | |
191 }; | 193 }; |
192 | 194 |
193 // This class tracks a given page load, starting from navigation start / | 195 // This class tracks a given page load, starting from navigation start / |
194 // provisional load, until a new navigation commits or the navigation fails. It | 196 // provisional load, until a new navigation commits or the navigation fails. It |
195 // also records RAPPOR/UMA about the page load. | 197 // also records RAPPOR/UMA about the page load. |
196 // MetricsWebContentsObserver manages a set of provisional PageLoadTrackers, as | 198 // MetricsWebContentsObserver manages a set of provisional PageLoadTrackers, as |
197 // well as a committed PageLoadTracker. | 199 // well as a committed PageLoadTracker. |
198 class PageLoadTracker { | 200 class PageLoadTracker : public PageLoadMetricsObservable { |
Randy Smith (Not in Mondays)
2015/11/28 22:03:13
I know it's not part of this CL, but why the disti
Charlie Harrison
2015/11/30 16:39:29
The reason we made PageLoadMetricsObservable was s
Randy Smith (Not in Mondays)
2015/12/01 22:34:03
So I disagree with this as an architectural choice
| |
199 public: | 201 public: |
200 // Caller must guarantee that the observers and embedder_interface pointers | 202 // Caller must guarantee that the observers and embedder_interface pointers |
201 // outlives this class. | 203 // outlives this class. |
202 PageLoadTracker(bool in_foreground, | 204 PageLoadTracker(bool in_foreground, |
203 PageLoadMetricsEmbedderInterface* embedder_interface, | 205 PageLoadMetricsEmbedderInterface* embedder_interface, |
204 content::NavigationHandle* navigation_handle, | 206 content::NavigationHandle* navigation_handle); |
205 base::ObserverList<PageLoadMetricsObserver, true>* observers); | 207 ~PageLoadTracker() override; |
206 ~PageLoadTracker(); | |
207 void Redirect(content::NavigationHandle* navigation_handle); | 208 void Redirect(content::NavigationHandle* navigation_handle); |
208 void Commit(content::NavigationHandle* navigation_handle); | 209 void Commit(content::NavigationHandle* navigation_handle); |
209 void WebContentsHidden(); | 210 void WebContentsHidden(); |
210 void WebContentsShown(); | 211 void WebContentsShown(); |
211 | 212 |
212 // Returns true if the timing was successfully updated. | 213 // Returns true if the timing was successfully updated. |
213 bool UpdateTiming(const PageLoadTiming& timing); | 214 bool UpdateTiming(const PageLoadTiming& timing); |
214 void RecordProvisionalEvent(ProvisionalLoadEvent event); | 215 void RecordProvisionalEvent(ProvisionalLoadEvent event); |
215 void RecordCommittedEvent(CommittedLoadEvent event, bool backgrounded); | 216 void RecordCommittedEvent(CommittedRelevantLoadEvent event, |
217 bool backgrounded); | |
216 bool HasBackgrounded(); | 218 bool HasBackgrounded(); |
217 | 219 |
220 void SetRendererTracked(bool renderer_tracked); | |
221 bool RendererTracked() { return renderer_tracked_; } | |
Randy Smith (Not in Mondays)
2015/11/28 22:03:13
Note that by the Google style guide these may be n
Charlie Harrison
2015/11/30 16:39:29
Good point. I'll change it in this case. I changed
| |
222 | |
223 // PageLoadMetricsObservable implementation | |
224 void AddObserver(PageLoadMetricsObserver* observer) override; | |
225 void RemoveObserver(PageLoadMetricsObserver* observer) override; | |
226 | |
218 private: | 227 private: |
219 PageLoadExtraInfo GetPageLoadMetricsInfo(); | 228 PageLoadExtraInfo GetPageLoadMetricsInfo(); |
220 // Only valid to call post-commit. | 229 // Only valid to call post-commit. |
221 const GURL& GetCommittedURL(); | 230 const GURL& GetCommittedURL(); |
222 | 231 |
223 base::TimeDelta GetBackgroundDelta(); | 232 base::TimeDelta GetBackgroundDelta(); |
224 void RecordTimingHistograms(); | 233 void RecordTimingHistograms(); |
225 void RecordRappor(); | 234 void RecordRappor(); |
226 | 235 |
236 // Whether the renderer should be sending timing IPCs to this page load. | |
237 bool renderer_tracked_; | |
238 | |
227 bool has_commit_; | 239 bool has_commit_; |
228 | 240 |
229 // The navigation start in TimeTicks, not the wall time reported by Blink. | 241 // The navigation start in TimeTicks, not the wall time reported by Blink. |
230 const base::TimeTicks navigation_start_; | 242 const base::TimeTicks navigation_start_; |
231 | 243 |
232 // We record separate metrics for events that occur after a background, | 244 // We record separate metrics for events that occur after a background, |
233 // because metrics like layout/paint are delayed artificially | 245 // because metrics like layout/paint are delayed artificially |
234 // when they occur in the background. | 246 // when they occur in the background. |
235 base::TimeTicks background_time_; | 247 base::TimeTicks background_time_; |
236 base::TimeTicks foreground_time_; | 248 base::TimeTicks foreground_time_; |
237 bool started_in_foreground_; | 249 bool started_in_foreground_; |
238 | 250 |
239 PageLoadTiming timing_; | 251 PageLoadTiming timing_; |
240 GURL url_; | 252 GURL url_; |
241 | 253 |
242 // Interface to chrome features. Must outlive the class. | 254 // Interface to chrome features. Must outlive the class. |
243 PageLoadMetricsEmbedderInterface* const embedder_interface_; | 255 PageLoadMetricsEmbedderInterface* const embedder_interface_; |
244 | 256 |
245 // List of observers. This must outlive the class. | 257 // List of observers. This must outlive the class. |
Randy Smith (Not in Mondays)
2015/11/28 22:03:13
Is the "outlive" sentence still true/useful now th
Charlie Harrison
2015/11/30 16:39:29
Nope. Good catch.
| |
246 base::ObserverList<PageLoadMetricsObserver, true>* observers_; | 258 base::ObserverList<PageLoadMetricsObserver, true> observers_; |
247 | 259 |
248 DISALLOW_COPY_AND_ASSIGN(PageLoadTracker); | 260 DISALLOW_COPY_AND_ASSIGN(PageLoadTracker); |
249 }; | 261 }; |
250 | 262 |
251 // MetricsWebContentsObserver logs page load UMA metrics based on | 263 // MetricsWebContentsObserver logs page load UMA metrics based on |
252 // IPC messages received from a MetricsRenderFrameObserver. | 264 // IPC messages received from a MetricsRenderFrameObserver. |
253 class MetricsWebContentsObserver | 265 class MetricsWebContentsObserver |
254 : public content::WebContentsObserver, | 266 : public content::WebContentsObserver, |
255 public content::WebContentsUserData<MetricsWebContentsObserver>, | 267 public content::WebContentsUserData<MetricsWebContentsObserver> { |
256 public PageLoadMetricsObservable { | |
257 public: | 268 public: |
258 // Note that the returned metrics is owned by the web contents. | 269 // Note that the returned metrics is owned by the web contents. |
259 // The caller must guarantee that the RapporService (if non-null) will | 270 // The caller must guarantee that the RapporService (if non-null) will |
260 // outlive the WebContents. | 271 // outlive the WebContents. |
261 static MetricsWebContentsObserver* CreateForWebContents( | 272 static MetricsWebContentsObserver* CreateForWebContents( |
262 content::WebContents* web_contents, | 273 content::WebContents* web_contents, |
263 scoped_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); | 274 scoped_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); |
264 MetricsWebContentsObserver( | 275 MetricsWebContentsObserver( |
265 content::WebContents* web_contents, | 276 content::WebContents* web_contents, |
266 scoped_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); | 277 scoped_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); |
267 ~MetricsWebContentsObserver() override; | 278 ~MetricsWebContentsObserver() override; |
268 | 279 |
269 void AddObserver(PageLoadMetricsObserver* observer) override; | |
270 void RemoveObserver(PageLoadMetricsObserver* observer) override; | |
271 | |
272 // content::WebContentsObserver implementation: | 280 // content::WebContentsObserver implementation: |
273 bool OnMessageReceived(const IPC::Message& message, | 281 bool OnMessageReceived(const IPC::Message& message, |
274 content::RenderFrameHost* render_frame_host) override; | 282 content::RenderFrameHost* render_frame_host) override; |
275 void DidStartNavigation( | 283 void DidStartNavigation( |
276 content::NavigationHandle* navigation_handle) override; | 284 content::NavigationHandle* navigation_handle) override; |
277 void DidFinishNavigation( | 285 void DidFinishNavigation( |
278 content::NavigationHandle* navigation_handle) override; | 286 content::NavigationHandle* navigation_handle) override; |
279 void DidRedirectNavigation( | 287 void DidRedirectNavigation( |
280 content::NavigationHandle* navigation_handle) override; | 288 content::NavigationHandle* navigation_handle) override; |
281 | 289 |
(...skipping 12 matching lines...) Expand all Loading... | |
294 | 302 |
295 // This map tracks all of the navigations ongoing that are not committed | 303 // This map tracks all of the navigations ongoing that are not committed |
296 // yet. Once a navigation is committed, it moves from the map to | 304 // yet. Once a navigation is committed, it moves from the map to |
297 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only | 305 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only |
298 // valid until commit time, when we remove it from the map. | 306 // valid until commit time, when we remove it from the map. |
299 std::map<content::NavigationHandle*, scoped_ptr<PageLoadTracker>> | 307 std::map<content::NavigationHandle*, scoped_ptr<PageLoadTracker>> |
300 provisional_loads_; | 308 provisional_loads_; |
301 scoped_ptr<PageLoadTracker> committed_load_; | 309 scoped_ptr<PageLoadTracker> committed_load_; |
302 | 310 |
303 scoped_ptr<PageLoadMetricsEmbedderInterface> embedder_interface_; | 311 scoped_ptr<PageLoadMetricsEmbedderInterface> embedder_interface_; |
304 base::ObserverList<PageLoadMetricsObserver, true> observers_; | |
305 | 312 |
306 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); | 313 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); |
307 }; | 314 }; |
308 | 315 |
309 } // namespace page_load_metrics | 316 } // namespace page_load_metrics |
310 | 317 |
311 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_O BSERVER_H_ | 318 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_O BSERVER_H_ |
OLD | NEW |