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 { |
(...skipping 17 matching lines...) Expand all Loading... |
28 extra_request_complete_info) { | 28 extra_request_complete_info) { |
29 if (extra_request_complete_info.was_cached) { | 29 if (extra_request_complete_info.was_cached) { |
30 cache_bytes_ += extra_request_complete_info.raw_body_bytes; | 30 cache_bytes_ += extra_request_complete_info.raw_body_bytes; |
31 } else { | 31 } else { |
32 network_bytes_ += extra_request_complete_info.raw_body_bytes; | 32 network_bytes_ += extra_request_complete_info.raw_body_bytes; |
33 } | 33 } |
34 } | 34 } |
35 | 35 |
36 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 36 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
37 MediaPageLoadMetricsObserver::FlushMetricsOnAppEnterBackground( | 37 MediaPageLoadMetricsObserver::FlushMetricsOnAppEnterBackground( |
38 const page_load_metrics::PageLoadTiming& timing, | 38 const page_load_metrics::mojom::PageLoadTiming& timing, |
39 const page_load_metrics::PageLoadExtraInfo& info) { | 39 const page_load_metrics::PageLoadExtraInfo& info) { |
40 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the | 40 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the |
41 // 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() |
42 // 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 |
43 // notification, so we record final metrics collected up to this point. | 43 // notification, so we record final metrics collected up to this point. |
44 if (info.did_commit && played_media_) { | 44 if (info.did_commit && played_media_) { |
45 RecordByteHistograms(); | 45 RecordByteHistograms(); |
46 } | 46 } |
47 return STOP_OBSERVING; | 47 return STOP_OBSERVING; |
48 } | 48 } |
49 | 49 |
50 void MediaPageLoadMetricsObserver::OnComplete( | 50 void MediaPageLoadMetricsObserver::OnComplete( |
51 const page_load_metrics::PageLoadTiming& timing, | 51 const page_load_metrics::mojom::PageLoadTiming& timing, |
52 const page_load_metrics::PageLoadExtraInfo& info) { | 52 const page_load_metrics::PageLoadExtraInfo& info) { |
53 if (!played_media_) | 53 if (!played_media_) |
54 return; | 54 return; |
55 RecordByteHistograms(); | 55 RecordByteHistograms(); |
56 } | 56 } |
57 | 57 |
58 void MediaPageLoadMetricsObserver::MediaStartedPlaying( | 58 void MediaPageLoadMetricsObserver::MediaStartedPlaying( |
59 const content::WebContentsObserver::MediaPlayerInfo& video_type, | 59 const content::WebContentsObserver::MediaPlayerInfo& video_type, |
60 bool is_in_main_frame) { | 60 bool is_in_main_frame) { |
61 if (played_media_) | 61 if (played_media_) |
62 return; | 62 return; |
63 // 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. |
64 played_media_ = true; | 64 played_media_ = true; |
65 } | 65 } |
66 | 66 |
67 void MediaPageLoadMetricsObserver::RecordByteHistograms() { | 67 void MediaPageLoadMetricsObserver::RecordByteHistograms() { |
68 DCHECK(played_media_); | 68 DCHECK(played_media_); |
69 PAGE_BYTES_HISTOGRAM(kHistogramNetworkBytes, network_bytes_); | 69 PAGE_BYTES_HISTOGRAM(kHistogramNetworkBytes, network_bytes_); |
70 PAGE_BYTES_HISTOGRAM(kHistogramCacheBytes, cache_bytes_); | 70 PAGE_BYTES_HISTOGRAM(kHistogramCacheBytes, cache_bytes_); |
71 PAGE_BYTES_HISTOGRAM(kHistogramTotalBytes, network_bytes_ + cache_bytes_); | 71 PAGE_BYTES_HISTOGRAM(kHistogramTotalBytes, network_bytes_ + cache_bytes_); |
72 } | 72 } |
OLD | NEW |