diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-08 23:57:56 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-08 23:57:56 +0000 |
commit | b8bcaa73b993105ee1d85161bb4d3408a90114ff (patch) | |
tree | a76884d5f5fd6661c0f765e5d6fdd811bc37d0d2 /remoting | |
parent | 11a17275506145bc0cddc9a33a90fc1788b03add (diff) | |
download | chromium_src-b8bcaa73b993105ee1d85161bb4d3408a90114ff.zip chromium_src-b8bcaa73b993105ee1d85161bb4d3408a90114ff.tar.gz chromium_src-b8bcaa73b993105ee1d85161bb4d3408a90114ff.tar.bz2 |
Add abstract interfaces for the transport layer.
Renamed PepperChannel to Transport and added TransportFactory. The new
interfaces abstract transport layer for the signaling layer.
BUG=110485,109630
Review URL: http://codereview.chromium.org/9325036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121094 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/protocol/connection_to_host.cc | 6 | ||||
-rw-r--r-- | remoting/protocol/pepper_session.cc | 63 | ||||
-rw-r--r-- | remoting/protocol/pepper_session.h | 17 | ||||
-rw-r--r-- | remoting/protocol/pepper_session_manager.cc | 5 | ||||
-rw-r--r-- | remoting/protocol/pepper_session_manager.h | 7 | ||||
-rw-r--r-- | remoting/protocol/pepper_session_unittest.cc | 3 | ||||
-rw-r--r-- | remoting/protocol/pepper_transport_factory.cc (renamed from remoting/protocol/pepper_stream_channel.cc) | 154 | ||||
-rw-r--r-- | remoting/protocol/pepper_transport_factory.h | 34 | ||||
-rw-r--r-- | remoting/protocol/transport.h | 130 | ||||
-rw-r--r-- | remoting/remoting.gyp | 6 |
10 files changed, 345 insertions, 80 deletions
diff --git a/remoting/protocol/connection_to_host.cc b/remoting/protocol/connection_to_host.cc index 0bdc5c3..9352712 100644 --- a/remoting/protocol/connection_to_host.cc +++ b/remoting/protocol/connection_to_host.cc @@ -16,8 +16,8 @@ #include "remoting/protocol/client_control_dispatcher.h" #include "remoting/protocol/client_event_dispatcher.h" #include "remoting/protocol/client_stub.h" -#include "remoting/protocol/jingle_session_manager.h" #include "remoting/protocol/pepper_session_manager.h" +#include "remoting/protocol/pepper_transport_factory.h" #include "remoting/protocol/video_reader.h" #include "remoting/protocol/video_stub.h" #include "remoting/protocol/util.h" @@ -70,7 +70,9 @@ void ConnectionToHost::Connect(scoped_refptr<XmppProxy> xmpp_proxy, signal_strategy_->AddListener(this); signal_strategy_->Connect(); - session_manager_.reset(new PepperSessionManager(pp_instance_)); + scoped_ptr<TransportFactory> transport_factory( + new PepperTransportFactory(pp_instance_)); + session_manager_.reset(new PepperSessionManager(transport_factory.Pass())); session_manager_->Init(signal_strategy_.get(), this, NetworkSettings(allow_nat_traversal_)); } diff --git a/remoting/protocol/pepper_session.cc b/remoting/protocol/pepper_session.cc index 614e9c6..2ac5c15 100644 --- a/remoting/protocol/pepper_session.cc +++ b/remoting/protocol/pepper_session.cc @@ -11,10 +11,10 @@ #include "remoting/base/constants.h" #include "remoting/jingle_glue/iq_sender.h" #include "remoting/protocol/authenticator.h" +#include "remoting/protocol/channel_authenticator.h" #include "remoting/protocol/content_description.h" #include "remoting/protocol/jingle_messages.h" #include "remoting/protocol/pepper_session_manager.h" -#include "remoting/protocol/pepper_stream_channel.h" #include "third_party/libjingle/source/talk/p2p/base/candidate.h" #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" @@ -121,19 +121,27 @@ void PepperSession::CreateStreamChannel( scoped_ptr<ChannelAuthenticator> channel_authenticator = authenticator_->CreateChannelAuthenticator(); - PepperStreamChannel* channel = new PepperStreamChannel( - this, name, callback); - channels_[name] = channel; - channel->Connect(session_manager_->pp_instance_, - session_manager_->transport_config_, - channel_authenticator.Pass()); + scoped_ptr<StreamTransport> channel = + session_manager_->transport_factory_->CreateStreamTransport(); + channel->Initialize(name, session_manager_->transport_config_, + this, channel_authenticator.Pass()); + channel->Connect(callback); + channels_[name] = channel.release(); } void PepperSession::CreateDatagramChannel( const std::string& name, const DatagramChannelCallback& callback) { - // TODO(sergeyu): Implement datagram channel support. - NOTREACHED(); + DCHECK(!channels_[name]); + + scoped_ptr<ChannelAuthenticator> channel_authenticator = + authenticator_->CreateChannelAuthenticator(); + scoped_ptr<DatagramTransport> channel = + session_manager_->transport_factory_->CreateDatagramTransport(); + channel->Initialize(name, session_manager_->transport_config_, + this, channel_authenticator.Pass()); + channel->Connect(callback); + channels_[name] = channel.release(); } void PepperSession::CancelChannelCreation(const std::string& name) { @@ -180,6 +188,25 @@ void PepperSession::Close() { CloseInternal(false); } +void PepperSession::OnTransportCandidate(Transport* transport, + const cricket::Candidate& candidate) { + pending_candidates_.push_back(candidate); + + if (!transport_infos_timer_.IsRunning()) { + // Delay sending the new candidates in case we get more candidates + // that we can send in one message. + transport_infos_timer_.Start( + FROM_HERE, base::TimeDelta::FromMilliseconds(kTransportInfoSendDelayMs), + this, &PepperSession::SendTransportInfo); + } +} + +void PepperSession::OnTransportDeleted(Transport* transport) { + ChannelsMap::iterator it = channels_.find(transport->name()); + DCHECK_EQ(it->second, transport); + channels_.erase(it); +} + void PepperSession::OnIncomingMessage(const JingleMessage& message, JingleMessageReply* reply) { DCHECK(CalledOnValidThread()); @@ -374,18 +401,6 @@ void PepperSession::OnSessionInfoResponse(const buzz::XmlElement* response) { } } -void PepperSession::AddLocalCandidate(const cricket::Candidate& candidate) { - pending_candidates_.push_back(candidate); - - if (!transport_infos_timer_.IsRunning()) { - // Delay sending the new candidates in case we get more candidates - // that we can send in one message. - transport_infos_timer_.Start( - FROM_HERE, base::TimeDelta::FromMilliseconds(kTransportInfoSendDelayMs), - this, &PepperSession::SendTransportInfo); - } -} - void PepperSession::OnTransportInfoResponse(const buzz::XmlElement* response) { const std::string& type = response->Attr(buzz::QName("", "type")); if (type != "result") { @@ -402,12 +417,6 @@ void PepperSession::OnTransportInfoResponse(const buzz::XmlElement* response) { } } -void PepperSession::OnDeleteChannel(PepperChannel* channel) { - ChannelsMap::iterator it = channels_.find(channel->name()); - DCHECK_EQ(it->second, channel); - channels_.erase(it); -} - void PepperSession::SendTransportInfo() { JingleMessage message(peer_jid_, JingleMessage::TRANSPORT_INFO, session_id_); message.candidates.swap(pending_candidates_); diff --git a/remoting/protocol/pepper_session.h b/remoting/protocol/pepper_session.h index 391e808..c8c87e7 100644 --- a/remoting/protocol/pepper_session.h +++ b/remoting/protocol/pepper_session.h @@ -16,6 +16,7 @@ #include "remoting/protocol/jingle_messages.h" #include "remoting/protocol/session.h" #include "remoting/protocol/session_config.h" +#include "remoting/protocol/transport.h" namespace net { class Socket; @@ -29,13 +30,13 @@ class IqRequest; namespace protocol { class Authenticator; -class PepperChannel; class PepperSessionManager; // Implements the protocol::Session interface using the Pepper P2P // Transport API. Created by PepperSessionManager for incoming and // outgoing connections. -class PepperSession : public Session { +class PepperSession : public Session, + public Transport::EventHandler { public: virtual ~PepperSession(); @@ -58,11 +59,17 @@ class PepperSession : public Session { virtual void set_config(const SessionConfig& config) OVERRIDE; virtual void Close() OVERRIDE; + // Transport::EventHandler interface. + virtual void OnTransportCandidate( + Transport* transport, + const cricket::Candidate& candidate) OVERRIDE; + virtual void OnTransportDeleted(Transport* transport) OVERRIDE; + private: friend class PepperSessionManager; friend class PepperStreamChannel; - typedef std::map<std::string, PepperChannel*> ChannelsMap; + typedef std::map<std::string, Transport*> ChannelsMap; explicit PepperSession(PepperSessionManager* session_manager); @@ -95,10 +102,6 @@ class PepperSession : public Session { void ProcessAuthenticationStep(); void OnSessionInfoResponse(const buzz::XmlElement* response); - // Called by PepperChannel. - void AddLocalCandidate(const cricket::Candidate& candidate); - void OnDeleteChannel(PepperChannel* channel); - void SendTransportInfo(); void OnTransportInfoResponse(const buzz::XmlElement* response); diff --git a/remoting/protocol/pepper_session_manager.cc b/remoting/protocol/pepper_session_manager.cc index b45a315..c8a67c6 100644 --- a/remoting/protocol/pepper_session_manager.cc +++ b/remoting/protocol/pepper_session_manager.cc @@ -19,8 +19,9 @@ using buzz::QName; namespace remoting { namespace protocol { -PepperSessionManager::PepperSessionManager(pp::Instance* pp_instance) - : pp_instance_(pp_instance), +PepperSessionManager::PepperSessionManager( + scoped_ptr<TransportFactory> transport_factory) + : transport_factory_(transport_factory.Pass()), signal_strategy_(NULL), listener_(NULL), ready_(false) { diff --git a/remoting/protocol/pepper_session_manager.h b/remoting/protocol/pepper_session_manager.h index 508c161..0e9a41f 100644 --- a/remoting/protocol/pepper_session_manager.h +++ b/remoting/protocol/pepper_session_manager.h @@ -12,8 +12,8 @@ #include "base/memory/ref_counted.h" #include "net/base/x509_certificate.h" #include "remoting/jingle_glue/signal_strategy.h" -#include "remoting/protocol/pepper_channel.h" #include "remoting/protocol/session_manager.h" +#include "remoting/protocol/transport.h" #include "remoting/protocol/transport_config.h" namespace pp { @@ -44,7 +44,8 @@ class PepperSession; class PepperSessionManager : public SessionManager, public SignalStrategy::Listener { public: - explicit PepperSessionManager(pp::Instance* pp_instance); + explicit PepperSessionManager( + scoped_ptr<TransportFactory> transport_factory); virtual ~PepperSessionManager(); // SessionManager interface. @@ -83,7 +84,7 @@ class PepperSessionManager : public SessionManager, // Called by PepperSession when it is being destroyed. void SessionDestroyed(PepperSession* session); - pp::Instance* pp_instance_; + scoped_ptr<TransportFactory> transport_factory_; SignalStrategy* signal_strategy_; scoped_ptr<AuthenticatorFactory> authenticator_factory_; diff --git a/remoting/protocol/pepper_session_unittest.cc b/remoting/protocol/pepper_session_unittest.cc index 134f28f..0f14b3e 100644 --- a/remoting/protocol/pepper_session_unittest.cc +++ b/remoting/protocol/pepper_session_unittest.cc @@ -107,7 +107,8 @@ class PepperSessionTest : public testing::Test { EXPECT_CALL(client_server_listener_, OnSessionManagerReady()) .Times(1); - client_server_.reset(new PepperSessionManager(NULL)); + client_server_.reset(new PepperSessionManager( + scoped_ptr<TransportFactory>(NULL))); client_server_->Init(client_signal_strategy_.get(), &client_server_listener_, NetworkSettings()); } diff --git a/remoting/protocol/pepper_stream_channel.cc b/remoting/protocol/pepper_transport_factory.cc index 98fd3aa..4b4b978 100644 --- a/remoting/protocol/pepper_stream_channel.cc +++ b/remoting/protocol/pepper_transport_factory.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "remoting/protocol/pepper_stream_channel.h" +#include "remoting/protocol/pepper_transport_factory.h" #include "base/bind.h" #include "crypto/hmac.h" @@ -17,7 +17,7 @@ #include "ppapi/cpp/dev/transport_dev.h" #include "ppapi/cpp/var.h" #include "remoting/protocol/channel_authenticator.h" -#include "remoting/protocol/pepper_session.h" +#include "remoting/protocol/pepper_transport_socket_adapter.h" #include "remoting/protocol/transport_config.h" #include "third_party/libjingle/source/talk/p2p/base/candidate.h" @@ -35,35 +35,97 @@ const int kTcpAckDelayMilliseconds = 10; const int kTcpReceiveBufferSize = 256 * 1024; const int kTcpSendBufferSize = kTcpReceiveBufferSize + 30 * 1024; -} // namespace - -PepperStreamChannel::PepperStreamChannel( - PepperSession* session, - const std::string& name, - const Session::StreamChannelCallback& callback) - : session_(session), - name_(name), - callback_(callback), +class PepperStreamTransport : public StreamTransport, + public PepperTransportSocketAdapter::Observer { + public: + PepperStreamTransport(pp::Instance* pp_instance); + virtual ~PepperStreamTransport(); + + // StreamTransport interface. + virtual void Initialize( + const std::string& name, + const TransportConfig& config, + Transport::EventHandler* event_handler, + scoped_ptr<ChannelAuthenticator> authenticator) OVERRIDE; + virtual void Connect( + const StreamTransport::ConnectedCallback& callback) OVERRIDE; + virtual void AddRemoteCandidate(const cricket::Candidate& candidate) OVERRIDE; + virtual const std::string& name() const OVERRIDE; + virtual bool is_connected() const OVERRIDE; + + // PepperTransportSocketAdapter::Observer interface. + virtual void OnChannelDeleted() OVERRIDE; + virtual void OnChannelNewLocalCandidate( + const std::string& candidate) OVERRIDE; + + private: + void OnP2PConnect(int result); + void OnAuthenticationDone(net::Error error, + scoped_ptr<net::StreamSocket> socket); + + void NotifyConnected(scoped_ptr<net::StreamSocket> socket); + void NotifyConnectFailed(); + + pp::Instance* pp_instance_; + std::string name_; + TransportConfig config_; + EventHandler* event_handler_; + StreamTransport::ConnectedCallback callback_; + scoped_ptr<ChannelAuthenticator> authenticator_; + + // We own |channel_| until it is connected. After that + // |authenticator_| owns it. + scoped_ptr<PepperTransportSocketAdapter> owned_channel_; + PepperTransportSocketAdapter* channel_; + + // Indicates that we've finished connecting. + bool connected_; + + DISALLOW_COPY_AND_ASSIGN(PepperStreamTransport); +}; + +PepperStreamTransport::PepperStreamTransport(pp::Instance* pp_instance) + : pp_instance_(pp_instance), + event_handler_(NULL), channel_(NULL), connected_(false) { } -PepperStreamChannel::~PepperStreamChannel() { - session_->OnDeleteChannel(this); +PepperStreamTransport::~PepperStreamTransport() { + DCHECK(event_handler_); + event_handler_->OnTransportDeleted(this); // Channel should be already destroyed if we were connected. DCHECK(!connected_ || channel_ == NULL); } -void PepperStreamChannel::Connect( - pp::Instance* pp_instance, - const TransportConfig& transport_config, +void PepperStreamTransport::Initialize( + const std::string& name, + const TransportConfig& config, + Transport::EventHandler* event_handler, scoped_ptr<ChannelAuthenticator> authenticator) { DCHECK(CalledOnValidThread()); + DCHECK(!name.empty()); + DCHECK(event_handler); + + // Can be initialized only once. + DCHECK(name_.empty()); + + name_ = name; + config_ = config; + event_handler_ = event_handler; authenticator_ = authenticator.Pass(); +} + +void PepperStreamTransport::Connect( + const StreamTransport::ConnectedCallback& callback) { + DCHECK(CalledOnValidThread()); + + // Initialize() must be called first. + DCHECK(!name_.empty()); pp::Transport_Dev* transport = - new pp::Transport_Dev(pp_instance, name_.c_str(), + new pp::Transport_Dev(pp_instance_, name_.c_str(), PP_TRANSPORTTYPE_STREAM); if (transport->SetProperty(PP_TRANSPORTPROPERTY_TCP_RECEIVE_WINDOW, @@ -85,22 +147,22 @@ void PepperStreamChannel::Connect( LOG(ERROR) << "Failed to set TCP ACK delay."; } - if (transport_config.nat_traversal) { + if (config_.nat_traversal) { if (transport->SetProperty( PP_TRANSPORTPROPERTY_STUN_SERVER, - pp::Var(transport_config.stun_server)) != PP_OK) { + pp::Var(config_.stun_server)) != PP_OK) { LOG(ERROR) << "Failed to set STUN server."; } if (transport->SetProperty( PP_TRANSPORTPROPERTY_RELAY_SERVER, - pp::Var(transport_config.relay_server)) != PP_OK) { + pp::Var(config_.relay_server)) != PP_OK) { LOG(ERROR) << "Failed to set relay server."; } if (transport->SetProperty( PP_TRANSPORTPROPERTY_RELAY_PASSWORD, - pp::Var(transport_config.relay_token)) != PP_OK) { + pp::Var(config_.relay_token)) != PP_OK) { LOG(ERROR) << "Failed to set relay token."; } @@ -119,30 +181,30 @@ void PepperStreamChannel::Connect( channel_ = new PepperTransportSocketAdapter(transport, name_, this); owned_channel_.reset(channel_); - int result = channel_->Connect(base::Bind(&PepperStreamChannel::OnP2PConnect, - base::Unretained(this))); + int result = channel_->Connect( + base::Bind(&PepperStreamTransport::OnP2PConnect, base::Unretained(this))); if (result != net::ERR_IO_PENDING) OnP2PConnect(result); } -void PepperStreamChannel::AddRemoteCandidate( +void PepperStreamTransport::AddRemoteCandidate( const cricket::Candidate& candidate) { DCHECK(CalledOnValidThread()); if (channel_) channel_->AddRemoteCandidate(jingle_glue::SerializeP2PCandidate(candidate)); } -const std::string& PepperStreamChannel::name() const { +const std::string& PepperStreamTransport::name() const { DCHECK(CalledOnValidThread()); return name_; } -bool PepperStreamChannel::is_connected() const { +bool PepperStreamTransport::is_connected() const { DCHECK(CalledOnValidThread()); return connected_; } -void PepperStreamChannel::OnChannelDeleted() { +void PepperStreamTransport::OnChannelDeleted() { if (connected_) { channel_ = NULL; // The PepperTransportSocketAdapter is being deleted, so delete @@ -151,7 +213,7 @@ void PepperStreamChannel::OnChannelDeleted() { } } -void PepperStreamChannel::OnChannelNewLocalCandidate( +void PepperStreamTransport::OnChannelNewLocalCandidate( const std::string& candidate) { DCHECK(CalledOnValidThread()); @@ -159,23 +221,25 @@ void PepperStreamChannel::OnChannelNewLocalCandidate( if (!jingle_glue::DeserializeP2PCandidate(candidate, &candidate_value)) { LOG(ERROR) << "Failed to parse candidate " << candidate; } - session_->AddLocalCandidate(candidate_value); + event_handler_->OnTransportCandidate(this, candidate_value); } -void PepperStreamChannel::OnP2PConnect(int result) { +void PepperStreamTransport::OnP2PConnect(int result) { DCHECK(CalledOnValidThread()); - if (result != net::OK) + if (result != net::OK) { NotifyConnectFailed(); + return; + } authenticator_->SecureAndAuthenticate( owned_channel_.PassAs<net::StreamSocket>(), - base::Bind(&PepperStreamChannel::OnAuthenticationDone, + base::Bind(&PepperStreamTransport::OnAuthenticationDone, base::Unretained(this))); } -void PepperStreamChannel::OnAuthenticationDone( +void PepperStreamTransport::OnAuthenticationDone( net::Error error, scoped_ptr<net::StreamSocket> socket) { DCHECK(CalledOnValidThread()); if (error != net::OK) { @@ -186,14 +250,14 @@ void PepperStreamChannel::OnAuthenticationDone( NotifyConnected(socket.Pass()); } -void PepperStreamChannel::NotifyConnected( +void PepperStreamTransport::NotifyConnected( scoped_ptr<net::StreamSocket> socket) { DCHECK(!connected_); callback_.Run(socket.Pass()); connected_ = true; } -void PepperStreamChannel::NotifyConnectFailed() { +void PepperStreamTransport::NotifyConnectFailed() { channel_ = NULL; owned_channel_.reset(); authenticator_.reset(); @@ -201,5 +265,25 @@ void PepperStreamChannel::NotifyConnectFailed() { NotifyConnected(scoped_ptr<net::StreamSocket>(NULL)); } +} // namespace + +PepperTransportFactory::PepperTransportFactory( + pp::Instance* pp_instance) + : pp_instance_(pp_instance) { +} + +PepperTransportFactory::~PepperTransportFactory() { +} + +scoped_ptr<StreamTransport> PepperTransportFactory::CreateStreamTransport() { + return scoped_ptr<StreamTransport>(new PepperStreamTransport(pp_instance_)); +} + +scoped_ptr<DatagramTransport> +PepperTransportFactory::CreateDatagramTransport() { + NOTIMPLEMENTED(); + return scoped_ptr<DatagramTransport>(NULL); +} + } // namespace protocol } // namespace remoting diff --git a/remoting/protocol/pepper_transport_factory.h b/remoting/protocol/pepper_transport_factory.h new file mode 100644 index 0000000..94e7bbe --- /dev/null +++ b/remoting/protocol/pepper_transport_factory.h @@ -0,0 +1,34 @@ +// 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_PROTOCOL_PEPPER_TRANSPORT_FACTORY_H_ +#define REMOTING_PROTOCOL_PEPPER_TRANSPORT_FACTORY_H_ + +#include "remoting/protocol/transport.h" + +namespace pp { +class Instance; +} // namespace pp + +namespace remoting { +namespace protocol { + +class PepperTransportFactory : public TransportFactory { + public: + PepperTransportFactory(pp::Instance* pp_instance); + virtual ~PepperTransportFactory(); + + virtual scoped_ptr<StreamTransport> CreateStreamTransport() OVERRIDE; + virtual scoped_ptr<DatagramTransport> CreateDatagramTransport() OVERRIDE; + + private: + pp::Instance* pp_instance_; + + DISALLOW_COPY_AND_ASSIGN(PepperTransportFactory); +}; + +} // namespace protocol +} // namespace remoting + +#endif // REMOTING_PROTOCOL_PEPPER_TRANSPORT_FACTORY_H_ diff --git a/remoting/protocol/transport.h b/remoting/protocol/transport.h new file mode 100644 index 0000000..3b4bc2a --- /dev/null +++ b/remoting/protocol/transport.h @@ -0,0 +1,130 @@ +// 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. +// +// This file defines the interface for peer-to-peer transport. There +// are two types of transport: StreamTransport and DatagramTransport. +// They must both be created using TransportFactory instances and they +// provide the same interface, except that one should be used for +// reliable stream connection and the other one for unreliable +// datagram connection. The Transport interface itself doesn't provide +// methods to send/receive data. Instead it creates an instance of +// net::Socket or net::SocketStream which provides access to the data +// channel. After a new transport is Initialize()'ed the Connect() +// method must be called. Connect() starts asynchronous creation and +// initialization of the connection socket that can be used later to +// send and receive data. The socket is passed to the callback +// specified in the Connect() call. The Transport object must exist +// during the whole lifetime of the connection socket. Later deletion +// of the connection socket causes teardown of the corresponding +// Transport object. + +#ifndef REMOTING_PROTOCOL_TRANSPORT_H_ +#define REMOTING_PROTOCOL_TRANSPORT_H_ + +#include <string> + +#include "base/basictypes.h" +#include "base/callback_forward.h" +#include "base/memory/scoped_ptr.h" +#include "base/threading/non_thread_safe.h" + +namespace cricket { +class Candidate; +} // namespace cricket + +namespace net { +class Socket; +class StreamSocket; +} // namespace net + +namespace remoting { +namespace protocol { + +class ChannelAuthenticator; +struct TransportConfig; + +class Transport : public base::NonThreadSafe { + public: + class EventHandler { + public: + EventHandler() {}; + virtual ~EventHandler() {}; + + // Called when the transport generates a new candidate that needs + // to be passed to the AddRemoteCandidate() method on the remote + // end of the connection. + virtual void OnTransportCandidate(Transport* transport, + const cricket::Candidate& candidate) = 0; + + // Called when the transport is about to be deleted. + virtual void OnTransportDeleted(Transport* transport) = 0; + }; + + Transport() {} + virtual ~Transport() {} + + // Intialize the transport with the specified parameters. + // |authenticator| is used to secure and authenticate the connection. + virtual void Initialize(const std::string& name, + const TransportConfig& config, + Transport::EventHandler* event_handler, + scoped_ptr<ChannelAuthenticator> authenticator) = 0; + + // Adds |candidate| received from the peer. + virtual void AddRemoteCandidate(const cricket::Candidate& candidate) = 0; + + // Name of the channel. It is used to identify the channel and + // disambiguate candidates it generates from candidates generated by + // parallel connections. + virtual const std::string& name() const = 0; + + // Returns true if the channel is already connected. + virtual bool is_connected() const = 0; + + private: + DISALLOW_COPY_AND_ASSIGN(Transport); +}; + +class StreamTransport : public Transport { + public: + typedef base::Callback<void(scoped_ptr<net::StreamSocket>)> ConnectedCallback; + + StreamTransport() { } + virtual ~StreamTransport() { } + + virtual void Connect(const ConnectedCallback& callback) = 0; + + private: + DISALLOW_COPY_AND_ASSIGN(StreamTransport); +}; + +class DatagramTransport : public Transport { + public: + typedef base::Callback<void(scoped_ptr<net::Socket>)> ConnectedCallback; + + DatagramTransport() { } + virtual ~DatagramTransport() { } + + virtual void Connect(const ConnectedCallback& callback) = 0; + + private: + DISALLOW_COPY_AND_ASSIGN(DatagramTransport); +}; + +class TransportFactory { + public: + TransportFactory() { } + virtual ~TransportFactory() { } + + virtual scoped_ptr<StreamTransport> CreateStreamTransport() = 0; + virtual scoped_ptr<DatagramTransport> CreateDatagramTransport() = 0; + + private: + DISALLOW_COPY_AND_ASSIGN(TransportFactory); +}; + +} // namespace protocol +} // namespace remoting + +#endif // REMOTING_PROTOCOL_TRANSPORT_H_ diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp index 50be11a..fddac6a 100644 --- a/remoting/remoting.gyp +++ b/remoting/remoting.gyp @@ -818,13 +818,12 @@ 'protocol/message_reader.h', 'protocol/negotiating_authenticator.cc', 'protocol/negotiating_authenticator.h', - 'protocol/pepper_channel.h', 'protocol/pepper_session.cc', 'protocol/pepper_session.h', 'protocol/pepper_session_manager.cc', 'protocol/pepper_session_manager.h', - 'protocol/pepper_stream_channel.cc', - 'protocol/pepper_stream_channel.h', + 'protocol/pepper_transport_factory.cc', + 'protocol/pepper_transport_factory.h', 'protocol/pepper_transport_socket_adapter.cc', 'protocol/pepper_transport_socket_adapter.h', 'protocol/protobuf_video_reader.cc', @@ -851,6 +850,7 @@ 'protocol/socket_reader_base.h', 'protocol/ssl_hmac_channel_authenticator.cc', 'protocol/ssl_hmac_channel_authenticator.h', + 'protocol/transport.h', 'protocol/transport_config.cc', 'protocol/transport_config.h', 'protocol/util.cc', |