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" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 // SendQueuedMediaEvents() will enqueue the most recent event of this | 85 // SendQueuedMediaEvents() will enqueue the most recent event of this |
86 // kind, if any, prior to sending the event batch. | 86 // kind, if any, prior to sending the event batch. |
87 break; | 87 break; |
88 | 88 |
89 case media::MediaLogEvent::DURATION_SET: | 89 case media::MediaLogEvent::DURATION_SET: |
90 // Similar to the extents changed message, this may fire many times for | 90 // Similar to the extents changed message, this may fire many times for |
91 // badly muxed media. Suppress within our rate limits here. | 91 // badly muxed media. Suppress within our rate limits here. |
92 last_duration_changed_event_.swap(event); | 92 last_duration_changed_event_.swap(event); |
93 break; | 93 break; |
94 | 94 |
95 // Hold onto the most recent PIPELINE_ERROR and MEDIA_LOG_ERROR_ENTRY for | 95 // Hold onto the most recent PIPELINE_ERROR and the first, if any, |
96 // use in GetLastErrorMessage(). | 96 // MEDIA_LOG_ERROR_ENTRY for use in GetErrorMessage(). |
97 case media::MediaLogEvent::PIPELINE_ERROR: | 97 case media::MediaLogEvent::PIPELINE_ERROR: |
98 queued_media_events_.push_back(*event); | 98 queued_media_events_.push_back(*event); |
99 last_pipeline_error_.swap(event); | 99 last_pipeline_error_.swap(event); |
100 break; | 100 break; |
101 case media::MediaLogEvent::MEDIA_ERROR_LOG_ENTRY: | 101 case media::MediaLogEvent::MEDIA_ERROR_LOG_ENTRY: |
102 queued_media_events_.push_back(*event); | 102 queued_media_events_.push_back(*event); |
103 last_media_error_log_entry_.swap(event); | 103 if (!cached_media_error_for_message_) |
| 104 cached_media_error_for_message_ = std::move(event); |
104 break; | 105 break; |
105 | 106 |
106 // Just enqueue all other event types for throttled transmission. | 107 // Just enqueue all other event types for throttled transmission. |
107 default: | 108 default: |
108 queued_media_events_.push_back(*event); | 109 queued_media_events_.push_back(*event); |
109 } | 110 } |
110 | 111 |
111 if (ipc_send_pending_) | 112 if (ipc_send_pending_) |
112 return; | 113 return; |
113 | 114 |
(...skipping 13 matching lines...) Expand all Loading... |
127 // It's been more than a second so send ASAP. | 128 // It's been more than a second so send ASAP. |
128 if (task_runner_->BelongsToCurrentThread()) { | 129 if (task_runner_->BelongsToCurrentThread()) { |
129 SendQueuedMediaEvents(); | 130 SendQueuedMediaEvents(); |
130 return; | 131 return; |
131 } | 132 } |
132 task_runner_->PostTask( | 133 task_runner_->PostTask( |
133 FROM_HERE, | 134 FROM_HERE, |
134 base::Bind(&RenderMediaLog::SendQueuedMediaEvents, weak_this_)); | 135 base::Bind(&RenderMediaLog::SendQueuedMediaEvents, weak_this_)); |
135 } | 136 } |
136 | 137 |
137 std::string RenderMediaLog::GetLastErrorMessage() { | 138 std::string RenderMediaLog::GetErrorMessage() { |
138 base::AutoLock auto_lock(lock_); | 139 base::AutoLock auto_lock(lock_); |
139 | 140 |
140 // Return the conditional concatenation of the last pipeline error and the | 141 // Keep message structure in sync with |
141 // last media error log. | 142 // HTMLMediaElement::BuildElementErrorMessage(). |
| 143 |
142 std::stringstream result; | 144 std::stringstream result; |
143 if (last_pipeline_error_) { | 145 if (last_pipeline_error_) |
144 result << MediaEventToLogString(*last_pipeline_error_) | 146 result << MediaEventToMessageString(*last_pipeline_error_); |
145 << (last_media_error_log_entry_ ? ", " : ""); | 147 |
| 148 if (cached_media_error_for_message_) { |
| 149 DCHECK(last_pipeline_error_) |
| 150 << "Message with detail should be associated with a pipeline error"; |
| 151 // This ':' lets web apps extract the UA-specific-error-code from the |
| 152 // MediaError.message prefix. |
| 153 result << ": " |
| 154 << MediaEventToMessageString(*cached_media_error_for_message_); |
146 } | 155 } |
147 if (last_media_error_log_entry_) | 156 |
148 result << MediaEventToLogString(*last_media_error_log_entry_); | |
149 return result.str(); | 157 return result.str(); |
150 } | 158 } |
151 | 159 |
152 void RenderMediaLog::RecordRapporWithSecurityOrigin(const std::string& metric) { | 160 void RenderMediaLog::RecordRapporWithSecurityOrigin(const std::string& metric) { |
153 if (!task_runner_->BelongsToCurrentThread()) { | 161 if (!task_runner_->BelongsToCurrentThread()) { |
154 task_runner_->PostTask( | 162 task_runner_->PostTask( |
155 FROM_HERE, base::Bind(&RenderMediaLog::RecordRapporWithSecurityOrigin, | 163 FROM_HERE, base::Bind(&RenderMediaLog::RecordRapporWithSecurityOrigin, |
156 weak_this_, metric)); | 164 weak_this_, metric)); |
157 return; | 165 return; |
158 } | 166 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 tick_clock_.swap(tick_clock); | 204 tick_clock_.swap(tick_clock); |
197 last_ipc_send_time_ = tick_clock_->NowTicks(); | 205 last_ipc_send_time_ = tick_clock_->NowTicks(); |
198 } | 206 } |
199 | 207 |
200 void RenderMediaLog::SetTaskRunnerForTesting( | 208 void RenderMediaLog::SetTaskRunnerForTesting( |
201 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 209 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
202 task_runner_ = task_runner; | 210 task_runner_ = task_runner; |
203 } | 211 } |
204 | 212 |
205 } // namespace content | 213 } // namespace content |
OLD | NEW |