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