| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 const char kUkmLoadEventName[] = "DocumentTiming.NavigationToLoadEventFired"; | 21 const char kUkmLoadEventName[] = "DocumentTiming.NavigationToLoadEventFired"; |
| 22 const char kUkmFirstContentfulPaintName[] = | 22 const char kUkmFirstContentfulPaintName[] = |
| 23 "PaintTiming.NavigationToFirstContentfulPaint"; | 23 "PaintTiming.NavigationToFirstContentfulPaint"; |
| 24 const char kUkmFirstMeaningfulPaintName[] = | 24 const char kUkmFirstMeaningfulPaintName[] = |
| 25 "Experimental.PaintTiming.NavigationToFirstMeaningfulPaint"; | 25 "Experimental.PaintTiming.NavigationToFirstMeaningfulPaint"; |
| 26 const char kUkmForegroundDurationName[] = "PageTiming.ForegroundDuration"; | 26 const char kUkmForegroundDurationName[] = "PageTiming.ForegroundDuration"; |
| 27 const char kUkmFailedProvisionaLoadName[] = | 27 const char kUkmFailedProvisionaLoadName[] = |
| 28 "PageTiming.NavigationToFailedProvisionalLoad"; | 28 "PageTiming.NavigationToFailedProvisionalLoad"; |
| 29 const char kUkmEffectiveConnectionType[] = | 29 const char kUkmEffectiveConnectionType[] = |
| 30 "Net.EffectiveConnectionType.OnNavigationStart"; | 30 "Net.EffectiveConnectionType.OnNavigationStart"; |
| 31 const char kUkmHttpRttEstimate[] = "Net.HttpRttEstimate.OnNavigationStart"; |
| 32 const char kUkmTransportRttEstimate[] = |
| 33 "Net.TransportRttEstimate.OnNavigationStart"; |
| 31 const char kUkmNetErrorCode[] = "Net.ErrorCode.OnFailedProvisionalLoad"; | 34 const char kUkmNetErrorCode[] = "Net.ErrorCode.OnFailedProvisionalLoad"; |
| 32 const char kUkmPageTransition[] = "Navigation.PageTransition"; | 35 const char kUkmPageTransition[] = "Navigation.PageTransition"; |
| 33 | 36 |
| 34 } // namespace internal | 37 } // namespace internal |
| 35 | 38 |
| 36 namespace { | 39 namespace { |
| 37 | 40 |
| 38 UINetworkQualityEstimatorService* GetNQEService( | 41 UINetworkQualityEstimatorService* GetNQEService( |
| 39 content::WebContents* web_contents) { | 42 content::WebContents* web_contents) { |
| 40 Profile* profile = | 43 Profile* profile = |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // When OnStart is invoked, we don't yet know whether we're observing a web | 77 // When OnStart is invoked, we don't yet know whether we're observing a web |
| 75 // page load, vs another kind of load (e.g. a download or a PDF). Thus, | 78 // page load, vs another kind of load (e.g. a download or a PDF). Thus, |
| 76 // metrics and source information should not be recorded here. Instead, we | 79 // metrics and source information should not be recorded here. Instead, we |
| 77 // store data we might want to persist in member variables below, and later | 80 // store data we might want to persist in member variables below, and later |
| 78 // record UKM metrics for that data once we've confirmed that we're observing | 81 // record UKM metrics for that data once we've confirmed that we're observing |
| 79 // a web page load. | 82 // a web page load. |
| 80 | 83 |
| 81 if (network_quality_provider_) { | 84 if (network_quality_provider_) { |
| 82 effective_connection_type_ = | 85 effective_connection_type_ = |
| 83 network_quality_provider_->GetEffectiveConnectionType(); | 86 network_quality_provider_->GetEffectiveConnectionType(); |
| 87 http_rtt_estimate_ = network_quality_provider_->GetHttpRTT(); |
| 88 transport_rtt_estimate_ = network_quality_provider_->GetTransportRTT(); |
| 84 } | 89 } |
| 85 page_transition_ = navigation_handle->GetPageTransition(); | 90 page_transition_ = navigation_handle->GetPageTransition(); |
| 86 return CONTINUE_OBSERVING; | 91 return CONTINUE_OBSERVING; |
| 87 } | 92 } |
| 88 | 93 |
| 89 UkmPageLoadMetricsObserver::ObservePolicy UkmPageLoadMetricsObserver::OnCommit( | 94 UkmPageLoadMetricsObserver::ObservePolicy UkmPageLoadMetricsObserver::OnCommit( |
| 90 content::NavigationHandle* navigation_handle) { | 95 content::NavigationHandle* navigation_handle) { |
| 91 // The PageTransition for the navigation may be updated on commit. | 96 // The PageTransition for the navigation may be updated on commit. |
| 92 page_transition_ = navigation_handle->GetPageTransition(); | 97 page_transition_ = navigation_handle->GetPageTransition(); |
| 93 return CONTINUE_OBSERVING; | 98 return CONTINUE_OBSERVING; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 page_load_metrics::GetInitialForegroundDuration(info, | 185 page_load_metrics::GetInitialForegroundDuration(info, |
| 181 app_background_time); | 186 app_background_time); |
| 182 if (foreground_duration) { | 187 if (foreground_duration) { |
| 183 builder->AddMetric(internal::kUkmForegroundDurationName, | 188 builder->AddMetric(internal::kUkmForegroundDurationName, |
| 184 foreground_duration.value().InMilliseconds()); | 189 foreground_duration.value().InMilliseconds()); |
| 185 } | 190 } |
| 186 if (effective_connection_type_ != net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { | 191 if (effective_connection_type_ != net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { |
| 187 builder->AddMetric(internal::kUkmEffectiveConnectionType, | 192 builder->AddMetric(internal::kUkmEffectiveConnectionType, |
| 188 static_cast<int64_t>(effective_connection_type_)); | 193 static_cast<int64_t>(effective_connection_type_)); |
| 189 } | 194 } |
| 195 if (http_rtt_estimate_) { |
| 196 builder->AddMetric( |
| 197 internal::kUkmHttpRttEstimate, |
| 198 static_cast<int64_t>(http_rtt_estimate_.value().InMilliseconds())); |
| 199 } |
| 200 if (transport_rtt_estimate_) { |
| 201 builder->AddMetric( |
| 202 internal::kUkmTransportRttEstimate, |
| 203 static_cast<int64_t>(transport_rtt_estimate_.value().InMilliseconds())); |
| 204 } |
| 190 // page_transition_ fits in a uint32_t, so we can safely cast to int64_t. | 205 // page_transition_ fits in a uint32_t, so we can safely cast to int64_t. |
| 191 builder->AddMetric(internal::kUkmPageTransition, | 206 builder->AddMetric(internal::kUkmPageTransition, |
| 192 static_cast<int64_t>(page_transition_)); | 207 static_cast<int64_t>(page_transition_)); |
| 193 } | 208 } |
| OLD | NEW |