diff options
author | garykac@chromium.org <garykac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-03 21:56:42 +0000 |
---|---|---|
committer | garykac@chromium.org <garykac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-03 21:56:42 +0000 |
commit | 230d2fd2e1cafaab5cd5e4d2a9f64b4ae272550a (patch) | |
tree | 8aa02e4a85f0d314a4419a434037e163a41981c8 /remoting/protocol | |
parent | 3296839602c5c54cae0b0fb0a9d6623a5ba65895 (diff) | |
download | chromium_src-230d2fd2e1cafaab5cd5e4d2a9f64b4ae272550a.zip chromium_src-230d2fd2e1cafaab5cd5e4d2a9f64b4ae272550a.tar.gz chromium_src-230d2fd2e1cafaab5cd5e4d2a9f64b4ae272550a.tar.bz2 |
Rename classes for Chromoting:
ChromotocolServer -> protocol::SessionManager
ChromotocolConnection -> protocol::Session
BUG=none
TEST=compiles + make chromoting connection
Review URL: http://codereview.chromium.org/4313001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64971 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/protocol')
25 files changed, 588 insertions, 526 deletions
diff --git a/remoting/protocol/chromotocol_server.h b/remoting/protocol/chromotocol_server.h deleted file mode 100644 index 3f7f494..0000000 --- a/remoting/protocol/chromotocol_server.h +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (c) 2010 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 purprose of ChromotocolServer is to facilitate creation of chromotocol -// connections. Both host and client use it to establish chromotocol -// connections. JingleChromotocolServer implements this inteface using -// libjingle. -// -// OUTGOING CONNECTIONS -// Connect() must be used to create new connection to a remote host. The -// returned connection is initially in INITIALIZING state. Later state is -// changed to CONNECTED if the connection is accepted by the host or CLOSED -// if the connection is rejected. -// -// INCOMING CONNECTIONS -// The IncomingConnectionCallback is called when a client attempts to connect. -// The callback function decides whether the connection should be accepted or -// rejected. -// -// CONNECTION OWNERSHIP AND SHUTDOWN -// ChromotocolServer owns all ChromotocolConnections it creates. The server -// must not be closed while connections created by the server are still in use. -// When shutting down the Close() method for the connection and the server -// objects must be called in the following order: ChromotocolConnection, -// ChromotocolServer, JingleClient. The same order must be followed in the case -// of rejected and failed connections. -// -// PROTOCOL VERSION NEGOTIATION -// When client connects to a host it sends a session-initiate stanza with list -// of supported configurations for each channel. If the host decides to accept -// connection, then it selects configuration that is supported by both sides -// and then replies with the session-accept stanza that contans selected -// configuration. The configuration specified in the session-accept is used -// for the session. -// -// The CandidateChromotocolConfig class represents list of configurations -// supported by an endpoint. The |chromotocol_config| argument in the Connect() -// specifies configuration supported on the client side. When the host receives -// session-initiate stanza, the IncomingConnectionCallback is called. The -// configuration sent in the session-intiate staza is available via -// ChromotocolConnnection::candidate_config(). If an incoming connection is -// being accepted then the IncomingConnectionCallback callback function must -// select session configuration and then set it with -// ChromotocolConnection::set_config(). - -#ifndef REMOTING_PROTOCOL_CHROMOTOCOL_SERVER_H_ -#define REMOTING_PROTOCOL_CHROMOTOCOL_SERVER_H_ - -#include <string> - -#include "base/callback.h" -#include "base/ref_counted.h" -#include "remoting/protocol/chromotocol_connection.h" - -class Task; - -namespace remoting { - -// Generic interface for Chromotocol server. -class ChromotocolServer : public base::RefCountedThreadSafe<ChromotocolServer> { - public: - enum IncomingConnectionResponse { - ACCEPT, - INCOMPATIBLE, - DECLINE, - }; - - // IncomingConnectionCallback is called when a new connection is received. If - // the callback decides to accept the connection it should set the second - // argument to ACCEPT. Otherwise it should set it to DECLINE, or - // INCOMPATIBLE. INCOMPATIBLE indicates that the session has incompartible - // configuration, and cannot be accepted. - // If the callback accepts connection then it must also set configuration - // for the new connection using ChromotocolConnection::set_config(). - typedef Callback2<ChromotocolConnection*, IncomingConnectionResponse*>::Type - IncomingConnectionCallback; - - // Initializes connection to the host |jid|. Ownership of the - // |chromotocol_config| is passed to the new connection. - virtual scoped_refptr<ChromotocolConnection> Connect( - const std::string& jid, - CandidateChromotocolConfig* chromotocol_config, - ChromotocolConnection::StateChangeCallback* state_change_callback) = 0; - - // Close server and all current connections. |close_task| is executed after - // the session client/ is actually closed. No callbacks are called after - // |closed_task| is executed. - virtual void Close(Task* closed_task) = 0; - - protected: - friend class base::RefCountedThreadSafe<ChromotocolServer>; - - ChromotocolServer() { } - virtual ~ChromotocolServer() { } - - private: - DISALLOW_COPY_AND_ASSIGN(ChromotocolServer); -}; - -} // namespace remoting - -#endif // REMOTING_PROTOCOL_CHROMOTOCOL_SERVER_H_ diff --git a/remoting/protocol/fake_connection.cc b/remoting/protocol/fake_session.cc index 3288b2a..492f4d8 100644 --- a/remoting/protocol/fake_connection.cc +++ b/remoting/protocol/fake_session.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/fake_connection.h" +#include "remoting/protocol/fake_session.h" #include "base/message_loop.h" #include "net/base/io_buffer.h" @@ -10,6 +10,8 @@ namespace remoting { +namespace protocol { + const char kTestJid[] = "host1@gmail.com/chromoting123"; FakeSocket::FakeSocket() @@ -69,66 +71,68 @@ bool FakeSocket::SetSendBufferSize(int32 size) { return false; } -FakeChromotocolConnection::FakeChromotocolConnection() +FakeSession::FakeSession() : candidate_config_(CandidateChromotocolConfig::CreateDefault()), config_(ChromotocolConfig::CreateDefault()), message_loop_(NULL), jid_(kTestJid) { } -FakeChromotocolConnection::~FakeChromotocolConnection() { } +FakeSession::~FakeSession() { } -void FakeChromotocolConnection::SetStateChangeCallback( +void FakeSession::SetStateChangeCallback( StateChangeCallback* callback) { callback_.reset(callback); } -FakeSocket* FakeChromotocolConnection::control_channel() { +FakeSocket* FakeSession::control_channel() { return &control_channel_; } -FakeSocket* FakeChromotocolConnection::event_channel() { +FakeSocket* FakeSession::event_channel() { return &event_channel_; } -FakeSocket* FakeChromotocolConnection::video_channel() { +FakeSocket* FakeSession::video_channel() { return &video_channel_; } -FakeSocket* FakeChromotocolConnection::video_rtp_channel() { +FakeSocket* FakeSession::video_rtp_channel() { return &video_rtp_channel_; } -FakeSocket* FakeChromotocolConnection::video_rtcp_channel() { +FakeSocket* FakeSession::video_rtcp_channel() { return &video_rtcp_channel_; } -const std::string& FakeChromotocolConnection::jid() { +const std::string& FakeSession::jid() { return jid_; } -MessageLoop* FakeChromotocolConnection::message_loop() { +MessageLoop* FakeSession::message_loop() { return message_loop_; } const CandidateChromotocolConfig* -FakeChromotocolConnection::candidate_config() { +FakeSession::candidate_config() { return candidate_config_.get(); } -const ChromotocolConfig* FakeChromotocolConnection::config() { +const ChromotocolConfig* FakeSession::config() { CHECK(config_.get()); return config_.get(); } -void FakeChromotocolConnection::set_config(const ChromotocolConfig* config) { +void FakeSession::set_config(const ChromotocolConfig* config) { config_.reset(config); } -void FakeChromotocolConnection::Close(Task* closed_task) { +void FakeSession::Close(Task* closed_task) { closed_ = true; closed_task->Run(); delete closed_task; } +} // namespace protocol + } // namespace remoting diff --git a/remoting/protocol/fake_connection.h b/remoting/protocol/fake_session.h index ddc9cab..d325351 100644 --- a/remoting/protocol/fake_connection.h +++ b/remoting/protocol/fake_session.h @@ -2,17 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef REMOTING_PROTOCOL_FAKE_CONNECTION_H_ -#define REMOTING_PROTOCOL_FAKE_CONNECTION_H_ +#ifndef REMOTING_PROTOCOL_FAKE_SESSION_H_ +#define REMOTING_PROTOCOL_FAKE_SESSION_H_ #include <vector> #include "base/scoped_ptr.h" #include "net/socket/socket.h" -#include "remoting/protocol/chromotocol_connection.h" +#include "remoting/protocol/session.h" namespace remoting { +namespace protocol { + extern const char kTestJid[]; // FakeSocket implement net::Socket interface for FakeConnection. All data @@ -50,12 +52,12 @@ class FakeSocket : public net::Socket { int input_pos_; }; -// FakeChromotocolConnection is a dummy ChromotocolConnection that uses -// FakeSocket for all channels. -class FakeChromotocolConnection : public ChromotocolConnection { +// FakeSession is a dummy protocol::Session that uses FakeSocket for all +// channels. +class FakeSession : public Session { public: - FakeChromotocolConnection(); - virtual ~FakeChromotocolConnection(); + FakeSession(); + virtual ~FakeSession(); StateChangeCallback* state_change_callback() { return callback_.get(); } @@ -97,6 +99,8 @@ class FakeChromotocolConnection : public ChromotocolConnection { bool closed_; }; +} // namespace protocol + } // namespace remoting -#endif // REMOTING_PROTOCOL_FAKE_CONNECTION_H_ +#endif // REMOTING_PROTOCOL_FAKE_SESSION_H_ diff --git a/remoting/protocol/host_message_dispatcher.cc b/remoting/protocol/host_message_dispatcher.cc index 5406813..d75de95 100644 --- a/remoting/protocol/host_message_dispatcher.cc +++ b/remoting/protocol/host_message_dispatcher.cc @@ -6,12 +6,11 @@ #include "remoting/base/multiple_array_input_stream.h" #include "remoting/proto/control.pb.h" #include "remoting/proto/event.pb.h" -#include "remoting/proto/video.pb.h" -#include "remoting/protocol/chromotocol_connection.h" #include "remoting/protocol/host_message_dispatcher.h" #include "remoting/protocol/host_stub.h" #include "remoting/protocol/input_stub.h" #include "remoting/protocol/message_reader.h" +#include "remoting/protocol/session.h" namespace { @@ -52,10 +51,10 @@ HostMessageDispatcher::~HostMessageDispatcher() { } bool HostMessageDispatcher::Initialize( - ChromotocolConnection* connection, + protocol::Session* session, HostStub* host_stub, InputStub* input_stub) { - if (!connection || !host_stub || !input_stub || - !connection->event_channel() || !connection->control_channel()) { + if (!session || !host_stub || !input_stub || + !session->event_channel() || !session->control_channel()) { return false; } @@ -66,10 +65,10 @@ bool HostMessageDispatcher::Initialize( // Initialize the readers on the sockets provided by channels. event_message_reader_->Init<EventMessage>( - connection->event_channel(), + session->event_channel(), NewCallback(this, &HostMessageDispatcher::OnEventMessageReceived)); control_message_reader_->Init<ControlMessage>( - connection->control_channel(), + session->control_channel(), NewCallback(this, &HostMessageDispatcher::OnControlMessageReceived)); return true; } diff --git a/remoting/protocol/host_message_dispatcher.h b/remoting/protocol/host_message_dispatcher.h index 7357723..cd95b26 100644 --- a/remoting/protocol/host_message_dispatcher.h +++ b/remoting/protocol/host_message_dispatcher.h @@ -12,7 +12,6 @@ namespace remoting { -class ChromotocolConnection; class EventMessage; class MessageReader; @@ -21,14 +20,15 @@ namespace protocol { class ControlMessage; class HostStub; class InputStub; +class Session; // A message dispatcher used to listen for messages received in -// ChromotocolConnection. It dispatches messages to the corresponding +// protocol::Session. It dispatches messages to the corresponding // handler. // // Internally it contains an EventStreamReader that decodes data on // communications channels into protocol buffer messages. -// EventStreamReader is registered with ChromotocolConnection given to it. +// EventStreamReader is registered with protocol::Session given to it. // // Object of this class is owned by ChromotingHost to dispatch messages // to itself. @@ -42,7 +42,7 @@ class HostMessageDispatcher : // Initialize the message dispatcher with the given connection and // message handlers. // Return true if initalization was successful. - bool Initialize(ChromotocolConnection* connection, + bool Initialize(protocol::Session* session, HostStub* host_stub, InputStub* input_stub); private: diff --git a/remoting/protocol/jingle_chromotocol_connection.cc b/remoting/protocol/jingle_session.cc index 01b7bac..4ed6b4f 100644 --- a/remoting/protocol/jingle_chromotocol_connection.cc +++ b/remoting/protocol/jingle_session.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/jingle_chromotocol_connection.h" +#include "remoting/protocol/jingle_session.h" #include "base/message_loop.h" #include "net/base/net_errors.h" @@ -10,17 +10,18 @@ #include "remoting/jingle_glue/channel_socket_adapter.h" #include "remoting/jingle_glue/jingle_thread.h" #include "remoting/jingle_glue/stream_socket_adapter.h" -#include "remoting/protocol/jingle_chromotocol_server.h" +#include "remoting/protocol/jingle_session_manager.h" #include "third_party/libjingle/source/talk/base/thread.h" #include "third_party/libjingle/source/talk/p2p/base/session.h" #include "third_party/libjingle/source/talk/session/tunnel/pseudotcpchannel.h" using cricket::BaseSession; using cricket::PseudoTcpChannel; -using cricket::Session; namespace remoting { +namespace protocol { + namespace { const char kControlChannelName[] = "control"; const char kEventChannelName[] = "event"; @@ -29,118 +30,118 @@ const char kVideoRtpChannelName[] = "videortp"; const char kVideoRtcpChannelName[] = "videortcp"; } // namespace -const char JingleChromotocolConnection::kChromotingContentName[] = "chromoting"; +const char JingleSession::kChromotingContentName[] = "chromoting"; -JingleChromotocolConnection::JingleChromotocolConnection( - JingleChromotocolServer* server) - : server_(server), +JingleSession::JingleSession( + JingleSessionManager* jingle_session_manager) + : jingle_session_manager_(jingle_session_manager), state_(INITIALIZING), closed_(false), - session_(NULL), + cricket_session_(NULL), event_channel_(NULL), video_channel_(NULL) { } -JingleChromotocolConnection::~JingleChromotocolConnection() { +JingleSession::~JingleSession() { DCHECK(closed_); } -void JingleChromotocolConnection::Init(Session* session) { - DCHECK_EQ(server_->message_loop(), MessageLoop::current()); +void JingleSession::Init(cricket::Session* cricket_session) { + DCHECK_EQ(jingle_session_manager_->message_loop(), MessageLoop::current()); - session_ = session; - jid_ = session_->remote_name(); - session_->SignalState.connect( - this, &JingleChromotocolConnection::OnSessionState); + cricket_session_ = cricket_session; + jid_ = cricket_session_->remote_name(); + cricket_session_->SignalState.connect( + this, &JingleSession::OnSessionState); } -bool JingleChromotocolConnection::HasSession(cricket::Session* session) { - return session_ == session; +bool JingleSession::HasSession(cricket::Session* cricket_session) { + return cricket_session_ == cricket_session; } -Session* JingleChromotocolConnection::ReleaseSession() { - DCHECK_EQ(server_->message_loop(), MessageLoop::current()); +cricket::Session* JingleSession::ReleaseSession() { + DCHECK_EQ(jingle_session_manager_->message_loop(), MessageLoop::current()); SetState(CLOSED); - Session* session = session_; - if (session_) - session_->SignalState.disconnect(this); - session_ = NULL; + cricket::Session* session = cricket_session_; + if (cricket_session_) + cricket_session_->SignalState.disconnect(this); + cricket_session_ = NULL; closed_ = true; return session; } -void JingleChromotocolConnection::SetStateChangeCallback( +void JingleSession::SetStateChangeCallback( StateChangeCallback* callback) { - DCHECK_EQ(server_->message_loop(), MessageLoop::current()); + DCHECK_EQ(jingle_session_manager_->message_loop(), MessageLoop::current()); DCHECK(callback); state_change_callback_.reset(callback); } -net::Socket* JingleChromotocolConnection::control_channel() { - DCHECK_EQ(server_->message_loop(), MessageLoop::current()); +net::Socket* JingleSession::control_channel() { + DCHECK_EQ(jingle_session_manager_->message_loop(), MessageLoop::current()); return control_channel_adapter_.get(); } -net::Socket* JingleChromotocolConnection::event_channel() { - DCHECK_EQ(server_->message_loop(), MessageLoop::current()); +net::Socket* JingleSession::event_channel() { + DCHECK_EQ(jingle_session_manager_->message_loop(), MessageLoop::current()); return event_channel_adapter_.get(); } // TODO(sergeyu): Remove this method after we switch to RTP. -net::Socket* JingleChromotocolConnection::video_channel() { - DCHECK_EQ(server_->message_loop(), MessageLoop::current()); +net::Socket* JingleSession::video_channel() { + DCHECK_EQ(jingle_session_manager_->message_loop(), MessageLoop::current()); return video_channel_adapter_.get(); } -net::Socket* JingleChromotocolConnection::video_rtp_channel() { - DCHECK_EQ(server_->message_loop(), MessageLoop::current()); +net::Socket* JingleSession::video_rtp_channel() { + DCHECK_EQ(jingle_session_manager_->message_loop(), MessageLoop::current()); return video_rtp_channel_.get(); } -net::Socket* JingleChromotocolConnection::video_rtcp_channel() { - DCHECK_EQ(server_->message_loop(), MessageLoop::current()); +net::Socket* JingleSession::video_rtcp_channel() { + DCHECK_EQ(jingle_session_manager_->message_loop(), MessageLoop::current()); return video_rtcp_channel_.get(); } -const std::string& JingleChromotocolConnection::jid() { +const std::string& JingleSession::jid() { // No synchronization is needed because jid_ is not changed // after new connection is passed to JingleChromotocolServer callback. return jid_; } -MessageLoop* JingleChromotocolConnection::message_loop() { - return server_->message_loop(); +MessageLoop* JingleSession::message_loop() { + return jingle_session_manager_->message_loop(); } const CandidateChromotocolConfig* -JingleChromotocolConnection::candidate_config() { +JingleSession::candidate_config() { DCHECK(candidate_config_.get()); return candidate_config_.get(); } -void JingleChromotocolConnection::set_candidate_config( +void JingleSession::set_candidate_config( const CandidateChromotocolConfig* candidate_config) { DCHECK(!candidate_config_.get()); DCHECK(candidate_config); candidate_config_.reset(candidate_config); } -const ChromotocolConfig* JingleChromotocolConnection::config() { +const ChromotocolConfig* JingleSession::config() { DCHECK(config_.get()); return config_.get(); } -void JingleChromotocolConnection::set_config(const ChromotocolConfig* config) { +void JingleSession::set_config(const ChromotocolConfig* config) { DCHECK(!config_.get()); DCHECK(config); config_.reset(config); } -void JingleChromotocolConnection::Close(Task* closed_task) { - if (MessageLoop::current() != server_->message_loop()) { - server_->message_loop()->PostTask( - FROM_HERE, NewRunnableMethod(this, &JingleChromotocolConnection::Close, +void JingleSession::Close(Task* closed_task) { + if (MessageLoop::current() != jingle_session_manager_->message_loop()) { + jingle_session_manager_->message_loop()->PostTask( + FROM_HERE, NewRunnableMethod(this, &JingleSession::Close, closed_task)); return; } @@ -150,7 +151,7 @@ void JingleChromotocolConnection::Close(Task* closed_task) { control_channel_adapter_->Close(net::ERR_CONNECTION_CLOSED); if (control_channel_) { - control_channel_->OnSessionTerminate(session_); + control_channel_->OnSessionTerminate(cricket_session_); control_channel_ = NULL; } @@ -158,7 +159,7 @@ void JingleChromotocolConnection::Close(Task* closed_task) { event_channel_adapter_->Close(net::ERR_CONNECTION_CLOSED); if (event_channel_) { - event_channel_->OnSessionTerminate(session_); + event_channel_->OnSessionTerminate(cricket_session_); event_channel_ = NULL; } @@ -166,7 +167,7 @@ void JingleChromotocolConnection::Close(Task* closed_task) { video_channel_adapter_->Close(net::ERR_CONNECTION_CLOSED); if (video_channel_) { - video_channel_->OnSessionTerminate(session_); + video_channel_->OnSessionTerminate(cricket_session_); video_channel_ = NULL; } @@ -175,8 +176,8 @@ void JingleChromotocolConnection::Close(Task* closed_task) { if (video_rtcp_channel_.get()) video_rtcp_channel_->Close(net::ERR_CONNECTION_CLOSED); - if (session_) - session_->Terminate(); + if (cricket_session_) + cricket_session_->Terminate(); SetState(CLOSED); @@ -187,29 +188,29 @@ void JingleChromotocolConnection::Close(Task* closed_task) { delete closed_task; } -void JingleChromotocolConnection::OnSessionState( +void JingleSession::OnSessionState( BaseSession* session, BaseSession::State state) { - DCHECK_EQ(session_, session); + DCHECK_EQ(cricket_session_, session); switch (state) { - case Session::STATE_SENTINITIATE: - case Session::STATE_RECEIVEDINITIATE: + case cricket::Session::STATE_SENTINITIATE: + case cricket::Session::STATE_RECEIVEDINITIATE: OnInitiate(); break; - case Session::STATE_SENTACCEPT: - case Session::STATE_RECEIVEDACCEPT: + case cricket::Session::STATE_SENTACCEPT: + case cricket::Session::STATE_RECEIVEDACCEPT: OnAccept(); break; - case Session::STATE_SENTTERMINATE: - case Session::STATE_RECEIVEDTERMINATE: - case Session::STATE_SENTREJECT: - case Session::STATE_RECEIVEDREJECT: + case cricket::Session::STATE_SENTTERMINATE: + case cricket::Session::STATE_RECEIVEDTERMINATE: + case cricket::Session::STATE_SENTREJECT: + case cricket::Session::STATE_RECEIVEDREJECT: OnTerminate(); break; - case Session::STATE_DEINIT: + case cricket::Session::STATE_DEINIT: // Close() must have been called before this. NOTREACHED(); break; @@ -220,17 +221,17 @@ void JingleChromotocolConnection::OnSessionState( } } -void JingleChromotocolConnection::OnInitiate() { - jid_ = session_->remote_name(); +void JingleSession::OnInitiate() { + jid_ = cricket_session_->remote_name(); std::string content_name; - // If we initiate the connection, we get to specify the content name. When + // If we initiate the session, we get to specify the content name. When // accepting one, the remote end specifies it. - if (session_->initiator()) { + if (cricket_session_->initiator()) { content_name = kChromotingContentName; } else { const cricket::ContentInfo* content; - content = session_->remote_description()->FirstContentByType( + content = cricket_session_->remote_description()->FirstContentByType( kChromotingXmlNamespace); CHECK(content); content_name = content->name; @@ -238,45 +239,48 @@ void JingleChromotocolConnection::OnInitiate() { // Create video RTP channels. video_rtp_channel_.reset(new TransportChannelSocketAdapter( - session_->CreateChannel(content_name, kVideoRtpChannelName))); + cricket_session_->CreateChannel(content_name, kVideoRtpChannelName))); video_rtcp_channel_.reset(new TransportChannelSocketAdapter( - session_->CreateChannel(content_name, kVideoRtcpChannelName))); + cricket_session_->CreateChannel(content_name, kVideoRtcpChannelName))); // Create control channel. - control_channel_ = new PseudoTcpChannel(server_->jingle_thread(), session_); + control_channel_ = new PseudoTcpChannel( + jingle_session_manager_->jingle_thread(), cricket_session_); control_channel_->Connect(content_name, kControlChannelName); control_channel_adapter_.reset(new StreamSocketAdapter( control_channel_->GetStream())); // Create event channel. - event_channel_ = new PseudoTcpChannel(server_->jingle_thread(), session_); + event_channel_ = new PseudoTcpChannel( + jingle_session_manager_->jingle_thread(), cricket_session_); event_channel_->Connect(content_name, kEventChannelName); event_channel_adapter_.reset(new StreamSocketAdapter( event_channel_->GetStream())); // Create video channel. // TODO(sergeyu): Remove video channel when we are ready to switch to RTP. - video_channel_ = new PseudoTcpChannel(server_->jingle_thread(), session_); + video_channel_ = new PseudoTcpChannel( + jingle_session_manager_->jingle_thread(), cricket_session_); video_channel_->Connect(content_name, kVideoChannelName); video_channel_adapter_.reset(new StreamSocketAdapter( video_channel_->GetStream())); - if (!session_->initiator()) - server_->AcceptConnection(this, session_); + if (!cricket_session_->initiator()) + jingle_session_manager_->AcceptConnection(this, cricket_session_); SetState(CONNECTING); } -void JingleChromotocolConnection::OnAccept() { - // Set config for outgoing connections. - if (session_->initiator()) { +void JingleSession::OnAccept() { + // Set the config if we are the one who initiated the session. + if (cricket_session_->initiator()) { const cricket::ContentInfo* content = - session_->remote_description()->FirstContentByType( + cricket_session_->remote_description()->FirstContentByType( kChromotingXmlNamespace); CHECK(content); - const ChromotocolContentDescription* content_description = - static_cast<const ChromotocolContentDescription*>(content->description); + const protocol::ContentDescription* content_description = + static_cast<const protocol::ContentDescription*>(content->description); ChromotocolConfig* config = content_description->config()->GetFinalConfig(); // Terminate the session if the config we received is invalid. @@ -284,7 +288,7 @@ void JingleChromotocolConnection::OnAccept() { // TODO(sergeyu): Inform the user that the host is misbehaving? LOG(ERROR) << "Terminating outgoing session after an " "invalid session description has been received."; - session_->Terminate(); + cricket_session_->Terminate(); return; } @@ -294,25 +298,25 @@ void JingleChromotocolConnection::OnAccept() { SetState(CONNECTED); } -void JingleChromotocolConnection::OnTerminate() { +void JingleSession::OnTerminate() { if (control_channel_adapter_.get()) control_channel_adapter_->Close(net::ERR_CONNECTION_ABORTED); if (control_channel_) { - control_channel_->OnSessionTerminate(session_); + control_channel_->OnSessionTerminate(cricket_session_); control_channel_ = NULL; } if (event_channel_adapter_.get()) event_channel_adapter_->Close(net::ERR_CONNECTION_ABORTED); if (event_channel_) { - event_channel_->OnSessionTerminate(session_); + event_channel_->OnSessionTerminate(cricket_session_); event_channel_ = NULL; } if (video_channel_adapter_.get()) video_channel_adapter_->Close(net::ERR_CONNECTION_ABORTED); if (video_channel_) { - video_channel_->OnSessionTerminate(session_); + video_channel_->OnSessionTerminate(cricket_session_); video_channel_ = NULL; } @@ -326,7 +330,7 @@ void JingleChromotocolConnection::OnTerminate() { closed_ = true; } -void JingleChromotocolConnection::SetState(State new_state) { +void JingleSession::SetState(State new_state) { if (new_state != state_) { state_ = new_state; if (!closed_ && state_change_callback_.get()) @@ -334,4 +338,6 @@ void JingleChromotocolConnection::SetState(State new_state) { } } +} // namespace protocol + } // namespace remoting diff --git a/remoting/protocol/jingle_chromotocol_connection.h b/remoting/protocol/jingle_session.h index d139aef..dcebbd1 100644 --- a/remoting/protocol/jingle_chromotocol_connection.h +++ b/remoting/protocol/jingle_session.h @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef REMOTING_PROTOCOL_JINGLE_CHROMOTOCOL_CONNECTION_H_ -#define REMOTING_PROTOCOL_JINGLE_CHROMOTOCOL_CONNECTION_H_ +#ifndef REMOTING_PROTOCOL_JINGLE_SESSION_H_ +#define REMOTING_PROTOCOL_JINGLE_SESSION_H_ #include "base/lock.h" #include "base/ref_counted.h" -#include "remoting/protocol/chromotocol_connection.h" +#include "remoting/protocol/session.h" #include "third_party/libjingle/source/talk/base/sigslot.h" #include "third_party/libjingle/source/talk/p2p/base/session.h" @@ -21,21 +21,24 @@ class Socket; namespace remoting { -class JingleChromotocolServer; class StreamSocketAdapter; class TransportChannelSocketAdapter; -// Implements ChromotocolConnection that work over libjingle session (the +namespace protocol { + +class JingleSessionManager; + +// Implements protocol::Session that work over libjingle session (the // cricket::Session object is passed to Init() method). Created -// by JingleChromotocolServer for incoming and outgoing connections. -class JingleChromotocolConnection : public ChromotocolConnection, - public sigslot::has_slots<> { +// by JingleSessionManager for incoming and outgoing connections. +class JingleSession : public protocol::Session, + public sigslot::has_slots<> { public: static const char kChromotingContentName[]; - explicit JingleChromotocolConnection(JingleChromotocolServer* client); + explicit JingleSession(JingleSessionManager* client); - // ChromotocolConnection interface. + // Chromotocol Session interface. virtual void SetStateChangeCallback(StateChangeCallback* callback); virtual net::Socket* control_channel(); @@ -56,15 +59,15 @@ class JingleChromotocolConnection : public ChromotocolConnection, virtual void Close(Task* closed_task); protected: - virtual ~JingleChromotocolConnection(); + virtual ~JingleSession(); private: - friend class JingleChromotocolServer; + friend class JingleSessionManager; - // Called by JingleChromotocolServer. + // Called by JingleSessionManager. void set_candidate_config(const CandidateChromotocolConfig* candidate_config); - void Init(cricket::Session* session); - bool HasSession(cricket::Session* session); + void Init(cricket::Session* cricket_session); + bool HasSession(cricket::Session* cricket_session); cricket::Session* ReleaseSession(); // Used for Session.SignalState sigslot. @@ -77,8 +80,8 @@ class JingleChromotocolConnection : public ChromotocolConnection, void SetState(State new_state); - // JingleChromotocolServer that created this connection. - scoped_refptr<JingleChromotocolServer> server_; + // JingleSessionManager that created this session. + scoped_refptr<JingleSessionManager> jingle_session_manager_; State state_; scoped_ptr<StateChangeCallback> state_change_callback_; @@ -90,7 +93,7 @@ class JingleChromotocolConnection : public ChromotocolConnection, std::string jid_; // The corresponding libjingle session. - cricket::Session* session_; + cricket::Session* cricket_session_; scoped_ptr<const CandidateChromotocolConfig> candidate_config_; scoped_ptr<const ChromotocolConfig> config_; @@ -104,9 +107,11 @@ class JingleChromotocolConnection : public ChromotocolConnection, scoped_ptr<TransportChannelSocketAdapter> video_rtp_channel_; scoped_ptr<TransportChannelSocketAdapter> video_rtcp_channel_; - DISALLOW_COPY_AND_ASSIGN(JingleChromotocolConnection); + DISALLOW_COPY_AND_ASSIGN(JingleSession); }; +} // namespace protocol + } // namespace remoting -#endif // REMOTING_PROTOCOL_JINGLE_CHROMOTOCOL_CONNECTION_H_ +#endif // REMOTING_PROTOCOL_JINGLE_SESSION_H_ diff --git a/remoting/protocol/jingle_chromotocol_server.cc b/remoting/protocol/jingle_session_manager.cc index b0f680b..8784f83 100644 --- a/remoting/protocol/jingle_chromotocol_server.cc +++ b/remoting/protocol/jingle_session_manager.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/jingle_chromotocol_server.h" +#include "remoting/protocol/jingle_session_manager.h" #include "base/message_loop.h" #include "base/string_number_conversions.h" @@ -14,13 +14,13 @@ using cricket::ContentDescription; using cricket::SessionDescription; -using cricket::Session; -using cricket::SessionManager; using buzz::QName; using buzz::XmlElement; namespace remoting { +namespace protocol { + namespace { const char kDefaultNs[] = ""; @@ -150,62 +150,62 @@ bool ParseChannelConfig(const XmlElement* element, bool codec_required, } // namespace -ChromotocolContentDescription::ChromotocolContentDescription( +ContentDescription::ContentDescription( const CandidateChromotocolConfig* config) : candidate_config_(config) { } -ChromotocolContentDescription::~ChromotocolContentDescription() { } +ContentDescription::~ContentDescription() { } -JingleChromotocolServer::JingleChromotocolServer( +JingleSessionManager::JingleSessionManager( JingleThread* jingle_thread) : jingle_thread_(jingle_thread), - session_manager_(NULL), + cricket_session_manager_(NULL), allow_local_ips_(false), closed_(false) { DCHECK(jingle_thread_); } -void JingleChromotocolServer::Init( +void JingleSessionManager::Init( const std::string& local_jid, - cricket::SessionManager* session_manager, - IncomingConnectionCallback* incoming_connection_callback) { + cricket::SessionManager* cricket_session_manager, + IncomingSessionCallback* incoming_session_callback) { if (MessageLoop::current() != message_loop()) { message_loop()->PostTask( FROM_HERE, NewRunnableMethod( - this, &JingleChromotocolServer::Init, - local_jid, session_manager, incoming_connection_callback)); + this, &JingleSessionManager::Init, + local_jid, cricket_session_manager, incoming_session_callback)); return; } - DCHECK(session_manager); - DCHECK(incoming_connection_callback); + DCHECK(cricket_session_manager); + DCHECK(incoming_session_callback); local_jid_ = local_jid; - incoming_connection_callback_.reset(incoming_connection_callback); - session_manager_ = session_manager; - session_manager_->AddClient(kChromotingXmlNamespace, this); + incoming_session_callback_.reset(incoming_session_callback); + cricket_session_manager_ = cricket_session_manager; + cricket_session_manager_->AddClient(kChromotingXmlNamespace, this); } -JingleChromotocolServer::~JingleChromotocolServer() { +JingleSessionManager::~JingleSessionManager() { DCHECK(closed_); } -void JingleChromotocolServer::Close(Task* closed_task) { +void JingleSessionManager::Close(Task* closed_task) { if (MessageLoop::current() != message_loop()) { message_loop()->PostTask( - FROM_HERE, NewRunnableMethod(this, &JingleChromotocolServer::Close, + FROM_HERE, NewRunnableMethod(this, &JingleSessionManager::Close, closed_task)); return; } if (!closed_) { // Close all connections. - session_manager_->RemoveClient(kChromotingXmlNamespace); - while (!connections_.empty()) { - Session* session = connections_.front()->ReleaseSession(); - session_manager_->DestroySession(session); - connections_.pop_front(); + cricket_session_manager_->RemoveClient(kChromotingXmlNamespace); + while (!sessions_.empty()) { + cricket::Session* session = sessions_.front()->ReleaseSession(); + cricket_session_manager_->DestroySession(session); + sessions_.pop_front(); } closed_ = true; } @@ -214,125 +214,125 @@ void JingleChromotocolServer::Close(Task* closed_task) { delete closed_task; } -void JingleChromotocolServer::set_allow_local_ips(bool allow_local_ips) { +void JingleSessionManager::set_allow_local_ips(bool allow_local_ips) { allow_local_ips_ = allow_local_ips; } -scoped_refptr<ChromotocolConnection> JingleChromotocolServer::Connect( +scoped_refptr<protocol::Session> JingleSessionManager::Connect( const std::string& jid, CandidateChromotocolConfig* chromotocol_config, - ChromotocolConnection::StateChangeCallback* state_change_callback) { + protocol::Session::StateChangeCallback* state_change_callback) { // Can be called from any thread. - scoped_refptr<JingleChromotocolConnection> connection( - new JingleChromotocolConnection(this)); - connection->set_candidate_config(chromotocol_config); + scoped_refptr<JingleSession> jingle_session( + new JingleSession(this)); + jingle_session->set_candidate_config(chromotocol_config); message_loop()->PostTask( - FROM_HERE, NewRunnableMethod(this, &JingleChromotocolServer::DoConnect, - connection, jid, + FROM_HERE, NewRunnableMethod(this, &JingleSessionManager::DoConnect, + jingle_session, jid, state_change_callback)); - return connection; + return jingle_session; } -void JingleChromotocolServer::DoConnect( - scoped_refptr<JingleChromotocolConnection> connection, +void JingleSessionManager::DoConnect( + scoped_refptr<JingleSession> jingle_session, const std::string& jid, - ChromotocolConnection::StateChangeCallback* state_change_callback) { + protocol::Session::StateChangeCallback* state_change_callback) { DCHECK_EQ(message_loop(), MessageLoop::current()); - Session* session = session_manager_->CreateSession( + cricket::Session* cricket_session = cricket_session_manager_->CreateSession( local_jid_, kChromotingXmlNamespace); // Initialize connection object before we send initiate stanza. - connection->SetStateChangeCallback(state_change_callback); - connection->Init(session); - connections_.push_back(connection); + jingle_session->SetStateChangeCallback(state_change_callback); + jingle_session->Init(cricket_session); + sessions_.push_back(jingle_session); - session->Initiate( - jid, CreateSessionDescription(connection->candidate_config()->Clone())); + cricket_session->Initiate( + jid, + CreateSessionDescription(jingle_session->candidate_config()->Clone())); } -JingleThread* JingleChromotocolServer::jingle_thread() { +JingleThread* JingleSessionManager::jingle_thread() { return jingle_thread_; } -MessageLoop* JingleChromotocolServer::message_loop() { +MessageLoop* JingleSessionManager::message_loop() { return jingle_thread_->message_loop(); } -void JingleChromotocolServer::OnSessionCreate( - Session* session, bool incoming) { +void JingleSessionManager::OnSessionCreate( + cricket::Session* cricket_session, bool incoming) { DCHECK_EQ(message_loop(), MessageLoop::current()); // Allow local connections if neccessary. - session->set_allow_local_ips(allow_local_ips_); + cricket_session->set_allow_local_ips(allow_local_ips_); // If this is an outcoming session the connection object is already // created. if (incoming) { - JingleChromotocolConnection* connection = - new JingleChromotocolConnection(this); - connections_.push_back(make_scoped_refptr(connection)); - connection->Init(session); + JingleSession* jingle_session = new JingleSession(this); + sessions_.push_back(make_scoped_refptr(jingle_session)); + jingle_session->Init(cricket_session); } } -void JingleChromotocolServer::OnSessionDestroy(Session* session) { +void JingleSessionManager::OnSessionDestroy(cricket::Session* cricket_session) { DCHECK_EQ(message_loop(), MessageLoop::current()); - std::list<scoped_refptr<JingleChromotocolConnection> >::iterator it; - for (it = connections_.begin(); it != connections_.end(); ++it) { - if ((*it)->HasSession(session)) { + std::list<scoped_refptr<JingleSession> >::iterator it; + for (it = sessions_.begin(); it != sessions_.end(); ++it) { + if ((*it)->HasSession(cricket_session)) { (*it)->ReleaseSession(); - connections_.erase(it); + sessions_.erase(it); return; } } } -void JingleChromotocolServer::AcceptConnection( - JingleChromotocolConnection* connection, - Session* session) { +void JingleSessionManager::AcceptConnection( + JingleSession* jingle_session, + cricket::Session* cricket_session) { DCHECK_EQ(message_loop(), MessageLoop::current()); // Reject connection if we are closed. if (closed_) { - session->Reject(cricket::STR_TERMINATE_DECLINE); + cricket_session->Reject(cricket::STR_TERMINATE_DECLINE); return; } const cricket::SessionDescription* session_description = - session->remote_description(); + cricket_session->remote_description(); const cricket::ContentInfo* content = session_description->FirstContentByType(kChromotingXmlNamespace); CHECK(content); - const ChromotocolContentDescription* content_description = - static_cast<const ChromotocolContentDescription*>(content->description); - connection->set_candidate_config(content_description->config()->Clone()); + const ContentDescription* content_description = + static_cast<const ContentDescription*>(content->description); + jingle_session->set_candidate_config(content_description->config()->Clone()); - IncomingConnectionResponse response = ChromotocolServer::DECLINE; + IncomingSessionResponse response = protocol::SessionManager::DECLINE; // Always reject connection if there is no callback. - if (incoming_connection_callback_.get()) - incoming_connection_callback_->Run(connection, &response); + if (incoming_session_callback_.get()) + incoming_session_callback_->Run(jingle_session, &response); switch (response) { - case ChromotocolServer::ACCEPT: { + case protocol::SessionManager::ACCEPT: { // Connection must be configured by the callback. - DCHECK(connection->config()); + DCHECK(jingle_session->config()); CandidateChromotocolConfig* candidate_config = - CandidateChromotocolConfig::CreateFrom(connection->config()); - session->Accept(CreateSessionDescription(candidate_config)); + CandidateChromotocolConfig::CreateFrom(jingle_session->config()); + cricket_session->Accept(CreateSessionDescription(candidate_config)); break; } - case ChromotocolServer::INCOMPATIBLE: { - session->Reject(cricket::STR_TERMINATE_INCOMPATIBLE_PARAMETERS); + case protocol::SessionManager::INCOMPATIBLE: { + cricket_session->Reject(cricket::STR_TERMINATE_INCOMPATIBLE_PARAMETERS); break; } - case ChromotocolServer::DECLINE: { - session->Reject(cricket::STR_TERMINATE_DECLINE); + case protocol::SessionManager::DECLINE: { + cricket_session->Reject(cricket::STR_TERMINATE_DECLINE); break; } @@ -343,7 +343,7 @@ void JingleChromotocolServer::AcceptConnection( } // Parse content description generated by WriteContent(). -bool JingleChromotocolServer::ParseContent( +bool JingleSessionManager::ParseContent( cricket::SignalingProtocol protocol, const XmlElement* element, const cricket::ContentDescription** content, @@ -405,7 +405,7 @@ bool JingleChromotocolServer::ParseContent( config->SetInitialResolution(resolution); - *content = new ChromotocolContentDescription(config.release()); + *content = new ContentDescription(config.release()); return true; } LOG(ERROR) << "Invalid description: " << element->Str(); @@ -421,13 +421,13 @@ bool JingleChromotocolServer::ParseContent( // <initial-resolution width="800" height="600" /> // </description> // -bool JingleChromotocolServer::WriteContent( +bool JingleSessionManager::WriteContent( cricket::SignalingProtocol protocol, const cricket::ContentDescription* content, XmlElement** elem, cricket::WriteError* error) { - const ChromotocolContentDescription* desc = - static_cast<const ChromotocolContentDescription*>(content); + const ContentDescription* desc = + static_cast<const ContentDescription*>(content); XmlElement* root = new XmlElement( QName(kChromotingXmlNamespace, kDescriptionTag), true); @@ -464,13 +464,15 @@ bool JingleChromotocolServer::WriteContent( return true; } -SessionDescription* JingleChromotocolServer::CreateSessionDescription( +SessionDescription* JingleSessionManager::CreateSessionDescription( const CandidateChromotocolConfig* config) { SessionDescription* desc = new SessionDescription(); - desc->AddContent(JingleChromotocolConnection::kChromotingContentName, + desc->AddContent(JingleSession::kChromotingContentName, kChromotingXmlNamespace, - new ChromotocolContentDescription(config)); + new ContentDescription(config)); return desc; } +} // namespace protocol + } // namespace remoting diff --git a/remoting/protocol/jingle_chromotocol_server.h b/remoting/protocol/jingle_session_manager.h index 84f7697..7241002 100644 --- a/remoting/protocol/jingle_chromotocol_server.h +++ b/remoting/protocol/jingle_session_manager.h @@ -2,16 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef REMOTING_PROTOCOL_JINGLE_CHROMOTOCOL_SERVER_H_ -#define REMOTING_PROTOCOL_JINGLE_CHROMOTOCOL_SERVER_H_ +#ifndef REMOTING_PROTOCOL_JINGLE_SESSION_MANAGER_H_ +#define REMOTING_PROTOCOL_JINGLE_SESSION_MANAGER_H_ #include <list> #include <string> #include "base/lock.h" #include "base/ref_counted.h" -#include "remoting/protocol/chromotocol_server.h" -#include "remoting/protocol/jingle_chromotocol_connection.h" +#include "remoting/protocol/jingle_session.h" +#include "remoting/protocol/session_manager.h" #include "third_party/libjingle/source/talk/p2p/base/session.h" #include "third_party/libjingle/source/talk/p2p/base/sessionclient.h" #include "third_party/libjingle/source/talk/p2p/base/sessiondescription.h" @@ -26,15 +26,16 @@ namespace remoting { class JingleThread; +namespace protocol { + // ContentDescription used for chromoting sessions. It simply wraps // CandidateChromotocolConfig. CandidateChromotocolConfig doesn't inherit // from ContentDescription to avoid dependency on libjingle in -// ChromotocolConnection interface. -class ChromotocolContentDescription : public cricket::ContentDescription { +// Chromotocol Session interface. +class ContentDescription : public cricket::ContentDescription { public: - explicit ChromotocolContentDescription( - const CandidateChromotocolConfig* config); - ~ChromotocolContentDescription(); + explicit ContentDescription(const CandidateChromotocolConfig* config); + ~ContentDescription(); const CandidateChromotocolConfig* config() const { return candidate_config_.get(); @@ -47,33 +48,33 @@ class ChromotocolContentDescription : public cricket::ContentDescription { // This class implements SessionClient for Chromoting sessions. It acts as a // server that accepts chromoting connections and can also make new connections // to other hosts. -class JingleChromotocolServer - : public ChromotocolServer, +class JingleSessionManager + : public protocol::SessionManager, public cricket::SessionClient { public: - explicit JingleChromotocolServer(JingleThread* jingle_thread); + explicit JingleSessionManager(remoting::JingleThread* jingle_thread); // Initializes the session client. Doesn't accept ownership of the // |session_manager|. Close() must be called _before_ the |session_manager| // is destroyed. virtual void Init(const std::string& local_jid, - cricket::SessionManager* session_manager, - IncomingConnectionCallback* incoming_connection_callback); + cricket::SessionManager* cricket_session_manager, + IncomingSessionCallback* incoming_session_callback); // ChromotocolServer interface. - virtual scoped_refptr<ChromotocolConnection> Connect( + virtual scoped_refptr<protocol::Session> Connect( const std::string& jid, CandidateChromotocolConfig* chromotocol_config, - ChromotocolConnection::StateChangeCallback* state_change_callback); + protocol::Session::StateChangeCallback* state_change_callback); virtual void Close(Task* closed_task); void set_allow_local_ips(bool allow_local_ips); protected: - virtual ~JingleChromotocolServer(); + virtual ~JingleSessionManager(); private: - friend class JingleChromotocolConnection; + friend class JingleSession; // The jingle thread used by this object. JingleThread* jingle_thread(); @@ -82,22 +83,22 @@ class JingleChromotocolServer MessageLoop* message_loop(); // Called by JingleChromotocolConnection when a new connection is initiated. - void AcceptConnection(JingleChromotocolConnection* connection, - cricket::Session* session); + void AcceptConnection(JingleSession* jingle_session, + cricket::Session* cricket_session); void DoConnect( - scoped_refptr<JingleChromotocolConnection> connection, + scoped_refptr<JingleSession> jingle_session, const std::string& jid, - ChromotocolConnection::StateChangeCallback* state_change_callback); + protocol::Session::StateChangeCallback* state_change_callback); - // Creates outgoing session description for an incoming connection. + // Creates outgoing session description for an incoming session. cricket::SessionDescription* CreateSessionDescription( const CandidateChromotocolConfig* config); // cricket::SessionClient interface. - virtual void OnSessionCreate(cricket::Session* session, + virtual void OnSessionCreate(cricket::Session* cricket_session, bool received_initiate); - virtual void OnSessionDestroy(cricket::Session* session); + virtual void OnSessionDestroy(cricket::Session* cricket_session); virtual bool ParseContent(cricket::SignalingProtocol protocol, const buzz::XmlElement* elem, @@ -110,17 +111,19 @@ class JingleChromotocolServer std::string local_jid_; JingleThread* jingle_thread_; - cricket::SessionManager* session_manager_; - scoped_ptr<IncomingConnectionCallback> incoming_connection_callback_; + cricket::SessionManager* cricket_session_manager_; + scoped_ptr<IncomingSessionCallback> incoming_session_callback_; bool allow_local_ips_; bool closed_; - std::list<scoped_refptr<JingleChromotocolConnection> > connections_; + std::list<scoped_refptr<JingleSession> > sessions_; - DISALLOW_COPY_AND_ASSIGN(JingleChromotocolServer); + DISALLOW_COPY_AND_ASSIGN(JingleSessionManager); }; +} // namespace protocol + } // namespace remoting -#endif // REMOTING_PROTOCOL_JINGLE_CHROMOTOCOL_SERVER_H_ +#endif // REMOTING_PROTOCOL_JINGLE_SESSION_MANAGER_H_ diff --git a/remoting/protocol/jingle_chromotocol_connection_unittest.cc b/remoting/protocol/jingle_session_unittest.cc index 2d0cb8e..eb02831 100644 --- a/remoting/protocol/jingle_chromotocol_connection_unittest.cc +++ b/remoting/protocol/jingle_session_unittest.cc @@ -9,8 +9,8 @@ #include "net/base/io_buffer.h" #include "net/base/net_errors.h" #include "net/socket/socket.h" -#include "remoting/protocol/jingle_chromotocol_connection.h" -#include "remoting/protocol/jingle_chromotocol_server.h" +#include "remoting/protocol/jingle_session.h" +#include "remoting/protocol/jingle_session_manager.h" #include "remoting/protocol/session_manager_pair.h" #include "remoting/jingle_glue/jingle_thread.h" #include "testing/gmock/include/gmock/gmock.h" @@ -27,13 +27,17 @@ using testing::SetArgumentPointee; using testing::WithArg; namespace remoting { -class JingleChromotocolConnectionTest; +namespace protocol { +class JingleSessionTest; +} // namespace protocol } // namespace remoting -DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::JingleChromotocolConnectionTest); +DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::protocol::JingleSessionTest); namespace remoting { +namespace protocol { + namespace { // Send 100 messages 1024 bytes each. UDP messages are sent with 10ms delay // between messages (about 1 second for 100 messages). @@ -43,29 +47,29 @@ const int kTestDataSize = kMessages * kMessageSize; const int kUdpWriteDelayMs = 10; } // namespace -class MockServerCallback { +class MockSessionManagerCallback { public: - MOCK_METHOD2(OnIncomingConnection, - void(ChromotocolConnection*, - ChromotocolServer::IncomingConnectionResponse*)); + MOCK_METHOD2(OnIncomingSession, + void(Session*, + SessionManager::IncomingSessionResponse*)); }; -class MockConnectionCallback { +class MockSessionCallback { public: - MOCK_METHOD1(OnStateChange, void(ChromotocolConnection::State)); + MOCK_METHOD1(OnStateChange, void(Session::State)); }; -class JingleChromotocolConnectionTest : public testing::Test { +class JingleSessionTest : public testing::Test { public: // Helper method to copy to set value of client_connection_. - void SetHostConnection(ChromotocolConnection* connection) { - DCHECK(connection); - host_connection_ = connection; - host_connection_->SetStateChangeCallback( + void SetHostSession(Session* session) { + DCHECK(session); + host_session_ = session; + host_session_->SetStateChangeCallback( NewCallback(&host_connection_callback_, - &MockConnectionCallback::OnStateChange)); + &MockSessionCallback::OnStateChange)); - connection->set_config(ChromotocolConfig::CreateDefault()); + session->set_config(ChromotocolConfig::CreateDefault()); } protected: @@ -74,15 +78,15 @@ class JingleChromotocolConnectionTest : public testing::Test { } virtual void TearDown() { - CloseConnections(); + CloseSessions(); if (host_server_) { host_server_->Close(NewRunnableFunction( - &JingleChromotocolConnectionTest::DoNothing)); + &JingleSessionTest::DoNothing)); } if (client_server_) { client_server_->Close(NewRunnableFunction( - &JingleChromotocolConnectionTest::DoNothing)); + &JingleSessionTest::DoNothing)); } thread_.Stop(); } @@ -91,18 +95,18 @@ class JingleChromotocolConnectionTest : public testing::Test { // SessionManagerPair must be initialized on the jingle thread. thread_.message_loop()->PostTask( FROM_HERE, NewRunnableMethod( - this, &JingleChromotocolConnectionTest::DoCreateServerPair)); + this, &JingleSessionTest::DoCreateServerPair)); SyncWithJingleThread(); } - void CloseConnections() { - if (host_connection_) { - host_connection_->Close(NewRunnableFunction( - &JingleChromotocolConnectionTest::DoNothing)); + void CloseSessions() { + if (host_session_) { + host_session_->Close(NewRunnableFunction( + &JingleSessionTest::DoNothing)); } - if (client_connection_) { - client_connection_->Close(NewRunnableFunction( - &JingleChromotocolConnectionTest::DoNothing)); + if (client_session_) { + client_session_->Close(NewRunnableFunction( + &JingleSessionTest::DoNothing)); } SyncWithJingleThread(); } @@ -110,61 +114,62 @@ class JingleChromotocolConnectionTest : public testing::Test { void DoCreateServerPair() { session_manager_pair_ = new SessionManagerPair(&thread_); session_manager_pair_->Init(); - host_server_ = new JingleChromotocolServer(&thread_); + host_server_ = new JingleSessionManager(&thread_); host_server_->set_allow_local_ips(true); host_server_->Init(SessionManagerPair::kHostJid, session_manager_pair_->host_session_manager(), NewCallback(&host_server_callback_, - &MockServerCallback::OnIncomingConnection)); - client_server_ = new JingleChromotocolServer(&thread_); + &MockSessionManagerCallback::OnIncomingSession)); + + client_server_ = new JingleSessionManager(&thread_); client_server_->set_allow_local_ips(true); client_server_->Init( SessionManagerPair::kClientJid, session_manager_pair_->client_session_manager(), NewCallback(&client_server_callback_, - &MockServerCallback::OnIncomingConnection)); + &MockSessionManagerCallback::OnIncomingSession)); } bool InitiateConnection() { - EXPECT_CALL(host_server_callback_, OnIncomingConnection(_, _)) + EXPECT_CALL(host_server_callback_, OnIncomingSession(_, _)) .WillOnce(DoAll( WithArg<0>(Invoke( - this, &JingleChromotocolConnectionTest::SetHostConnection)), - SetArgumentPointee<1>(ChromotocolServer::ACCEPT))); + this, &JingleSessionTest::SetHostSession)), + SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); base::WaitableEvent host_connected_event(false, false); EXPECT_CALL(host_connection_callback_, - OnStateChange(ChromotocolConnection::CONNECTING)) + OnStateChange(Session::CONNECTING)) .Times(1); EXPECT_CALL(host_connection_callback_, - OnStateChange(ChromotocolConnection::CONNECTED)) + OnStateChange(Session::CONNECTED)) .Times(1) .WillOnce(InvokeWithoutArgs(&host_connected_event, &base::WaitableEvent::Signal)); // Expect that the connection will be closed eventually. EXPECT_CALL(host_connection_callback_, - OnStateChange(ChromotocolConnection::CLOSED)) + OnStateChange(Session::CLOSED)) .Times(1); base::WaitableEvent client_connected_event(false, false); EXPECT_CALL(client_connection_callback_, - OnStateChange(ChromotocolConnection::CONNECTING)) + OnStateChange(Session::CONNECTING)) .Times(1); EXPECT_CALL(client_connection_callback_, - OnStateChange(ChromotocolConnection::CONNECTED)) + OnStateChange(Session::CONNECTED)) .Times(1) .WillOnce(InvokeWithoutArgs(&client_connected_event, &base::WaitableEvent::Signal)); // Expect that the connection will be closed eventually. EXPECT_CALL(client_connection_callback_, - OnStateChange(ChromotocolConnection::CLOSED)) + OnStateChange(Session::CLOSED)) .Times(1); - client_connection_ = client_server_->Connect( + client_session_ = client_server_->Connect( SessionManagerPair::kHostJid, CandidateChromotocolConfig::CreateDefault(), NewCallback(&client_connection_callback_, - &MockConnectionCallback::OnStateChange)); + &MockSessionCallback::OnStateChange)); return host_connected_event.TimedWait(base::TimeDelta::FromMilliseconds( TestTimeouts::action_max_timeout_ms())) && @@ -187,15 +192,15 @@ class JingleChromotocolConnectionTest : public testing::Test { JingleThread thread_; scoped_refptr<SessionManagerPair> session_manager_pair_; - scoped_refptr<JingleChromotocolServer> host_server_; - MockServerCallback host_server_callback_; - scoped_refptr<JingleChromotocolServer> client_server_; - MockServerCallback client_server_callback_; - - scoped_refptr<ChromotocolConnection> host_connection_; - MockConnectionCallback host_connection_callback_; - scoped_refptr<ChromotocolConnection> client_connection_; - MockConnectionCallback client_connection_callback_; + scoped_refptr<JingleSessionManager> host_server_; + MockSessionManagerCallback host_server_callback_; + scoped_refptr<JingleSessionManager> client_server_; + MockSessionManagerCallback client_server_callback_; + + scoped_refptr<Session> host_session_; + MockSessionCallback host_connection_callback_; + scoped_refptr<Session> client_session_; + MockSessionCallback client_connection_callback_; }; class ChannelTesterBase : public base::RefCountedThreadSafe<ChannelTesterBase> { @@ -209,11 +214,11 @@ class ChannelTesterBase : public base::RefCountedThreadSafe<ChannelTesterBase> { }; ChannelTesterBase(MessageLoop* message_loop, - ChromotocolConnection* host_connection, - ChromotocolConnection* client_connection) + Session* host_session, + Session* client_session) : message_loop_(message_loop), - host_connection_(host_connection), - client_connection_(client_connection), + host_session_(host_session), + client_session_(client_session), done_event_(true, false) { } @@ -234,8 +239,8 @@ class ChannelTesterBase : public base::RefCountedThreadSafe<ChannelTesterBase> { protected: void DoStart(ChannelType channel) { - socket_1_ = SelectChannel(host_connection_, channel); - socket_2_ = SelectChannel(client_connection_, channel); + socket_1_ = SelectChannel(host_session_, channel); + socket_2_ = SelectChannel(client_session_, channel); InitBuffers(); DoRead(); @@ -246,19 +251,19 @@ class ChannelTesterBase : public base::RefCountedThreadSafe<ChannelTesterBase> { virtual void DoWrite() = 0; virtual void DoRead() = 0; - net::Socket* SelectChannel(ChromotocolConnection* connection, + net::Socket* SelectChannel(Session* session, ChannelType channel) { switch (channel) { case CONTROL: - return connection->control_channel(); + return session->control_channel(); case EVENT: - return connection->event_channel(); + return session->event_channel(); case VIDEO: - return connection->video_channel(); + return session->video_channel(); case VIDEO_RTP: - return connection->video_rtp_channel(); + return session->video_rtp_channel(); case VIDEO_RTCP: - return connection->video_rtcp_channel(); + return session->video_rtcp_channel(); default: NOTREACHED(); return NULL; @@ -266,8 +271,8 @@ class ChannelTesterBase : public base::RefCountedThreadSafe<ChannelTesterBase> { } MessageLoop* message_loop_; - scoped_refptr<ChromotocolConnection> host_connection_; - scoped_refptr<ChromotocolConnection> client_connection_; + scoped_refptr<Session> host_session_; + scoped_refptr<Session> client_session_; net::Socket* socket_1_; net::Socket* socket_2_; base::WaitableEvent done_event_; @@ -276,9 +281,9 @@ class ChannelTesterBase : public base::RefCountedThreadSafe<ChannelTesterBase> { class TCPChannelTester : public ChannelTesterBase { public: TCPChannelTester(MessageLoop* message_loop, - ChromotocolConnection* host_connection, - ChromotocolConnection* client_connection) - : ChannelTesterBase(message_loop, host_connection, client_connection), + Session* host_session, + Session* client_session) + : ChannelTesterBase(message_loop, host_session, client_session), ALLOW_THIS_IN_INITIALIZER_LIST( write_cb_(this, &TCPChannelTester::OnWritten)), ALLOW_THIS_IN_INITIALIZER_LIST( @@ -385,9 +390,9 @@ class TCPChannelTester : public ChannelTesterBase { class UDPChannelTester : public ChannelTesterBase { public: UDPChannelTester(MessageLoop* message_loop, - ChromotocolConnection* host_connection, - ChromotocolConnection* client_connection) - : ChannelTesterBase(message_loop, host_connection, client_connection), + Session* host_session, + Session* client_session) + : ChannelTesterBase(message_loop, host_session, client_session), ALLOW_THIS_IN_INITIALIZER_LIST( write_cb_(this, &UDPChannelTester::OnWritten)), ALLOW_THIS_IN_INITIALIZER_LIST( @@ -509,33 +514,33 @@ class UDPChannelTester : public ChannelTesterBase { }; // Verify that we can create and destory server objects without a connection. -TEST_F(JingleChromotocolConnectionTest, CreateAndDestoy) { +TEST_F(JingleSessionTest, CreateAndDestoy) { CreateServerPair(); } -// Verify that incoming connection can be rejected, and that the status +// Verify that incoming session can be rejected, and that the status // of the connection is set to CLOSED in this case. -TEST_F(JingleChromotocolConnectionTest, RejectConnection) { +TEST_F(JingleSessionTest, RejectConnection) { CreateServerPair(); - // Reject incoming connection. - EXPECT_CALL(host_server_callback_, OnIncomingConnection(_, _)) - .WillOnce(SetArgumentPointee<1>(ChromotocolServer::DECLINE)); + // Reject incoming session. + EXPECT_CALL(host_server_callback_, OnIncomingSession(_, _)) + .WillOnce(SetArgumentPointee<1>(protocol::SessionManager::DECLINE)); base::WaitableEvent done_event(false, false); EXPECT_CALL(client_connection_callback_, - OnStateChange(ChromotocolConnection::CONNECTING)) + OnStateChange(Session::CONNECTING)) .Times(1); EXPECT_CALL(client_connection_callback_, - OnStateChange(ChromotocolConnection::CLOSED)) + OnStateChange(Session::CLOSED)) .Times(1) .WillOnce(InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)); - client_connection_ = client_server_->Connect( + client_session_ = client_server_->Connect( SessionManagerPair::kHostJid, CandidateChromotocolConfig::CreateDefault(), NewCallback(&client_connection_callback_, - &MockConnectionCallback::OnStateChange)); + &MockSessionCallback::OnStateChange)); ASSERT_TRUE( done_event.TimedWait(base::TimeDelta::FromMilliseconds( @@ -543,70 +548,72 @@ TEST_F(JingleChromotocolConnectionTest, RejectConnection) { } // Verify that we can connect two endpoints. -TEST_F(JingleChromotocolConnectionTest, Connect) { +TEST_F(JingleSessionTest, Connect) { CreateServerPair(); ASSERT_TRUE(InitiateConnection()); } // Verify that data can be transmitted over the event channel. -TEST_F(JingleChromotocolConnectionTest, TestControlChannel) { +TEST_F(JingleSessionTest, TestControlChannel) { CreateServerPair(); ASSERT_TRUE(InitiateConnection()); scoped_refptr<TCPChannelTester> tester( - new TCPChannelTester(thread_.message_loop(), host_connection_, - client_connection_)); + new TCPChannelTester(thread_.message_loop(), host_session_, + client_session_)); tester->Start(ChannelTesterBase::CONTROL); ASSERT_TRUE(tester->WaitFinished()); tester->CheckResults(); // Connections must be closed while |tester| still exists. - CloseConnections(); + CloseSessions(); } // Verify that data can be transmitted over the video channel. -TEST_F(JingleChromotocolConnectionTest, TestVideoChannel) { +TEST_F(JingleSessionTest, TestVideoChannel) { CreateServerPair(); ASSERT_TRUE(InitiateConnection()); scoped_refptr<TCPChannelTester> tester( - new TCPChannelTester(thread_.message_loop(), host_connection_, - client_connection_)); + new TCPChannelTester(thread_.message_loop(), host_session_, + client_session_)); tester->Start(ChannelTesterBase::VIDEO); ASSERT_TRUE(tester->WaitFinished()); tester->CheckResults(); // Connections must be closed while |tester| still exists. - CloseConnections(); + CloseSessions(); } // Verify that data can be transmitted over the event channel. -TEST_F(JingleChromotocolConnectionTest, TestEventChannel) { +TEST_F(JingleSessionTest, TestEventChannel) { CreateServerPair(); ASSERT_TRUE(InitiateConnection()); scoped_refptr<TCPChannelTester> tester( - new TCPChannelTester(thread_.message_loop(), host_connection_, - client_connection_)); + new TCPChannelTester(thread_.message_loop(), host_session_, + client_session_)); tester->Start(ChannelTesterBase::EVENT); ASSERT_TRUE(tester->WaitFinished()); tester->CheckResults(); // Connections must be closed while |tester| still exists. - CloseConnections(); + CloseSessions(); } // Verify that data can be transmitted over the video RTP channel. -TEST_F(JingleChromotocolConnectionTest, TestVideoRtpChannel) { +TEST_F(JingleSessionTest, TestVideoRtpChannel) { CreateServerPair(); ASSERT_TRUE(InitiateConnection()); scoped_refptr<UDPChannelTester> tester( - new UDPChannelTester(thread_.message_loop(), host_connection_, - client_connection_)); + new UDPChannelTester(thread_.message_loop(), host_session_, + client_session_)); tester->Start(ChannelTesterBase::VIDEO_RTP); ASSERT_TRUE(tester->WaitFinished()); tester->CheckResults(); // Connections must be closed while |tester| still exists. - CloseConnections(); + CloseSessions(); } +} // namespace protocol + } // namespace remoting diff --git a/remoting/protocol/message_reader.cc b/remoting/protocol/message_reader.cc index 79e2b7a..be07f86 100644 --- a/remoting/protocol/message_reader.cc +++ b/remoting/protocol/message_reader.cc @@ -10,7 +10,6 @@ #include "net/socket/socket.h" #include "remoting/base/multiple_array_input_stream.h" #include "remoting/proto/internal.pb.h" -#include "remoting/protocol/chromotocol_connection.h" namespace remoting { diff --git a/remoting/protocol/protobuf_video_reader.cc b/remoting/protocol/protobuf_video_reader.cc index 70ac3cf..e809bd9 100644 --- a/remoting/protocol/protobuf_video_reader.cc +++ b/remoting/protocol/protobuf_video_reader.cc @@ -5,16 +5,16 @@ #include "remoting/protocol/protobuf_video_reader.h" #include "base/task.h" -#include "remoting/protocol/chromotocol_connection.h" +#include "remoting/protocol/session.h" namespace remoting { ProtobufVideoReader::ProtobufVideoReader() { } ProtobufVideoReader::~ProtobufVideoReader() { } -void ProtobufVideoReader::Init(ChromotocolConnection* connection, +void ProtobufVideoReader::Init(protocol::Session* session, VideoStub* video_stub) { - reader_.Init<VideoPacket>(connection->video_channel(), + reader_.Init<VideoPacket>(session->video_channel(), NewCallback(this, &ProtobufVideoReader::OnNewData)); video_stub_ = video_stub; } diff --git a/remoting/protocol/protobuf_video_reader.h b/remoting/protocol/protobuf_video_reader.h index cad98c5..fab8f44 100644 --- a/remoting/protocol/protobuf_video_reader.h +++ b/remoting/protocol/protobuf_video_reader.h @@ -10,13 +10,17 @@ namespace remoting { +namespace protocol { +class Session; +} // namespace protocol + class ProtobufVideoReader : public VideoReader { public: ProtobufVideoReader(); virtual ~ProtobufVideoReader(); // VideoReader interface. - virtual void Init(ChromotocolConnection* connection, VideoStub* video_stub); + virtual void Init(protocol::Session* session, VideoStub* video_stub); virtual void Close(); private: diff --git a/remoting/protocol/protobuf_video_writer.cc b/remoting/protocol/protobuf_video_writer.cc index 96b4e34..b4d6999 100644 --- a/remoting/protocol/protobuf_video_writer.cc +++ b/remoting/protocol/protobuf_video_writer.cc @@ -4,8 +4,8 @@ #include "remoting/protocol/protobuf_video_writer.h" -#include "remoting/protocol/chromotocol_connection.h" #include "remoting/protocol/rtp_writer.h" +#include "remoting/protocol/session.h" #include "remoting/protocol/util.h" namespace remoting { @@ -14,10 +14,10 @@ ProtobufVideoWriter::ProtobufVideoWriter() { } ProtobufVideoWriter::~ProtobufVideoWriter() { } -void ProtobufVideoWriter::Init(ChromotocolConnection* connection) { +void ProtobufVideoWriter::Init(protocol::Session* session) { buffered_writer_ = new BufferedSocketWriter(); // TODO(sergeyu): Provide WriteFailedCallback for the buffered writer. - buffered_writer_->Init(connection->video_channel(), NULL); + buffered_writer_->Init(session->video_channel(), NULL); } void ProtobufVideoWriter::SendPacket(const VideoPacket& packet) { diff --git a/remoting/protocol/protobuf_video_writer.h b/remoting/protocol/protobuf_video_writer.h index 02d3034..c1ba183 100644 --- a/remoting/protocol/protobuf_video_writer.h +++ b/remoting/protocol/protobuf_video_writer.h @@ -10,6 +10,10 @@ namespace remoting { +namespace protocol { +class Session; +} // namespace protocol + class BufferedSocketWriter; class ProtobufVideoWriter : public VideoWriter { @@ -18,7 +22,7 @@ class ProtobufVideoWriter : public VideoWriter { virtual ~ProtobufVideoWriter(); // VideoWriter interface. - virtual void Init(ChromotocolConnection* connection); + virtual void Init(protocol::Session* session); virtual void SendPacket(const VideoPacket& packet); virtual int GetPendingPackets(); virtual void Close(); diff --git a/remoting/protocol/protocol_test_client.cc b/remoting/protocol/protocol_test_client.cc index b28e96d..3ea145a 100644 --- a/remoting/protocol/protocol_test_client.cc +++ b/remoting/protocol/protocol_test_client.cc @@ -24,12 +24,14 @@ extern "C" { #include "remoting/base/constants.h" #include "remoting/jingle_glue/jingle_client.h" #include "remoting/jingle_glue/jingle_thread.h" -#include "remoting/protocol/jingle_chromotocol_server.h" +#include "remoting/protocol/jingle_session_manager.h" using remoting::kChromotingTokenServiceName; namespace remoting { +namespace protocol { + namespace { const int kBufferSize = 4096; } // namespace @@ -42,7 +44,7 @@ class ProtocolTestConnection ProtocolTestConnection(ProtocolTestClient* client, MessageLoop* message_loop) : client_(client), message_loop_(message_loop), - connection_(NULL), + session_(NULL), ALLOW_THIS_IN_INITIALIZER_LIST( write_cb_(this, &ProtocolTestConnection::OnWritten)), pending_write_(false), @@ -51,13 +53,13 @@ class ProtocolTestConnection closed_event_(true, false) { } - void Init(ChromotocolConnection* connection); + void Init(Session* session); void Write(const std::string& str); void Read(); void Close(); - // ChromotocolConnection::Callback interface. - virtual void OnStateChange(ChromotocolConnection::State state); + // Session::Callback interface. + virtual void OnStateChange(Session::State state); private: void DoWrite(scoped_refptr<net::IOBuffer> buf, int size); void DoRead(); @@ -71,7 +73,7 @@ class ProtocolTestConnection ProtocolTestClient* client_; MessageLoop* message_loop_; - scoped_refptr<ChromotocolConnection> connection_; + scoped_refptr<Session> session_; net::CompletionCallbackImpl<ProtocolTestConnection> write_cb_; bool pending_write_; net::CompletionCallbackImpl<ProtocolTestConnection> read_cb_; @@ -97,10 +99,10 @@ class ProtocolTestClient // JingleClient::Callback interface. virtual void OnStateChange(JingleClient* client, JingleClient::State state); - // callback for JingleChromotocolServer interface. - virtual void OnNewChromotocolConnection( - ChromotocolConnection* connection, - ChromotocolServer::IncomingConnectionResponse* response); + // callback for JingleSessionManager interface. + virtual void OnNewSession( + Session* session, + SessionManager::IncomingSessionResponse* response); private: typedef std::list<scoped_refptr<ProtocolTestConnection> > ConnectionsList; @@ -110,15 +112,15 @@ class ProtocolTestClient std::string host_jid_; scoped_refptr<JingleClient> client_; - scoped_refptr<JingleChromotocolServer> server_; + scoped_refptr<JingleSessionManager> session_manager_; ConnectionsList connections_; Lock connections_lock_; base::WaitableEvent closed_event_; }; -void ProtocolTestConnection::Init(ChromotocolConnection* connection) { - connection_ = connection; +void ProtocolTestConnection::Init(Session* session) { + session_ = session; } void ProtocolTestConnection::Write(const std::string& str) { @@ -139,7 +141,7 @@ void ProtocolTestConnection::DoWrite( return; } - net::Socket* channel = connection_->event_channel(); + net::Socket* channel = session_->event_channel(); if (channel != NULL) { int result = channel->Write(buf, size, &write_cb_); if (result < 0) { @@ -162,7 +164,7 @@ void ProtocolTestConnection::Read() { void ProtocolTestConnection::DoRead() { read_buffer_ = new net::IOBuffer(kBufferSize); while (true) { - int result = connection_->event_channel()->Read( + int result = session_->event_channel()->Read( read_buffer_, kBufferSize, &read_cb_); if (result < 0) { if (result != net::ERR_IO_PENDING) @@ -175,7 +177,7 @@ void ProtocolTestConnection::DoRead() { } void ProtocolTestConnection::Close() { - connection_->Close( + session_->Close( NewRunnableMethod(this, &ProtocolTestConnection::OnFinishedClosing)); closed_event_.Wait(); } @@ -184,14 +186,13 @@ void ProtocolTestConnection::OnFinishedClosing() { closed_event_.Signal(); } -void ProtocolTestConnection::OnStateChange( - ChromotocolConnection::State state) { - LOG(INFO) << "State of " << connection_->jid() << " changed to " << state; - if (state == ChromotocolConnection::CONNECTED) { +void ProtocolTestConnection::OnStateChange(Session::State state) { + LOG(INFO) << "State of " << session_->jid() << " changed to " << state; + if (state == Session::CONNECTED) { // Start reading after we've connected. Read(); - } else if (state == ChromotocolConnection::CLOSED) { - std::cerr << "Connection to " << connection_->jid() + } else if (state == Session::CLOSED) { + std::cerr << "Connection to " << session_->jid() << " closed" << std::endl; client_->OnConnectionClosed(this); } @@ -212,7 +213,7 @@ void ProtocolTestConnection::HandleReadResult(int result) { if (result > 0) { std::string str(reinterpret_cast<const char*>(read_buffer_->data()), result); - std::cout << "(" << connection_->jid() << "): " << str << std::endl; + std::cout << "(" << session_->jid() << "): " << str << std::endl; } else { LOG(ERROR) << "Read() returned error " << result; } @@ -226,7 +227,7 @@ void ProtocolTestClient::Run(const std::string& username, client_ = new JingleClient(&jingle_thread); client_->Init(username, auth_token, kChromotingTokenServiceName, this); - server_ = new JingleChromotocolServer(&jingle_thread); + session_manager_ = new JingleSessionManager(&jingle_thread); host_jid_ = host_jid; @@ -253,8 +254,8 @@ void ProtocolTestClient::Run(const std::string& username, connections_.pop_front(); } - if (server_) { - server_->Close( + if (session_manager_) { + session_manager_->Close( NewRunnableMethod(this, &ProtocolTestClient::OnFinishedClosing)); closed_event_.Wait(); } @@ -276,15 +277,15 @@ void ProtocolTestClient::OnStateChange( if (state == JingleClient::CONNECTED) { std::cerr << "Connected as " << client->GetFullJid() << std::endl; - server_->Init( + session_manager_->Init( client_->GetFullJid(), client_->session_manager(), - NewCallback(this, &ProtocolTestClient::OnNewChromotocolConnection)); - server_->set_allow_local_ips(true); + NewCallback(this, &ProtocolTestClient::OnNewSession)); + session_manager_->set_allow_local_ips(true); if (host_jid_ != "") { ProtocolTestConnection* connection = new ProtocolTestConnection(this, client_->message_loop()); - connection->Init(server_->Connect( + connection->Init(session_manager_->Connect( host_jid_, CandidateChromotocolConfig::CreateDefault(), NewCallback(connection, &ProtocolTestConnection::OnStateChange))); @@ -295,19 +296,19 @@ void ProtocolTestClient::OnStateChange( } } -void ProtocolTestClient::OnNewChromotocolConnection( - ChromotocolConnection* connection, - ChromotocolServer::IncomingConnectionResponse* response) { - std::cerr << "Accepting connection from " << connection->jid() << std::endl; +void ProtocolTestClient::OnNewSession( + Session* session, + SessionManager::IncomingSessionResponse* response) { + std::cerr << "Accepting connection from " << session->jid() << std::endl; - connection->set_config(ChromotocolConfig::CreateDefault()); - *response = ChromotocolServer::ACCEPT; + session->set_config(ChromotocolConfig::CreateDefault()); + *response = SessionManager::ACCEPT; ProtocolTestConnection* test_connection = new ProtocolTestConnection(this, client_->message_loop()); - connection->SetStateChangeCallback( + session->SetStateChangeCallback( NewCallback(test_connection, &ProtocolTestConnection::OnStateChange)); - test_connection->Init(connection); + test_connection->Init(session); AutoLock auto_lock(connections_lock_); connections_.push_back(make_scoped_refptr(test_connection)); } @@ -329,9 +330,11 @@ void ProtocolTestClient::DestroyConnection( } } +} // namespace protocol + } // namespace remoting -using remoting::ProtocolTestClient; +using remoting::protocol::ProtocolTestClient; void usage(char* command) { std::cerr << "Usage: " << command << "--username=<username>" << std::endl diff --git a/remoting/protocol/rtp_video_reader.cc b/remoting/protocol/rtp_video_reader.cc index 8de6d91..8f30613 100644 --- a/remoting/protocol/rtp_video_reader.cc +++ b/remoting/protocol/rtp_video_reader.cc @@ -5,16 +5,16 @@ #include "remoting/protocol/rtp_video_reader.h" #include "base/task.h" -#include "remoting/protocol/chromotocol_connection.h" +#include "remoting/protocol/session.h" namespace remoting { RtpVideoReader::RtpVideoReader() { } RtpVideoReader::~RtpVideoReader() { } -void RtpVideoReader::Init(ChromotocolConnection* connection, +void RtpVideoReader::Init(protocol::Session* session, VideoStub* video_stub) { - rtp_reader_.Init(connection->video_rtp_channel(), + rtp_reader_.Init(session->video_rtp_channel(), NewCallback(this, &RtpVideoReader::OnRtpPacket)); video_stub_ = video_stub; } diff --git a/remoting/protocol/rtp_video_reader.h b/remoting/protocol/rtp_video_reader.h index d7f526e..39a8c33 100644 --- a/remoting/protocol/rtp_video_reader.h +++ b/remoting/protocol/rtp_video_reader.h @@ -10,13 +10,17 @@ namespace remoting { +namespace protocol { +class Session; +} // namespace protocol + class RtpVideoReader : public VideoReader { public: RtpVideoReader(); virtual ~RtpVideoReader(); // VideoReader interface. - virtual void Init(ChromotocolConnection* connection, VideoStub* video_stub); + virtual void Init(protocol::Session* session, VideoStub* video_stub); virtual void Close(); private: diff --git a/remoting/protocol/rtp_video_writer.cc b/remoting/protocol/rtp_video_writer.cc index 6307c0c..5fb645c 100644 --- a/remoting/protocol/rtp_video_writer.cc +++ b/remoting/protocol/rtp_video_writer.cc @@ -4,7 +4,7 @@ #include "remoting/protocol/rtp_video_writer.h" -#include "remoting/protocol/chromotocol_connection.h" +#include "remoting/protocol/session.h" #include "remoting/protocol/rtp_writer.h" namespace remoting { @@ -13,9 +13,9 @@ RtpVideoWriter::RtpVideoWriter() { } RtpVideoWriter::~RtpVideoWriter() { } -void RtpVideoWriter::Init(ChromotocolConnection* connection) { - rtp_writer_.Init(connection->video_rtp_channel(), - connection->video_rtcp_channel()); +void RtpVideoWriter::Init(protocol::Session* session) { + rtp_writer_.Init(session->video_rtp_channel(), + session->video_rtcp_channel()); } void RtpVideoWriter::SendPacket(const VideoPacket& packet) { diff --git a/remoting/protocol/rtp_video_writer.h b/remoting/protocol/rtp_video_writer.h index 4084576..a0bd3b9 100644 --- a/remoting/protocol/rtp_video_writer.h +++ b/remoting/protocol/rtp_video_writer.h @@ -10,13 +10,17 @@ namespace remoting { +namespace protocol { +class Session; +} // namespace protocol + class RtpVideoWriter : public VideoWriter { public: RtpVideoWriter(); virtual ~RtpVideoWriter(); // VideoWriter interface. - virtual void Init(ChromotocolConnection* connection); + virtual void Init(protocol::Session* session); virtual void SendPacket(const VideoPacket& packet); virtual int GetPendingPackets(); virtual void Close(); diff --git a/remoting/protocol/chromotocol_connection.h b/remoting/protocol/session.h index bbb4586..9319fef 100644 --- a/remoting/protocol/chromotocol_connection.h +++ b/remoting/protocol/session.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef REMOTING_PROTOCOL_CHROMOTOCOL_CONNECTION_H_ -#define REMOTING_PROTOCOL_CHROMOTOCOL_CONNECTION_H_ +#ifndef REMOTING_PROTOCOL_SESSION_H_ +#define REMOTING_PROTOCOL_SESSION_H_ #include <string> @@ -19,12 +19,14 @@ class Socket; namespace remoting { +namespace protocol { + // Generic interface for Chromotocol connection used by both client and host. // Provides access to the connection channels, but doesn't depend on the // protocol used for each channel. // TODO(sergeyu): Remove refcounting? -class ChromotocolConnection - : public base::RefCountedThreadSafe<ChromotocolConnection> { +class Session + : public base::RefCountedThreadSafe<Session> { public: enum State { INITIALIZING, @@ -80,15 +82,17 @@ class ChromotocolConnection virtual void Close(Task* closed_task) = 0; protected: - friend class base::RefCountedThreadSafe<ChromotocolConnection>; + friend class base::RefCountedThreadSafe<Session>; - ChromotocolConnection() { } - virtual ~ChromotocolConnection() { } + Session() { } + virtual ~Session() { } private: - DISALLOW_COPY_AND_ASSIGN(ChromotocolConnection); + DISALLOW_COPY_AND_ASSIGN(Session); }; +} // namespace protocol + } // namespace remoting -#endif // REMOTING_PROTOCOL_CHROMOTOCOL_CONNECTION_H_ +#endif // REMOTING_PROTOCOL_SESSION_H_ diff --git a/remoting/protocol/session_manager.h b/remoting/protocol/session_manager.h new file mode 100644 index 0000000..ab8cdcf --- /dev/null +++ b/remoting/protocol/session_manager.h @@ -0,0 +1,106 @@ +// Copyright (c) 2010 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 purprose of SessionManager is to facilitate creation of chromotocol +// sessions. Both host and client use it to establish chromotocol +// sessions. JingleChromotocolServer implements this inteface using +// libjingle. +// +// OUTGOING SESSIONS +// Connect() must be used to create new session to a remote host. The +// returned sessionion is initially in INITIALIZING state. Later state is +// changed to CONNECTED if the session is accepted by the host or CLOSED +// if the session is rejected. +// +// INCOMING SESSIONS +// The IncomingSessionCallback is called when a client attempts to connect. +// The callback function decides whether the session should be accepted or +// rejected. +// +// SESSION OWNERSHIP AND SHUTDOWN +// SessionManager owns all Chromotocol Session it creates. The server +// must not be closed while sessions created by the server are still in use. +// When shutting down the Close() method for the sessionion and the server +// objects must be called in the following order: Session, +// SessionManager, JingleClient. The same order must be followed in the case +// of rejected and failed sessions. +// +// PROTOCOL VERSION NEGOTIATION +// When client connects to a host it sends a session-initiate stanza with list +// of supported configurations for each channel. If the host decides to accept +// session, then it selects configuration that is supported by both sides +// and then replies with the session-accept stanza that contans selected +// configuration. The configuration specified in the session-accept is used +// for the session. +// +// The CandidateChromotocolConfig class represents list of configurations +// supported by an endpoint. The |chromotocol_config| argument in the Connect() +// specifies configuration supported on the client side. When the host receives +// session-initiate stanza, the IncomingSessionCallback is called. The +// configuration sent in the session-intiate staza is available via +// ChromotocolConnnection::candidate_config(). If an incoming session is +// being accepted then the IncomingSessionCallback callback function must +// select session configuration and then set it with Session::set_config(). + +#ifndef REMOTING_PROTOCOL_SESSION_MANAGER_H_ +#define REMOTING_PROTOCOL_SESSION_MANAGER_H_ + +#include <string> + +#include "base/callback.h" +#include "base/ref_counted.h" +#include "remoting/protocol/session.h" + +class Task; + +namespace remoting { + +namespace protocol { + +// Generic interface for Chromoting session manager. +class SessionManager : public base::RefCountedThreadSafe<SessionManager> { + public: + enum IncomingSessionResponse { + ACCEPT, + INCOMPATIBLE, + DECLINE, + }; + + // IncomingSessionCallback is called when a new session is received. If + // the callback decides to accept the session it should set the second + // argument to ACCEPT. Otherwise it should set it to DECLINE, or + // INCOMPATIBLE. INCOMPATIBLE indicates that the session has incompatible + // configuration, and cannot be accepted. + // If the callback accepts session then it must also set configuration + // for the new session using Session::set_config(). + typedef Callback2<Session*, IncomingSessionResponse*>::Type + IncomingSessionCallback; + + // Initializes session to the host |jid|. Ownership of the + // |chromotocol_config| is passed to the new session. + virtual scoped_refptr<Session> Connect( + const std::string& jid, + CandidateChromotocolConfig* chromotocol_config, + Session::StateChangeCallback* state_change_callback) = 0; + + // Close session manager and all current sessions. |close_task| is executed + // after the session client is actually closed. No callbacks are called after + // |closed_task| is executed. + virtual void Close(Task* closed_task) = 0; + + protected: + friend class base::RefCountedThreadSafe<SessionManager>; + + SessionManager() { } + virtual ~SessionManager() { } + + private: + DISALLOW_COPY_AND_ASSIGN(SessionManager); +}; + +} // namespace protocol + +} // namespace remoting + +#endif // REMOTING_PROTOCOL_SESSION_MANAGER_H_ diff --git a/remoting/protocol/stream_writer.cc b/remoting/protocol/stream_writer.cc index 9d1f2a7..2ed9121 100644 --- a/remoting/protocol/stream_writer.cc +++ b/remoting/protocol/stream_writer.cc @@ -6,7 +6,6 @@ #include "base/message_loop.h" #include "remoting/protocol/buffered_socket_writer.h" -#include "remoting/protocol/chromotocol_connection.h" #include "remoting/protocol/util.h" namespace remoting { diff --git a/remoting/protocol/video_reader.h b/remoting/protocol/video_reader.h index ca39619..0c8ef87 100644 --- a/remoting/protocol/video_reader.h +++ b/remoting/protocol/video_reader.h @@ -14,6 +14,10 @@ namespace remoting { +namespace protocol { +class Session; +} // namespace protocol + class ChromotocolConfig; class ChromotocolConnection; @@ -25,7 +29,7 @@ class VideoReader { // Initializies the reader. Doesn't take ownership of either |connection| // or |video_stub|. - virtual void Init(ChromotocolConnection* connection, + virtual void Init(protocol::Session* session, VideoStub* video_stub) = 0; // Closes the reader. The stub should not be called after Close(). diff --git a/remoting/protocol/video_writer.h b/remoting/protocol/video_writer.h index 9c98a8e..49bdeb6 100644 --- a/remoting/protocol/video_writer.h +++ b/remoting/protocol/video_writer.h @@ -15,6 +15,10 @@ namespace remoting { +namespace protocol { +class Session; +} // namespace protocol + class ChromotocolConfig; class ChromotocolConnection; @@ -26,7 +30,7 @@ class VideoWriter { static VideoWriter* Create(const ChromotocolConfig* config); // Initializes the writer. - virtual void Init(ChromotocolConnection* connection) = 0; + virtual void Init(protocol::Session* session) = 0; // Sends the |packet|. virtual void SendPacket(const VideoPacket& packet) = 0; |