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> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/location.h" | 10 #include "base/location.h" |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
11 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
12 #include "base/time/default_tick_clock.h" | 14 #include "base/time/default_tick_clock.h" |
13 #include "content/common/view_messages.h" | 15 #include "content/common/view_messages.h" |
14 #include "content/public/renderer/render_thread.h" | 16 #include "content/public/renderer/render_thread.h" |
15 | 17 |
16 namespace { | 18 namespace { |
(...skipping 27 matching lines...) Expand all Loading... |
44 void RenderMediaLog::AddEvent(scoped_ptr<media::MediaLogEvent> event) { | 46 void RenderMediaLog::AddEvent(scoped_ptr<media::MediaLogEvent> event) { |
45 Log(event.get()); | 47 Log(event.get()); |
46 | 48 |
47 // For enforcing delay until it's been a second since the last ipc message was | 49 // For enforcing delay until it's been a second since the last ipc message was |
48 // sent. | 50 // sent. |
49 base::TimeDelta delay_for_next_ipc_send; | 51 base::TimeDelta delay_for_next_ipc_send; |
50 | 52 |
51 { | 53 { |
52 base::AutoLock auto_lock(lock_); | 54 base::AutoLock auto_lock(lock_); |
53 | 55 |
54 // Keep track of the latest buffered extents properties to avoid sending | 56 switch (event->type) { |
55 // thousands of events over IPC. See http://crbug.com/352585 for details. | 57 case media::MediaLogEvent::BUFFERED_EXTENTS_CHANGED: |
56 if (event->type == media::MediaLogEvent::BUFFERED_EXTENTS_CHANGED) | 58 // Keep track of the latest buffered extents properties to avoid sending |
57 last_buffered_extents_changed_event_.swap(event); | 59 // thousands of events over IPC. See http://crbug.com/352585 for |
58 else | 60 // details. |
59 queued_media_events_.push_back(*event); | 61 last_buffered_extents_changed_event_.swap(event); |
| 62 // SendQueuedMediaEvents() will enqueue the most recent event of this |
| 63 // kind, if any, prior to sending the event batch. |
| 64 break; |
| 65 |
| 66 // Hold onto the most recent PIPELINE_ERROR and MEDIA_LOG_ERROR_ENTRY for |
| 67 // use in GetLastErrorMessage(). |
| 68 case media::MediaLogEvent::PIPELINE_ERROR: |
| 69 queued_media_events_.push_back(*event); |
| 70 last_pipeline_error_.swap(event); |
| 71 break; |
| 72 case media::MediaLogEvent::MEDIA_ERROR_LOG_ENTRY: |
| 73 queued_media_events_.push_back(*event); |
| 74 last_media_error_log_entry_.swap(event); |
| 75 break; |
| 76 |
| 77 // Just enqueue all other event types for throttled transmission. |
| 78 default: |
| 79 queued_media_events_.push_back(*event); |
| 80 } |
60 | 81 |
61 if (ipc_send_pending_) | 82 if (ipc_send_pending_) |
62 return; | 83 return; |
63 | 84 |
64 ipc_send_pending_ = true; | 85 ipc_send_pending_ = true; |
65 delay_for_next_ipc_send = base::TimeDelta::FromSeconds(1) - | 86 delay_for_next_ipc_send = base::TimeDelta::FromSeconds(1) - |
66 (tick_clock_->NowTicks() - last_ipc_send_time_); | 87 (tick_clock_->NowTicks() - last_ipc_send_time_); |
67 } | 88 } |
68 | 89 |
69 if (delay_for_next_ipc_send > base::TimeDelta()) { | 90 if (delay_for_next_ipc_send > base::TimeDelta()) { |
70 task_runner_->PostDelayedTask( | 91 task_runner_->PostDelayedTask( |
71 FROM_HERE, base::Bind(&RenderMediaLog::SendQueuedMediaEvents, this), | 92 FROM_HERE, base::Bind(&RenderMediaLog::SendQueuedMediaEvents, this), |
72 delay_for_next_ipc_send); | 93 delay_for_next_ipc_send); |
73 return; | 94 return; |
74 } | 95 } |
75 | 96 |
76 // It's been more than a second so send ASAP. | 97 // It's been more than a second so send ASAP. |
77 if (task_runner_->BelongsToCurrentThread()) { | 98 if (task_runner_->BelongsToCurrentThread()) { |
78 SendQueuedMediaEvents(); | 99 SendQueuedMediaEvents(); |
79 return; | 100 return; |
80 } | 101 } |
81 task_runner_->PostTask( | 102 task_runner_->PostTask( |
82 FROM_HERE, base::Bind(&RenderMediaLog::SendQueuedMediaEvents, this)); | 103 FROM_HERE, base::Bind(&RenderMediaLog::SendQueuedMediaEvents, this)); |
83 } | 104 } |
84 | 105 |
| 106 std::string RenderMediaLog::GetLastErrorMessage() { |
| 107 base::AutoLock auto_lock(lock_); |
| 108 |
| 109 // Return the conditional concatenation of the last pipeline error and the |
| 110 // last media error log. |
| 111 std::stringstream result; |
| 112 if (last_pipeline_error_) { |
| 113 result << MediaEventToLogString(*last_pipeline_error_) |
| 114 << (last_media_error_log_entry_ ? ", " : ""); |
| 115 } |
| 116 if (last_media_error_log_entry_) |
| 117 result << MediaEventToLogString(*last_media_error_log_entry_); |
| 118 return result.str(); |
| 119 } |
| 120 |
85 void RenderMediaLog::SendQueuedMediaEvents() { | 121 void RenderMediaLog::SendQueuedMediaEvents() { |
86 DCHECK(task_runner_->BelongsToCurrentThread()); | 122 DCHECK(task_runner_->BelongsToCurrentThread()); |
87 | 123 |
88 std::vector<media::MediaLogEvent> events_to_send; | 124 std::vector<media::MediaLogEvent> events_to_send; |
89 { | 125 { |
90 base::AutoLock auto_lock(lock_); | 126 base::AutoLock auto_lock(lock_); |
91 | 127 |
92 DCHECK(ipc_send_pending_); | 128 DCHECK(ipc_send_pending_); |
93 ipc_send_pending_ = false; | 129 ipc_send_pending_ = false; |
94 | 130 |
(...skipping 18 matching lines...) Expand all Loading... |
113 tick_clock_.swap(tick_clock); | 149 tick_clock_.swap(tick_clock); |
114 last_ipc_send_time_ = tick_clock_->NowTicks(); | 150 last_ipc_send_time_ = tick_clock_->NowTicks(); |
115 } | 151 } |
116 | 152 |
117 void RenderMediaLog::SetTaskRunnerForTesting( | 153 void RenderMediaLog::SetTaskRunnerForTesting( |
118 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 154 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
119 task_runner_ = task_runner; | 155 task_runner_ = task_runner; |
120 } | 156 } |
121 | 157 |
122 } // namespace content | 158 } // namespace content |
OLD | NEW |