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 <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/synchronization/lock.h" |
11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
12 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
13 #include "media/base/media_log.h" | 14 #include "media/base/media_log.h" |
14 | 15 |
15 namespace base { | 16 namespace base { |
16 class TickClock; | 17 class TickClock; |
17 } | 18 } |
18 | 19 |
19 namespace content { | 20 namespace content { |
20 | 21 |
(...skipping 12 matching lines...) Expand all Loading... |
33 void AddEvent(scoped_ptr<media::MediaLogEvent> event) override; | 34 void AddEvent(scoped_ptr<media::MediaLogEvent> event) override; |
34 | 35 |
35 // Will reset |last_ipc_send_time_| with the value of NowTicks(). | 36 // Will reset |last_ipc_send_time_| with the value of NowTicks(). |
36 void SetTickClockForTesting(scoped_ptr<base::TickClock> tick_clock); | 37 void SetTickClockForTesting(scoped_ptr<base::TickClock> tick_clock); |
37 void SetTaskRunnerForTesting( | 38 void SetTaskRunnerForTesting( |
38 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | 39 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
39 | 40 |
40 private: | 41 private: |
41 ~RenderMediaLog() override; | 42 ~RenderMediaLog() override; |
42 | 43 |
43 // Add event on the |task_runner_|. | 44 // Posted as a delayed task on |task_runner_| to throttle ipc message |
44 void AddEventInternal(scoped_ptr<media::MediaLogEvent> event); | 45 // frequency. |
45 | |
46 // Posted as a delayed task to throttle ipc message frequency. | |
47 void SendQueuedMediaEvents(); | 46 void SendQueuedMediaEvents(); |
48 | 47 |
49 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 48 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 49 |
| 50 // |lock_| serializes access to |tick_clock_|, |last_ipc_send_time_|, |
| 51 // |queued_media_events_|, |ipc_send_pending_| and |
| 52 // |last_buffered_extents_changed_event_|. It allows any render process thread |
| 53 // to AddEvent(), while preserving their sequence for throttled send on |
| 54 // |task_runner_|. |
| 55 mutable base::Lock lock_; |
50 scoped_ptr<base::TickClock> tick_clock_; | 56 scoped_ptr<base::TickClock> tick_clock_; |
51 base::TimeTicks last_ipc_send_time_; | 57 base::TimeTicks last_ipc_send_time_; |
52 std::vector<media::MediaLogEvent> queued_media_events_; | 58 std::vector<media::MediaLogEvent> queued_media_events_; |
53 | 59 |
| 60 // For enforcing max 1 pending send. |
| 61 bool ipc_send_pending_; |
| 62 |
54 // Limits the number buffered extents changed events we send over IPC to one. | 63 // Limits the number buffered extents changed events we send over IPC to one. |
55 scoped_ptr<media::MediaLogEvent> last_buffered_extents_changed_event_; | 64 scoped_ptr<media::MediaLogEvent> last_buffered_extents_changed_event_; |
56 | 65 |
57 DISALLOW_COPY_AND_ASSIGN(RenderMediaLog); | 66 DISALLOW_COPY_AND_ASSIGN(RenderMediaLog); |
58 }; | 67 }; |
59 | 68 |
60 } // namespace content | 69 } // namespace content |
61 | 70 |
62 #endif // CONTENT_RENDERER_MEDIA_RENDER_MEDIA_LOG_H_ | 71 #endif // CONTENT_RENDERER_MEDIA_RENDER_MEDIA_LOG_H_ |
OLD | NEW |