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/browser/media/media_internals_proxy.h" | 5 #include "content/browser/media/media_internals_proxy.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" |
9 #include "content/browser/media/media_internals_handler.h" | 11 #include "content/browser/media/media_internals_handler.h" |
10 #include "content/public/browser/content_browser_client.h" | 12 #include "content/public/browser/content_browser_client.h" |
11 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
12 #include "content/public/browser/notification_types.h" | 14 #include "content/public/browser/notification_types.h" |
13 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
14 #include "content/public/browser/web_ui.h" | 16 #include "content/public/browser/web_ui.h" |
15 | 17 |
16 namespace content { | 18 namespace content { |
17 | 19 |
18 static const int kMediaInternalsProxyEventDelayMilliseconds = 100; | 20 static const int kMediaInternalsProxyEventDelayMilliseconds = 100; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 handler_->OnUpdate(update); | 151 handler_->OnUpdate(update); |
150 } | 152 } |
151 | 153 |
152 void MediaInternalsProxy::AddNetEventOnUIThread(base::Value* entry) { | 154 void MediaInternalsProxy::AddNetEventOnUIThread(base::Value* entry) { |
153 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 155 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
154 | 156 |
155 // Send the updates to the page in kMediaInternalsProxyEventDelayMilliseconds | 157 // Send the updates to the page in kMediaInternalsProxyEventDelayMilliseconds |
156 // if an update is not already pending. | 158 // if an update is not already pending. |
157 if (!pending_net_updates_) { | 159 if (!pending_net_updates_) { |
158 pending_net_updates_.reset(new base::ListValue()); | 160 pending_net_updates_.reset(new base::ListValue()); |
159 base::MessageLoop::current()->PostDelayedTask( | 161 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
160 FROM_HERE, | 162 FROM_HERE, |
161 base::Bind(&MediaInternalsProxy::SendNetEventsOnUIThread, this), | 163 base::Bind(&MediaInternalsProxy::SendNetEventsOnUIThread, this), |
162 base::TimeDelta::FromMilliseconds( | 164 base::TimeDelta::FromMilliseconds( |
163 kMediaInternalsProxyEventDelayMilliseconds)); | 165 kMediaInternalsProxyEventDelayMilliseconds)); |
164 } | 166 } |
165 pending_net_updates_->Append(entry); | 167 pending_net_updates_->Append(entry); |
166 } | 168 } |
167 | 169 |
168 void MediaInternalsProxy::SendNetEventsOnUIThread() { | 170 void MediaInternalsProxy::SendNetEventsOnUIThread() { |
169 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 171 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
170 CallJavaScriptFunctionOnUIThread("media.onNetUpdate", | 172 CallJavaScriptFunctionOnUIThread("media.onNetUpdate", |
171 pending_net_updates_.release()); | 173 pending_net_updates_.release()); |
172 } | 174 } |
173 | 175 |
174 void MediaInternalsProxy::CallJavaScriptFunctionOnUIThread( | 176 void MediaInternalsProxy::CallJavaScriptFunctionOnUIThread( |
175 const std::string& function, base::Value* args) { | 177 const std::string& function, base::Value* args) { |
176 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 178 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
177 scoped_ptr<base::Value> args_value(args); | 179 scoped_ptr<base::Value> args_value(args); |
178 std::vector<const base::Value*> args_vector; | 180 std::vector<const base::Value*> args_vector; |
179 args_vector.push_back(args_value.get()); | 181 args_vector.push_back(args_value.get()); |
180 base::string16 update = WebUI::GetJavascriptCall(function, args_vector); | 182 base::string16 update = WebUI::GetJavascriptCall(function, args_vector); |
181 UpdateUIOnUIThread(update); | 183 UpdateUIOnUIThread(update); |
182 } | 184 } |
183 | 185 |
184 } // namespace content | 186 } // namespace content |
OLD | NEW |