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/media/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/media/webrtc_internals_message_handler.h" |
| 10 #include "content/public/browser/web_ui.h" |
| 11 |
| 12 using content::BrowserThread; |
| 13 using media::WebRTCInternals; |
| 14 |
| 15 WebRTCInternalsProxy::WebRTCInternalsProxy() {} |
| 16 |
| 17 void WebRTCInternalsProxy::OnUpdate(const std::string& command, |
| 18 const base::Value* args) { |
| 19 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 20 std::vector<const Value*> args_vector; |
| 21 args_vector.push_back(args); |
| 22 string16 update = content::WebUI::GetJavascriptCall(command, args_vector); |
| 23 |
| 24 BrowserThread::PostTask( |
| 25 BrowserThread::UI, FROM_HERE, |
| 26 base::Bind(&WebRTCInternalsProxy::UpdateOnUIThread, this, update)); |
| 27 } |
| 28 |
| 29 void WebRTCInternalsProxy::Attach(WebRTCInternalsMessageHandler* handler) { |
| 30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 31 handler_ = handler; |
| 32 BrowserThread::PostTask( |
| 33 BrowserThread::IO, FROM_HERE, |
| 34 base::Bind(&WebRTCInternalsProxy::ObserveWebRTCInternalsOnIOThread, |
| 35 this)); |
| 36 } |
| 37 |
| 38 void WebRTCInternalsProxy::Detach() { |
| 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 40 handler_ = NULL; |
| 41 BrowserThread::PostTask( |
| 42 BrowserThread::IO, FROM_HERE, |
| 43 base::Bind( |
| 44 &WebRTCInternalsProxy::StopObservingWebRTCInternalsOnIOThread, this)); |
| 45 } |
| 46 |
| 47 WebRTCInternalsProxy::~WebRTCInternalsProxy() {} |
| 48 |
| 49 void WebRTCInternalsProxy::ObserveWebRTCInternalsOnIOThread() { |
| 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 51 WebRTCInternals::GetInstance()->AddObserver(this); |
| 52 } |
| 53 |
| 54 void WebRTCInternalsProxy::StopObservingWebRTCInternalsOnIOThread() { |
| 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 56 WebRTCInternals::GetInstance()->RemoveObserver(this); |
| 57 } |
| 58 |
| 59 void WebRTCInternalsProxy::UpdateOnUIThread(const string16& update) { |
| 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 61 if (handler_) |
| 62 handler_->OnUpdate(update); |
| 63 } |
OLD | NEW |