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

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: 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 #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 : played_media_(false), cache_bytes_(0), network_bytes_(0) {}
24
25 MediaPageLoadMetricsObserver::~MediaPageLoadMetricsObserver() {}
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 if (!played_media_)
41 return STOP_OBSERVING;
42 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the
43 // app is about to be backgrounded, as part of the Activity.onPause()
44 // flow. After this method is invoked, Chrome may be killed without further
45 // notification, so we record final metrics collected up to this point.
46 if (!info.did_commit) {
47 RecordByteHistograms();
Charlie Harrison 2017/03/08 14:33:58 Don't we want to Record only if the page commit?
RyanSturm 2017/03/08 17:45:36 Wow. Thanks for finding that. Added a test case.
48 }
49 return STOP_OBSERVING;
50 }
51
52 void MediaPageLoadMetricsObserver::OnComplete(
53 const page_load_metrics::PageLoadTiming& timing,
54 const page_load_metrics::PageLoadExtraInfo& info) {
55 if (!played_media_)
56 return;
57 RecordByteHistograms();
58 }
59
60 void MediaPageLoadMetricsObserver::OnLoadingBehaviorObserved(
61 const page_load_metrics::PageLoadExtraInfo& info) {
62 if (played_media_)
63 return;
64
65 played_media_ =
66 (info.metadata.behavior_flags &
67 blink::WebLoadingBehaviorFlag::WebLoadingBehaviorMediaPlayed) != 0;
68 }
69
70 void MediaPageLoadMetricsObserver::RecordByteHistograms() {
71 DCHECK(played_media_);
72 PAGE_BYTES_HISTOGRAM(kHistogramNetworkBytes, network_bytes_);
73 PAGE_BYTES_HISTOGRAM(kHistogramCacheBytes, cache_bytes_);
74 PAGE_BYTES_HISTOGRAM(kHistogramTotalBytes, network_bytes_ + cache_bytes_);
75 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698