OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "chrome/browser/page_load_metrics/page_load_tracker.h" | 5 #include "chrome/browser/page_load_metrics/page_load_tracker.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <ostream> | 8 #include <ostream> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "chrome/browser/page_load_metrics/browser_page_track_decider.h" |
15 #include "chrome/browser/page_load_metrics/page_load_metrics_embedder_interface.
h" | 16 #include "chrome/browser/page_load_metrics/page_load_metrics_embedder_interface.
h" |
16 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" | 17 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
17 #include "chrome/browser/prerender/prerender_contents.h" | 18 #include "chrome/browser/prerender/prerender_contents.h" |
18 #include "chrome/common/page_load_metrics/page_load_timing.h" | 19 #include "chrome/common/page_load_metrics/page_load_timing.h" |
19 #include "content/public/browser/navigation_details.h" | 20 #include "content/public/browser/navigation_details.h" |
20 #include "content/public/browser/navigation_handle.h" | 21 #include "content/public/browser/navigation_handle.h" |
| 22 #include "content/public/browser/render_frame_host.h" |
21 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
22 #include "content/public/browser/web_contents_observer.h" | 24 #include "content/public/browser/web_contents_observer.h" |
23 #include "content/public/common/browser_side_navigation_policy.h" | 25 #include "content/public/common/browser_side_navigation_policy.h" |
24 #include "ui/base/page_transition_types.h" | 26 #include "ui/base/page_transition_types.h" |
25 | 27 |
26 // This macro invokes the specified method on each observer, passing the | 28 // This macro invokes the specified method on each observer, passing the |
27 // variable length arguments as the method's arguments, and removes the observer | 29 // variable length arguments as the method's arguments, and removes the observer |
28 // from the list of observers if the given method returns STOP_OBSERVING. | 30 // from the list of observers if the given method returns STOP_OBSERVING. |
29 #define INVOKE_AND_PRUNE_OBSERVERS(observers, Method, ...) \ | 31 #define INVOKE_AND_PRUNE_OBSERVERS(observers, Method, ...) \ |
30 for (auto it = observers.begin(); it != observers.end();) { \ | 32 for (auto it = observers.begin(); it != observers.end();) { \ |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 navigation_handle->GetWebContents()->GetContentsMimeType()); | 506 navigation_handle->GetWebContents()->GetContentsMimeType()); |
505 | 507 |
506 INVOKE_AND_PRUNE_OBSERVERS(observers_, OnCommit, navigation_handle); | 508 INVOKE_AND_PRUNE_OBSERVERS(observers_, OnCommit, navigation_handle); |
507 LogAbortChainHistograms(navigation_handle); | 509 LogAbortChainHistograms(navigation_handle); |
508 } | 510 } |
509 | 511 |
510 void PageLoadTracker::DidFinishSubFrameNavigation( | 512 void PageLoadTracker::DidFinishSubFrameNavigation( |
511 content::NavigationHandle* navigation_handle) { | 513 content::NavigationHandle* navigation_handle) { |
512 INVOKE_AND_PRUNE_OBSERVERS(observers_, OnDidFinishSubFrameNavigation, | 514 INVOKE_AND_PRUNE_OBSERVERS(observers_, OnDidFinishSubFrameNavigation, |
513 navigation_handle); | 515 navigation_handle); |
| 516 |
| 517 if (!navigation_handle->HasCommitted()) |
| 518 return; |
| 519 |
| 520 // We have a new committed navigation, so discard information about the |
| 521 // previously committed navigation. |
| 522 child_frame_navigation_start_offset_.erase( |
| 523 navigation_handle->GetFrameTreeNodeId()); |
| 524 |
| 525 BrowserPageTrackDecider decider(embedder_interface_, |
| 526 navigation_handle->GetWebContents(), |
| 527 navigation_handle); |
| 528 if (decider.ShouldTrack()) { |
| 529 DCHECK_GE(navigation_handle->NavigationStart(), navigation_start_); |
| 530 base::TimeDelta navigation_delta = |
| 531 navigation_handle->NavigationStart() - navigation_start_; |
| 532 child_frame_navigation_start_offset_.insert(std::make_pair( |
| 533 navigation_handle->GetFrameTreeNodeId(), navigation_delta)); |
| 534 } |
514 } | 535 } |
515 | 536 |
516 void PageLoadTracker::FailedProvisionalLoad( | 537 void PageLoadTracker::FailedProvisionalLoad( |
517 content::NavigationHandle* navigation_handle, | 538 content::NavigationHandle* navigation_handle, |
518 base::TimeTicks failed_load_time) { | 539 base::TimeTicks failed_load_time) { |
519 DCHECK(!failed_provisional_load_info_); | 540 DCHECK(!failed_provisional_load_info_); |
520 failed_provisional_load_info_.reset(new FailedProvisionalLoadInfo( | 541 failed_provisional_load_info_.reset(new FailedProvisionalLoadInfo( |
521 failed_load_time - navigation_handle->NavigationStart(), | 542 failed_load_time - navigation_handle->NavigationStart(), |
522 navigation_handle->GetNetErrorCode())); | 543 navigation_handle->GetNetErrorCode())); |
523 } | 544 } |
(...skipping 30 matching lines...) Expand all Loading... |
554 if (destination.navigation_start() > first_paint_time) | 575 if (destination.navigation_start() > first_paint_time) |
555 first_paint_to_navigation = | 576 first_paint_to_navigation = |
556 destination.navigation_start() - first_paint_time; | 577 destination.navigation_start() - first_paint_time; |
557 PAGE_LOAD_HISTOGRAM(internal::kClientRedirectFirstPaintToNavigation, | 578 PAGE_LOAD_HISTOGRAM(internal::kClientRedirectFirstPaintToNavigation, |
558 first_paint_to_navigation); | 579 first_paint_to_navigation); |
559 } else { | 580 } else { |
560 UMA_HISTOGRAM_BOOLEAN(internal::kClientRedirectWithoutPaint, true); | 581 UMA_HISTOGRAM_BOOLEAN(internal::kClientRedirectWithoutPaint, true); |
561 } | 582 } |
562 } | 583 } |
563 | 584 |
564 void PageLoadTracker::UpdateChildFrameMetadata( | 585 void PageLoadTracker::UpdateSubFrameTiming( |
| 586 content::RenderFrameHost* render_frame_host, |
| 587 const PageLoadTiming& new_timing, |
| 588 const PageLoadMetadata& new_metadata) { |
| 589 UpdateSubFrameMetadata(new_metadata); |
| 590 const auto it = child_frame_navigation_start_offset_.find( |
| 591 render_frame_host->GetFrameTreeNodeId()); |
| 592 if (it == child_frame_navigation_start_offset_.end()) { |
| 593 // We received timing information for an untracked load. Ignore it. |
| 594 RecordInternalError(ERR_SUBFRAME_IPC_WITH_NO_RELEVANT_LOAD); |
| 595 return; |
| 596 } |
| 597 const PageLoadExtraInfo info = ComputePageLoadExtraInfo(); |
| 598 for (const auto& observer : observers_) { |
| 599 observer->OnSubFrameTimingUpdate(render_frame_host->GetFrameTreeNodeId(), |
| 600 it->second, new_timing, new_metadata, |
| 601 info); |
| 602 } |
| 603 } |
| 604 |
| 605 void PageLoadTracker::UpdateSubFrameMetadata( |
565 const PageLoadMetadata& child_metadata) { | 606 const PageLoadMetadata& child_metadata) { |
566 // Merge the child loading behavior flags with any we've already observed, | 607 // Merge the child loading behavior flags with any we've already observed, |
567 // possibly from other child frames. | 608 // possibly from other child frames. |
568 const int last_child_loading_behavior_flags = | 609 const int last_child_loading_behavior_flags = |
569 child_frame_metadata_.behavior_flags; | 610 child_frame_metadata_.behavior_flags; |
570 child_frame_metadata_.behavior_flags |= child_metadata.behavior_flags; | 611 child_frame_metadata_.behavior_flags |= child_metadata.behavior_flags; |
571 if (last_child_loading_behavior_flags == child_frame_metadata_.behavior_flags) | 612 if (last_child_loading_behavior_flags == child_frame_metadata_.behavior_flags) |
572 return; | 613 return; |
573 | 614 |
574 PageLoadExtraInfo extra_info(ComputePageLoadExtraInfo()); | 615 PageLoadExtraInfo extra_info(ComputePageLoadExtraInfo()); |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 observer->MediaStartedPlaying(video_type, is_in_main_frame); | 853 observer->MediaStartedPlaying(video_type, is_in_main_frame); |
813 } | 854 } |
814 | 855 |
815 void PageLoadTracker::OnNavigationDelayComplete(base::TimeDelta scheduled_delay, | 856 void PageLoadTracker::OnNavigationDelayComplete(base::TimeDelta scheduled_delay, |
816 base::TimeDelta actual_delay) { | 857 base::TimeDelta actual_delay) { |
817 for (const auto& observer : observers_) | 858 for (const auto& observer : observers_) |
818 observer->OnNavigationDelayComplete(scheduled_delay, actual_delay); | 859 observer->OnNavigationDelayComplete(scheduled_delay, actual_delay); |
819 } | 860 } |
820 | 861 |
821 } // namespace page_load_metrics | 862 } // namespace page_load_metrics |
OLD | NEW |