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_track_lifetime_metrics_host. h" | |
6 | |
7 #include "base/metrics/histogram.h" | |
8 #include "content/common/media/media_track_lifetime_metrics_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 MediaTrackLifetimeMetricsHost::MediaTrackLifetimeMetricsHost( | |
22 RenderProcessHost* owner) | |
23 : BrowserMessageFilter(MediaTrackLifetimeMetricsHostMsgStart), | |
24 owner_(owner) { | |
25 owner_->AddObserver(this); | |
26 } | |
27 | |
28 MediaTrackLifetimeMetricsHost::~MediaTrackLifetimeMetricsHost() { | |
29 owner_->RemoveObserver(this); | |
30 | |
31 DCHECK(tracks_.empty()); | |
32 } | |
33 | |
34 bool MediaTrackLifetimeMetricsHost::OnMessageReceived( | |
35 const IPC::Message& message, | |
36 bool* message_was_ok) { | |
37 bool handled = true; | |
38 | |
39 IPC_BEGIN_MESSAGE_MAP_EX(MediaTrackLifetimeMetricsHost, | |
40 message, | |
41 *message_was_ok) | |
42 IPC_MESSAGE_HANDLER(MediaTrackLifetimeMetrics_AddTrack, OnAddTrack) | |
43 IPC_MESSAGE_HANDLER(MediaTrackLifetimeMetrics_RemoveTrack, OnRemoveTrack) | |
44 IPC_MESSAGE_UNHANDLED(handled = false) | |
45 IPC_END_MESSAGE_MAP_EX() | |
46 | |
47 return handled; | |
48 } | |
49 | |
50 void MediaTrackLifetimeMetricsHost::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 ReportDuration(it->second.first, it->second.second); | |
perkj_chrome
2014/03/11 08:05:21
nit: can you use temp variables instead of second.
Jói
2014/03/11 17:36:33
I added a temp IsAudioPlusTimestamp variable then
| |
63 } | |
64 tracks_.clear(); | |
65 } | |
66 | |
67 void MediaTrackLifetimeMetricsHost::OnAddTrack(const std::string& id, | |
68 bool is_audio) { | |
69 DCHECK(tracks_.find(id) == tracks_.end()); | |
perkj_chrome
2014/03/11 08:05:21
To make this a bit harder - the same track can the
| |
70 | |
71 tracks_[id] = IsAudioPlusTimestamp(is_audio, base::TimeTicks::Now()); | |
72 } | |
73 | |
74 void MediaTrackLifetimeMetricsHost::OnRemoveTrack(const std::string& id) { | |
75 DCHECK(tracks_.find(id) != tracks_.end()); | |
76 | |
77 IsAudioPlusTimestamp& info = tracks_[id]; | |
78 ReportDuration(info.first, info.second); | |
79 tracks_.erase(id); | |
80 } | |
81 | |
82 void MediaTrackLifetimeMetricsHost::ReportDuration(bool is_audio, | |
83 base::TimeTicks start_time) { | |
84 base::TimeDelta duration = start_time - base::TimeTicks::Now(); | |
85 if (is_audio) { | |
86 UMA_HISTOGRAM_TIMES_16H("WebRTC.ReceivedAudioTrackDuration", duration); | |
perkj_chrome
2014/03/11 08:05:21
Will we not have the same problem for local tracks
Jói
2014/03/11 17:36:33
I think we had settled on track duration in the de
| |
87 } else { | |
88 UMA_HISTOGRAM_TIMES_16H("WebRTC.ReceivedVideoTrackDuration", duration); | |
89 } | |
90 } | |
91 | |
92 } // namespace content | |
OLD | NEW |