diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-13 23:42:18 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-13 23:42:18 +0000 |
commit | 04a97ada0f1f07675bad41f641c675e558e3a4a2 (patch) | |
tree | 010bb2f372ff7100712a45a2803c4049e37aaa47 /remoting | |
parent | f26c5562d76ec0a10c6906d595ab32d42deec410 (diff) | |
download | chromium_src-04a97ada0f1f07675bad41f641c675e558e3a4a2.zip chromium_src-04a97ada0f1f07675bad41f641c675e558e3a4a2.tar.gz chromium_src-04a97ada0f1f07675bad41f641c675e558e3a4a2.tar.bz2 |
Remove XmppProxy and JavascriptSignalStrategy.
Instead of using XmppProxy and JavascriptSignalStrategy to provide
signaling for the client the client plugin now uses the new
PepperSignalStrategy class which implements SignalStrategy
interface directly.
R=garykac@chromium.org
Review URL: https://codereview.chromium.org/16168008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206220 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/client/chromoting_client.cc | 16 | ||||
-rw-r--r-- | remoting/client/chromoting_client.h | 10 | ||||
-rw-r--r-- | remoting/client/plugin/chromoting_instance.cc | 37 | ||||
-rw-r--r-- | remoting/client/plugin/chromoting_instance.h | 12 | ||||
-rw-r--r-- | remoting/client/plugin/pepper_signal_strategy.cc | 74 | ||||
-rw-r--r-- | remoting/client/plugin/pepper_signal_strategy.h | 52 | ||||
-rw-r--r-- | remoting/client/plugin/pepper_xmpp_proxy.cc | 58 | ||||
-rw-r--r-- | remoting/client/plugin/pepper_xmpp_proxy.h | 65 | ||||
-rw-r--r-- | remoting/jingle_glue/javascript_signal_strategy.cc | 106 | ||||
-rw-r--r-- | remoting/jingle_glue/javascript_signal_strategy.h | 59 | ||||
-rw-r--r-- | remoting/jingle_glue/xmpp_proxy.h | 55 | ||||
-rw-r--r-- | remoting/protocol/connection_to_host.cc | 42 | ||||
-rw-r--r-- | remoting/protocol/connection_to_host.h | 8 | ||||
-rw-r--r-- | remoting/remoting.gyp | 7 |
14 files changed, 169 insertions, 432 deletions
diff --git a/remoting/client/chromoting_client.cc b/remoting/client/chromoting_client.cc index 013060c..73a762d 100644 --- a/remoting/client/chromoting_client.cc +++ b/remoting/client/chromoting_client.cc @@ -51,7 +51,7 @@ ChromotingClient::~ChromotingClient() { } void ChromotingClient::Start( - scoped_refptr<XmppProxy> xmpp_proxy, + SignalStrategy* signal_strategy, scoped_ptr<protocol::TransportFactory> transport_factory) { DCHECK(task_runner_->BelongsToCurrentThread()); @@ -67,8 +67,7 @@ void ChromotingClient::Start( // Create a WeakPtr to ourself for to use for all posted tasks. weak_ptr_ = weak_factory_.GetWeakPtr(); - connection_->Connect(xmpp_proxy, - config_.local_jid, + connection_->Connect(signal_strategy, config_.host_jid, config_.host_public_key, transport_factory.Pass(), @@ -80,21 +79,10 @@ void ChromotingClient::Start( audio_decode_scheduler_.get()); } -void ChromotingClient::Stop(const base::Closure& shutdown_task) { - DCHECK(task_runner_->BelongsToCurrentThread()); - - connection_->Disconnect(base::Bind(&ChromotingClient::OnDisconnected, - weak_ptr_, shutdown_task)); -} - FrameProducer* ChromotingClient::GetFrameProducer() { return rectangle_decoder_.get(); } -void ChromotingClient::OnDisconnected(const base::Closure& shutdown_task) { - shutdown_task.Run(); -} - ChromotingStats* ChromotingClient::GetStats() { DCHECK(task_runner_->BelongsToCurrentThread()); return rectangle_decoder_->GetStats(); diff --git a/remoting/client/chromoting_client.h b/remoting/client/chromoting_client.h index eb044be..3ccde00c 100644 --- a/remoting/client/chromoting_client.h +++ b/remoting/client/chromoting_client.h @@ -19,7 +19,6 @@ #include "remoting/protocol/connection_to_host.h" #include "remoting/protocol/input_stub.h" #include "remoting/protocol/video_stub.h" -#include "remoting/jingle_glue/xmpp_proxy.h" namespace base { class SingleThreadTaskRunner; @@ -38,6 +37,7 @@ class ClientUserInterface; class FrameConsumerProxy; class FrameProducer; class RectangleUpdateDecoder; +class SignalStrategy; class ChromotingClient : public protocol::ConnectionToHost::HostEventCallback, public protocol::ClientStub { @@ -51,10 +51,10 @@ class ChromotingClient : public protocol::ConnectionToHost::HostEventCallback, virtual ~ChromotingClient(); - // Start/stop the client. Must be called on the main thread. - void Start(scoped_refptr<XmppProxy> xmpp_proxy, + // Start the client. Must be called on the main thread. |signal_strategy| + // must outlive the client. + void Start(SignalStrategy* signal_strategy, scoped_ptr<protocol::TransportFactory> transport_factory); - void Stop(const base::Closure& shutdown_task); FrameProducer* GetFrameProducer(); @@ -88,8 +88,6 @@ class ChromotingClient : public protocol::ConnectionToHost::HostEventCallback, // Called when all channels are connected. void OnChannelsConnected(); - void OnDisconnected(const base::Closure& shutdown_task); - // The following are not owned by this class. ClientConfig config_; scoped_refptr<base::SingleThreadTaskRunner> task_runner_; diff --git a/remoting/client/plugin/chromoting_instance.cc b/remoting/client/plugin/chromoting_instance.cc index 16ed423..7bcc084 100644 --- a/remoting/client/plugin/chromoting_instance.cc +++ b/remoting/client/plugin/chromoting_instance.cc @@ -16,7 +16,6 @@ #include "base/strings/string_split.h" #include "base/strings/stringprintf.h" #include "base/synchronization/lock.h" -#include "base/synchronization/waitable_event.h" #include "base/threading/thread.h" #include "base/values.h" #include "googleurl/src/gurl.h" @@ -38,7 +37,7 @@ #include "remoting/client/plugin/pepper_port_allocator.h" #include "remoting/client/plugin/pepper_token_fetcher.h" #include "remoting/client/plugin/pepper_view.h" -#include "remoting/client/plugin/pepper_xmpp_proxy.h" +#include "remoting/client/plugin/pepper_signal_strategy.h" #include "remoting/client/rectangle_update_decoder.h" #include "remoting/protocol/connection_to_host.h" #include "remoting/protocol/host_stub.h" @@ -213,12 +212,9 @@ ChromotingInstance::~ChromotingInstance() { // PepperView must be destroyed before the client. view_.reset(); - if (client_.get()) { - client_->Stop(base::Bind(&PluginThreadTaskRunner::Quit, - plugin_task_runner_)); - } else { - plugin_task_runner_->Quit(); - } + client_.reset(); + + plugin_task_runner_->Quit(); // Ensure that nothing touches the plugin thread delegate after this point. plugin_task_runner_->DetachAndRunShutdownLoop(); @@ -680,11 +676,10 @@ void ChromotingInstance::Connect(const ClientConfig& config) { LOG(INFO) << "Connecting to " << config.host_jid << ". Local jid: " << config.local_jid << "."; - // Setup the XMPP Proxy. - xmpp_proxy_ = new PepperXmppProxy( - base::Bind(&ChromotingInstance::SendOutgoingIq, AsWeakPtr()), - plugin_task_runner_.get(), - context_.main_task_runner()); + // Setup the PepperSignalStrategy. + signal_strategy_.reset(new PepperSignalStrategy( + config.local_jid, + base::Bind(&ChromotingInstance::SendOutgoingIq, AsWeakPtr()))); scoped_ptr<cricket::HttpPortAllocatorBase> port_allocator( PepperPortAllocator::Create(this)); @@ -692,7 +687,7 @@ void ChromotingInstance::Connect(const ClientConfig& config) { new protocol::LibjingleTransportFactory(port_allocator.Pass(), false)); // Kick off the connection. - client_->Start(xmpp_proxy_, transport_factory.Pass()); + client_->Start(signal_strategy_.get(), transport_factory.Pass()); // Start timer that periodically sends perf stats. plugin_task_runner_->PostDelayedTask( @@ -707,14 +702,8 @@ void ChromotingInstance::Disconnect() { view_.reset(); LOG(INFO) << "Disconnecting from host."; - if (client_.get()) { - // TODO(sergeyu): Should we disconnect asynchronously? - base::WaitableEvent done_event(true, false); - client_->Stop(base::Bind(&base::WaitableEvent::Signal, - base::Unretained(&done_event))); - done_event.Wait(); - client_.reset(); - } + + client_.reset(); // Disconnect the input pipeline and teardown the connection. mouse_input_filter_.set_input_stub(NULL); @@ -724,8 +713,8 @@ void ChromotingInstance::Disconnect() { void ChromotingInstance::OnIncomingIq(const std::string& iq) { // Just ignore the message if it's received before Connect() is called. It's // likely to be a leftover from a previous session, so it's safe to ignore it. - if (xmpp_proxy_.get()) - xmpp_proxy_->OnIq(iq); + if (signal_strategy_) + signal_strategy_->OnIncomingMessage(iq); } void ChromotingInstance::ReleaseAllKeys() { diff --git a/remoting/client/plugin/chromoting_instance.h b/remoting/client/plugin/chromoting_instance.h index 9cc85ec..40f470f 100644 --- a/remoting/client/plugin/chromoting_instance.h +++ b/remoting/client/plugin/chromoting_instance.h @@ -61,7 +61,7 @@ class FrameConsumerProxy; class PepperAudioPlayer; class PepperTokenFetcher; class PepperView; -class PepperXmppProxy; +class PepperSignalStrategy; class RectangleUpdateDecoder; struct ClientConfig; @@ -205,7 +205,7 @@ class ChromotingInstance : // Posts trapped keys to the web-app to handle. void SendTrappedKey(uint32 usb_keycode, bool pressed); - // Callback for PepperXmppProxy. + // Callback for PepperSignalStrategy. void SendOutgoingIq(const std::string& iq); void SendPerfStats(); @@ -233,6 +233,8 @@ class ChromotingInstance : scoped_ptr<PepperView> view_; pp::View plugin_view_; + scoped_ptr<PepperSignalStrategy> signal_strategy_; + scoped_ptr<protocol::ConnectionToHost> host_connection_; scoped_ptr<ChromotingClient> client_; @@ -245,12 +247,6 @@ class ChromotingInstance : KeyEventMapper key_mapper_; PepperInputHandler input_handler_; - // XmppProxy is a refcounted interface used to perform thread-switching and - // detaching between objects whose lifetimes are controlled by pepper, and - // jingle_glue objects. This is used when if we start a sandboxed jingle - // connection. - scoped_refptr<PepperXmppProxy> xmpp_proxy_; - // PIN Fetcher. bool use_async_pin_dialog_; protocol::SecretFetchedCallback secret_fetched_callback_; diff --git a/remoting/client/plugin/pepper_signal_strategy.cc b/remoting/client/plugin/pepper_signal_strategy.cc new file mode 100644 index 0000000..4cf0330 --- /dev/null +++ b/remoting/client/plugin/pepper_signal_strategy.cc @@ -0,0 +1,74 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "remoting/client/plugin/pepper_signal_strategy.h" + +#include "base/string_number_conversions.h" +#include "third_party/libjingle/source/talk/xmllite/xmlelement.h" + +namespace remoting { + +PepperSignalStrategy::PepperSignalStrategy( + std::string local_jid, + const SendIqCallback& send_iq_callback) + : local_jid_(local_jid), + send_iq_callback_(send_iq_callback), + last_id_(0) { +} + +PepperSignalStrategy::~PepperSignalStrategy() { +} + +void PepperSignalStrategy::OnIncomingMessage(const std::string& message) { + scoped_ptr<buzz::XmlElement> stanza(buzz::XmlElement::ForStr(message)); + if (!stanza.get()) { + LOG(WARNING) << "Malformed XMPP stanza received: " << message; + return; + } + + ObserverListBase<Listener>::Iterator it(listeners_); + Listener* listener; + while ((listener = it.GetNext()) != NULL) { + if (listener->OnSignalStrategyIncomingStanza(stanza.get())) + break; + } +} + +void PepperSignalStrategy::Connect() { +} + +void PepperSignalStrategy::Disconnect() { +} + +SignalStrategy::State PepperSignalStrategy::GetState() const { + return CONNECTED; +} + +SignalStrategy::Error PepperSignalStrategy::GetError() const { + return OK; +} + +std::string PepperSignalStrategy::GetLocalJid() const { + return local_jid_; +} + +void PepperSignalStrategy::AddListener(Listener* listener) { + listeners_.AddObserver(listener); +} + +void PepperSignalStrategy::RemoveListener(Listener* listener) { + listeners_.RemoveObserver(listener); +} + +bool PepperSignalStrategy::SendStanza(scoped_ptr<buzz::XmlElement> stanza) { + send_iq_callback_.Run(stanza->Str()); + return true; +} + +std::string PepperSignalStrategy::GetNextId() { + ++last_id_; + return base::IntToString(last_id_); +} + +} // namespace remoting diff --git a/remoting/client/plugin/pepper_signal_strategy.h b/remoting/client/plugin/pepper_signal_strategy.h new file mode 100644 index 0000000..f5fab46 --- /dev/null +++ b/remoting/client/plugin/pepper_signal_strategy.h @@ -0,0 +1,52 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef REMOTING_CLIENT_PLUGIN_PEPPER_XMPP_PROXY_H_ +#define REMOTING_CLIENT_PLUGIN_PEPPER_XMPP_PROXY_H_ + +#include "base/callback.h" +#include "base/observer_list.h" +#include "remoting/jingle_glue/signal_strategy.h" + +namespace base { +class SingleThreadTaskRunner; +} // namespace base + +namespace remoting { + +class PepperSignalStrategy : public SignalStrategy { + public: + typedef base::Callback<void(const std::string&)> SendIqCallback; + + PepperSignalStrategy(std::string local_jid, + const SendIqCallback& send_iq_callback); + virtual ~PepperSignalStrategy(); + + void OnIncomingMessage(const std::string& message); + + // SignalStrategy interface. + virtual void Connect() OVERRIDE; + virtual void Disconnect() OVERRIDE; + virtual State GetState() const OVERRIDE; + virtual Error GetError() const OVERRIDE; + virtual std::string GetLocalJid() const OVERRIDE; + virtual void AddListener(Listener* listener) OVERRIDE; + virtual void RemoveListener(Listener* listener) OVERRIDE; + virtual bool SendStanza(scoped_ptr<buzz::XmlElement> stanza) OVERRIDE; + virtual std::string GetNextId() OVERRIDE; + + private: + std::string local_jid_; + SendIqCallback send_iq_callback_; + + ObserverList<Listener> listeners_; + + int last_id_; + + DISALLOW_COPY_AND_ASSIGN(PepperSignalStrategy); +}; + +} // namespace remoting + +#endif // REMOTING_CLIENT_PLUGIN_PEPPER_XMPP_PROXY_H_ diff --git a/remoting/client/plugin/pepper_xmpp_proxy.cc b/remoting/client/plugin/pepper_xmpp_proxy.cc deleted file mode 100644 index 62f4ad0..0000000 --- a/remoting/client/plugin/pepper_xmpp_proxy.cc +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "remoting/client/plugin/pepper_xmpp_proxy.h" - -#include "base/bind.h" -#include "base/location.h" -#include "base/message_loop/message_loop_proxy.h" - -namespace remoting { - -PepperXmppProxy::PepperXmppProxy( - const SendIqCallback& send_iq_callback, - base::SingleThreadTaskRunner* plugin_task_runner, - base::SingleThreadTaskRunner* callback_task_runner) - : send_iq_callback_(send_iq_callback), - plugin_task_runner_(plugin_task_runner), - callback_task_runner_(callback_task_runner) { - DCHECK(plugin_task_runner_->BelongsToCurrentThread()); -} - -PepperXmppProxy::~PepperXmppProxy() { -} - -void PepperXmppProxy::AttachCallback( - base::WeakPtr<ResponseCallback> callback) { - DCHECK(callback_task_runner_->BelongsToCurrentThread()); - callback_ = callback; -} - -void PepperXmppProxy::DetachCallback() { - DCHECK(callback_task_runner_->BelongsToCurrentThread()); - callback_.reset(); -} - -void PepperXmppProxy::SendIq(const std::string& request_xml) { - if (!plugin_task_runner_->BelongsToCurrentThread()) { - plugin_task_runner_->PostTask(FROM_HERE, base::Bind( - &PepperXmppProxy::SendIq, this, request_xml)); - return; - } - - send_iq_callback_.Run(request_xml); -} - -void PepperXmppProxy::OnIq(const std::string& response_xml) { - if (!callback_task_runner_->BelongsToCurrentThread()) { - callback_task_runner_->PostTask( - FROM_HERE, base::Bind(&PepperXmppProxy::OnIq, this, response_xml)); - return; - } - - if (callback_.get()) - callback_->OnIq(response_xml); -} - -} // namespace remoting diff --git a/remoting/client/plugin/pepper_xmpp_proxy.h b/remoting/client/plugin/pepper_xmpp_proxy.h deleted file mode 100644 index 0c1bc79..0000000 --- a/remoting/client/plugin/pepper_xmpp_proxy.h +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef REMOTING_CLIENT_PLUGIN_PEPPER_XMPP_PROXY_H_ -#define REMOTING_CLIENT_PLUGIN_PEPPER_XMPP_PROXY_H_ - -#include "base/callback.h" -#include "base/memory/ref_counted.h" -#include "base/memory/weak_ptr.h" -#include "remoting/jingle_glue/xmpp_proxy.h" - -namespace base { -class SingleThreadTaskRunner; -} // namespace base - -namespace remoting { - -class PepperXmppProxy : public XmppProxy { - public: - typedef base::Callback<void(const std::string&)> SendIqCallback; - - // |plugin_task_runner| is the thread on which |send_iq_callback| is - // called. Normally the callback will call JavaScript, so this has - // to be the task runner that corresponds to the plugin - // thread. |callback_task_runner| is used to call the callback - // registered with AttachCallback(). - PepperXmppProxy( - const SendIqCallback& send_iq_callback, - base::SingleThreadTaskRunner* plugin_task_runner, - base::SingleThreadTaskRunner* callback_task_runner); - - // Registered the callback class with this object. - // - // - This method has subtle thread semantics! - - // - // It must be called on the callback thread itself. The weak pointer also - // must be constructed on the callback thread. That means, you cannot just - // create a WeakPtr on, say the pepper thread, and then pass execution of - // this function callback with the weak pointer bound as a parameter. That - // will fail because the WeakPtr will have been created on the wrong thread. - virtual void AttachCallback( - base::WeakPtr<ResponseCallback> callback) OVERRIDE; - virtual void DetachCallback() OVERRIDE; - - virtual void SendIq(const std::string& request_xml) OVERRIDE; - virtual void OnIq(const std::string& response_xml); - - private: - virtual ~PepperXmppProxy(); - - SendIqCallback send_iq_callback_; - - scoped_refptr<base::SingleThreadTaskRunner> plugin_task_runner_; - scoped_refptr<base::SingleThreadTaskRunner> callback_task_runner_; - - // Must only be access on callback_message_loop_. - base::WeakPtr<ResponseCallback> callback_; - - DISALLOW_COPY_AND_ASSIGN(PepperXmppProxy); -}; - -} // namespace remoting - -#endif // REMOTING_CLIENT_PLUGIN_PEPPER_XMPP_PROXY_H_ diff --git a/remoting/jingle_glue/javascript_signal_strategy.cc b/remoting/jingle_glue/javascript_signal_strategy.cc deleted file mode 100644 index 7b45eba..0000000 --- a/remoting/jingle_glue/javascript_signal_strategy.cc +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "remoting/jingle_glue/javascript_signal_strategy.h" - -#include <algorithm> - -#include "base/logging.h" -#include "base/strings/string_number_conversions.h" -#include "remoting/jingle_glue/xmpp_proxy.h" -#include "third_party/libjingle/source/talk/xmllite/xmlelement.h" - -namespace remoting { - -JavascriptSignalStrategy::JavascriptSignalStrategy(const std::string& local_jid) - : local_jid_(local_jid), - last_id_(0) { -} - -JavascriptSignalStrategy::~JavascriptSignalStrategy() { - DCHECK_EQ(listeners_.size(), 0U); - Disconnect(); -} - -void JavascriptSignalStrategy::AttachXmppProxy( - scoped_refptr<XmppProxy> xmpp_proxy) { - DCHECK(CalledOnValidThread()); - xmpp_proxy_ = xmpp_proxy; -} - -void JavascriptSignalStrategy::Connect() { - DCHECK(CalledOnValidThread()); - - xmpp_proxy_->AttachCallback(AsWeakPtr()); - FOR_EACH_OBSERVER(Listener, listeners_, - OnSignalStrategyStateChange(CONNECTED)); -} - -void JavascriptSignalStrategy::Disconnect() { - DCHECK(CalledOnValidThread()); - - if (xmpp_proxy_.get()) - xmpp_proxy_->DetachCallback(); - FOR_EACH_OBSERVER(Listener, listeners_, - OnSignalStrategyStateChange(DISCONNECTED)); -} - -SignalStrategy::State JavascriptSignalStrategy::GetState() const { - DCHECK(CalledOnValidThread()); - // TODO(sergeyu): Extend XmppProxy to provide status of the - // connection. - return CONNECTED; -} - -SignalStrategy::Error JavascriptSignalStrategy::GetError() const { - DCHECK(CalledOnValidThread()); - // TODO(sergeyu): Extend XmppProxy to provide status of the - // connection. - return OK; -} - -std::string JavascriptSignalStrategy::GetLocalJid() const { - DCHECK(CalledOnValidThread()); - return local_jid_; -} - -void JavascriptSignalStrategy::AddListener(Listener* listener) { - DCHECK(CalledOnValidThread()); - listeners_.AddObserver(listener); -} - -void JavascriptSignalStrategy::RemoveListener(Listener* listener) { - DCHECK(CalledOnValidThread()); - listeners_.RemoveObserver(listener); -} - -bool JavascriptSignalStrategy::SendStanza(scoped_ptr<buzz::XmlElement> stanza) { - DCHECK(CalledOnValidThread()); - xmpp_proxy_->SendIq(stanza->Str()); - return true; -} - -std::string JavascriptSignalStrategy::GetNextId() { - DCHECK(CalledOnValidThread()); - ++last_id_; - return base::IntToString(last_id_); -} - -void JavascriptSignalStrategy::OnIq(const std::string& stanza_str) { - DCHECK(CalledOnValidThread()); - scoped_ptr<buzz::XmlElement> stanza(buzz::XmlElement::ForStr(stanza_str)); - if (!stanza.get()) { - LOG(WARNING) << "Malformed XMPP stanza received: " << stanza_str; - return; - } - - ObserverListBase<Listener>::Iterator it(listeners_); - Listener* listener; - while ((listener = it.GetNext()) != NULL) { - if (listener->OnSignalStrategyIncomingStanza(stanza.get())) - break; - } -} - -} // namespace remoting diff --git a/remoting/jingle_glue/javascript_signal_strategy.h b/remoting/jingle_glue/javascript_signal_strategy.h deleted file mode 100644 index eaab7a2..0000000 --- a/remoting/jingle_glue/javascript_signal_strategy.h +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef REMOTING_JINGLE_GLUE_JAVASCRIPT_SIGNAL_STRATEGY_H_ -#define REMOTING_JINGLE_GLUE_JAVASCRIPT_SIGNAL_STRATEGY_H_ - -#include "remoting/jingle_glue/signal_strategy.h" - -#include <vector> - -#include "base/compiler_specific.h" -#include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" -#include "base/observer_list.h" -#include "base/threading/non_thread_safe.h" -#include "remoting/jingle_glue/xmpp_proxy.h" - -namespace remoting { - -class XmppProxy; - -class JavascriptSignalStrategy : public SignalStrategy, - public XmppProxy::ResponseCallback, - public base::NonThreadSafe { - public: - explicit JavascriptSignalStrategy(const std::string& local_jid); - virtual ~JavascriptSignalStrategy(); - - void AttachXmppProxy(scoped_refptr<XmppProxy> xmpp_proxy); - - // SignalStrategy interface. - virtual void Connect() OVERRIDE; - virtual void Disconnect() OVERRIDE; - virtual State GetState() const OVERRIDE; - virtual Error GetError() const OVERRIDE; - virtual std::string GetLocalJid() const OVERRIDE; - virtual void AddListener(Listener* listener) OVERRIDE; - virtual void RemoveListener(Listener* listener) OVERRIDE; - virtual bool SendStanza(scoped_ptr<buzz::XmlElement> stanza) OVERRIDE; - virtual std::string GetNextId() OVERRIDE; - - // XmppProxy::ResponseCallback interface. - virtual void OnIq(const std::string& stanza) OVERRIDE; - - private: - std::string local_jid_; - scoped_refptr<XmppProxy> xmpp_proxy_; - - ObserverList<Listener> listeners_; - - int last_id_; - - DISALLOW_COPY_AND_ASSIGN(JavascriptSignalStrategy); -}; - -} // namespace remoting - -#endif // REMOTING_JINGLE_GLUE_JAVASCRIPT_SIGNAL_STRATEGY_H_ diff --git a/remoting/jingle_glue/xmpp_proxy.h b/remoting/jingle_glue/xmpp_proxy.h deleted file mode 100644 index 34bb974..0000000 --- a/remoting/jingle_glue/xmpp_proxy.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// The XmppProxy is a shim interface that allows a class from layers above -// the protocol to insert custom logic for dispatching the XMPP requests -// necessary for creating a jingle connection. -// -// The primary motivator for this is to allow libjingle to be sandboxed in the -// client by proxying the XMPP requests up through javascript into a -// javascript-based XMPP connection back into the GoogleTalk network. It's -// essentially a clean hack. - -#ifndef REMOTING_JINGLE_GLUE_XMPP_PROXY_H_ -#define REMOTING_JINGLE_GLUE_XMPP_PROXY_H_ - -#include <string> - -#include "base/memory/ref_counted.h" -#include "base/memory/weak_ptr.h" - -namespace remoting { - -class XmppProxy : public base::RefCountedThreadSafe<XmppProxy> { - public: - XmppProxy() {} - - class ResponseCallback : public base::SupportsWeakPtr<ResponseCallback> { - public: - ResponseCallback() {} - virtual ~ResponseCallback() {} - virtual void OnIq(const std::string& response_xml) = 0; - - private: - DISALLOW_COPY_AND_ASSIGN(ResponseCallback); - }; - - // These two must be called on the callback's message_loop. Callback will - // always been run on the callback_loop. - virtual void AttachCallback(base::WeakPtr<ResponseCallback> callback) = 0; - virtual void DetachCallback() = 0; - - virtual void SendIq(const std::string& iq_request_xml) = 0; - - protected: - friend class base::RefCountedThreadSafe<XmppProxy>; - virtual ~XmppProxy() {} - - private: - DISALLOW_COPY_AND_ASSIGN(XmppProxy); -}; - -} // namespace remoting - -#endif // REMOTING_JINGLE_GLUE_XMPP_PROXY_H_ diff --git a/remoting/protocol/connection_to_host.cc b/remoting/protocol/connection_to_host.cc index 43b9950..c8fa089 100644 --- a/remoting/protocol/connection_to_host.cc +++ b/remoting/protocol/connection_to_host.cc @@ -8,8 +8,7 @@ #include "base/callback.h" #include "base/location.h" #include "remoting/base/constants.h" -#include "remoting/jingle_glue/javascript_signal_strategy.h" -#include "remoting/jingle_glue/xmpp_signal_strategy.h" +#include "remoting/jingle_glue/signal_strategy.h" #include "remoting/protocol/audio_reader.h" #include "remoting/protocol/audio_stub.h" #include "remoting/protocol/auth_util.h" @@ -36,11 +35,22 @@ ConnectionToHost::ConnectionToHost( clipboard_stub_(NULL), video_stub_(NULL), audio_stub_(NULL), + signal_strategy_(NULL), state_(INITIALIZING), error_(OK) { } ConnectionToHost::~ConnectionToHost() { + CloseChannels(); + + if (session_.get()) + session_.reset(); + + if (session_manager_.get()) + session_manager_.reset(); + + if (signal_strategy_) + signal_strategy_->RemoveListener(this); } ClipboardStub* ConnectionToHost::clipboard_stub() { @@ -56,8 +66,7 @@ InputStub* ConnectionToHost::input_stub() { return &event_forwarder_; } -void ConnectionToHost::Connect(scoped_refptr<XmppProxy> xmpp_proxy, - const std::string& local_jid, +void ConnectionToHost::Connect(SignalStrategy* signal_strategy, const std::string& host_jid, const std::string& host_public_key, scoped_ptr<TransportFactory> transport_factory, @@ -67,6 +76,7 @@ void ConnectionToHost::Connect(scoped_refptr<XmppProxy> xmpp_proxy, ClipboardStub* clipboard_stub, VideoStub* video_stub, AudioStub* audio_stub) { + signal_strategy_ = signal_strategy; event_callback_ = event_callback; client_stub_ = client_stub; clipboard_stub_ = clipboard_stub; @@ -79,38 +89,16 @@ void ConnectionToHost::Connect(scoped_refptr<XmppProxy> xmpp_proxy, host_jid_ = host_jid; host_public_key_ = host_public_key; - JavascriptSignalStrategy* strategy = new JavascriptSignalStrategy(local_jid); - strategy->AttachXmppProxy(xmpp_proxy); - signal_strategy_.reset(strategy); signal_strategy_->AddListener(this); signal_strategy_->Connect(); session_manager_.reset(new JingleSessionManager( transport_factory.Pass(), allow_nat_traversal_)); - session_manager_->Init(signal_strategy_.get(), this); + session_manager_->Init(signal_strategy_, this); SetState(CONNECTING, OK); } -void ConnectionToHost::Disconnect(const base::Closure& shutdown_task) { - DCHECK(CalledOnValidThread()); - - CloseChannels(); - - if (session_.get()) - session_.reset(); - - if (session_manager_.get()) - session_manager_.reset(); - - if (signal_strategy_.get()) { - signal_strategy_->RemoveListener(this); - signal_strategy_.reset(); - } - - shutdown_task.Run(); -} - const SessionConfig& ConnectionToHost::config() { return session_->config(); } diff --git a/remoting/protocol/connection_to_host.h b/remoting/protocol/connection_to_host.h index 1c93b5d..3167b8e 100644 --- a/remoting/protocol/connection_to_host.h +++ b/remoting/protocol/connection_to_host.h @@ -77,8 +77,8 @@ class ConnectionToHost : public SignalStrategy::Listener, ConnectionToHost(bool allow_nat_traversal); virtual ~ConnectionToHost(); - virtual void Connect(scoped_refptr<XmppProxy> xmpp_proxy, - const std::string& local_jid, + // |signal_strategy| must outlive connection. + virtual void Connect(SignalStrategy* signal_strategy, const std::string& host_jid, const std::string& host_public_key, scoped_ptr<TransportFactory> transport_factory, @@ -89,8 +89,6 @@ class ConnectionToHost : public SignalStrategy::Listener, VideoStub* video_stub, AudioStub* audio_stub); - virtual void Disconnect(const base::Closure& shutdown_task); - virtual const SessionConfig& config(); // Stubs for sending data to the host. @@ -147,7 +145,7 @@ class ConnectionToHost : public SignalStrategy::Listener, VideoStub* video_stub_; AudioStub* audio_stub_; - scoped_ptr<SignalStrategy> signal_strategy_; + SignalStrategy* signal_strategy_; scoped_ptr<SessionManager> session_manager_; scoped_ptr<Session> session_; diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp index 0ed274a..17c1526 100644 --- a/remoting/remoting.gyp +++ b/remoting/remoting.gyp @@ -1977,8 +1977,8 @@ 'client/plugin/pepper_view.h', 'client/plugin/pepper_util.cc', 'client/plugin/pepper_util.h', - 'client/plugin/pepper_xmpp_proxy.cc', - 'client/plugin/pepper_xmpp_proxy.h', + 'client/plugin/pepper_signal_strategy.cc', + 'client/plugin/pepper_signal_strategy.h', ], }, # end of target 'remoting_client_plugin' @@ -2447,12 +2447,9 @@ 'jingle_glue/chromium_socket_factory.h', 'jingle_glue/iq_sender.cc', 'jingle_glue/iq_sender.h', - 'jingle_glue/javascript_signal_strategy.cc', - 'jingle_glue/javascript_signal_strategy.h', 'jingle_glue/jingle_info_request.cc', 'jingle_glue/jingle_info_request.h', 'jingle_glue/signal_strategy.h', - 'jingle_glue/xmpp_proxy.h', 'jingle_glue/xmpp_signal_strategy.cc', 'jingle_glue/xmpp_signal_strategy.h', ], |