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 "components/page_load_metrics/browser/metrics_web_contents_observer.h" | 5 #include "components/page_load_metrics/browser/metrics_web_contents_observer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/location.h" | 11 #include "base/location.h" |
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.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/metrics/user_metrics.h" | 15 #include "base/metrics/user_metrics.h" |
16 #include "components/page_load_metrics/browser/page_load_metrics_util.h" | 16 #include "components/page_load_metrics/browser/page_load_metrics_util.h" |
17 #include "components/page_load_metrics/common/page_load_metrics_messages.h" | 17 #include "components/page_load_metrics/common/page_load_metrics_messages.h" |
18 #include "components/page_load_metrics/common/page_load_timing.h" | 18 #include "components/page_load_metrics/common/page_load_timing.h" |
19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/navigation_details.h" | 20 #include "content/public/browser/navigation_details.h" |
21 #include "content/public/browser/navigation_handle.h" | 21 #include "content/public/browser/navigation_handle.h" |
22 #include "content/public/browser/render_frame_host.h" | 22 #include "content/public/browser/render_frame_host.h" |
23 #include "content/public/browser/render_view_host.h" | 23 #include "content/public/browser/render_view_host.h" |
24 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
25 #include "content/public/browser/web_contents_observer.h" | 25 #include "content/public/browser/web_contents_observer.h" |
26 #include "content/public/browser/web_contents_user_data.h" | 26 #include "content/public/browser/web_contents_user_data.h" |
27 #include "ipc/ipc_message.h" | 27 #include "ipc/ipc_message.h" |
28 #include "ipc/ipc_message_macros.h" | 28 #include "ipc/ipc_message_macros.h" |
29 #include "services/shell/public/cpp/interface_registry.h" | |
29 #include "ui/base/page_transition_types.h" | 30 #include "ui/base/page_transition_types.h" |
30 | 31 |
31 DEFINE_WEB_CONTENTS_USER_DATA_KEY( | 32 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
32 page_load_metrics::MetricsWebContentsObserver); | 33 page_load_metrics::MetricsWebContentsObserver); |
33 | 34 |
34 namespace page_load_metrics { | 35 namespace page_load_metrics { |
35 | 36 |
36 namespace internal { | 37 namespace internal { |
37 | 38 |
38 const char kErrorEvents[] = "PageLoad.Events.InternalError"; | 39 const char kErrorEvents[] = "PageLoad.Events.InternalError"; |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
565 return; | 566 return; |
566 } | 567 } |
567 abort_type_ = abort_type; | 568 abort_type_ = abort_type; |
568 abort_time_ = timestamp; | 569 abort_time_ = timestamp; |
569 | 570 |
570 if (is_certainly_browser_timestamp) { | 571 if (is_certainly_browser_timestamp) { |
571 ClampBrowserTimestampIfInterProcessTimeTickSkew(&abort_time_); | 572 ClampBrowserTimestampIfInterProcessTimeTickSkew(&abort_time_); |
572 } | 573 } |
573 } | 574 } |
574 | 575 |
576 PageLoadMetricsImpl::PageLoadMetricsImpl(MetricsWebContentsObserver* observer, | |
577 content::RenderFrameHost* host) | |
578 : observer_(observer), host_(host), binding_(this) {} | |
579 | |
580 PageLoadMetricsImpl::~PageLoadMetricsImpl() = default; | |
581 | |
582 void PageLoadMetricsImpl::Bind( | |
583 mojo::InterfaceRequest<mojom::PageLoadMetrics> request) { | |
584 binding_.Bind(std::move(request)); | |
585 } | |
586 | |
587 void PageLoadMetricsImpl::TimingUpdated(const PageLoadTiming& timing, | |
588 const PageLoadMetadata& metadata) { | |
589 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
590 observer_->OnTimingUpdated(host_, timing, metadata); | |
591 } | |
592 | |
575 // static | 593 // static |
576 MetricsWebContentsObserver::MetricsWebContentsObserver( | 594 MetricsWebContentsObserver::MetricsWebContentsObserver( |
577 content::WebContents* web_contents, | 595 content::WebContents* web_contents, |
578 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) | 596 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) |
579 : content::WebContentsObserver(web_contents), | 597 : content::WebContentsObserver(web_contents), |
580 in_foreground_(false), | 598 in_foreground_(false), |
581 embedder_interface_(std::move(embedder_interface)), | 599 embedder_interface_(std::move(embedder_interface)), |
582 has_navigated_(false) { | 600 has_navigated_(false) { |
583 RegisterInputEventObserver(web_contents->GetRenderViewHost()); | 601 RegisterInputEventObserver(web_contents->GetRenderViewHost()); |
584 } | 602 } |
(...skipping 28 matching lines...) Expand all Loading... | |
613 host->GetWidget()->RemoveInputEventObserver(this); | 631 host->GetWidget()->RemoveInputEventObserver(this); |
614 } | 632 } |
615 | 633 |
616 void MetricsWebContentsObserver::RenderViewHostChanged( | 634 void MetricsWebContentsObserver::RenderViewHostChanged( |
617 content::RenderViewHost* old_host, | 635 content::RenderViewHost* old_host, |
618 content::RenderViewHost* new_host) { | 636 content::RenderViewHost* new_host) { |
619 UnregisterInputEventObserver(old_host); | 637 UnregisterInputEventObserver(old_host); |
620 RegisterInputEventObserver(new_host); | 638 RegisterInputEventObserver(new_host); |
621 } | 639 } |
622 | 640 |
623 bool MetricsWebContentsObserver::OnMessageReceived( | |
624 const IPC::Message& message, | |
625 content::RenderFrameHost* render_frame_host) { | |
626 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
627 bool handled = true; | |
628 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(MetricsWebContentsObserver, message, | |
629 render_frame_host) | |
630 IPC_MESSAGE_HANDLER(PageLoadMetricsMsg_TimingUpdated, OnTimingUpdated) | |
631 IPC_MESSAGE_UNHANDLED(handled = false) | |
632 IPC_END_MESSAGE_MAP() | |
633 return handled; | |
634 } | |
635 | |
636 void MetricsWebContentsObserver::DidStartNavigation( | 641 void MetricsWebContentsObserver::DidStartNavigation( |
637 content::NavigationHandle* navigation_handle) { | 642 content::NavigationHandle* navigation_handle) { |
638 if (!navigation_handle->IsInMainFrame()) | 643 if (!navigation_handle->IsInMainFrame()) |
639 return; | 644 return; |
640 if (embedder_interface_->IsPrerendering(web_contents())) | 645 if (embedder_interface_->IsPrerendering(web_contents())) |
641 return; | 646 return; |
642 if (navigation_handle->GetURL().spec().compare(url::kAboutBlankURL) == 0) | 647 if (navigation_handle->GetURL().spec().compare(url::kAboutBlankURL) == 0) |
643 return; | 648 return; |
644 | 649 |
645 std::unique_ptr<PageLoadTracker> last_aborted = | 650 std::unique_ptr<PageLoadTracker> last_aborted = |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
875 aborted_provisional_loads_.pop_back(); | 880 aborted_provisional_loads_.pop_back(); |
876 | 881 |
877 base::TimeTicks timestamp = new_navigation->NavigationStart(); | 882 base::TimeTicks timestamp = new_navigation->NavigationStart(); |
878 if (last_aborted_load->IsLikelyProvisionalAbort(timestamp)) | 883 if (last_aborted_load->IsLikelyProvisionalAbort(timestamp)) |
879 last_aborted_load->UpdateAbort(ABORT_UNKNOWN_NAVIGATION, timestamp, false); | 884 last_aborted_load->UpdateAbort(ABORT_UNKNOWN_NAVIGATION, timestamp, false); |
880 | 885 |
881 aborted_provisional_loads_.clear(); | 886 aborted_provisional_loads_.clear(); |
882 return last_aborted_load; | 887 return last_aborted_load; |
883 } | 888 } |
884 | 889 |
890 void MetricsWebContentsObserver::RenderFrameCreated( | |
891 content::RenderFrameHost* render_frame_host) { | |
892 CreateRegisteredInterface(render_frame_host); | |
893 } | |
894 | |
895 void MetricsWebContentsObserver::RenderFrameHostChanged( | |
896 content::RenderFrameHost* old_host, | |
897 content::RenderFrameHost* new_host) { | |
898 CreateRegisteredInterface(new_host); | |
899 } | |
900 void MetricsWebContentsObserver::WebContentsDestroyed() { | |
901 // At this point we no longer accept any more requests, as OnTimingUpdated | |
902 // requires the WebContents to exist. | |
903 registered_interfaces_.clear(); | |
904 } | |
905 | |
906 void MetricsWebContentsObserver::CreateRegisteredInterface( | |
907 content::RenderFrameHost* host) { | |
908 registered_interfaces_.push_back( | |
Sam McNally
2016/07/07 05:10:48
Do you need to create the interface impls eagerly?
tibell
2016/07/08 01:12:53
Done.
| |
909 base::MakeUnique<PageLoadMetricsImpl>(this, host)); | |
910 host->GetInterfaceRegistry()->AddInterface( | |
911 base::Bind(&PageLoadMetricsImpl::Bind, | |
912 base::Unretained(registered_interfaces_.back().get()))); | |
913 } | |
914 | |
885 void MetricsWebContentsObserver::OnTimingUpdated( | 915 void MetricsWebContentsObserver::OnTimingUpdated( |
886 content::RenderFrameHost* render_frame_host, | 916 content::RenderFrameHost* render_frame_host, |
887 const PageLoadTiming& timing, | 917 const PageLoadTiming& timing, |
888 const PageLoadMetadata& metadata) { | 918 const PageLoadMetadata& metadata) { |
889 bool error = false; | 919 bool error = false; |
890 if (!committed_load_ || !committed_load_->renderer_tracked()) { | 920 if (!committed_load_ || !committed_load_->renderer_tracked()) { |
891 RecordInternalError(ERR_IPC_WITH_NO_RELEVANT_LOAD); | 921 RecordInternalError(ERR_IPC_WITH_NO_RELEVANT_LOAD); |
892 error = true; | 922 error = true; |
893 } | 923 } |
894 | 924 |
(...skipping 17 matching lines...) Expand all Loading... | |
912 | 942 |
913 if (!committed_load_->UpdateTiming(timing, metadata)) { | 943 if (!committed_load_->UpdateTiming(timing, metadata)) { |
914 // If the page load tracker cannot update its timing, something is wrong | 944 // If the page load tracker cannot update its timing, something is wrong |
915 // with the IPC (it's from another load, or it's invalid in some other way). | 945 // with the IPC (it's from another load, or it's invalid in some other way). |
916 // We expect this to be a rare occurrence. | 946 // We expect this to be a rare occurrence. |
917 RecordInternalError(ERR_BAD_TIMING_IPC); | 947 RecordInternalError(ERR_BAD_TIMING_IPC); |
918 } | 948 } |
919 } | 949 } |
920 | 950 |
921 } // namespace page_load_metrics | 951 } // namespace page_load_metrics |
OLD | NEW |