Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/page_load_metrics/observers/media_page_load_metrics_obs erver.h" | |
| 6 | |
| 7 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" | |
| 8 #include "chrome/common/page_load_metrics/page_load_timing.h" | |
| 9 #include "third_party/WebKit/public/platform/WebLoadingBehaviorFlag.h" | |
| 10 | |
| 11 namespace { | |
| 12 | |
| 13 const char kHistogramNetworkBytes[] = | |
| 14 "PageLoad.Clients.MediaPageLoad.Experimental.Bytes.Network"; | |
| 15 const char kHistogramCacheBytes[] = | |
| 16 "PageLoad.Clients.MediaPageLoad.Experimental.Bytes.Cache"; | |
| 17 const char kHistogramTotalBytes[] = | |
| 18 "PageLoad.Clients.MediaPageLoad.Experimental.Bytes.Total"; | |
| 19 | |
| 20 } // namespace | |
| 21 | |
| 22 MediaPageLoadMetricsObserver::MediaPageLoadMetricsObserver() | |
| 23 : cache_bytes_(0), network_bytes_(0), played_media_(false) {} | |
| 24 | |
| 25 MediaPageLoadMetricsObserver::~MediaPageLoadMetricsObserver() {} | |
|
mlamouri (slow - plz ping)
2017/03/13 18:38:27
nit: = default;
RyanSturm
2017/03/13 23:38:24
Done. I've only rarely seen "default" for destruct
| |
| 26 | |
| 27 void MediaPageLoadMetricsObserver::OnLoadedResource( | |
| 28 const page_load_metrics::ExtraRequestInfo& extra_request_info) { | |
| 29 if (extra_request_info.was_cached) { | |
| 30 cache_bytes_ += extra_request_info.raw_body_bytes; | |
| 31 } else { | |
| 32 network_bytes_ += extra_request_info.raw_body_bytes; | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | |
| 37 MediaPageLoadMetricsObserver::FlushMetricsOnAppEnterBackground( | |
| 38 const page_load_metrics::PageLoadTiming& timing, | |
| 39 const page_load_metrics::PageLoadExtraInfo& info) { | |
| 40 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the | |
| 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 | |
| 43 // notification, so we record final metrics collected up to this point. | |
| 44 if (info.did_commit && played_media_) { | |
| 45 RecordByteHistograms(); | |
| 46 } | |
| 47 return STOP_OBSERVING; | |
| 48 } | |
| 49 | |
| 50 void MediaPageLoadMetricsObserver::OnComplete( | |
| 51 const page_load_metrics::PageLoadTiming& timing, | |
| 52 const page_load_metrics::PageLoadExtraInfo& info) { | |
| 53 if (!played_media_) | |
| 54 return; | |
| 55 RecordByteHistograms(); | |
| 56 } | |
| 57 | |
| 58 void MediaPageLoadMetricsObserver::OnLoadingBehaviorObserved( | |
| 59 const page_load_metrics::PageLoadExtraInfo& info) { | |
| 60 if (played_media_) | |
| 61 return; | |
| 62 | |
| 63 played_media_ = | |
| 64 (info.metadata.behavior_flags & | |
| 65 blink::WebLoadingBehaviorFlag::WebLoadingBehaviorMediaPlayed) != 0; | |
| 66 } | |
| 67 | |
| 68 void MediaPageLoadMetricsObserver::RecordByteHistograms() { | |
| 69 DCHECK(played_media_); | |
| 70 PAGE_BYTES_HISTOGRAM(kHistogramNetworkBytes, network_bytes_); | |
| 71 PAGE_BYTES_HISTOGRAM(kHistogramCacheBytes, cache_bytes_); | |
| 72 PAGE_BYTES_HISTOGRAM(kHistogramTotalBytes, network_bytes_ + cache_bytes_); | |
| 73 } | |
| OLD | NEW |