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

Side by Side Diff: content/browser/media/android/media_session_uma_helper.cc

Issue 1698933004: Make MediaSession a runtime-enabled feature on Desktop. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 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 2015 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/android/media_session_uma_helper.h"
6
7 #include <utility>
8
9 #include "base/metrics/histogram_base.h"
10 #include "base/metrics/histogram_macros.h"
11 #include "base/time/default_clock.h"
12
13 namespace content {
14
15 using HistogramBase = base::HistogramBase;
16
17 MediaSessionUmaHelper::MediaSessionUmaHelper()
18 : clock_(new base::DefaultClock())
19 {}
20
21 MediaSessionUmaHelper::~MediaSessionUmaHelper()
22 {}
23
24 void MediaSessionUmaHelper::RecordSessionSuspended(
25 MediaSessionSuspendedSource source) const {
26 UMA_HISTOGRAM_ENUMERATION(
27 "Media.Session.Suspended",
28 static_cast<HistogramBase::Sample>(source),
29 static_cast<HistogramBase::Sample>(MediaSessionSuspendedSource::Count));
30 }
31
32 void MediaSessionUmaHelper::RecordRequestAudioFocusResult(bool result) const {
33 UMA_HISTOGRAM_BOOLEAN("Media.Session.RequestAudioFocusResult", result);
34 }
35
36 void MediaSessionUmaHelper::OnSessionActive() {
37 current_active_time_ = clock_->Now();
38 }
39
40 void MediaSessionUmaHelper::OnSessionSuspended() {
41 if (current_active_time_.is_null())
42 return;
43
44 total_active_time_ += clock_->Now() - current_active_time_;
45 current_active_time_ = base::Time();
46 }
47
48 void MediaSessionUmaHelper::OnSessionInactive() {
49 if (!current_active_time_.is_null()) {
50 total_active_time_ += clock_->Now() - current_active_time_;
51 current_active_time_ = base::Time();
52 }
53
54 if (total_active_time_.is_zero())
55 return;
56
57 UMA_HISTOGRAM_LONG_TIMES("Media.Session.ActiveTime", total_active_time_);
58 total_active_time_ = base::TimeDelta();
59 }
60
61 void MediaSessionUmaHelper::SetClockForTest(
62 scoped_ptr<base::Clock> testing_clock) {
63 clock_ = std::move(testing_clock);
64 }
65
66 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698