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