OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "content/browser/renderer_host/media/media_stream_track_metrics_host.h" |
| 6 |
| 7 #include "base/metrics/histogram.h" |
| 8 #include "content/common/media/media_stream_track_metrics_host_messages.h" |
| 9 |
| 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), \ |
| 16 50); |
| 17 |
| 18 namespace content { |
| 19 |
| 20 MediaStreamTrackMetricsHost::MediaStreamTrackMetricsHost() |
| 21 : BrowserMessageFilter(MediaStreamTrackMetricsHostMsgStart) { |
| 22 } |
| 23 |
| 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(); |
| 28 it != tracks_.end(); |
| 29 ++it) { |
| 30 IsAudioPlusTimestamp& audio_and_timestamp = it->second; |
| 31 ReportDuration(audio_and_timestamp.first, audio_and_timestamp.second); |
| 32 } |
| 33 tracks_.clear(); |
| 34 } |
| 35 |
| 36 bool MediaStreamTrackMetricsHost::OnMessageReceived( |
| 37 const IPC::Message& message, |
| 38 bool* message_was_ok) { |
| 39 bool handled = true; |
| 40 |
| 41 IPC_BEGIN_MESSAGE_MAP_EX(MediaStreamTrackMetricsHost, |
| 42 message, |
| 43 *message_was_ok) |
| 44 IPC_MESSAGE_HANDLER(MediaStreamTrackMetricsHost_AddTrack, OnAddTrack) |
| 45 IPC_MESSAGE_HANDLER(MediaStreamTrackMetricsHost_RemoveTrack, OnRemoveTrack) |
| 46 IPC_MESSAGE_UNHANDLED(handled = false) |
| 47 IPC_END_MESSAGE_MAP_EX() |
| 48 |
| 49 return handled; |
| 50 } |
| 51 |
| 52 void MediaStreamTrackMetricsHost::OnAddTrack(uint64 id, |
| 53 bool is_audio, |
| 54 bool is_remote) { |
| 55 DCHECK(tracks_.find(id) == tracks_.end()); |
| 56 DCHECK(is_remote); // Always the case for now. |
| 57 |
| 58 tracks_[id] = IsAudioPlusTimestamp(is_audio, base::TimeTicks::Now()); |
| 59 } |
| 60 |
| 61 void MediaStreamTrackMetricsHost::OnRemoveTrack(uint64 id) { |
| 62 DCHECK(tracks_.find(id) != tracks_.end()); |
| 63 |
| 64 IsAudioPlusTimestamp& info = tracks_[id]; |
| 65 ReportDuration(info.first, info.second); |
| 66 tracks_.erase(id); |
| 67 } |
| 68 |
| 69 void MediaStreamTrackMetricsHost::ReportDuration(bool is_audio, |
| 70 base::TimeTicks start_time) { |
| 71 base::TimeDelta duration = base::TimeTicks::Now() - start_time; |
| 72 if (is_audio) { |
| 73 UMA_HISTOGRAM_TIMES_16H("WebRTC.ReceivedAudioTrackDuration", duration); |
| 74 } else { |
| 75 UMA_HISTOGRAM_TIMES_16H("WebRTC.ReceivedVideoTrackDuration", duration); |
| 76 } |
| 77 } |
| 78 |
| 79 } // namespace content |
OLD | NEW |