| 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/media_page_load_metrics_obs
erver.h" | 5 #include "chrome/browser/page_load_metrics/observers/media_page_load_metrics_obs
erver.h" |
| 6 | 6 |
| 7 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" | 7 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
| 8 #include "chrome/common/page_load_metrics/page_load_timing.h" | 8 #include "chrome/common/page_load_metrics/page_load_timing.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| 11 | 11 |
| 12 const char kHistogramNetworkBytes[] = | 12 const char kHistogramNetworkBytes[] = |
| 13 "PageLoad.Clients.MediaPageLoad.Experimental.Bytes.Network"; | 13 "PageLoad.Clients.MediaPageLoad.Experimental.Bytes.Network"; |
| 14 const char kHistogramCacheBytes[] = | 14 const char kHistogramCacheBytes[] = |
| 15 "PageLoad.Clients.MediaPageLoad.Experimental.Bytes.Cache"; | 15 "PageLoad.Clients.MediaPageLoad.Experimental.Bytes.Cache"; |
| 16 const char kHistogramTotalBytes[] = | 16 const char kHistogramTotalBytes[] = |
| 17 "PageLoad.Clients.MediaPageLoad.Experimental.Bytes.Total"; | 17 "PageLoad.Clients.MediaPageLoad.Experimental.Bytes.Total"; |
| 18 | 18 |
| 19 } // namespace | 19 } // namespace |
| 20 | 20 |
| 21 MediaPageLoadMetricsObserver::MediaPageLoadMetricsObserver() | 21 MediaPageLoadMetricsObserver::MediaPageLoadMetricsObserver() |
| 22 : cache_bytes_(0), network_bytes_(0), played_media_(false) {} | 22 : cache_bytes_(0), network_bytes_(0), played_media_(false) {} |
| 23 | 23 |
| 24 MediaPageLoadMetricsObserver::~MediaPageLoadMetricsObserver() = default; | 24 MediaPageLoadMetricsObserver::~MediaPageLoadMetricsObserver() = default; |
| 25 | 25 |
| 26 void MediaPageLoadMetricsObserver::OnLoadedResource( | 26 void MediaPageLoadMetricsObserver::OnLoadedResource( |
| 27 const page_load_metrics::ExtraRequestInfo& extra_request_info) { | 27 const page_load_metrics::ExtraRequestCompleteInfo& |
| 28 if (extra_request_info.was_cached) { | 28 extra_request_complete_info) { |
| 29 cache_bytes_ += extra_request_info.raw_body_bytes; | 29 if (extra_request_complete_info.was_cached) { |
| 30 cache_bytes_ += extra_request_complete_info.raw_body_bytes; |
| 30 } else { | 31 } else { |
| 31 network_bytes_ += extra_request_info.raw_body_bytes; | 32 network_bytes_ += extra_request_complete_info.raw_body_bytes; |
| 32 } | 33 } |
| 33 } | 34 } |
| 34 | 35 |
| 35 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 36 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
| 36 MediaPageLoadMetricsObserver::FlushMetricsOnAppEnterBackground( | 37 MediaPageLoadMetricsObserver::FlushMetricsOnAppEnterBackground( |
| 37 const page_load_metrics::PageLoadTiming& timing, | 38 const page_load_metrics::PageLoadTiming& timing, |
| 38 const page_load_metrics::PageLoadExtraInfo& info) { | 39 const page_load_metrics::PageLoadExtraInfo& info) { |
| 39 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the | 40 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the |
| 40 // app is about to be backgrounded, as part of the Activity.onPause() | 41 // app is about to be backgrounded, as part of the Activity.onPause() |
| 41 // flow. After this method is invoked, Chrome may be killed without further | 42 // flow. After this method is invoked, Chrome may be killed without further |
| (...skipping 20 matching lines...) Expand all Loading... |
| 62 // Track media (audio or video) in all frames of the page load. | 63 // Track media (audio or video) in all frames of the page load. |
| 63 played_media_ = true; | 64 played_media_ = true; |
| 64 } | 65 } |
| 65 | 66 |
| 66 void MediaPageLoadMetricsObserver::RecordByteHistograms() { | 67 void MediaPageLoadMetricsObserver::RecordByteHistograms() { |
| 67 DCHECK(played_media_); | 68 DCHECK(played_media_); |
| 68 PAGE_BYTES_HISTOGRAM(kHistogramNetworkBytes, network_bytes_); | 69 PAGE_BYTES_HISTOGRAM(kHistogramNetworkBytes, network_bytes_); |
| 69 PAGE_BYTES_HISTOGRAM(kHistogramCacheBytes, cache_bytes_); | 70 PAGE_BYTES_HISTOGRAM(kHistogramCacheBytes, cache_bytes_); |
| 70 PAGE_BYTES_HISTOGRAM(kHistogramTotalBytes, network_bytes_ + cache_bytes_); | 71 PAGE_BYTES_HISTOGRAM(kHistogramTotalBytes, network_bytes_ + cache_bytes_); |
| 71 } | 72 } |
| OLD | NEW |