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 "content/browser/renderer_host/media/media_stream_track_metrics_host.h"
7 #include "base/metrics/histogram.h"
8 #include "content/common/media/media_stream_track_metrics_host_messages.h"
10 // We use a histogram with a maximum bucket of 16 hours to infinity
11 // for track durations.
12 #define UMA_HISTOGRAM_TIMES_16H(name, sample) \
13 UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, \
14 base::TimeDelta::FromMilliseconds(100), \
15 base::TimeDelta::FromHours(16), \
20 MediaStreamTrackMetricsHost::MediaStreamTrackMetricsHost()
21 : BrowserMessageFilter(MediaStreamTrackMetricsHostMsgStart
) {
24 MediaStreamTrackMetricsHost::~MediaStreamTrackMetricsHost() {
25 // Our render process has exited. We won't receive any more IPC
26 // messages from it. Assume all tracks ended now.
27 for (TrackMap::iterator it
= tracks_
.begin();
30 TrackInfo
& info
= it
->second
;
36 bool MediaStreamTrackMetricsHost::OnMessageReceived(
37 const IPC::Message
& message
) {
40 IPC_BEGIN_MESSAGE_MAP(MediaStreamTrackMetricsHost
, message
)
41 IPC_MESSAGE_HANDLER(MediaStreamTrackMetricsHost_AddTrack
, OnAddTrack
)
42 IPC_MESSAGE_HANDLER(MediaStreamTrackMetricsHost_RemoveTrack
, OnRemoveTrack
)
43 IPC_MESSAGE_UNHANDLED(handled
= false)
49 void MediaStreamTrackMetricsHost::OnAddTrack(uint64 id
,
52 if (tracks_
.find(id
) != tracks_
.end())
55 TrackInfo info
= {is_audio
, is_remote
, base::TimeTicks::Now()};
59 void MediaStreamTrackMetricsHost::OnRemoveTrack(uint64 id
) {
60 if (tracks_
.find(id
) == tracks_
.end())
63 TrackInfo
& info
= tracks_
[id
];
68 void MediaStreamTrackMetricsHost::ReportDuration(const TrackInfo
& info
) {
69 base::TimeDelta duration
= base::TimeTicks::Now() - info
.timestamp
;
72 DVLOG(3) << "WebRTC.ReceivedAudioTrackDuration: " << duration
.InSeconds();
73 UMA_HISTOGRAM_TIMES_16H("WebRTC.ReceivedAudioTrackDuration", duration
);
75 DVLOG(3) << "WebRTC.ReceivedVideoTrackDuration: " << duration
.InSeconds();
76 UMA_HISTOGRAM_TIMES_16H("WebRTC.ReceivedVideoTrackDuration", duration
);
80 DVLOG(3) << "WebRTC.SentAudioTrackDuration: " << duration
.InSeconds();
81 UMA_HISTOGRAM_TIMES_16H("WebRTC.SentAudioTrackDuration", duration
);
83 DVLOG(3) << "WebRTC.SentVideoTrackDuration: " << duration
.InSeconds();
84 UMA_HISTOGRAM_TIMES_16H("WebRTC.SentVideoTrackDuration", duration
);
89 } // namespace content