| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_RENDERER_MEDIA_RENDER_MEDIA_LOG_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_RENDER_MEDIA_LOG_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_RENDER_MEDIA_LOG_H_ | 6 #define CONTENT_RENDERER_MEDIA_RENDER_MEDIA_LOG_H_ |
| 7 | 7 |
| 8 #include <string> |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 13 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 14 #include "media/base/media_log.h" | 15 #include "media/base/media_log.h" |
| 15 | 16 |
| 16 namespace base { | 17 namespace base { |
| 17 class TickClock; | 18 class TickClock; |
| 18 } | 19 } |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 | 22 |
| 22 // RenderMediaLog is an implementation of MediaLog that forwards events to the | 23 // RenderMediaLog is an implementation of MediaLog that forwards events to the |
| 23 // browser process, throttling as necessary. | 24 // browser process, throttling as necessary. |
| 24 // | 25 // |
| 26 // It also caches the last error events to support renderer-side reporting to |
| 27 // entities like HTMLMediaElement and devtools console. |
| 28 // |
| 25 // To minimize the number of events sent over the wire, only the latest event | 29 // To minimize the number of events sent over the wire, only the latest event |
| 26 // added is sent for high frequency events (e.g., BUFFERED_EXTENTS_CHANGED). | 30 // added is sent for high frequency events (e.g., BUFFERED_EXTENTS_CHANGED). |
| 27 // | 31 // |
| 28 // It must be constructed on the render thread. | 32 // It must be constructed on the render thread. |
| 29 class CONTENT_EXPORT RenderMediaLog : public media::MediaLog { | 33 class CONTENT_EXPORT RenderMediaLog : public media::MediaLog { |
| 30 public: | 34 public: |
| 31 RenderMediaLog(); | 35 RenderMediaLog(); |
| 32 | 36 |
| 33 // MediaLog implementation. | 37 // MediaLog implementation. |
| 34 void AddEvent(scoped_ptr<media::MediaLogEvent> event) override; | 38 void AddEvent(scoped_ptr<media::MediaLogEvent> event) override; |
| 39 std::string GetLastErrorMessage() override; |
| 35 | 40 |
| 36 // Will reset |last_ipc_send_time_| with the value of NowTicks(). | 41 // Will reset |last_ipc_send_time_| with the value of NowTicks(). |
| 37 void SetTickClockForTesting(scoped_ptr<base::TickClock> tick_clock); | 42 void SetTickClockForTesting(scoped_ptr<base::TickClock> tick_clock); |
| 38 void SetTaskRunnerForTesting( | 43 void SetTaskRunnerForTesting( |
| 39 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | 44 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
| 40 | 45 |
| 41 private: | 46 private: |
| 42 ~RenderMediaLog() override; | 47 ~RenderMediaLog() override; |
| 43 | 48 |
| 44 // Posted as a delayed task on |task_runner_| to throttle ipc message | 49 // Posted as a delayed task on |task_runner_| to throttle ipc message |
| 45 // frequency. | 50 // frequency. |
| 46 void SendQueuedMediaEvents(); | 51 void SendQueuedMediaEvents(); |
| 47 | 52 |
| 48 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 53 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 49 | 54 |
| 50 // |lock_| serializes access to |tick_clock_|, |last_ipc_send_time_|, | 55 // |lock_| protects access to all of the following member variables. It |
| 51 // |queued_media_events_|, |ipc_send_pending_| and | 56 // allows any render process thread to AddEvent(), while preserving their |
| 52 // |last_buffered_extents_changed_event_|. It allows any render process thread | 57 // sequence for throttled send on |task_runner_| and coherent retrieval by |
| 53 // to AddEvent(), while preserving their sequence for throttled send on | 58 // GetLastErrorMessage(). |
| 54 // |task_runner_|. | |
| 55 mutable base::Lock lock_; | 59 mutable base::Lock lock_; |
| 56 scoped_ptr<base::TickClock> tick_clock_; | 60 scoped_ptr<base::TickClock> tick_clock_; |
| 57 base::TimeTicks last_ipc_send_time_; | 61 base::TimeTicks last_ipc_send_time_; |
| 58 std::vector<media::MediaLogEvent> queued_media_events_; | 62 std::vector<media::MediaLogEvent> queued_media_events_; |
| 59 | 63 |
| 60 // For enforcing max 1 pending send. | 64 // For enforcing max 1 pending send. |
| 61 bool ipc_send_pending_; | 65 bool ipc_send_pending_; |
| 62 | 66 |
| 63 // Limits the number buffered extents changed events we send over IPC to one. | 67 // Limits the number buffered extents changed events we send over IPC to one. |
| 64 scoped_ptr<media::MediaLogEvent> last_buffered_extents_changed_event_; | 68 scoped_ptr<media::MediaLogEvent> last_buffered_extents_changed_event_; |
| 65 | 69 |
| 70 // Holds a copy of the most recent MEDIA_ERROR_LOG_ENTRY, if any. |
| 71 scoped_ptr<media::MediaLogEvent> last_media_error_log_entry_; |
| 72 |
| 73 // Holds a copy of the most recent PIPELINE_ERROR, if any. |
| 74 scoped_ptr<media::MediaLogEvent> last_pipeline_error_; |
| 75 |
| 66 DISALLOW_COPY_AND_ASSIGN(RenderMediaLog); | 76 DISALLOW_COPY_AND_ASSIGN(RenderMediaLog); |
| 67 }; | 77 }; |
| 68 | 78 |
| 69 } // namespace content | 79 } // namespace content |
| 70 | 80 |
| 71 #endif // CONTENT_RENDERER_MEDIA_RENDER_MEDIA_LOG_H_ | 81 #endif // CONTENT_RENDERER_MEDIA_RENDER_MEDIA_LOG_H_ |
| OLD | NEW |