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 10 matching lines...) Expand all Loading... |
21 #define MEDIA_EVENT_LOG_UTILITY DVLOG(1) | 21 #define MEDIA_EVENT_LOG_UTILITY DVLOG(1) |
22 #endif | 22 #endif |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 // Print an event to the chromium log. | 26 // Print an event to the chromium log. |
27 void Log(media::MediaLogEvent* event) { | 27 void Log(media::MediaLogEvent* event) { |
28 if (event->type == media::MediaLogEvent::PIPELINE_ERROR || | 28 if (event->type == media::MediaLogEvent::PIPELINE_ERROR || |
29 event->type == media::MediaLogEvent::MEDIA_ERROR_LOG_ENTRY) { | 29 event->type == media::MediaLogEvent::MEDIA_ERROR_LOG_ENTRY) { |
30 LOG(ERROR) << "MediaEvent: " | 30 LOG(ERROR) << "MediaEvent: " |
31 << media::MediaLog::MediaEventToLogString(*event); | 31 << media::MediaLog::MediaEventToLogString(*event, true); |
32 } else if (event->type != media::MediaLogEvent::BUFFERED_EXTENTS_CHANGED && | 32 } else if (event->type != media::MediaLogEvent::BUFFERED_EXTENTS_CHANGED && |
33 event->type != media::MediaLogEvent::PROPERTY_CHANGE && | 33 event->type != media::MediaLogEvent::PROPERTY_CHANGE && |
34 event->type != media::MediaLogEvent::WATCH_TIME_UPDATE && | 34 event->type != media::MediaLogEvent::WATCH_TIME_UPDATE && |
35 event->type != media::MediaLogEvent::NETWORK_ACTIVITY_SET) { | 35 event->type != media::MediaLogEvent::NETWORK_ACTIVITY_SET) { |
36 MEDIA_EVENT_LOG_UTILITY << "MediaEvent: " | 36 MEDIA_EVENT_LOG_UTILITY |
37 << media::MediaLog::MediaEventToLogString(*event); | 37 << "MediaEvent: " |
| 38 << media::MediaLog::MediaEventToLogString(*event, true); |
38 } | 39 } |
39 } | 40 } |
40 | 41 |
| 42 // Limit the number of recent MEDIA_ERROR_LOG_ENTRY retained for use in |
| 43 // GetErrorMessages(). Older entries are dropped to make room for newer ones. |
| 44 const int kMaxErrorLogEntries = 20; |
| 45 |
41 } // namespace | 46 } // namespace |
42 | 47 |
43 namespace content { | 48 namespace content { |
44 | 49 |
45 RenderMediaLog::RenderMediaLog(const GURL& security_origin) | 50 RenderMediaLog::RenderMediaLog(const GURL& security_origin) |
46 : security_origin_(security_origin), | 51 : security_origin_(security_origin), |
47 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 52 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
48 tick_clock_(new base::DefaultTickClock()), | 53 tick_clock_(new base::DefaultTickClock()), |
49 last_ipc_send_time_(tick_clock_->NowTicks()), | 54 last_ipc_send_time_(tick_clock_->NowTicks()), |
50 ipc_send_pending_(false) { | 55 ipc_send_pending_(false) { |
(...skipping 20 matching lines...) Expand all Loading... |
71 // SendQueuedMediaEvents() will enqueue the most recent event of this | 76 // SendQueuedMediaEvents() will enqueue the most recent event of this |
72 // kind, if any, prior to sending the event batch. | 77 // kind, if any, prior to sending the event batch. |
73 break; | 78 break; |
74 | 79 |
75 case media::MediaLogEvent::DURATION_SET: | 80 case media::MediaLogEvent::DURATION_SET: |
76 // Similar to the extents changed message, this may fire many times for | 81 // Similar to the extents changed message, this may fire many times for |
77 // badly muxed media. Suppress within our rate limits here. | 82 // badly muxed media. Suppress within our rate limits here. |
78 last_duration_changed_event_.swap(event); | 83 last_duration_changed_event_.swap(event); |
79 break; | 84 break; |
80 | 85 |
81 // Hold onto the most recent PIPELINE_ERROR and MEDIA_LOG_ERROR_ENTRY for | 86 // Hold onto the most recent PIPELINE_ERROR and (potentially multiple, |
82 // use in GetLastErrorMessage(). | 87 // capped number of) MEDIA_LOG_ERROR_ENTRY for use in GetErrorMessages(). |
83 case media::MediaLogEvent::PIPELINE_ERROR: | 88 case media::MediaLogEvent::PIPELINE_ERROR: |
84 queued_media_events_.push_back(*event); | 89 queued_media_events_.push_back(*event); |
85 last_pipeline_error_.swap(event); | 90 last_pipeline_error_.swap(event); |
86 break; | 91 break; |
87 case media::MediaLogEvent::MEDIA_ERROR_LOG_ENTRY: | 92 case media::MediaLogEvent::MEDIA_ERROR_LOG_ENTRY: |
88 queued_media_events_.push_back(*event); | 93 queued_media_events_.push_back(*event); |
89 last_media_error_log_entry_.swap(event); | 94 recent_media_error_log_entries_.push_back(std::move(event)); |
| 95 if (recent_media_error_log_entries_.size() > kMaxErrorLogEntries) |
| 96 recent_media_error_log_entries_.pop_front(); |
90 break; | 97 break; |
91 | 98 |
92 // Just enqueue all other event types for throttled transmission. | 99 // Just enqueue all other event types for throttled transmission. |
93 default: | 100 default: |
94 queued_media_events_.push_back(*event); | 101 queued_media_events_.push_back(*event); |
95 } | 102 } |
96 | 103 |
97 if (ipc_send_pending_) | 104 if (ipc_send_pending_) |
98 return; | 105 return; |
99 | 106 |
(...skipping 11 matching lines...) Expand all Loading... |
111 | 118 |
112 // It's been more than a second so send ASAP. | 119 // It's been more than a second so send ASAP. |
113 if (task_runner_->BelongsToCurrentThread()) { | 120 if (task_runner_->BelongsToCurrentThread()) { |
114 SendQueuedMediaEvents(); | 121 SendQueuedMediaEvents(); |
115 return; | 122 return; |
116 } | 123 } |
117 task_runner_->PostTask( | 124 task_runner_->PostTask( |
118 FROM_HERE, base::Bind(&RenderMediaLog::SendQueuedMediaEvents, this)); | 125 FROM_HERE, base::Bind(&RenderMediaLog::SendQueuedMediaEvents, this)); |
119 } | 126 } |
120 | 127 |
121 std::string RenderMediaLog::GetLastErrorMessage() { | 128 std::map<std::string, std::vector<std::string>> |
| 129 RenderMediaLog::GetErrorMessages() { |
122 base::AutoLock auto_lock(lock_); | 130 base::AutoLock auto_lock(lock_); |
123 | 131 |
124 // Return the conditional concatenation of the last pipeline error and the | 132 std::map<std::string, std::vector<std::string>> result; |
125 // last media error log. | |
126 std::stringstream result; | |
127 if (last_pipeline_error_) { | 133 if (last_pipeline_error_) { |
128 result << MediaEventToLogString(*last_pipeline_error_) | 134 result[EventTypeToString(last_pipeline_error_->type)].push_back( |
129 << (last_media_error_log_entry_ ? ", " : ""); | 135 MediaEventToLogString(*last_pipeline_error_, false)); |
130 } | 136 } |
131 if (last_media_error_log_entry_) | 137 |
132 result << MediaEventToLogString(*last_media_error_log_entry_); | 138 for (const auto& entry : recent_media_error_log_entries_) { |
133 return result.str(); | 139 result[EventTypeToString(entry->type)].push_back( |
| 140 MediaEventToLogString(*entry, false)); |
| 141 } |
| 142 |
| 143 return result; |
134 } | 144 } |
135 | 145 |
136 void RenderMediaLog::RecordRapporWithSecurityOrigin(const std::string& metric) { | 146 void RenderMediaLog::RecordRapporWithSecurityOrigin(const std::string& metric) { |
137 if (!task_runner_->BelongsToCurrentThread()) { | 147 if (!task_runner_->BelongsToCurrentThread()) { |
138 task_runner_->PostTask( | 148 task_runner_->PostTask( |
139 FROM_HERE, base::Bind(&RenderMediaLog::RecordRapporWithSecurityOrigin, | 149 FROM_HERE, base::Bind(&RenderMediaLog::RecordRapporWithSecurityOrigin, |
140 this, metric)); | 150 this, metric)); |
141 return; | 151 return; |
142 } | 152 } |
143 | 153 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 tick_clock_.swap(tick_clock); | 190 tick_clock_.swap(tick_clock); |
181 last_ipc_send_time_ = tick_clock_->NowTicks(); | 191 last_ipc_send_time_ = tick_clock_->NowTicks(); |
182 } | 192 } |
183 | 193 |
184 void RenderMediaLog::SetTaskRunnerForTesting( | 194 void RenderMediaLog::SetTaskRunnerForTesting( |
185 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 195 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
186 task_runner_ = task_runner; | 196 task_runner_ = task_runner; |
187 } | 197 } |
188 | 198 |
189 } // namespace content | 199 } // namespace content |
OLD | NEW |