OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/webui/webrtc_internals_proxy.h" |
| 6 |
| 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/media/webrtc_internals.h" |
| 9 #include "chrome/browser/ui/webui/webrtc_internals_message_handler.h" |
| 10 #include "content/public/browser/web_ui.h" |
| 11 |
| 12 using content::BrowserThread; |
| 13 |
| 14 WebRTCInternalsProxy::WebRTCInternalsProxy() {} |
| 15 |
| 16 void WebRTCInternalsProxy::OnUpdate(const std::string& command, |
| 17 const base::Value* args) { |
| 18 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 19 std::vector<const Value*> args_vector; |
| 20 args_vector.push_back(args); |
| 21 string16 update = content::WebUI::GetJavascriptCall(command, args_vector); |
| 22 |
| 23 BrowserThread::PostTask( |
| 24 BrowserThread::UI, FROM_HERE, |
| 25 base::Bind(&WebRTCInternalsProxy::UpdateOnUIThread, this, update)); |
| 26 } |
| 27 |
| 28 void WebRTCInternalsProxy::Attach(WebRTCInternalsMessageHandler* handler) { |
| 29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 30 handler_ = handler; |
| 31 BrowserThread::PostTask( |
| 32 BrowserThread::IO, FROM_HERE, |
| 33 base::Bind(&WebRTCInternalsProxy::ObserveWebRTCInternalsOnIOThread, |
| 34 this)); |
| 35 } |
| 36 |
| 37 void WebRTCInternalsProxy::Detach() { |
| 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 39 handler_ = NULL; |
| 40 BrowserThread::PostTask( |
| 41 BrowserThread::IO, FROM_HERE, |
| 42 base::Bind( |
| 43 &WebRTCInternalsProxy::StopObservingWebRTCInternalsOnIOThread, this)); |
| 44 } |
| 45 |
| 46 WebRTCInternalsProxy::~WebRTCInternalsProxy() {} |
| 47 |
| 48 void WebRTCInternalsProxy::ObserveWebRTCInternalsOnIOThread() { |
| 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 50 WebRTCInternals::GetInstance()->AddObserver(this); |
| 51 } |
| 52 |
| 53 void WebRTCInternalsProxy::StopObservingWebRTCInternalsOnIOThread() { |
| 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 55 WebRTCInternals::GetInstance()->RemoveObserver(this); |
| 56 } |
| 57 |
| 58 void WebRTCInternalsProxy::UpdateOnUIThread(const string16& update) { |
| 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 60 if (handler_) |
| 61 handler_->OnUpdate(update); |
| 62 } |
OLD | NEW |