| 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/lofi_page_load_metrics_obse
rver.h" | 5 #include "chrome/browser/page_load_metrics/observers/lofi_page_load_metrics_obse
rver.h" |
| 6 | 6 |
| 7 #include "base/optional.h" | 7 #include "base/optional.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" | 9 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" |
| 10 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" | 10 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 content::NavigationHandle* navigation_handle, | 52 content::NavigationHandle* navigation_handle, |
| 53 const GURL& currently_committed_url, | 53 const GURL& currently_committed_url, |
| 54 bool started_in_foreground) { | 54 bool started_in_foreground) { |
| 55 if (!started_in_foreground) | 55 if (!started_in_foreground) |
| 56 return STOP_OBSERVING; | 56 return STOP_OBSERVING; |
| 57 return CONTINUE_OBSERVING; | 57 return CONTINUE_OBSERVING; |
| 58 } | 58 } |
| 59 | 59 |
| 60 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 60 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
| 61 LoFiPageLoadMetricsObserver::FlushMetricsOnAppEnterBackground( | 61 LoFiPageLoadMetricsObserver::FlushMetricsOnAppEnterBackground( |
| 62 const page_load_metrics::PageLoadTiming& timing, | 62 const page_load_metrics::mojom::PageLoadTiming& timing, |
| 63 const page_load_metrics::PageLoadExtraInfo& info) { | 63 const page_load_metrics::PageLoadExtraInfo& info) { |
| 64 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the | 64 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the |
| 65 // app is about to be backgrounded, as part of the Activity.onPause() | 65 // app is about to be backgrounded, as part of the Activity.onPause() |
| 66 // flow. After this method is invoked, Chrome may be killed without further | 66 // flow. After this method is invoked, Chrome may be killed without further |
| 67 // notification. | 67 // notification. |
| 68 if (num_network_lofi_resources_ > 0 && info.did_commit) { | 68 if (num_network_lofi_resources_ > 0 && info.did_commit) { |
| 69 RecordPageSizeUMA(); | 69 RecordPageSizeUMA(); |
| 70 RecordTimingMetrics(timing, info); | 70 RecordTimingMetrics(timing, info); |
| 71 } | 71 } |
| 72 return STOP_OBSERVING; | 72 return STOP_OBSERVING; |
| 73 } | 73 } |
| 74 | 74 |
| 75 void LoFiPageLoadMetricsObserver::OnComplete( | 75 void LoFiPageLoadMetricsObserver::OnComplete( |
| 76 const page_load_metrics::PageLoadTiming& timing, | 76 const page_load_metrics::mojom::PageLoadTiming& timing, |
| 77 const page_load_metrics::PageLoadExtraInfo& info) { | 77 const page_load_metrics::PageLoadExtraInfo& info) { |
| 78 if (num_network_lofi_resources_ == 0) | 78 if (num_network_lofi_resources_ == 0) |
| 79 return; | 79 return; |
| 80 RecordPageSizeUMA(); | 80 RecordPageSizeUMA(); |
| 81 RecordTimingMetrics(timing, info); | 81 RecordTimingMetrics(timing, info); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void LoFiPageLoadMetricsObserver::RecordPageSizeUMA() const { | 84 void LoFiPageLoadMetricsObserver::RecordPageSizeUMA() const { |
| 85 PAGE_RESOURCE_COUNT_HISTOGRAM(lofi_names::kNumNetworkResources, | 85 PAGE_RESOURCE_COUNT_HISTOGRAM(lofi_names::kNumNetworkResources, |
| 86 num_network_resources_); | 86 num_network_resources_); |
| 87 PAGE_RESOURCE_COUNT_HISTOGRAM(lofi_names::kNumNetworkLoFiResources, | 87 PAGE_RESOURCE_COUNT_HISTOGRAM(lofi_names::kNumNetworkLoFiResources, |
| 88 num_network_lofi_resources_); | 88 num_network_lofi_resources_); |
| 89 PAGE_BYTES_HISTOGRAM(lofi_names::kNetworkBytes, network_bytes_); | 89 PAGE_BYTES_HISTOGRAM(lofi_names::kNetworkBytes, network_bytes_); |
| 90 PAGE_BYTES_HISTOGRAM(lofi_names::kLoFiNetworkBytes, lofi_network_bytes_); | 90 PAGE_BYTES_HISTOGRAM(lofi_names::kLoFiNetworkBytes, lofi_network_bytes_); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void LoFiPageLoadMetricsObserver::RecordTimingMetrics( | 93 void LoFiPageLoadMetricsObserver::RecordTimingMetrics( |
| 94 const page_load_metrics::PageLoadTiming& timing, | 94 const page_load_metrics::mojom::PageLoadTiming& timing, |
| 95 const page_load_metrics::PageLoadExtraInfo& info) { | 95 const page_load_metrics::PageLoadExtraInfo& info) { |
| 96 if (WasStartedInForegroundOptionalEventInForeground( | 96 if (WasStartedInForegroundOptionalEventInForeground( |
| 97 timing.document_timing.load_event_start, info)) { | 97 timing.document_timing->load_event_start, info)) { |
| 98 PAGE_LOAD_HISTOGRAM(lofi_names::kNavigationToLoadEvent, | 98 PAGE_LOAD_HISTOGRAM(lofi_names::kNavigationToLoadEvent, |
| 99 timing.document_timing.load_event_start.value()); | 99 timing.document_timing->load_event_start.value()); |
| 100 } | 100 } |
| 101 if (WasStartedInForegroundOptionalEventInForeground( | 101 if (WasStartedInForegroundOptionalEventInForeground( |
| 102 timing.paint_timing.first_contentful_paint, info)) { | 102 timing.paint_timing->first_contentful_paint, info)) { |
| 103 PAGE_LOAD_HISTOGRAM(lofi_names::kNavigationToFirstContentfulPaint, | 103 PAGE_LOAD_HISTOGRAM(lofi_names::kNavigationToFirstContentfulPaint, |
| 104 timing.paint_timing.first_contentful_paint.value()); | 104 timing.paint_timing->first_contentful_paint.value()); |
| 105 } | 105 } |
| 106 if (WasStartedInForegroundOptionalEventInForeground( | 106 if (WasStartedInForegroundOptionalEventInForeground( |
| 107 timing.paint_timing.first_meaningful_paint, info)) { | 107 timing.paint_timing->first_meaningful_paint, info)) { |
| 108 PAGE_LOAD_HISTOGRAM(lofi_names::kNavigationToFirstMeaningfulPaint, | 108 PAGE_LOAD_HISTOGRAM(lofi_names::kNavigationToFirstMeaningfulPaint, |
| 109 timing.paint_timing.first_meaningful_paint.value()); | 109 timing.paint_timing->first_meaningful_paint.value()); |
| 110 } | 110 } |
| 111 if (WasStartedInForegroundOptionalEventInForeground( | 111 if (WasStartedInForegroundOptionalEventInForeground( |
| 112 timing.paint_timing.first_image_paint, info)) { | 112 timing.paint_timing->first_image_paint, info)) { |
| 113 PAGE_LOAD_HISTOGRAM(lofi_names::kNavigationToFirstImagePaint, | 113 PAGE_LOAD_HISTOGRAM(lofi_names::kNavigationToFirstImagePaint, |
| 114 timing.paint_timing.first_image_paint.value()); | 114 timing.paint_timing->first_image_paint.value()); |
| 115 } | 115 } |
| 116 if (WasStartedInForegroundOptionalEventInForeground( | 116 if (WasStartedInForegroundOptionalEventInForeground( |
| 117 timing.parse_timing.parse_stop, info)) { | 117 timing.parse_timing->parse_stop, info)) { |
| 118 PAGE_LOAD_HISTOGRAM( | 118 PAGE_LOAD_HISTOGRAM( |
| 119 lofi_names::kParseBlockedOnScriptLoad, | 119 lofi_names::kParseBlockedOnScriptLoad, |
| 120 timing.parse_timing.parse_blocked_on_script_load_duration.value()); | 120 timing.parse_timing->parse_blocked_on_script_load_duration.value()); |
| 121 PAGE_LOAD_HISTOGRAM(lofi_names::kParseDuration, | 121 PAGE_LOAD_HISTOGRAM(lofi_names::kParseDuration, |
| 122 timing.parse_timing.parse_stop.value() - | 122 timing.parse_timing->parse_stop.value() - |
| 123 timing.parse_timing.parse_start.value()); | 123 timing.parse_timing->parse_start.value()); |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 | 126 |
| 127 void LoFiPageLoadMetricsObserver::OnLoadedResource( | 127 void LoFiPageLoadMetricsObserver::OnLoadedResource( |
| 128 const page_load_metrics::ExtraRequestCompleteInfo& | 128 const page_load_metrics::ExtraRequestCompleteInfo& |
| 129 extra_request_complete_info) { | 129 extra_request_complete_info) { |
| 130 if (extra_request_complete_info.was_cached) | 130 if (extra_request_complete_info.was_cached) |
| 131 return; | 131 return; |
| 132 ++num_network_resources_; | 132 ++num_network_resources_; |
| 133 network_bytes_ += extra_request_complete_info.raw_body_bytes; | 133 network_bytes_ += extra_request_complete_info.raw_body_bytes; |
| 134 original_network_bytes_ += | 134 original_network_bytes_ += |
| 135 extra_request_complete_info.original_network_content_length; | 135 extra_request_complete_info.original_network_content_length; |
| 136 if (extra_request_complete_info.data_reduction_proxy_data && | 136 if (extra_request_complete_info.data_reduction_proxy_data && |
| 137 (extra_request_complete_info.data_reduction_proxy_data->lofi_received() || | 137 (extra_request_complete_info.data_reduction_proxy_data->lofi_received() || |
| 138 extra_request_complete_info.data_reduction_proxy_data | 138 extra_request_complete_info.data_reduction_proxy_data |
| 139 ->client_lofi_requested())) { | 139 ->client_lofi_requested())) { |
| 140 ++num_network_lofi_resources_; | 140 ++num_network_lofi_resources_; |
| 141 lofi_network_bytes_ += extra_request_complete_info.raw_body_bytes; | 141 lofi_network_bytes_ += extra_request_complete_info.raw_body_bytes; |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 | 144 |
| 145 } // namespace data_reduction_proxy | 145 } // namespace data_reduction_proxy |
| OLD | NEW |