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 #include "content/renderer/media/render_media_log.h" | 5 #include "content/renderer/media/render_media_log.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
14 #include "base/time/default_tick_clock.h" | 14 #include "base/time/default_tick_clock.h" |
15 #include "content/common/view_messages.h" | 15 #include "content/common/view_messages.h" |
| 16 #include "content/public/common/content_client.h" |
| 17 #include "content/public/renderer/content_renderer_client.h" |
16 #include "content/public/renderer/render_thread.h" | 18 #include "content/public/renderer/render_thread.h" |
17 | 19 |
18 namespace { | 20 namespace { |
19 | 21 |
20 // Print an event to the chromium log. | 22 // Print an event to the chromium log. |
21 void Log(media::MediaLogEvent* event) { | 23 void Log(media::MediaLogEvent* event) { |
22 if (event->type == media::MediaLogEvent::PIPELINE_ERROR) { | 24 if (event->type == media::MediaLogEvent::PIPELINE_ERROR) { |
23 LOG(ERROR) << "MediaEvent: " | 25 LOG(ERROR) << "MediaEvent: " |
24 << media::MediaLog::MediaEventToLogString(*event); | 26 << media::MediaLog::MediaEventToLogString(*event); |
25 } else if (event->type != media::MediaLogEvent::BUFFERED_EXTENTS_CHANGED && | 27 } else if (event->type != media::MediaLogEvent::BUFFERED_EXTENTS_CHANGED && |
26 event->type != media::MediaLogEvent::PROPERTY_CHANGE && | 28 event->type != media::MediaLogEvent::PROPERTY_CHANGE && |
27 event->type != media::MediaLogEvent::NETWORK_ACTIVITY_SET) { | 29 event->type != media::MediaLogEvent::NETWORK_ACTIVITY_SET) { |
28 DVLOG(1) << "MediaEvent: " | 30 DVLOG(1) << "MediaEvent: " |
29 << media::MediaLog::MediaEventToLogString(*event); | 31 << media::MediaLog::MediaEventToLogString(*event); |
30 } | 32 } |
31 } | 33 } |
32 | 34 |
33 } // namespace | 35 } // namespace |
34 | 36 |
35 namespace content { | 37 namespace content { |
36 | 38 |
37 RenderMediaLog::RenderMediaLog() | 39 RenderMediaLog::RenderMediaLog(const GURL& security_origin) |
38 : task_runner_(base::ThreadTaskRunnerHandle::Get()), | 40 : security_origin_(security_origin), |
| 41 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
39 tick_clock_(new base::DefaultTickClock()), | 42 tick_clock_(new base::DefaultTickClock()), |
40 last_ipc_send_time_(tick_clock_->NowTicks()), | 43 last_ipc_send_time_(tick_clock_->NowTicks()), |
41 ipc_send_pending_(false) { | 44 ipc_send_pending_(false) { |
42 DCHECK(RenderThread::Get()) | 45 DCHECK(RenderThread::Get()) |
43 << "RenderMediaLog must be constructed on the render thread"; | 46 << "RenderMediaLog must be constructed on the render thread"; |
44 } | 47 } |
45 | 48 |
46 void RenderMediaLog::AddEvent(std::unique_ptr<media::MediaLogEvent> event) { | 49 void RenderMediaLog::AddEvent(std::unique_ptr<media::MediaLogEvent> event) { |
47 Log(event.get()); | 50 Log(event.get()); |
48 | 51 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 std::stringstream result; | 114 std::stringstream result; |
112 if (last_pipeline_error_) { | 115 if (last_pipeline_error_) { |
113 result << MediaEventToLogString(*last_pipeline_error_) | 116 result << MediaEventToLogString(*last_pipeline_error_) |
114 << (last_media_error_log_entry_ ? ", " : ""); | 117 << (last_media_error_log_entry_ ? ", " : ""); |
115 } | 118 } |
116 if (last_media_error_log_entry_) | 119 if (last_media_error_log_entry_) |
117 result << MediaEventToLogString(*last_media_error_log_entry_); | 120 result << MediaEventToLogString(*last_media_error_log_entry_); |
118 return result.str(); | 121 return result.str(); |
119 } | 122 } |
120 | 123 |
| 124 void RenderMediaLog::RecordRapporWithSecurityOrigin(const std::string& metric) { |
| 125 if (!task_runner_->BelongsToCurrentThread()) { |
| 126 task_runner_->PostTask( |
| 127 FROM_HERE, base::Bind(&RenderMediaLog::RecordRapporWithSecurityOrigin, |
| 128 this, metric)); |
| 129 return; |
| 130 } |
| 131 |
| 132 GetContentClient()->renderer()->RecordRapporURL(metric, security_origin_); |
| 133 } |
| 134 |
121 void RenderMediaLog::SendQueuedMediaEvents() { | 135 void RenderMediaLog::SendQueuedMediaEvents() { |
122 DCHECK(task_runner_->BelongsToCurrentThread()); | 136 DCHECK(task_runner_->BelongsToCurrentThread()); |
123 | 137 |
124 std::vector<media::MediaLogEvent> events_to_send; | 138 std::vector<media::MediaLogEvent> events_to_send; |
125 { | 139 { |
126 base::AutoLock auto_lock(lock_); | 140 base::AutoLock auto_lock(lock_); |
127 | 141 |
128 DCHECK(ipc_send_pending_); | 142 DCHECK(ipc_send_pending_); |
129 ipc_send_pending_ = false; | 143 ipc_send_pending_ = false; |
130 | 144 |
(...skipping 18 matching lines...) Expand all Loading... |
149 tick_clock_.swap(tick_clock); | 163 tick_clock_.swap(tick_clock); |
150 last_ipc_send_time_ = tick_clock_->NowTicks(); | 164 last_ipc_send_time_ = tick_clock_->NowTicks(); |
151 } | 165 } |
152 | 166 |
153 void RenderMediaLog::SetTaskRunnerForTesting( | 167 void RenderMediaLog::SetTaskRunnerForTesting( |
154 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 168 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
155 task_runner_ = task_runner; | 169 task_runner_ = task_runner; |
156 } | 170 } |
157 | 171 |
158 } // namespace content | 172 } // namespace content |
OLD | NEW |