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/time/default_clock.h" |
| 9 |
| 10 namespace content { |
| 11 |
| 12 AudibleMetrics::AudibleMetrics() |
| 13 : max_concurrent_audible_web_contents_in_session_(0), |
| 14 clock_(new base::DefaultClock()) { |
| 15 } |
| 16 |
| 17 AudibleMetrics::~AudibleMetrics() { |
| 18 } |
| 19 |
| 20 void AudibleMetrics::UpdateAudibleWebContentsState( |
| 21 WebContents* web_contents, bool audible) { |
| 22 bool found = |
| 23 audible_web_contents_.find(web_contents) != audible_web_contents_.end(); |
| 24 if (found == audible) |
| 25 return; |
| 26 |
| 27 if (audible) |
| 28 AddAudibleWebContents(web_contents); |
| 29 else |
| 30 RemoveAudibleWebContents(web_contents); |
| 31 } |
| 32 |
| 33 void AudibleMetrics::SetClockForTest(scoped_ptr<base::Clock> testing_clock) { |
| 34 clock_ = std::move(testing_clock); |
| 35 } |
| 36 |
| 37 void AudibleMetrics::AddAudibleWebContents(WebContents* web_contents) { |
| 38 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 39 "Media.Audible.ConcurrentTabsWhenStarting", audible_web_contents_.size(), |
| 40 0, 10, 11); |
| 41 |
| 42 audible_web_contents_.insert(web_contents); |
| 43 if (audible_web_contents_.size() > 1 && |
| 44 concurrent_web_contents_start_time_.is_null()) { |
| 45 concurrent_web_contents_start_time_ = clock_->Now(); |
| 46 } |
| 47 |
| 48 if (audible_web_contents_.size() > |
| 49 max_concurrent_audible_web_contents_in_session_) { |
| 50 max_concurrent_audible_web_contents_in_session_ = |
| 51 audible_web_contents_.size(); |
| 52 |
| 53 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 54 "Media.Audible.ConcurrentTabsInSession", |
| 55 max_concurrent_audible_web_contents_in_session_, |
| 56 1, 10, 10); |
| 57 } |
| 58 } |
| 59 |
| 60 void AudibleMetrics::RemoveAudibleWebContents(WebContents* web_contents) { |
| 61 audible_web_contents_.erase(web_contents); |
| 62 |
| 63 if (audible_web_contents_.size() <= 1 && |
| 64 !concurrent_web_contents_start_time_.is_null()) { |
| 65 base::TimeDelta concurrent_total_time = |
| 66 clock_->Now() - concurrent_web_contents_start_time_; |
| 67 concurrent_web_contents_start_time_ = base::Time(); |
| 68 |
| 69 UMA_HISTOGRAM_LONG_TIMES("Media.Audible.ConcurrentTabsTime", |
| 70 concurrent_total_time); |
| 71 } |
| 72 } |
| 73 |
| 74 } // namespace content |
OLD | NEW |