| 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.h" | 8 #include "base/message_loop.h" |
| 9 #include "content/browser/media/media_internals_handler.h" | 9 #include "content/browser/media/media_internals_handler.h" |
| 10 #include "content/public/browser/content_browser_client.h" | 10 #include "content/public/browser/content_browser_client.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 // Don't forward updates to a destructed UI. | 145 // Don't forward updates to a destructed UI. |
| 146 if (handler_) | 146 if (handler_) |
| 147 handler_->OnUpdate(update); | 147 handler_->OnUpdate(update); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void MediaInternalsProxy::AddNetEventOnUIThread(base::Value* entry) { | 150 void MediaInternalsProxy::AddNetEventOnUIThread(base::Value* entry) { |
| 151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 152 | 152 |
| 153 // Send the updates to the page in kMediaInternalsProxyEventDelayMilliseconds | 153 // Send the updates to the page in kMediaInternalsProxyEventDelayMilliseconds |
| 154 // if an update is not already pending. | 154 // if an update is not already pending. |
| 155 if (!pending_net_updates_.get()) { | 155 if (!pending_net_updates_) { |
| 156 pending_net_updates_.reset(new base::ListValue()); | 156 pending_net_updates_.reset(new base::ListValue()); |
| 157 MessageLoop::current()->PostDelayedTask( | 157 MessageLoop::current()->PostDelayedTask( |
| 158 FROM_HERE, | 158 FROM_HERE, |
| 159 base::Bind( | 159 base::Bind( |
| 160 &MediaInternalsProxy::SendNetEventsOnUIThread, this), | 160 &MediaInternalsProxy::SendNetEventsOnUIThread, this), |
| 161 base::TimeDelta::FromMilliseconds( | 161 base::TimeDelta::FromMilliseconds( |
| 162 kMediaInternalsProxyEventDelayMilliseconds)); | 162 kMediaInternalsProxyEventDelayMilliseconds)); |
| 163 } | 163 } |
| 164 pending_net_updates_->Append(entry); | 164 pending_net_updates_->Append(entry); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void MediaInternalsProxy::SendNetEventsOnUIThread() { | 167 void MediaInternalsProxy::SendNetEventsOnUIThread() { |
| 168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 169 CallJavaScriptFunctionOnUIThread("media.onNetUpdate", | 169 CallJavaScriptFunctionOnUIThread("media.onNetUpdate", |
| 170 pending_net_updates_.release()); | 170 pending_net_updates_.release()); |
| 171 } | 171 } |
| 172 | 172 |
| 173 void MediaInternalsProxy::CallJavaScriptFunctionOnUIThread( | 173 void MediaInternalsProxy::CallJavaScriptFunctionOnUIThread( |
| 174 const std::string& function, base::Value* args) { | 174 const std::string& function, base::Value* args) { |
| 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 176 scoped_ptr<base::Value> args_value(args); | 176 scoped_ptr<base::Value> args_value(args); |
| 177 std::vector<const base::Value*> args_vector; | 177 std::vector<const base::Value*> args_vector; |
| 178 args_vector.push_back(args_value.get()); | 178 args_vector.push_back(args_value.get()); |
| 179 string16 update = WebUI::GetJavascriptCall(function, args_vector); | 179 string16 update = WebUI::GetJavascriptCall(function, args_vector); |
| 180 UpdateUIOnUIThread(update); | 180 UpdateUIOnUIThread(update); |
| 181 } | 181 } |
| 182 | 182 |
| 183 } // namespace content | 183 } // namespace content |
| OLD | NEW |