Revert 268405 "Make sure that ScratchBuffer::Allocate() always r..."
[chromium-blink-merge.git] / content / browser / renderer_host / media / media_stream_track_metrics_host.h
blobb0d18f10be3952e6234680972834edaa0e313214
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 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_TRACK_METRICS_HOST_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_TRACK_METRICS_HOST_H_
8 #include <map>
9 #include <string>
11 #include "base/time/time.h"
12 #include "content/public/browser/browser_message_filter.h"
14 namespace content {
16 // Responsible for logging metrics about audio and video track
17 // lifetimes. These are based on messages from the renderer that are
18 // sent when tracks are created and destroyed. Unfortunately we can't
19 // reliably log the lifetime metric in the renderer because that
20 // process may be destroyed at any time by the fast shutdown path (see
21 // RenderProcessHost::FastShutdownIfPossible).
23 // There is one instance of this class per render process.
25 // If the renderer process goes away without sending messages that
26 // tracks were removed, this class instead infers that the tracks were
27 // removed.
28 class MediaStreamTrackMetricsHost
29 : public BrowserMessageFilter {
30 public:
31 explicit MediaStreamTrackMetricsHost();
33 protected:
34 virtual ~MediaStreamTrackMetricsHost();
36 // BrowserMessageFilter override.
37 virtual bool OnMessageReceived(const IPC::Message& message,
38 bool* message_was_ok) OVERRIDE;
40 private:
41 void OnAddTrack(uint64 id, bool is_audio, bool is_remote);
42 void OnRemoveTrack(uint64 id);
44 // Information for a track we're keeping in |tracks_|. |is_audio|
45 // specifies whether it's an audio or video track, |is_remote|
46 // specifies whether it's remote (received over a PeerConnection) or
47 // local (sent over a PeerConnection). |timestamp| specifies when
48 // the track was connected.
49 struct TrackInfo {
50 bool is_audio;
51 bool is_remote;
52 base::TimeTicks timestamp;
55 void ReportDuration(const TrackInfo& info);
57 // Values are unique (per renderer) track IDs.
58 typedef std::map<uint64, TrackInfo> TrackMap;
59 TrackMap tracks_;
62 } // namespace content
64 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_TRACK_METRICS_HOST_H_