1 // Copyright 2014 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.
5 #include "chrome/browser/media/android/remote/record_cast_action.h"
9 #include "base/metrics/histogram.h"
10 #include "content/public/browser/user_metrics.h"
11 #include "jni/RecordCastAction_jni.h"
12 #include "media/base/container_names.h"
14 using base::UserMetricsAction
;
15 using content::RecordAction
;
19 // When updating these values, remember to also update
20 // tools/histograms/histograms.xml.
21 enum CastPlayBackState
{
22 YT_PLAYER_SUCCESS
= 0,
23 YT_PLAYER_FAILURE
= 1,
24 DEFAULT_PLAYER_SUCCESS
= 2,
25 DEFAULT_PLAYER_FAILURE
= 3,
26 CAST_PLAYBACK_STATE_COUNT
= 4
29 // When updating these values, remember to also update
30 // tools/histograms/histograms.xml.
32 // This is actually a misnomer, it should be RemotePlaybackPlayerType, but it is
33 // more important that it matches the histogram name in histograms.xml.
34 // TODO(aberent) Change this once we are upstream, when can change it both here
35 // and in histogram.xml in the same CL.
36 enum RemotePlaybackDeviceType
{
40 REMOTE_PLAYBACK_DEVICE_TYPE_COUNT
= 3
45 namespace remote_media
{
46 static void RecordRemotePlaybackDeviceSelected(JNIEnv
*,
47 const JavaParamRef
<jclass
>&,
49 UMA_HISTOGRAM_ENUMERATION(
50 "Cast.Sender.DeviceType", device_type
, REMOTE_PLAYBACK_DEVICE_TYPE_COUNT
);
53 static void RecordCastPlayRequested(JNIEnv
*, const JavaParamRef
<jclass
>&) {
54 RecordAction(UserMetricsAction("Cast_Sender_CastPlayRequested"));
57 static void RecordCastDefaultPlayerResult(JNIEnv
*,
58 const JavaParamRef
<jclass
>&,
59 jboolean cast_success
) {
61 UMA_HISTOGRAM_ENUMERATION("Cast.Sender.CastPlayerResult",
62 DEFAULT_PLAYER_SUCCESS
,
63 CAST_PLAYBACK_STATE_COUNT
);
65 UMA_HISTOGRAM_ENUMERATION("Cast.Sender.CastPlayerResult",
66 DEFAULT_PLAYER_FAILURE
,
67 CAST_PLAYBACK_STATE_COUNT
);
71 static void RecordCastYouTubePlayerResult(JNIEnv
*,
72 const JavaParamRef
<jclass
>&,
73 jboolean cast_success
) {
75 UMA_HISTOGRAM_ENUMERATION("Cast.Sender.CastPlayerResult", YT_PLAYER_SUCCESS
,
76 CAST_PLAYBACK_STATE_COUNT
);
78 UMA_HISTOGRAM_ENUMERATION("Cast.Sender.CastPlayerResult", YT_PLAYER_FAILURE
,
79 CAST_PLAYBACK_STATE_COUNT
);
83 static void RecordCastMediaType(JNIEnv
*,
84 const JavaParamRef
<jclass
>&,
86 UMA_HISTOGRAM_ENUMERATION("Cast.Sender.CastMediaType", media_type
,
87 media::container_names::CONTAINER_MAX
);
90 static void RecordCastEndedTimeRemaining(JNIEnv
*,
91 const JavaParamRef
<jclass
>&,
92 jint video_total_time
,
93 jint time_left_in_video
) {
94 int percent_remaining
= 100;
95 if (video_total_time
> 0) {
96 // Get the percentage of video remaining, but bucketize into groups of 10
97 // since we don't really need that granular of data.
98 percent_remaining
= static_cast<int>(
99 10.0 * time_left_in_video
/ video_total_time
) * 10;
102 UMA_HISTOGRAM_ENUMERATION("Cast.Sender.CastTimeRemainingPercentage",
103 percent_remaining
, 101);
106 // Register native methods
107 bool RegisterRecordCastAction(JNIEnv
* env
) {
108 return RegisterNativesImpl(env
);
111 } // namespace remote_media