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 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" | 5 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.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> |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 return UserInitiatedInfo::RenderInitiated( | 58 return UserInitiatedInfo::RenderInitiated( |
59 navigation_handle->HasUserGesture(), | 59 navigation_handle->HasUserGesture(), |
60 committed_load && | 60 committed_load && |
61 committed_load->input_tracker()->FindAndConsumeInputEventsBefore( | 61 committed_load->input_tracker()->FindAndConsumeInputEventsBefore( |
62 navigation_handle->NavigationStart())); | 62 navigation_handle->NavigationStart())); |
63 } | 63 } |
64 | 64 |
65 } // namespace | 65 } // namespace |
66 | 66 |
67 // static | |
68 MetricsWebContentsObserver::MetricsWebContentsObserver( | 67 MetricsWebContentsObserver::MetricsWebContentsObserver( |
69 content::WebContents* web_contents, | 68 content::WebContents* web_contents, |
70 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) | 69 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) |
71 : content::WebContentsObserver(web_contents), | 70 : content::WebContentsObserver(web_contents), |
72 in_foreground_(false), | 71 in_foreground_(false), |
73 embedder_interface_(std::move(embedder_interface)), | 72 embedder_interface_(std::move(embedder_interface)), |
74 has_navigated_(false) { | 73 has_navigated_(false), |
| 74 page_load_metrics_binding_(web_contents, this) { |
75 RegisterInputEventObserver(web_contents->GetRenderViewHost()); | 75 RegisterInputEventObserver(web_contents->GetRenderViewHost()); |
76 } | 76 } |
77 | 77 |
| 78 // static |
78 MetricsWebContentsObserver* MetricsWebContentsObserver::CreateForWebContents( | 79 MetricsWebContentsObserver* MetricsWebContentsObserver::CreateForWebContents( |
79 content::WebContents* web_contents, | 80 content::WebContents* web_contents, |
80 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) { | 81 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) { |
81 DCHECK(web_contents); | 82 DCHECK(web_contents); |
82 | 83 |
83 MetricsWebContentsObserver* metrics = FromWebContents(web_contents); | 84 MetricsWebContentsObserver* metrics = FromWebContents(web_contents); |
84 if (!metrics) { | 85 if (!metrics) { |
85 metrics = new MetricsWebContentsObserver(web_contents, | 86 metrics = new MetricsWebContentsObserver(web_contents, |
86 std::move(embedder_interface)); | 87 std::move(embedder_interface)); |
87 web_contents->SetUserData(UserDataKey(), metrics); | 88 web_contents->SetUserData(UserDataKey(), metrics); |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 // updates. | 593 // updates. |
593 if (!timing.IsEmpty()) | 594 if (!timing.IsEmpty()) |
594 RecordInternalError(ERR_TIMING_IPC_FROM_SUBFRAME); | 595 RecordInternalError(ERR_TIMING_IPC_FROM_SUBFRAME); |
595 committed_load_->UpdateChildFrameMetadata(metadata); | 596 committed_load_->UpdateChildFrameMetadata(metadata); |
596 return; | 597 return; |
597 } | 598 } |
598 | 599 |
599 committed_load_->UpdateTiming(timing, metadata); | 600 committed_load_->UpdateTiming(timing, metadata); |
600 } | 601 } |
601 | 602 |
| 603 void MetricsWebContentsObserver::UpdateTiming( |
| 604 const PageLoadTiming& timing, |
| 605 const PageLoadMetadata& metadata) { |
| 606 content::RenderFrameHost* render_frame_host = |
| 607 page_load_metrics_binding_.GetCurrentTargetFrame(); |
| 608 OnTimingUpdated(render_frame_host, timing, metadata); |
| 609 } |
| 610 |
602 bool MetricsWebContentsObserver::ShouldTrackNavigation( | 611 bool MetricsWebContentsObserver::ShouldTrackNavigation( |
603 content::NavigationHandle* navigation_handle) const { | 612 content::NavigationHandle* navigation_handle) const { |
604 DCHECK(navigation_handle->IsInMainFrame()); | 613 DCHECK(navigation_handle->IsInMainFrame()); |
605 DCHECK(!navigation_handle->HasCommitted() || | 614 DCHECK(!navigation_handle->HasCommitted() || |
606 !navigation_handle->IsSameDocument()); | 615 !navigation_handle->IsSameDocument()); |
607 | 616 |
608 return BrowserPageTrackDecider(embedder_interface_.get(), web_contents(), | 617 return BrowserPageTrackDecider(embedder_interface_.get(), web_contents(), |
609 navigation_handle).ShouldTrack(); | 618 navigation_handle).ShouldTrack(); |
610 } | 619 } |
611 | 620 |
612 } // namespace page_load_metrics | 621 } // namespace page_load_metrics |
OLD | NEW |