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
3 // found in the LICENSE file.
4 
5 #include "components/page_load_metrics/browser/page_load_metrics_observer.h"
6 
7 #include <utility>
8 
9 namespace page_load_metrics {
10 
ExtraRequestCompleteInfo(const url::Origin & origin_of_final_url,const net::IPEndPoint & remote_endpoint,int frame_tree_node_id,bool was_cached,int64_t raw_body_bytes,int64_t original_network_content_length,std::unique_ptr<data_reduction_proxy::DataReductionProxyData> data_reduction_proxy_data,network::mojom::RequestDestination request_destination,int net_error,std::unique_ptr<net::LoadTimingInfo> load_timing_info)11 ExtraRequestCompleteInfo::ExtraRequestCompleteInfo(
12     const url::Origin& origin_of_final_url,
13     const net::IPEndPoint& remote_endpoint,
14     int frame_tree_node_id,
15     bool was_cached,
16     int64_t raw_body_bytes,
17     int64_t original_network_content_length,
18     std::unique_ptr<data_reduction_proxy::DataReductionProxyData>
19         data_reduction_proxy_data,
20     network::mojom::RequestDestination request_destination,
21     int net_error,
22     std::unique_ptr<net::LoadTimingInfo> load_timing_info)
23     : origin_of_final_url(origin_of_final_url),
24       remote_endpoint(remote_endpoint),
25       frame_tree_node_id(frame_tree_node_id),
26       was_cached(was_cached),
27       raw_body_bytes(raw_body_bytes),
28       original_network_content_length(original_network_content_length),
29       data_reduction_proxy_data(std::move(data_reduction_proxy_data)),
30       request_destination(request_destination),
31       net_error(net_error),
32       load_timing_info(std::move(load_timing_info)) {}
33 
ExtraRequestCompleteInfo(const ExtraRequestCompleteInfo & other)34 ExtraRequestCompleteInfo::ExtraRequestCompleteInfo(
35     const ExtraRequestCompleteInfo& other)
36     : origin_of_final_url(other.origin_of_final_url),
37       remote_endpoint(other.remote_endpoint),
38       frame_tree_node_id(other.frame_tree_node_id),
39       was_cached(other.was_cached),
40       raw_body_bytes(other.raw_body_bytes),
41       original_network_content_length(other.original_network_content_length),
42       data_reduction_proxy_data(
43           other.data_reduction_proxy_data == nullptr
44               ? nullptr
45               : other.data_reduction_proxy_data->DeepCopy()),
46       request_destination(other.request_destination),
47       net_error(other.net_error),
48       load_timing_info(other.load_timing_info == nullptr
49                            ? nullptr
50                            : std::make_unique<net::LoadTimingInfo>(
51                                  *other.load_timing_info)) {}
52 
~ExtraRequestCompleteInfo()53 ExtraRequestCompleteInfo::~ExtraRequestCompleteInfo() {}
54 
FailedProvisionalLoadInfo(base::TimeDelta interval,net::Error error)55 FailedProvisionalLoadInfo::FailedProvisionalLoadInfo(base::TimeDelta interval,
56                                                      net::Error error)
57     : time_to_failed_provisional_load(interval), error(error) {}
58 
~FailedProvisionalLoadInfo()59 FailedProvisionalLoadInfo::~FailedProvisionalLoadInfo() {}
60 
OnStart(content::NavigationHandle * navigation_handle,const GURL & currently_committed_url,bool started_in_foreground)61 PageLoadMetricsObserver::ObservePolicy PageLoadMetricsObserver::OnStart(
62     content::NavigationHandle* navigation_handle,
63     const GURL& currently_committed_url,
64     bool started_in_foreground) {
65   return CONTINUE_OBSERVING;
66 }
67 
OnRedirect(content::NavigationHandle * navigation_handle)68 PageLoadMetricsObserver::ObservePolicy PageLoadMetricsObserver::OnRedirect(
69     content::NavigationHandle* navigation_handle) {
70   return CONTINUE_OBSERVING;
71 }
72 
OnCommit(content::NavigationHandle * navigation_handle,ukm::SourceId source_id)73 PageLoadMetricsObserver::ObservePolicy PageLoadMetricsObserver::OnCommit(
74     content::NavigationHandle* navigation_handle,
75     ukm::SourceId source_id) {
76   return CONTINUE_OBSERVING;
77 }
78 
OnHidden(const mojom::PageLoadTiming & timing)79 PageLoadMetricsObserver::ObservePolicy PageLoadMetricsObserver::OnHidden(
80     const mojom::PageLoadTiming& timing) {
81   return CONTINUE_OBSERVING;
82 }
83 
OnShown()84 PageLoadMetricsObserver::ObservePolicy PageLoadMetricsObserver::OnShown() {
85   return CONTINUE_OBSERVING;
86 }
87 
88 PageLoadMetricsObserver::ObservePolicy
OnEnterBackForwardCache(const mojom::PageLoadTiming & timing)89 PageLoadMetricsObserver::OnEnterBackForwardCache(
90     const mojom::PageLoadTiming& timing) {
91   // Invoke OnComplete to ensure that recorded data is dumped.
92   OnComplete(timing);
93   return STOP_OBSERVING;
94 }
95 
96 PageLoadMetricsObserver::ObservePolicy
FlushMetricsOnAppEnterBackground(const mojom::PageLoadTiming & timing)97 PageLoadMetricsObserver::FlushMetricsOnAppEnterBackground(
98     const mojom::PageLoadTiming& timing) {
99   return CONTINUE_OBSERVING;
100 }
101 
102 PageLoadMetricsObserver::ObservePolicy
ShouldObserveMimeType(const std::string & mime_type) const103 PageLoadMetricsObserver::ShouldObserveMimeType(
104     const std::string& mime_type) const {
105   return IsStandardWebPageMimeType(mime_type) ? CONTINUE_OBSERVING
106                                               : STOP_OBSERVING;
107 }
108 
109 // static
IsStandardWebPageMimeType(const std::string & mime_type)110 bool PageLoadMetricsObserver::IsStandardWebPageMimeType(
111     const std::string& mime_type) {
112   return mime_type == "text/html" || mime_type == "application/xhtml+xml";
113 }
114 
GetDelegate() const115 const PageLoadMetricsObserverDelegate& PageLoadMetricsObserver::GetDelegate()
116     const {
117   // The delegate must exist and outlive the page load metrics observer.
118   DCHECK(delegate_);
119   return *delegate_;
120 }
121 
SetDelegate(PageLoadMetricsObserverDelegate * delegate)122 void PageLoadMetricsObserver::SetDelegate(
123     PageLoadMetricsObserverDelegate* delegate) {
124   delegate_ = delegate;
125 }
126 
127 }  // namespace page_load_metrics
128