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 CHROME_BROWSER_PAGE_LOAD_METRICS_PAGE_LOAD_METRICS_OBSERVER_H_ | 5 #ifndef CHROME_BROWSER_PAGE_LOAD_METRICS_PAGE_LOAD_METRICS_OBSERVER_H_ |
6 #define CHROME_BROWSER_PAGE_LOAD_METRICS_PAGE_LOAD_METRICS_OBSERVER_H_ | 6 #define CHROME_BROWSER_PAGE_LOAD_METRICS_PAGE_LOAD_METRICS_OBSERVER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 const base::Optional<base::TimeDelta>& first_background_time, | 115 const base::Optional<base::TimeDelta>& first_background_time, |
116 const base::Optional<base::TimeDelta>& first_foreground_time, | 116 const base::Optional<base::TimeDelta>& first_foreground_time, |
117 bool started_in_foreground, | 117 bool started_in_foreground, |
118 UserInitiatedInfo user_initiated_info, | 118 UserInitiatedInfo user_initiated_info, |
119 const GURL& url, | 119 const GURL& url, |
120 const GURL& start_url, | 120 const GURL& start_url, |
121 bool did_commit, | 121 bool did_commit, |
122 PageEndReason page_end_reason, | 122 PageEndReason page_end_reason, |
123 UserInitiatedInfo page_end_user_initiated_info, | 123 UserInitiatedInfo page_end_user_initiated_info, |
124 const base::Optional<base::TimeDelta>& page_end_time, | 124 const base::Optional<base::TimeDelta>& page_end_time, |
125 const PageLoadMetadata& main_frame_metadata, | 125 const mojom::PageLoadMetadata& main_frame_metadata, |
126 const PageLoadMetadata& subframe_metadata); | 126 const mojom::PageLoadMetadata& subframe_metadata); |
127 | 127 |
128 // Simplified version of the constructor, intended for use in tests. | 128 // Simplified version of the constructor, intended for use in tests. |
129 static PageLoadExtraInfo CreateForTesting(const GURL& url, | 129 static PageLoadExtraInfo CreateForTesting(const GURL& url, |
130 bool started_in_foreground); | 130 bool started_in_foreground); |
131 | 131 |
132 PageLoadExtraInfo(const PageLoadExtraInfo& other); | 132 PageLoadExtraInfo(const PageLoadExtraInfo& other); |
133 | 133 |
134 ~PageLoadExtraInfo(); | 134 ~PageLoadExtraInfo(); |
135 | 135 |
136 // The time the navigation was initiated. | 136 // The time the navigation was initiated. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 // * the page load is stopped | 185 // * the page load is stopped |
186 // * the tab hosting the page is closed | 186 // * the tab hosting the page is closed |
187 // * the render process hosting the page goes away | 187 // * the render process hosting the page goes away |
188 // * a new navigation which later commits is initiated in the same tab | 188 // * a new navigation which later commits is initiated in the same tab |
189 // This field will not be set if the page is still active and hasn't yet | 189 // This field will not be set if the page is still active and hasn't yet |
190 // finished. | 190 // finished. |
191 const base::Optional<base::TimeDelta> page_end_time; | 191 const base::Optional<base::TimeDelta> page_end_time; |
192 | 192 |
193 // Extra information supplied to the page load metrics system from the | 193 // Extra information supplied to the page load metrics system from the |
194 // renderer for the main frame. | 194 // renderer for the main frame. |
195 const PageLoadMetadata main_frame_metadata; | 195 const mojom::PageLoadMetadata main_frame_metadata; |
196 | 196 |
197 // PageLoadMetadata for subframes of the current page load. | 197 // PageLoadMetadata for subframes of the current page load. |
198 const PageLoadMetadata subframe_metadata; | 198 const mojom::PageLoadMetadata subframe_metadata; |
199 }; | 199 }; |
200 | 200 |
201 // Container for various information about a completed request within a page | 201 // Container for various information about a completed request within a page |
202 // load. | 202 // load. |
203 struct ExtraRequestCompleteInfo { | 203 struct ExtraRequestCompleteInfo { |
204 ExtraRequestCompleteInfo( | 204 ExtraRequestCompleteInfo( |
205 const GURL& url, | 205 const GURL& url, |
206 int frame_tree_node_id, | 206 int frame_tree_node_id, |
207 bool was_cached, | 207 bool was_cached, |
208 int64_t raw_body_bytes, | 208 int64_t raw_body_bytes, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 // was a same document navigation, or has been replaced. It is up to the | 303 // was a same document navigation, or has been replaced. It is up to the |
304 // observer to query |navigation_handle| to determine which happened. Note | 304 // observer to query |navigation_handle| to determine which happened. Note |
305 // that |navigation_handle| will be destroyed soon after this call. Don't | 305 // that |navigation_handle| will be destroyed soon after this call. Don't |
306 // hold a reference to it. | 306 // hold a reference to it. |
307 virtual ObservePolicy OnDidFinishSubFrameNavigation( | 307 virtual ObservePolicy OnDidFinishSubFrameNavigation( |
308 content::NavigationHandle* navigation_handle); | 308 content::NavigationHandle* navigation_handle); |
309 | 309 |
310 // OnHidden is triggered when a page leaves the foreground. It does not fire | 310 // OnHidden is triggered when a page leaves the foreground. It does not fire |
311 // when a foreground page is permanently closed; for that, listen to | 311 // when a foreground page is permanently closed; for that, listen to |
312 // OnComplete instead. | 312 // OnComplete instead. |
313 virtual ObservePolicy OnHidden(const PageLoadTiming& timing, | 313 virtual ObservePolicy OnHidden(const mojom::PageLoadTiming& timing, |
314 const PageLoadExtraInfo& extra_info); | 314 const PageLoadExtraInfo& extra_info); |
315 | 315 |
316 // OnShown is triggered when a page is brought to the foreground. It does not | 316 // OnShown is triggered when a page is brought to the foreground. It does not |
317 // fire when the page first loads; for that, listen for OnStart instead. | 317 // fire when the page first loads; for that, listen for OnStart instead. |
318 virtual ObservePolicy OnShown(); | 318 virtual ObservePolicy OnShown(); |
319 | 319 |
320 // Called before OnCommit. The observer should return whether it wishes to | 320 // Called before OnCommit. The observer should return whether it wishes to |
321 // observe navigations whose main resource has MIME type |mine_type|. The | 321 // observe navigations whose main resource has MIME type |mine_type|. The |
322 // default is to observe HTML and XHTML only. Note that PageLoadTrackers only | 322 // default is to observe HTML and XHTML only. Note that PageLoadTrackers only |
323 // track XHTML, HTML, and MHTML (related/multipart). | 323 // track XHTML, HTML, and MHTML (related/multipart). |
324 virtual ObservePolicy ShouldObserveMimeType( | 324 virtual ObservePolicy ShouldObserveMimeType( |
325 const std::string& mime_type) const; | 325 const std::string& mime_type) const; |
326 | 326 |
327 // The callbacks below are only invoked after a navigation commits, for | 327 // The callbacks below are only invoked after a navigation commits, for |
328 // tracked page loads. Page loads that don't meet the criteria for being | 328 // tracked page loads. Page loads that don't meet the criteria for being |
329 // tracked at the time a navigation commits will not receive any of the | 329 // tracked at the time a navigation commits will not receive any of the |
330 // callbacks below. | 330 // callbacks below. |
331 | 331 |
332 // OnTimingUpdate is triggered when an updated PageLoadTiming is | 332 // OnTimingUpdate is triggered when an updated PageLoadTiming is |
333 // available. This method may be called multiple times over the course of the | 333 // available. This method may be called multiple times over the course of the |
334 // page load. This method is currently only intended for use in testing. Most | 334 // page load. This method is currently only intended for use in testing. Most |
335 // implementers should implement one of the On* callbacks, such as | 335 // implementers should implement one of the On* callbacks, such as |
336 // OnFirstContentfulPaint or OnDomContentLoadedEventStart. Please email | 336 // OnFirstContentfulPaint or OnDomContentLoadedEventStart. Please email |
337 // loading-dev@chromium.org if you intend to override this method. | 337 // loading-dev@chromium.org if you intend to override this method. |
338 virtual void OnTimingUpdate(const PageLoadTiming& timing, | 338 virtual void OnTimingUpdate(const mojom::PageLoadTiming& timing, |
339 const PageLoadExtraInfo& extra_info) {} | 339 const PageLoadExtraInfo& extra_info) {} |
340 | 340 |
341 // OnUserInput is triggered when a new user input is passed in to | 341 // OnUserInput is triggered when a new user input is passed in to |
342 // web_contents. Contains a TimeDelta from navigation start. | 342 // web_contents. Contains a TimeDelta from navigation start. |
343 virtual void OnUserInput(const blink::WebInputEvent& event) {} | 343 virtual void OnUserInput(const blink::WebInputEvent& event) {} |
344 | 344 |
345 // The following methods are invoked at most once, when the timing for the | 345 // The following methods are invoked at most once, when the timing for the |
346 // associated event first becomes available. | 346 // associated event first becomes available. |
347 virtual void OnDomContentLoadedEventStart( | 347 virtual void OnDomContentLoadedEventStart( |
348 const PageLoadTiming& timing, | 348 const mojom::PageLoadTiming& timing, |
349 const PageLoadExtraInfo& extra_info) {} | 349 const PageLoadExtraInfo& extra_info) {} |
350 virtual void OnLoadEventStart(const PageLoadTiming& timing, | 350 virtual void OnLoadEventStart(const mojom::PageLoadTiming& timing, |
351 const PageLoadExtraInfo& extra_info) {} | 351 const PageLoadExtraInfo& extra_info) {} |
352 virtual void OnFirstLayout(const PageLoadTiming& timing, | 352 virtual void OnFirstLayout(const mojom::PageLoadTiming& timing, |
353 const PageLoadExtraInfo& extra_info) {} | 353 const PageLoadExtraInfo& extra_info) {} |
354 virtual void OnParseStart(const PageLoadTiming& timing, | 354 virtual void OnParseStart(const mojom::PageLoadTiming& timing, |
355 const PageLoadExtraInfo& extra_info) {} | 355 const PageLoadExtraInfo& extra_info) {} |
356 virtual void OnParseStop(const PageLoadTiming& timing, | 356 virtual void OnParseStop(const mojom::PageLoadTiming& timing, |
357 const PageLoadExtraInfo& extra_info) {} | 357 const PageLoadExtraInfo& extra_info) {} |
358 | 358 |
359 // On*PaintInPage(...) are invoked when the first relevant paint in the page, | 359 // On*PaintInPage(...) are invoked when the first relevant paint in the page, |
360 // across all frames, is observed. | 360 // across all frames, is observed. |
361 virtual void OnFirstPaintInPage(const PageLoadTiming& timing, | 361 virtual void OnFirstPaintInPage(const mojom::PageLoadTiming& timing, |
362 const PageLoadExtraInfo& extra_info) {} | 362 const PageLoadExtraInfo& extra_info) {} |
363 virtual void OnFirstTextPaintInPage(const PageLoadTiming& timing, | 363 virtual void OnFirstTextPaintInPage(const mojom::PageLoadTiming& timing, |
364 const PageLoadExtraInfo& extra_info) {} | 364 const PageLoadExtraInfo& extra_info) {} |
365 virtual void OnFirstImagePaintInPage(const PageLoadTiming& timing, | 365 virtual void OnFirstImagePaintInPage(const mojom::PageLoadTiming& timing, |
366 const PageLoadExtraInfo& extra_info) {} | 366 const PageLoadExtraInfo& extra_info) {} |
367 virtual void OnFirstContentfulPaintInPage( | 367 virtual void OnFirstContentfulPaintInPage( |
368 const PageLoadTiming& timing, | 368 const mojom::PageLoadTiming& timing, |
369 const PageLoadExtraInfo& extra_info) {} | 369 const PageLoadExtraInfo& extra_info) {} |
370 | 370 |
371 // Unlike other paint callbacks, OnFirstMeaningfulPaintInMainFrameDocument is | 371 // Unlike other paint callbacks, OnFirstMeaningfulPaintInMainFrameDocument is |
372 // tracked per document, and is reported for the main frame document only. | 372 // tracked per document, and is reported for the main frame document only. |
373 virtual void OnFirstMeaningfulPaintInMainFrameDocument( | 373 virtual void OnFirstMeaningfulPaintInMainFrameDocument( |
374 const PageLoadTiming& timing, | 374 const mojom::PageLoadTiming& timing, |
375 const PageLoadExtraInfo& extra_info) {} | 375 const PageLoadExtraInfo& extra_info) {} |
376 | 376 |
377 // Invoked when there is a change in either the main_frame_metadata or the | 377 // Invoked when there is a change in either the main_frame_metadata or the |
378 // subframe_metadata's loading behavior_flags. | 378 // subframe_metadata's loading behavior_flags. |
379 virtual void OnLoadingBehaviorObserved( | 379 virtual void OnLoadingBehaviorObserved( |
380 const page_load_metrics::PageLoadExtraInfo& extra_info) {} | 380 const page_load_metrics::PageLoadExtraInfo& extra_info) {} |
381 | 381 |
382 // Invoked when a media element starts playing. | 382 // Invoked when a media element starts playing. |
383 virtual void MediaStartedPlaying( | 383 virtual void MediaStartedPlaying( |
384 const content::WebContentsObserver::MediaPlayerInfo& video_type, | 384 const content::WebContentsObserver::MediaPlayerInfo& video_type, |
(...skipping 12 matching lines...) Expand all Loading... |
397 // the application may be killed at any time after this method is invoked | 397 // the application may be killed at any time after this method is invoked |
398 // without further notification. Note that this may be called both for | 398 // without further notification. Note that this may be called both for |
399 // provisional loads as well as committed loads. Implementations that only | 399 // provisional loads as well as committed loads. Implementations that only |
400 // want to track committed loads should check whether extra_info.committed_url | 400 // want to track committed loads should check whether extra_info.committed_url |
401 // is empty to determine if the load had committed. If the implementation | 401 // is empty to determine if the load had committed. If the implementation |
402 // returns CONTINUE_OBSERVING, this method may be called multiple times per | 402 // returns CONTINUE_OBSERVING, this method may be called multiple times per |
403 // observer, once for each time that the application enters the backround. | 403 // observer, once for each time that the application enters the backround. |
404 // | 404 // |
405 // The default implementation does nothing, and returns CONTINUE_OBSERVING. | 405 // The default implementation does nothing, and returns CONTINUE_OBSERVING. |
406 virtual ObservePolicy FlushMetricsOnAppEnterBackground( | 406 virtual ObservePolicy FlushMetricsOnAppEnterBackground( |
407 const PageLoadTiming& timing, | 407 const mojom::PageLoadTiming& timing, |
408 const PageLoadExtraInfo& extra_info); | 408 const PageLoadExtraInfo& extra_info); |
409 | 409 |
410 // One of OnComplete or OnFailedProvisionalLoad is invoked for tracked page | 410 // One of OnComplete or OnFailedProvisionalLoad is invoked for tracked page |
411 // loads, immediately before the observer is deleted. These callbacks will not | 411 // loads, immediately before the observer is deleted. These callbacks will not |
412 // be invoked for page loads that did not meet the criteria for being tracked | 412 // be invoked for page loads that did not meet the criteria for being tracked |
413 // at the time the navigation completed. The PageLoadTiming struct contains | 413 // at the time the navigation completed. The PageLoadTiming struct contains |
414 // timing data and the PageLoadExtraInfo struct contains other useful data | 414 // timing data and the PageLoadExtraInfo struct contains other useful data |
415 // collected over the course of the page load. Most observers should not need | 415 // collected over the course of the page load. Most observers should not need |
416 // to implement these callbacks, and should implement the On* timing callbacks | 416 // to implement these callbacks, and should implement the On* timing callbacks |
417 // instead. | 417 // instead. |
418 | 418 |
419 // OnComplete is invoked for tracked page loads that committed, immediately | 419 // OnComplete is invoked for tracked page loads that committed, immediately |
420 // before the observer is deleted. Observers that implement OnComplete may | 420 // before the observer is deleted. Observers that implement OnComplete may |
421 // also want to implement FlushMetricsOnAppEnterBackground, to avoid loss of | 421 // also want to implement FlushMetricsOnAppEnterBackground, to avoid loss of |
422 // data if the application is killed while in the background (this happens | 422 // data if the application is killed while in the background (this happens |
423 // frequently on Android). | 423 // frequently on Android). |
424 virtual void OnComplete(const PageLoadTiming& timing, | 424 virtual void OnComplete(const mojom::PageLoadTiming& timing, |
425 const PageLoadExtraInfo& extra_info) {} | 425 const PageLoadExtraInfo& extra_info) {} |
426 | 426 |
427 // OnFailedProvisionalLoad is invoked for tracked page loads that did not | 427 // OnFailedProvisionalLoad is invoked for tracked page loads that did not |
428 // commit, immediately before the observer is deleted. | 428 // commit, immediately before the observer is deleted. |
429 virtual void OnFailedProvisionalLoad( | 429 virtual void OnFailedProvisionalLoad( |
430 const FailedProvisionalLoadInfo& failed_provisional_load_info, | 430 const FailedProvisionalLoadInfo& failed_provisional_load_info, |
431 const PageLoadExtraInfo& extra_info) {} | 431 const PageLoadExtraInfo& extra_info) {} |
432 | 432 |
433 // Called whenever a request load begins. | 433 // Called whenever a request load begins. |
434 virtual void OnStartedResource( | 434 virtual void OnStartedResource( |
435 const ExtraRequestStartInfo& extra_request_start_info) {} | 435 const ExtraRequestStartInfo& extra_request_start_info) {} |
436 | 436 |
437 // Called whenever a request is loaded for this page load. This comes | 437 // Called whenever a request is loaded for this page load. This comes |
438 // unfiltered from the ResourceDispatcherHost and may include blob requests | 438 // unfiltered from the ResourceDispatcherHost and may include blob requests |
439 // and data uris. | 439 // and data uris. |
440 virtual void OnLoadedResource( | 440 virtual void OnLoadedResource( |
441 const ExtraRequestCompleteInfo& extra_request_complete_info) {} | 441 const ExtraRequestCompleteInfo& extra_request_complete_info) {} |
442 }; | 442 }; |
443 | 443 |
444 } // namespace page_load_metrics | 444 } // namespace page_load_metrics |
445 | 445 |
446 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_PAGE_LOAD_METRICS_OBSERVER_H_ | 446 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_PAGE_LOAD_METRICS_OBSERVER_H_ |
OLD | NEW |