OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 "content/browser/media/audible_metrics.h" | |
6 | |
7 #include "base/metrics/histogram_macros.h" | |
8 #include "base/metrics/user_metrics.h" | |
9 #include "base/time/default_tick_clock.h" | |
10 | |
11 namespace content { | |
12 | |
13 AudibleMetrics::AudibleMetrics() | |
14 : max_concurrent_audible_web_contents_in_session_(0), | |
15 clock_(new base::DefaultTickClock()) { | |
16 } | |
17 | |
18 AudibleMetrics::~AudibleMetrics() { | |
19 } | |
20 | |
21 void AudibleMetrics::UpdateAudibleWebContentsState( | |
22 const WebContents* web_contents, bool audible) { | |
23 bool found = | |
24 audible_web_contents_.find(web_contents) != audible_web_contents_.end(); | |
25 if (found == audible) | |
26 return; | |
27 | |
28 if (audible) | |
29 AddAudibleWebContents(web_contents); | |
30 else | |
31 RemoveAudibleWebContents(web_contents); | |
32 } | |
33 | |
34 void AudibleMetrics::SetClockForTest(scoped_ptr<base::TickClock> test_clock) { | |
35 clock_ = std::move(test_clock); | |
36 } | |
37 | |
38 void AudibleMetrics::AddAudibleWebContents(const WebContents* web_contents) { | |
39 base::RecordAction(base::UserMetricsAction("Media.Audible.AddTab")); | |
40 | |
41 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
42 "Media.Audible.ConcurrentTabsWhenStarting", audible_web_contents_.size(), | |
43 0, 10, 11); | |
Mark P
2016/01/20 00:19:16
the min bucket should be 1.
(We always have an "un
mlamouri (slow - plz ping)
2016/01/20 11:31:52
Done.
| |
44 | |
45 audible_web_contents_.insert(web_contents); | |
46 if (audible_web_contents_.size() > 1 && | |
47 concurrent_web_contents_start_time_.is_null()) { | |
48 concurrent_web_contents_start_time_ = clock_->NowTicks(); | |
49 } | |
50 | |
51 if (audible_web_contents_.size() > | |
52 max_concurrent_audible_web_contents_in_session_) { | |
53 max_concurrent_audible_web_contents_in_session_ = | |
54 audible_web_contents_.size(); | |
55 | |
56 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
57 "Media.Audible.ConcurrentTabsInSession", | |
58 max_concurrent_audible_web_contents_in_session_, | |
59 1, 10, 10); | |
Mark P
2016/01/20 00:19:15
nit: second 10 here might as well be 11 for consis
mlamouri (slow - plz ping)
2016/01/20 11:31:52
Done.
| |
60 } | |
61 } | |
62 | |
63 void AudibleMetrics::RemoveAudibleWebContents(const WebContents* web_contents) { | |
64 base::RecordAction(base::UserMetricsAction("Media.Audible.RemoveTab")); | |
65 | |
66 audible_web_contents_.erase(web_contents); | |
67 | |
68 if (audible_web_contents_.size() <= 1 && | |
69 !concurrent_web_contents_start_time_.is_null()) { | |
70 base::TimeDelta concurrent_total_time = | |
71 clock_->NowTicks() - concurrent_web_contents_start_time_; | |
72 concurrent_web_contents_start_time_ = base::TimeTicks(); | |
73 | |
74 UMA_HISTOGRAM_LONG_TIMES("Media.Audible.ConcurrentTabsTime", | |
75 concurrent_total_time); | |
76 } | |
77 } | |
78 | |
79 } // namespace content | |
OLD | NEW |