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 #include "content/public/browser/render_process_host.h" |
| 10 |
| 11 // We use a histogram with a maximum bucket of 16 hours to infinity |
| 12 // for track durations. |
| 13 #define UMA_HISTOGRAM_TIMES_16H(name, sample) \ |
| 14 UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, \ |
| 15 base::TimeDelta::FromMilliseconds(100), \ |
| 16 base::TimeDelta::FromHours(16), \ |
| 17 50); |
| 18 |
| 19 namespace content { |
| 20 |
| 21 MediaStreamTrackMetricsHost::MediaStreamTrackMetricsHost( |
| 22 RenderProcessHost* owner) |
| 23 : BrowserMessageFilter(MediaStreamTrackMetricsHostMsgStart), |
| 24 owner_(owner) { |
| 25 owner_->AddObserver(this); |
| 26 } |
| 27 |
| 28 MediaStreamTrackMetricsHost::~MediaStreamTrackMetricsHost() { |
| 29 owner_->RemoveObserver(this); |
| 30 |
| 31 DCHECK(tracks_.empty()); |
| 32 } |
| 33 |
| 34 bool MediaStreamTrackMetricsHost::OnMessageReceived( |
| 35 const IPC::Message& message, |
| 36 bool* message_was_ok) { |
| 37 bool handled = true; |
| 38 |
| 39 IPC_BEGIN_MESSAGE_MAP_EX(MediaStreamTrackMetricsHost, |
| 40 message, |
| 41 *message_was_ok) |
| 42 IPC_MESSAGE_HANDLER(MediaStreamTrackMetricsHost_AddTrack, OnAddTrack) |
| 43 IPC_MESSAGE_HANDLER(MediaStreamTrackMetricsHost_RemoveTrack, OnRemoveTrack) |
| 44 IPC_MESSAGE_UNHANDLED(handled = false) |
| 45 IPC_END_MESSAGE_MAP_EX() |
| 46 |
| 47 return handled; |
| 48 } |
| 49 |
| 50 void MediaStreamTrackMetricsHost::RenderProcessExited( |
| 51 RenderProcessHost* host, |
| 52 base::ProcessHandle handle, |
| 53 base::TerminationStatus status, |
| 54 int exit_code) { |
| 55 DCHECK_EQ(owner_, host); |
| 56 |
| 57 // Our render process has exited. We won't receive any more IPC |
| 58 // messages from it. Assume all tracks ended now. |
| 59 for (TrackMap::iterator it = tracks_.begin(); |
| 60 it != tracks_.end(); |
| 61 ++it) { |
| 62 IsAudioPlusTimestamp& audio_and_timestamp = it->second; |
| 63 ReportDuration(audio_and_timestamp.first, audio_and_timestamp.second); |
| 64 } |
| 65 tracks_.clear(); |
| 66 } |
| 67 |
| 68 void MediaStreamTrackMetricsHost::OnAddTrack(const std::string& id, |
| 69 bool is_audio, |
| 70 bool is_remote) { |
| 71 DCHECK(tracks_.find(id) == tracks_.end()); |
| 72 DCHECK(is_remote); // Always the case for now. |
| 73 |
| 74 tracks_[id] = IsAudioPlusTimestamp(is_audio, base::TimeTicks::Now()); |
| 75 } |
| 76 |
| 77 void MediaStreamTrackMetricsHost::OnRemoveTrack(const std::string& id) { |
| 78 DCHECK(tracks_.find(id) != tracks_.end()); |
| 79 |
| 80 IsAudioPlusTimestamp& info = tracks_[id]; |
| 81 ReportDuration(info.first, info.second); |
| 82 tracks_.erase(id); |
| 83 } |
| 84 |
| 85 void MediaStreamTrackMetricsHost::ReportDuration(bool is_audio, |
| 86 base::TimeTicks start_time) { |
| 87 base::TimeDelta duration = start_time - base::TimeTicks::Now(); |
| 88 if (is_audio) { |
| 89 UMA_HISTOGRAM_TIMES_16H("WebRTC.ReceivedAudioTrackDuration", duration); |
| 90 } else { |
| 91 UMA_HISTOGRAM_TIMES_16H("WebRTC.ReceivedVideoTrackDuration", duration); |
| 92 } |
| 93 } |
| 94 |
| 95 } // namespace content |
OLD | NEW |