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 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_TRACK_LIFETIME_METRICS_HOST_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_TRACK_LIFETIME_METRICS_HOST_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 |
| 11 #include "base/time/time.h" |
| 12 #include "content/public/browser/browser_message_filter.h" |
| 13 #include "content/public/browser/render_process_host_observer.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 // Responsible for logging metrics about audio and video track |
| 18 // lifetimes. These are based on messages from the renderer that are |
| 19 // sent when tracks are created and destroyed. Unfortunately we can't |
| 20 // reliably log the lifetime metric in the renderer because that |
| 21 // process may be destroyed at any time by the fast shutdown path (see |
| 22 // RenderProcessHost::FastShutdownIfPossible). |
| 23 // |
| 24 // There is one instance of this class per render process. |
| 25 // |
| 26 // If the renderer process goes away without sending messages that |
| 27 // tracks were removed, this class instead infers that the tracks were |
| 28 // removed. |
| 29 class MediaTrackLifetimeMetricsHost |
| 30 : public BrowserMessageFilter, |
| 31 public RenderProcessHostObserver { |
| 32 public: |
| 33 explicit MediaTrackLifetimeMetricsHost(RenderProcessHost* owner); |
| 34 |
| 35 protected: |
| 36 virtual ~MediaTrackLifetimeMetricsHost(); |
| 37 |
| 38 // BrowserMessageFilter override. |
| 39 virtual bool OnMessageReceived(const IPC::Message& message, |
| 40 bool* message_was_ok) OVERRIDE; |
| 41 |
| 42 // RenderProcessHostObserver override. |
| 43 virtual void RenderProcessExited(RenderProcessHost* host, |
| 44 base::ProcessHandle handle, |
| 45 base::TerminationStatus status, |
| 46 int exit_code) OVERRIDE; |
| 47 |
| 48 private: |
| 49 void OnAddTrack(const std::string& id, bool is_audio); |
| 50 void OnRemoveTrack(const std::string& id); |
| 51 |
| 52 void ReportDuration(bool is_audio, base::TimeTicks start_time); |
| 53 |
| 54 // Keys are track IDs, values are pairs: A boolean indicating |
| 55 // whether the track is an audio track, and a timestamp from when |
| 56 // the track was created. |
| 57 typedef std::pair<bool, base::TimeTicks> IsAudioPlusTimestamp; |
| 58 typedef std::map<std::string, IsAudioPlusTimestamp> TrackMap; |
| 59 TrackMap tracks_; |
| 60 |
| 61 // Non-owning pointer. |
| 62 RenderProcessHost* owner_; |
| 63 }; |
| 64 |
| 65 } // namespace content |
| 66 |
| 67 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_TRACK_LIFETIME_METRICS_HOST
_H_ |
OLD | NEW |