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 <ostream> | 8 #include <ostream> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/metrics/user_metrics.h" | 16 #include "base/metrics/user_metrics.h" |
17 #include "components/page_load_metrics/browser/page_load_metrics_util.h" | 17 #include "components/page_load_metrics/browser/page_load_metrics_util.h" |
18 #include "components/page_load_metrics/common/page_load_metrics_messages.h" | 18 #include "components/page_load_metrics/common/page_load_metrics_param_traits.h" |
19 #include "components/page_load_metrics/common/page_load_timing.h" | 19 #include "components/page_load_metrics/common/page_load_timing.h" |
20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
21 #include "content/public/browser/navigation_details.h" | 21 #include "content/public/browser/navigation_details.h" |
22 #include "content/public/browser/navigation_handle.h" | 22 #include "content/public/browser/navigation_handle.h" |
23 #include "content/public/browser/render_frame_host.h" | 23 #include "content/public/browser/render_frame_host.h" |
24 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
26 #include "content/public/browser/web_contents_observer.h" | 26 #include "content/public/browser/web_contents_observer.h" |
27 #include "content/public/browser/web_contents_user_data.h" | 27 #include "content/public/browser/web_contents_user_data.h" |
28 #include "ipc/ipc_message.h" | 28 #include "ipc/ipc_message.h" |
29 #include "ipc/ipc_message_macros.h" | 29 #include "ipc/ipc_message_macros.h" |
| 30 #include "services/shell/public/cpp/interface_registry.h" |
30 #include "ui/base/page_transition_types.h" | 31 #include "ui/base/page_transition_types.h" |
31 | 32 |
32 DEFINE_WEB_CONTENTS_USER_DATA_KEY( | 33 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
33 page_load_metrics::MetricsWebContentsObserver); | 34 page_load_metrics::MetricsWebContentsObserver); |
34 | 35 |
35 namespace page_load_metrics { | 36 namespace page_load_metrics { |
36 | 37 |
37 namespace internal { | 38 namespace internal { |
38 | 39 |
39 const char kErrorEvents[] = "PageLoad.Events.InternalError"; | 40 const char kErrorEvents[] = "PageLoad.Events.InternalError"; |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 return; | 568 return; |
568 } | 569 } |
569 abort_type_ = abort_type; | 570 abort_type_ = abort_type; |
570 abort_time_ = timestamp; | 571 abort_time_ = timestamp; |
571 | 572 |
572 if (is_certainly_browser_timestamp) { | 573 if (is_certainly_browser_timestamp) { |
573 ClampBrowserTimestampIfInterProcessTimeTickSkew(&abort_time_); | 574 ClampBrowserTimestampIfInterProcessTimeTickSkew(&abort_time_); |
574 } | 575 } |
575 } | 576 } |
576 | 577 |
| 578 class MetricsWebContentsObserver::PageLoadMetricsImpl |
| 579 : public mojom::PageLoadMetrics { |
| 580 public: |
| 581 // Does not take ownership of the arguments, which need to outlive this |
| 582 // object. |
| 583 PageLoadMetricsImpl(MetricsWebContentsObserver* observer, |
| 584 content::RenderFrameHost* host) |
| 585 : observer_(observer), host_(host), binding_(this) {} |
| 586 ~PageLoadMetricsImpl() override = default; |
| 587 |
| 588 // Factory for creating PageLoadMetricsImpl objects upon incoming connections. |
| 589 static void Create(MetricsWebContentsObserver* observer, |
| 590 content::RenderFrameHost* host, |
| 591 mojo::InterfaceRequest<mojom::PageLoadMetrics> request) { |
| 592 auto impl = base::MakeUnique<PageLoadMetricsImpl>(observer, host); |
| 593 impl->binding_.Bind(std::move(request)); |
| 594 observer->registered_interfaces_.push_back(std::move(impl)); |
| 595 } |
| 596 |
| 597 // mojom::PageLoadMetrics override. |
| 598 void TimingUpdated(const PageLoadTiming& timing, |
| 599 const PageLoadMetadata& metadata) override { |
| 600 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 601 observer_->OnTimingUpdated(host_, timing, metadata); |
| 602 } |
| 603 |
| 604 private: |
| 605 MetricsWebContentsObserver* const observer_; |
| 606 content::RenderFrameHost* const host_; |
| 607 mojo::Binding<mojom::PageLoadMetrics> binding_; |
| 608 |
| 609 DISALLOW_COPY_AND_ASSIGN(PageLoadMetricsImpl); |
| 610 }; |
| 611 |
577 // static | 612 // static |
578 MetricsWebContentsObserver::MetricsWebContentsObserver( | 613 MetricsWebContentsObserver::MetricsWebContentsObserver( |
579 content::WebContents* web_contents, | 614 content::WebContents* web_contents, |
580 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) | 615 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) |
581 : content::WebContentsObserver(web_contents), | 616 : content::WebContentsObserver(web_contents), |
582 in_foreground_(false), | 617 in_foreground_(false), |
583 embedder_interface_(std::move(embedder_interface)), | 618 embedder_interface_(std::move(embedder_interface)), |
584 has_navigated_(false) { | 619 has_navigated_(false) { |
585 RegisterInputEventObserver(web_contents->GetRenderViewHost()); | 620 RegisterInputEventObserver(web_contents->GetRenderViewHost()); |
586 } | 621 } |
(...skipping 28 matching lines...) Expand all Loading... |
615 host->GetWidget()->RemoveInputEventObserver(this); | 650 host->GetWidget()->RemoveInputEventObserver(this); |
616 } | 651 } |
617 | 652 |
618 void MetricsWebContentsObserver::RenderViewHostChanged( | 653 void MetricsWebContentsObserver::RenderViewHostChanged( |
619 content::RenderViewHost* old_host, | 654 content::RenderViewHost* old_host, |
620 content::RenderViewHost* new_host) { | 655 content::RenderViewHost* new_host) { |
621 UnregisterInputEventObserver(old_host); | 656 UnregisterInputEventObserver(old_host); |
622 RegisterInputEventObserver(new_host); | 657 RegisterInputEventObserver(new_host); |
623 } | 658 } |
624 | 659 |
625 bool MetricsWebContentsObserver::OnMessageReceived( | |
626 const IPC::Message& message, | |
627 content::RenderFrameHost* render_frame_host) { | |
628 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
629 bool handled = true; | |
630 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(MetricsWebContentsObserver, message, | |
631 render_frame_host) | |
632 IPC_MESSAGE_HANDLER(PageLoadMetricsMsg_TimingUpdated, OnTimingUpdated) | |
633 IPC_MESSAGE_UNHANDLED(handled = false) | |
634 IPC_END_MESSAGE_MAP() | |
635 return handled; | |
636 } | |
637 | |
638 void MetricsWebContentsObserver::DidStartNavigation( | 660 void MetricsWebContentsObserver::DidStartNavigation( |
639 content::NavigationHandle* navigation_handle) { | 661 content::NavigationHandle* navigation_handle) { |
640 if (!navigation_handle->IsInMainFrame()) | 662 if (!navigation_handle->IsInMainFrame()) |
641 return; | 663 return; |
642 | 664 |
643 std::unique_ptr<PageLoadTracker> last_aborted = | 665 std::unique_ptr<PageLoadTracker> last_aborted = |
644 NotifyAbortedProvisionalLoadsNewNavigation(navigation_handle); | 666 NotifyAbortedProvisionalLoadsNewNavigation(navigation_handle); |
645 | 667 |
646 int chain_size_same_url = 0; | 668 int chain_size_same_url = 0; |
647 int chain_size = 0; | 669 int chain_size = 0; |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 aborted_provisional_loads_.pop_back(); | 907 aborted_provisional_loads_.pop_back(); |
886 | 908 |
887 base::TimeTicks timestamp = new_navigation->NavigationStart(); | 909 base::TimeTicks timestamp = new_navigation->NavigationStart(); |
888 if (last_aborted_load->IsLikelyProvisionalAbort(timestamp)) | 910 if (last_aborted_load->IsLikelyProvisionalAbort(timestamp)) |
889 last_aborted_load->UpdateAbort(ABORT_UNKNOWN_NAVIGATION, timestamp, false); | 911 last_aborted_load->UpdateAbort(ABORT_UNKNOWN_NAVIGATION, timestamp, false); |
890 | 912 |
891 aborted_provisional_loads_.clear(); | 913 aborted_provisional_loads_.clear(); |
892 return last_aborted_load; | 914 return last_aborted_load; |
893 } | 915 } |
894 | 916 |
| 917 void MetricsWebContentsObserver::RenderFrameCreated( |
| 918 content::RenderFrameHost* render_frame_host) { |
| 919 RegisterInterfaceImpl(render_frame_host); |
| 920 } |
| 921 |
| 922 void MetricsWebContentsObserver::RenderFrameHostChanged( |
| 923 content::RenderFrameHost* old_host, |
| 924 content::RenderFrameHost* new_host) { |
| 925 RegisterInterfaceImpl(new_host); |
| 926 } |
| 927 void MetricsWebContentsObserver::WebContentsDestroyed() { |
| 928 // At this point we no longer accept any more requests, as OnTimingUpdated |
| 929 // requires the WebContents to exist. |
| 930 registered_interfaces_.clear(); |
| 931 } |
| 932 |
| 933 void MetricsWebContentsObserver::RegisterInterfaceImpl( |
| 934 content::RenderFrameHost* host) { |
| 935 host->GetInterfaceRegistry()->AddInterface( |
| 936 base::Bind(&PageLoadMetricsImpl::Create, base::Unretained(this), |
| 937 base::Unretained(host))); |
| 938 } |
| 939 |
895 void MetricsWebContentsObserver::OnTimingUpdated( | 940 void MetricsWebContentsObserver::OnTimingUpdated( |
896 content::RenderFrameHost* render_frame_host, | 941 content::RenderFrameHost* render_frame_host, |
897 const PageLoadTiming& timing, | 942 const PageLoadTiming& timing, |
898 const PageLoadMetadata& metadata) { | 943 const PageLoadMetadata& metadata) { |
899 bool error = false; | 944 bool error = false; |
900 if (!committed_load_) { | 945 if (!committed_load_) { |
901 RecordInternalError(ERR_IPC_WITH_NO_RELEVANT_LOAD); | 946 RecordInternalError(ERR_IPC_WITH_NO_RELEVANT_LOAD); |
902 error = true; | 947 error = true; |
903 } | 948 } |
904 | 949 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 if (navigation_handle->IsSamePage() || navigation_handle->IsErrorPage()) | 984 if (navigation_handle->IsSamePage() || navigation_handle->IsErrorPage()) |
940 return false; | 985 return false; |
941 const std::string& mime_type = web_contents()->GetContentsMimeType(); | 986 const std::string& mime_type = web_contents()->GetContentsMimeType(); |
942 if (mime_type != "text/html" && mime_type != "application/xhtml+xml") | 987 if (mime_type != "text/html" && mime_type != "application/xhtml+xml") |
943 return false; | 988 return false; |
944 } | 989 } |
945 return true; | 990 return true; |
946 } | 991 } |
947 | 992 |
948 } // namespace page_load_metrics | 993 } // namespace page_load_metrics |
OLD | NEW |