Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Side by Side Diff: chrome/browser/page_load_metrics/observers/media_page_load_metrics_observer.cc

Issue 2732293003: Adding UMA on page load size for pages with Media (Closed)
Patch Set: Switching to WCO::MediaStartedPlaying instead of behavior flag Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
10 namespace {
11
12 const char kHistogramNetworkBytes[] =
13 "PageLoad.Clients.MediaPageLoad.Experimental.Bytes.Network";
14 const char kHistogramCacheBytes[] =
15 "PageLoad.Clients.MediaPageLoad.Experimental.Bytes.Cache";
16 const char kHistogramTotalBytes[] =
17 "PageLoad.Clients.MediaPageLoad.Experimental.Bytes.Total";
18
19 } // namespace
20
21 MediaPageLoadMetricsObserver::MediaPageLoadMetricsObserver()
22 : cache_bytes_(0), network_bytes_(0), played_media_(false) {}
23
24 MediaPageLoadMetricsObserver::~MediaPageLoadMetricsObserver() = default;
25
26 void MediaPageLoadMetricsObserver::OnLoadedResource(
27 const page_load_metrics::ExtraRequestInfo& extra_request_info) {
28 if (extra_request_info.was_cached) {
29 cache_bytes_ += extra_request_info.raw_body_bytes;
30 } else {
31 network_bytes_ += extra_request_info.raw_body_bytes;
32 }
33 }
34
35 page_load_metrics::PageLoadMetricsObserver::ObservePolicy
36 MediaPageLoadMetricsObserver::FlushMetricsOnAppEnterBackground(
37 const page_load_metrics::PageLoadTiming& timing,
38 const page_load_metrics::PageLoadExtraInfo& info) {
39 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the
40 // 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 // notification, so we record final metrics collected up to this point.
43 if (info.did_commit && played_media_) {
44 RecordByteHistograms();
45 }
46 return STOP_OBSERVING;
47 }
48
49 void MediaPageLoadMetricsObserver::OnComplete(
50 const page_load_metrics::PageLoadTiming& timing,
51 const page_load_metrics::PageLoadExtraInfo& info) {
52 if (!played_media_)
53 return;
54 RecordByteHistograms();
55 }
56
57 void MediaPageLoadMetricsObserver::MediaStartedPlaying(
58 const content::WebContentsObserver::MediaPlayerInfo& video_type,
59 bool is_in_main_frame) {
60 if (played_media_)
61 return;
62 // Track media (audio or video) in all frames of the page load.
63 played_media_ = true;
64 }
65
66 void MediaPageLoadMetricsObserver::RecordByteHistograms() {
67 DCHECK(played_media_);
68 PAGE_BYTES_HISTOGRAM(kHistogramNetworkBytes, network_bytes_);
69 PAGE_BYTES_HISTOGRAM(kHistogramCacheBytes, cache_bytes_);
70 PAGE_BYTES_HISTOGRAM(kHistogramTotalBytes, network_bytes_ + cache_bytes_);
71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698