OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/observers/ukm_page_load_metrics_obser
ver.h" | 5 #include "chrome/browser/page_load_metrics/observers/ukm_page_load_metrics_obser
ver.h" |
6 #include "chrome/browser/browser_process.h" | 6 #include "chrome/browser/browser_process.h" |
7 #include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h" | 7 #include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h" |
8 #include "chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.h" | 8 #include "chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.h" |
9 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" | 9 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "components/ukm/ukm_entry_builder.h" | 11 #include "components/ukm/public/ukm_entry_builder.h" |
12 #include "components/ukm/ukm_service.h" | 12 #include "components/ukm/public/ukm_recorder.h" |
13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
14 | 14 |
15 namespace internal { | 15 namespace internal { |
16 | 16 |
17 const char kUkmPageLoadEventName[] = "PageLoad"; | 17 const char kUkmPageLoadEventName[] = "PageLoad"; |
18 const char kUkmParseStartName[] = "ParseTiming.NavigationToParseStart"; | 18 const char kUkmParseStartName[] = "ParseTiming.NavigationToParseStart"; |
19 const char kUkmDomContentLoadedName[] = | 19 const char kUkmDomContentLoadedName[] = |
20 "DocumentTiming.NavigationToDOMContentLoadedEventFired"; | 20 "DocumentTiming.NavigationToDOMContentLoadedEventFired"; |
21 const char kUkmLoadEventName[] = "DocumentTiming.NavigationToLoadEventFired"; | 21 const char kUkmLoadEventName[] = "DocumentTiming.NavigationToLoadEventFired"; |
22 const char kUkmFirstContentfulPaintName[] = | 22 const char kUkmFirstContentfulPaintName[] = |
(...skipping 22 matching lines...) Expand all Loading... |
45 if (!profile) | 45 if (!profile) |
46 return nullptr; | 46 return nullptr; |
47 return UINetworkQualityEstimatorServiceFactory::GetForProfile(profile); | 47 return UINetworkQualityEstimatorServiceFactory::GetForProfile(profile); |
48 } | 48 } |
49 | 49 |
50 } // namespace | 50 } // namespace |
51 | 51 |
52 // static | 52 // static |
53 std::unique_ptr<page_load_metrics::PageLoadMetricsObserver> | 53 std::unique_ptr<page_load_metrics::PageLoadMetricsObserver> |
54 UkmPageLoadMetricsObserver::CreateIfNeeded(content::WebContents* web_contents) { | 54 UkmPageLoadMetricsObserver::CreateIfNeeded(content::WebContents* web_contents) { |
55 if (!g_browser_process->ukm_service()) { | 55 if (!g_browser_process->ukm_recorder()) { |
56 return nullptr; | 56 return nullptr; |
57 } | 57 } |
58 return base::MakeUnique<UkmPageLoadMetricsObserver>( | 58 return base::MakeUnique<UkmPageLoadMetricsObserver>( |
59 GetNQEService(web_contents)); | 59 GetNQEService(web_contents)); |
60 } | 60 } |
61 | 61 |
62 UkmPageLoadMetricsObserver::UkmPageLoadMetricsObserver( | 62 UkmPageLoadMetricsObserver::UkmPageLoadMetricsObserver( |
63 net::NetworkQualityEstimator::NetworkQualityProvider* | 63 net::NetworkQualityEstimator::NetworkQualityProvider* |
64 network_quality_provider) | 64 network_quality_provider) |
65 : network_quality_provider_(network_quality_provider), | 65 : network_quality_provider_(network_quality_provider), |
66 source_id_(ukm::UkmService::GetNewSourceID()) {} | 66 source_id_(ukm::UkmRecorder::GetNewSourceID()) {} |
67 | 67 |
68 UkmPageLoadMetricsObserver::~UkmPageLoadMetricsObserver() = default; | 68 UkmPageLoadMetricsObserver::~UkmPageLoadMetricsObserver() = default; |
69 | 69 |
70 UkmPageLoadMetricsObserver::ObservePolicy UkmPageLoadMetricsObserver::OnStart( | 70 UkmPageLoadMetricsObserver::ObservePolicy UkmPageLoadMetricsObserver::OnStart( |
71 content::NavigationHandle* navigation_handle, | 71 content::NavigationHandle* navigation_handle, |
72 const GURL& currently_committed_url, | 72 const GURL& currently_committed_url, |
73 bool started_in_foreground) { | 73 bool started_in_foreground) { |
74 if (!started_in_foreground) | 74 if (!started_in_foreground) |
75 return STOP_OBSERVING; | 75 return STOP_OBSERVING; |
76 | 76 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 RecordTimingMetrics(timing); | 115 RecordTimingMetrics(timing); |
116 return STOP_OBSERVING; | 116 return STOP_OBSERVING; |
117 } | 117 } |
118 | 118 |
119 void UkmPageLoadMetricsObserver::OnFailedProvisionalLoad( | 119 void UkmPageLoadMetricsObserver::OnFailedProvisionalLoad( |
120 const page_load_metrics::FailedProvisionalLoadInfo& failed_load_info, | 120 const page_load_metrics::FailedProvisionalLoadInfo& failed_load_info, |
121 const page_load_metrics::PageLoadExtraInfo& extra_info) { | 121 const page_load_metrics::PageLoadExtraInfo& extra_info) { |
122 RecordPageLoadExtraInfoMetrics( | 122 RecordPageLoadExtraInfoMetrics( |
123 extra_info, base::TimeTicks() /* no app_background_time */); | 123 extra_info, base::TimeTicks() /* no app_background_time */); |
124 | 124 |
125 ukm::UkmService* ukm_service = g_browser_process->ukm_service(); | 125 ukm::UkmRecorder* ukm_recorder = g_browser_process->ukm_recorder(); |
126 std::unique_ptr<ukm::UkmEntryBuilder> builder = | 126 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_recorder->GetEntryBuilder( |
127 ukm_service->GetEntryBuilder(source_id_, internal::kUkmPageLoadEventName); | 127 source_id_, internal::kUkmPageLoadEventName); |
128 // Error codes have negative values, however we log net error code enum values | 128 // Error codes have negative values, however we log net error code enum values |
129 // for UMA histograms using the equivalent positive value. For consistency in | 129 // for UMA histograms using the equivalent positive value. For consistency in |
130 // UKM, we convert to a positive value here. | 130 // UKM, we convert to a positive value here. |
131 int64_t net_error_code = static_cast<int64_t>(failed_load_info.error) * -1; | 131 int64_t net_error_code = static_cast<int64_t>(failed_load_info.error) * -1; |
132 DCHECK_GE(net_error_code, 0); | 132 DCHECK_GE(net_error_code, 0); |
133 builder->AddMetric(internal::kUkmNetErrorCode, net_error_code); | 133 builder->AddMetric(internal::kUkmNetErrorCode, net_error_code); |
134 builder->AddMetric( | 134 builder->AddMetric( |
135 internal::kUkmFailedProvisionaLoadName, | 135 internal::kUkmFailedProvisionaLoadName, |
136 failed_load_info.time_to_failed_provisional_load.InMilliseconds()); | 136 failed_load_info.time_to_failed_provisional_load.InMilliseconds()); |
137 } | 137 } |
138 | 138 |
139 void UkmPageLoadMetricsObserver::OnComplete( | 139 void UkmPageLoadMetricsObserver::OnComplete( |
140 const page_load_metrics::PageLoadTiming& timing, | 140 const page_load_metrics::PageLoadTiming& timing, |
141 const page_load_metrics::PageLoadExtraInfo& info) { | 141 const page_load_metrics::PageLoadExtraInfo& info) { |
142 RecordPageLoadExtraInfoMetrics( | 142 RecordPageLoadExtraInfoMetrics( |
143 info, base::TimeTicks() /* no app_background_time */); | 143 info, base::TimeTicks() /* no app_background_time */); |
144 RecordTimingMetrics(timing); | 144 RecordTimingMetrics(timing); |
145 } | 145 } |
146 | 146 |
147 void UkmPageLoadMetricsObserver::RecordTimingMetrics( | 147 void UkmPageLoadMetricsObserver::RecordTimingMetrics( |
148 const page_load_metrics::PageLoadTiming& timing) { | 148 const page_load_metrics::PageLoadTiming& timing) { |
149 ukm::UkmService* ukm_service = g_browser_process->ukm_service(); | 149 ukm::UkmRecorder* ukm_recorder = g_browser_process->ukm_recorder(); |
150 std::unique_ptr<ukm::UkmEntryBuilder> builder = | 150 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_recorder->GetEntryBuilder( |
151 ukm_service->GetEntryBuilder(source_id_, internal::kUkmPageLoadEventName); | 151 source_id_, internal::kUkmPageLoadEventName); |
152 if (timing.parse_timing.parse_start) { | 152 if (timing.parse_timing.parse_start) { |
153 builder->AddMetric( | 153 builder->AddMetric( |
154 internal::kUkmParseStartName, | 154 internal::kUkmParseStartName, |
155 timing.parse_timing.parse_start.value().InMilliseconds()); | 155 timing.parse_timing.parse_start.value().InMilliseconds()); |
156 } | 156 } |
157 if (timing.document_timing.dom_content_loaded_event_start) { | 157 if (timing.document_timing.dom_content_loaded_event_start) { |
158 builder->AddMetric( | 158 builder->AddMetric( |
159 internal::kUkmDomContentLoadedName, | 159 internal::kUkmDomContentLoadedName, |
160 timing.document_timing.dom_content_loaded_event_start.value() | 160 timing.document_timing.dom_content_loaded_event_start.value() |
161 .InMilliseconds()); | 161 .InMilliseconds()); |
(...skipping 11 matching lines...) Expand all Loading... |
173 if (timing.paint_timing.first_meaningful_paint) { | 173 if (timing.paint_timing.first_meaningful_paint) { |
174 builder->AddMetric( | 174 builder->AddMetric( |
175 internal::kUkmFirstMeaningfulPaintName, | 175 internal::kUkmFirstMeaningfulPaintName, |
176 timing.paint_timing.first_meaningful_paint.value().InMilliseconds()); | 176 timing.paint_timing.first_meaningful_paint.value().InMilliseconds()); |
177 } | 177 } |
178 } | 178 } |
179 | 179 |
180 void UkmPageLoadMetricsObserver::RecordPageLoadExtraInfoMetrics( | 180 void UkmPageLoadMetricsObserver::RecordPageLoadExtraInfoMetrics( |
181 const page_load_metrics::PageLoadExtraInfo& info, | 181 const page_load_metrics::PageLoadExtraInfo& info, |
182 base::TimeTicks app_background_time) { | 182 base::TimeTicks app_background_time) { |
183 ukm::UkmService* ukm_service = g_browser_process->ukm_service(); | 183 ukm::UkmRecorder* ukm_recorder = g_browser_process->ukm_recorder(); |
184 ukm_service->UpdateSourceURL(source_id_, info.start_url); | 184 ukm_recorder->UpdateSourceURL(source_id_, info.start_url); |
185 ukm_service->UpdateSourceURL(source_id_, info.url); | 185 ukm_recorder->UpdateSourceURL(source_id_, info.url); |
186 | 186 |
187 std::unique_ptr<ukm::UkmEntryBuilder> builder = | 187 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_recorder->GetEntryBuilder( |
188 ukm_service->GetEntryBuilder(source_id_, internal::kUkmPageLoadEventName); | 188 source_id_, internal::kUkmPageLoadEventName); |
189 base::Optional<base::TimeDelta> foreground_duration = | 189 base::Optional<base::TimeDelta> foreground_duration = |
190 page_load_metrics::GetInitialForegroundDuration(info, | 190 page_load_metrics::GetInitialForegroundDuration(info, |
191 app_background_time); | 191 app_background_time); |
192 if (foreground_duration) { | 192 if (foreground_duration) { |
193 builder->AddMetric(internal::kUkmForegroundDurationName, | 193 builder->AddMetric(internal::kUkmForegroundDurationName, |
194 foreground_duration.value().InMilliseconds()); | 194 foreground_duration.value().InMilliseconds()); |
195 } | 195 } |
196 if (effective_connection_type_ != net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { | 196 if (effective_connection_type_ != net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { |
197 builder->AddMetric(internal::kUkmEffectiveConnectionType, | 197 builder->AddMetric(internal::kUkmEffectiveConnectionType, |
198 static_cast<int64_t>(effective_connection_type_)); | 198 static_cast<int64_t>(effective_connection_type_)); |
199 } | 199 } |
200 if (http_rtt_estimate_) { | 200 if (http_rtt_estimate_) { |
201 builder->AddMetric( | 201 builder->AddMetric( |
202 internal::kUkmHttpRttEstimate, | 202 internal::kUkmHttpRttEstimate, |
203 static_cast<int64_t>(http_rtt_estimate_.value().InMilliseconds())); | 203 static_cast<int64_t>(http_rtt_estimate_.value().InMilliseconds())); |
204 } | 204 } |
205 if (transport_rtt_estimate_) { | 205 if (transport_rtt_estimate_) { |
206 builder->AddMetric( | 206 builder->AddMetric( |
207 internal::kUkmTransportRttEstimate, | 207 internal::kUkmTransportRttEstimate, |
208 static_cast<int64_t>(transport_rtt_estimate_.value().InMilliseconds())); | 208 static_cast<int64_t>(transport_rtt_estimate_.value().InMilliseconds())); |
209 } | 209 } |
210 // page_transition_ fits in a uint32_t, so we can safely cast to int64_t. | 210 // page_transition_ fits in a uint32_t, so we can safely cast to int64_t. |
211 builder->AddMetric(internal::kUkmPageTransition, | 211 builder->AddMetric(internal::kUkmPageTransition, |
212 static_cast<int64_t>(page_transition_)); | 212 static_cast<int64_t>(page_transition_)); |
213 } | 213 } |
OLD | NEW |