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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // SendQueuedMediaEvents() will enqueue the most recent event of this | 71 // SendQueuedMediaEvents() will enqueue the most recent event of this |
72 // kind, if any, prior to sending the event batch. | 72 // kind, if any, prior to sending the event batch. |
73 break; | 73 break; |
74 | 74 |
75 case media::MediaLogEvent::DURATION_SET: | 75 case media::MediaLogEvent::DURATION_SET: |
76 // Similar to the extents changed message, this may fire many times for | 76 // Similar to the extents changed message, this may fire many times for |
77 // badly muxed media. Suppress within our rate limits here. | 77 // badly muxed media. Suppress within our rate limits here. |
78 last_duration_changed_event_.swap(event); | 78 last_duration_changed_event_.swap(event); |
79 break; | 79 break; |
80 | 80 |
81 // Hold onto the most recent PIPELINE_ERROR and MEDIA_LOG_ERROR_ENTRY for | 81 // Hold onto the most recent PIPELINE_ERROR and the first, if any, |
82 // use in GetLastErrorMessage(). | 82 // MEDIA_LOG_ERROR_ENTRY for use in GetErrorMessage(). |
83 case media::MediaLogEvent::PIPELINE_ERROR: | 83 case media::MediaLogEvent::PIPELINE_ERROR: |
84 queued_media_events_.push_back(*event); | 84 queued_media_events_.push_back(*event); |
85 last_pipeline_error_.swap(event); | 85 last_pipeline_error_.swap(event); |
86 break; | 86 break; |
87 case media::MediaLogEvent::MEDIA_ERROR_LOG_ENTRY: | 87 case media::MediaLogEvent::MEDIA_ERROR_LOG_ENTRY: |
88 queued_media_events_.push_back(*event); | 88 queued_media_events_.push_back(*event); |
89 last_media_error_log_entry_.swap(event); | 89 if (!cached_media_error_for_message_) |
| 90 cached_media_error_for_message_ = std::move(event); |
90 break; | 91 break; |
91 | 92 |
92 // Just enqueue all other event types for throttled transmission. | 93 // Just enqueue all other event types for throttled transmission. |
93 default: | 94 default: |
94 queued_media_events_.push_back(*event); | 95 queued_media_events_.push_back(*event); |
95 } | 96 } |
96 | 97 |
97 if (ipc_send_pending_) | 98 if (ipc_send_pending_) |
98 return; | 99 return; |
99 | 100 |
(...skipping 11 matching lines...) Expand all Loading... |
111 | 112 |
112 // It's been more than a second so send ASAP. | 113 // It's been more than a second so send ASAP. |
113 if (task_runner_->BelongsToCurrentThread()) { | 114 if (task_runner_->BelongsToCurrentThread()) { |
114 SendQueuedMediaEvents(); | 115 SendQueuedMediaEvents(); |
115 return; | 116 return; |
116 } | 117 } |
117 task_runner_->PostTask( | 118 task_runner_->PostTask( |
118 FROM_HERE, base::Bind(&RenderMediaLog::SendQueuedMediaEvents, this)); | 119 FROM_HERE, base::Bind(&RenderMediaLog::SendQueuedMediaEvents, this)); |
119 } | 120 } |
120 | 121 |
121 std::string RenderMediaLog::GetLastErrorMessage() { | 122 std::string RenderMediaLog::GetErrorMessage() { |
122 base::AutoLock auto_lock(lock_); | 123 base::AutoLock auto_lock(lock_); |
123 | 124 |
124 // Return the conditional concatenation of the last pipeline error and the | 125 // Keep message structure in sync with |
125 // last media error log. | 126 // HTMLMediaElement::BuildElementErrorMessage(). |
| 127 |
126 std::stringstream result; | 128 std::stringstream result; |
127 if (last_pipeline_error_) { | 129 if (last_pipeline_error_) |
128 result << MediaEventToLogString(*last_pipeline_error_) | 130 result << MediaEventToMessageString(*last_pipeline_error_); |
129 << (last_media_error_log_entry_ ? ", " : ""); | 131 |
| 132 if (cached_media_error_for_message_) { |
| 133 DCHECK(last_pipeline_error_) |
| 134 << "Message with detail should be associated with a pipeline error"; |
| 135 // This ':' lets web apps extract the UA-specific-error-code from the |
| 136 // MediaError.message prefix. |
| 137 result << ": " |
| 138 << MediaEventToMessageString(*cached_media_error_for_message_); |
130 } | 139 } |
131 if (last_media_error_log_entry_) | 140 |
132 result << MediaEventToLogString(*last_media_error_log_entry_); | |
133 return result.str(); | 141 return result.str(); |
134 } | 142 } |
135 | 143 |
136 void RenderMediaLog::RecordRapporWithSecurityOrigin(const std::string& metric) { | 144 void RenderMediaLog::RecordRapporWithSecurityOrigin(const std::string& metric) { |
137 if (!task_runner_->BelongsToCurrentThread()) { | 145 if (!task_runner_->BelongsToCurrentThread()) { |
138 task_runner_->PostTask( | 146 task_runner_->PostTask( |
139 FROM_HERE, base::Bind(&RenderMediaLog::RecordRapporWithSecurityOrigin, | 147 FROM_HERE, base::Bind(&RenderMediaLog::RecordRapporWithSecurityOrigin, |
140 this, metric)); | 148 this, metric)); |
141 return; | 149 return; |
142 } | 150 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 tick_clock_.swap(tick_clock); | 188 tick_clock_.swap(tick_clock); |
181 last_ipc_send_time_ = tick_clock_->NowTicks(); | 189 last_ipc_send_time_ = tick_clock_->NowTicks(); |
182 } | 190 } |
183 | 191 |
184 void RenderMediaLog::SetTaskRunnerForTesting( | 192 void RenderMediaLog::SetTaskRunnerForTesting( |
185 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 193 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
186 task_runner_ = task_runner; | 194 task_runner_ = task_runner; |
187 } | 195 } |
188 | 196 |
189 } // namespace content | 197 } // namespace content |
OLD | NEW |