diff options
Diffstat (limited to 'remoting/protocol')
13 files changed, 387 insertions, 331 deletions
diff --git a/remoting/protocol/chromoting_server.h b/remoting/protocol/chromoting_server.h deleted file mode 100644 index c378c8b..0000000 --- a/remoting/protocol/chromoting_server.h +++ /dev/null @@ -1,58 +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. - -#ifndef REMOTING_PROTOCOL_CHROMOTING_SERVER_H_ -#define REMOTING_PROTOCOL_CHROMOTING_SERVER_H_ - -#include <string> - -#include "base/callback.h" -#include "base/ref_counted.h" -#include "remoting/protocol/chromoting_connection.h" - -class Task; - -namespace remoting { - -// Generic interface for Chromoting server. -// TODO(sergeyu): Rename to ChromotocolServer. -// TODO(sergeyu): Add more documentation on how this interface is used. -class ChromotingServer : public base::RefCountedThreadSafe<ChromotingServer> { - public: - enum NewConnectionResponse { - ACCEPT, - INCOMPATIBLE, - DECLINE, - }; - - // NewConnectionCallback 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 ChromotingConnection::set_config(). - typedef Callback2<ChromotingConnection*, NewConnectionResponse*>::Type - NewConnectionCallback; - - // Initializes connection to the host |jid|. Ownership of the - // |chromotocol_config| is passed to the new connection. - virtual scoped_refptr<ChromotingConnection> Connect( - const std::string& jid, - CandidateChromotocolConfig* chromotocol_config, - ChromotingConnection::StateChangeCallback* state_change_callback) = 0; - - // Close connection. |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<ChromotingServer>; - virtual ~ChromotingServer() { } -}; - -} // namespace remoting - -#endif // REMOTING_PROTOCOL_CHROMOTING_SERVER_H_ diff --git a/remoting/protocol/chromoting_connection.h b/remoting/protocol/chromotocol_connection.h index cfc8d3d7..bbb4586 100644 --- a/remoting/protocol/chromoting_connection.h +++ b/remoting/protocol/chromotocol_connection.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_CHROMOTING_CONNECTION_H_ -#define REMOTING_PROTOCOL_CHROMOTING_CONNECTION_H_ +#ifndef REMOTING_PROTOCOL_CHROMOTOCOL_CONNECTION_H_ +#define REMOTING_PROTOCOL_CHROMOTOCOL_CONNECTION_H_ #include <string> @@ -19,13 +19,12 @@ class Socket; namespace remoting { -// Generic interface for Chromoting connection used by both client and host. +// 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? -// TODO(sergeyu): Rename to ChromotocolConnection. -class ChromotingConnection - : public base::RefCountedThreadSafe<ChromotingConnection> { +class ChromotocolConnection + : public base::RefCountedThreadSafe<ChromotocolConnection> { public: enum State { INITIALIZING, @@ -42,15 +41,15 @@ class ChromotingConnection virtual void SetStateChangeCallback(StateChangeCallback* callback) = 0; // Reliable PseudoTCP channels for this connection. - virtual net::Socket* GetControlChannel() = 0; - virtual net::Socket* GetEventChannel() = 0; + virtual net::Socket* control_channel() = 0; + virtual net::Socket* event_channel() = 0; // TODO(sergeyu): Remove VideoChannel, and use RTP channels instead. - virtual net::Socket* GetVideoChannel() = 0; + virtual net::Socket* video_channel() = 0; // Unreliable channels for this connection. - virtual net::Socket* GetVideoRtpChannel() = 0; - virtual net::Socket* GetVideoRtcpChannel() = 0; + virtual net::Socket* video_rtp_channel() = 0; + virtual net::Socket* video_rtcp_channel() = 0; // TODO(sergeyu): Make it possible to create/destroy additional channels // on-fly? @@ -72,8 +71,8 @@ class ChromotingConnection // Set protocol configuration for an incoming session. Must be called // on the host before the connection is accepted, from - // ChromotingServer::NewConnectionCallback. Ownership of |config| is given - // to the connection. + // ChromotocolServer::IncomingConnectionCallback. Ownership of |config| is + // given to the connection. virtual void set_config(const ChromotocolConfig* config) = 0; // Closes connection. Callbacks are guaranteed not to be called after @@ -81,10 +80,15 @@ class ChromotingConnection virtual void Close(Task* closed_task) = 0; protected: - friend class base::RefCountedThreadSafe<ChromotingConnection>; - virtual ~ChromotingConnection() { } + friend class base::RefCountedThreadSafe<ChromotocolConnection>; + + ChromotocolConnection() { } + virtual ~ChromotocolConnection() { } + + private: + DISALLOW_COPY_AND_ASSIGN(ChromotocolConnection); }; } // namespace remoting -#endif // REMOTING_PROTOCOL_CHROMOTING_CONNECTION_H_ +#endif // REMOTING_PROTOCOL_CHROMOTOCOL_CONNECTION_H_ diff --git a/remoting/protocol/chromotocol_server.h b/remoting/protocol/chromotocol_server.h new file mode 100644 index 0000000..3f7f494 --- /dev/null +++ b/remoting/protocol/chromotocol_server.h @@ -0,0 +1,103 @@ +// 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_connection.cc index e0bb28e..3288b2a 100644 --- a/remoting/protocol/fake_connection.cc +++ b/remoting/protocol/fake_connection.cc @@ -69,61 +69,63 @@ bool FakeSocket::SetSendBufferSize(int32 size) { return false; } -FakeChromotingConnection::FakeChromotingConnection() +FakeChromotocolConnection::FakeChromotocolConnection() : candidate_config_(CandidateChromotocolConfig::CreateDefault()), config_(ChromotocolConfig::CreateDefault()), message_loop_(NULL), jid_(kTestJid) { } -FakeChromotingConnection::~FakeChromotingConnection() { } +FakeChromotocolConnection::~FakeChromotocolConnection() { } -void FakeChromotingConnection::SetStateChangeCallback( +void FakeChromotocolConnection::SetStateChangeCallback( StateChangeCallback* callback) { callback_.reset(callback); } -FakeSocket* FakeChromotingConnection::GetControlChannel() { +FakeSocket* FakeChromotocolConnection::control_channel() { return &control_channel_; } -FakeSocket* FakeChromotingConnection::GetEventChannel() { +FakeSocket* FakeChromotocolConnection::event_channel() { return &event_channel_; } -FakeSocket* FakeChromotingConnection::GetVideoChannel() { +FakeSocket* FakeChromotocolConnection::video_channel() { return &video_channel_; } -FakeSocket* FakeChromotingConnection::GetVideoRtpChannel() { +FakeSocket* FakeChromotocolConnection::video_rtp_channel() { return &video_rtp_channel_; } -FakeSocket* FakeChromotingConnection::GetVideoRtcpChannel() { + +FakeSocket* FakeChromotocolConnection::video_rtcp_channel() { return &video_rtcp_channel_; } -const std::string& FakeChromotingConnection::jid() { +const std::string& FakeChromotocolConnection::jid() { return jid_; } -MessageLoop* FakeChromotingConnection::message_loop() { +MessageLoop* FakeChromotocolConnection::message_loop() { return message_loop_; } -const CandidateChromotocolConfig* FakeChromotingConnection::candidate_config() { +const CandidateChromotocolConfig* +FakeChromotocolConnection::candidate_config() { return candidate_config_.get(); } -const ChromotocolConfig* FakeChromotingConnection::config() { +const ChromotocolConfig* FakeChromotocolConnection::config() { CHECK(config_.get()); return config_.get(); } -void FakeChromotingConnection::set_config(const ChromotocolConfig* config) { +void FakeChromotocolConnection::set_config(const ChromotocolConfig* config) { config_.reset(config); } -void FakeChromotingConnection::Close(Task* closed_task) { +void FakeChromotocolConnection::Close(Task* closed_task) { closed_ = true; closed_task->Run(); delete closed_task; diff --git a/remoting/protocol/fake_connection.h b/remoting/protocol/fake_connection.h index b69ce6c..ddc9cab 100644 --- a/remoting/protocol/fake_connection.h +++ b/remoting/protocol/fake_connection.h @@ -9,7 +9,7 @@ #include "base/scoped_ptr.h" #include "net/socket/socket.h" -#include "remoting/protocol/chromoting_connection.h" +#include "remoting/protocol/chromotocol_connection.h" namespace remoting { @@ -50,12 +50,12 @@ class FakeSocket : public net::Socket { int input_pos_; }; -// FakeChromotingConnection is a dummy ChromotingConnection that uses +// FakeChromotocolConnection is a dummy ChromotocolConnection that uses // FakeSocket for all channels. -class FakeChromotingConnection : public ChromotingConnection { +class FakeChromotocolConnection : public ChromotocolConnection { public: - FakeChromotingConnection(); - virtual ~FakeChromotingConnection(); + FakeChromotocolConnection(); + virtual ~FakeChromotocolConnection(); StateChangeCallback* state_change_callback() { return callback_.get(); } @@ -67,12 +67,12 @@ class FakeChromotingConnection : public ChromotingConnection { virtual void SetStateChangeCallback(StateChangeCallback* callback); - virtual FakeSocket* GetControlChannel(); - virtual FakeSocket* GetEventChannel(); - virtual FakeSocket* GetVideoChannel(); + virtual FakeSocket* control_channel(); + virtual FakeSocket* event_channel(); + virtual FakeSocket* video_channel(); - virtual FakeSocket* GetVideoRtpChannel(); - virtual FakeSocket* GetVideoRtcpChannel(); + virtual FakeSocket* video_rtp_channel(); + virtual FakeSocket* video_rtcp_channel(); virtual const std::string& jid(); diff --git a/remoting/protocol/jingle_chromoting_connection.cc b/remoting/protocol/jingle_chromotocol_connection.cc index fe1cb7d..01b7bac 100644 --- a/remoting/protocol/jingle_chromoting_connection.cc +++ b/remoting/protocol/jingle_chromotocol_connection.cc @@ -2,14 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "remoting/protocol/jingle_chromoting_connection.h" +#include "remoting/protocol/jingle_chromotocol_connection.h" #include "base/message_loop.h" #include "net/base/net_errors.h" #include "remoting/base/constants.h" #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_chromoting_server.h" +#include "remoting/protocol/jingle_chromotocol_server.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" @@ -28,10 +29,10 @@ const char kVideoRtpChannelName[] = "videortp"; const char kVideoRtcpChannelName[] = "videortcp"; } // namespace -const char JingleChromotingConnection::kChromotingContentName[] = "chromoting"; +const char JingleChromotocolConnection::kChromotingContentName[] = "chromoting"; -JingleChromotingConnection::JingleChromotingConnection( - JingleChromotingServer* server) +JingleChromotocolConnection::JingleChromotocolConnection( + JingleChromotocolServer* server) : server_(server), state_(INITIALIZING), closed_(false), @@ -40,24 +41,24 @@ JingleChromotingConnection::JingleChromotingConnection( video_channel_(NULL) { } -JingleChromotingConnection::~JingleChromotingConnection() { +JingleChromotocolConnection::~JingleChromotocolConnection() { DCHECK(closed_); } -void JingleChromotingConnection::Init(Session* session) { +void JingleChromotocolConnection::Init(Session* session) { DCHECK_EQ(server_->message_loop(), MessageLoop::current()); session_ = session; jid_ = session_->remote_name(); session_->SignalState.connect( - this, &JingleChromotingConnection::OnSessionState); + this, &JingleChromotocolConnection::OnSessionState); } -bool JingleChromotingConnection::HasSession(cricket::Session* session) { +bool JingleChromotocolConnection::HasSession(cricket::Session* session) { return session_ == session; } -Session* JingleChromotingConnection::ReleaseSession() { +Session* JingleChromotocolConnection::ReleaseSession() { DCHECK_EQ(server_->message_loop(), MessageLoop::current()); SetState(CLOSED); @@ -69,77 +70,77 @@ Session* JingleChromotingConnection::ReleaseSession() { return session; } -void JingleChromotingConnection::SetStateChangeCallback( +void JingleChromotocolConnection::SetStateChangeCallback( StateChangeCallback* callback) { DCHECK_EQ(server_->message_loop(), MessageLoop::current()); DCHECK(callback); state_change_callback_.reset(callback); } -net::Socket* JingleChromotingConnection::GetControlChannel() { +net::Socket* JingleChromotocolConnection::control_channel() { DCHECK_EQ(server_->message_loop(), MessageLoop::current()); return control_channel_adapter_.get(); } -net::Socket* JingleChromotingConnection::GetEventChannel() { +net::Socket* JingleChromotocolConnection::event_channel() { DCHECK_EQ(server_->message_loop(), MessageLoop::current()); return event_channel_adapter_.get(); } // TODO(sergeyu): Remove this method after we switch to RTP. -net::Socket* JingleChromotingConnection::GetVideoChannel() { +net::Socket* JingleChromotocolConnection::video_channel() { DCHECK_EQ(server_->message_loop(), MessageLoop::current()); return video_channel_adapter_.get(); } -net::Socket* JingleChromotingConnection::GetVideoRtpChannel() { +net::Socket* JingleChromotocolConnection::video_rtp_channel() { DCHECK_EQ(server_->message_loop(), MessageLoop::current()); return video_rtp_channel_.get(); } -net::Socket* JingleChromotingConnection::GetVideoRtcpChannel() { +net::Socket* JingleChromotocolConnection::video_rtcp_channel() { DCHECK_EQ(server_->message_loop(), MessageLoop::current()); return video_rtcp_channel_.get(); } -const std::string& JingleChromotingConnection::jid() { +const std::string& JingleChromotocolConnection::jid() { // No synchronization is needed because jid_ is not changed - // after new connection is passed to JingleChromotingServer callback. + // after new connection is passed to JingleChromotocolServer callback. return jid_; } -MessageLoop* JingleChromotingConnection::message_loop() { +MessageLoop* JingleChromotocolConnection::message_loop() { return server_->message_loop(); } const CandidateChromotocolConfig* -JingleChromotingConnection::candidate_config() { +JingleChromotocolConnection::candidate_config() { DCHECK(candidate_config_.get()); return candidate_config_.get(); } -void JingleChromotingConnection::set_candidate_config( +void JingleChromotocolConnection::set_candidate_config( const CandidateChromotocolConfig* candidate_config) { DCHECK(!candidate_config_.get()); DCHECK(candidate_config); candidate_config_.reset(candidate_config); } -const ChromotocolConfig* JingleChromotingConnection::config() { +const ChromotocolConfig* JingleChromotocolConnection::config() { DCHECK(config_.get()); return config_.get(); } -void JingleChromotingConnection::set_config(const ChromotocolConfig* config) { +void JingleChromotocolConnection::set_config(const ChromotocolConfig* config) { DCHECK(!config_.get()); DCHECK(config); config_.reset(config); } -void JingleChromotingConnection::Close(Task* closed_task) { +void JingleChromotocolConnection::Close(Task* closed_task) { if (MessageLoop::current() != server_->message_loop()) { server_->message_loop()->PostTask( - FROM_HERE, NewRunnableMethod(this, &JingleChromotingConnection::Close, + FROM_HERE, NewRunnableMethod(this, &JingleChromotocolConnection::Close, closed_task)); return; } @@ -186,7 +187,7 @@ void JingleChromotingConnection::Close(Task* closed_task) { delete closed_task; } -void JingleChromotingConnection::OnSessionState( +void JingleChromotocolConnection::OnSessionState( BaseSession* session, BaseSession::State state) { DCHECK_EQ(session_, session); @@ -219,7 +220,7 @@ void JingleChromotingConnection::OnSessionState( } } -void JingleChromotingConnection::OnInitiate() { +void JingleChromotocolConnection::OnInitiate() { jid_ = session_->remote_name(); std::string content_name; @@ -242,24 +243,20 @@ void JingleChromotingConnection::OnInitiate() { session_->CreateChannel(content_name, kVideoRtcpChannelName))); // Create control channel. - // TODO(sergeyu): Don't use talk_base::Thread::Current() here. - control_channel_ = - new PseudoTcpChannel(talk_base::Thread::Current(), session_); + control_channel_ = new PseudoTcpChannel(server_->jingle_thread(), session_); control_channel_->Connect(content_name, kControlChannelName); control_channel_adapter_.reset(new StreamSocketAdapter( control_channel_->GetStream())); // Create event channel. - event_channel_ = - new PseudoTcpChannel(talk_base::Thread::Current(), session_); + event_channel_ = new PseudoTcpChannel(server_->jingle_thread(), 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(talk_base::Thread::Current(), session_); + video_channel_ = new PseudoTcpChannel(server_->jingle_thread(), session_); video_channel_->Connect(content_name, kVideoChannelName); video_channel_adapter_.reset(new StreamSocketAdapter( video_channel_->GetStream())); @@ -270,7 +267,7 @@ void JingleChromotingConnection::OnInitiate() { SetState(CONNECTING); } -void JingleChromotingConnection::OnAccept() { +void JingleChromotocolConnection::OnAccept() { // Set config for outgoing connections. if (session_->initiator()) { const cricket::ContentInfo* content = @@ -278,8 +275,8 @@ void JingleChromotingConnection::OnAccept() { kChromotingXmlNamespace); CHECK(content); - const ChromotingContentDescription* content_description = - static_cast<const ChromotingContentDescription*>(content->description); + const ChromotocolContentDescription* content_description = + static_cast<const ChromotocolContentDescription*>(content->description); ChromotocolConfig* config = content_description->config()->GetFinalConfig(); // Terminate the session if the config we received is invalid. @@ -297,7 +294,7 @@ void JingleChromotingConnection::OnAccept() { SetState(CONNECTED); } -void JingleChromotingConnection::OnTerminate() { +void JingleChromotocolConnection::OnTerminate() { if (control_channel_adapter_.get()) control_channel_adapter_->Close(net::ERR_CONNECTION_ABORTED); if (control_channel_) { @@ -329,7 +326,7 @@ void JingleChromotingConnection::OnTerminate() { closed_ = true; } -void JingleChromotingConnection::SetState(State new_state) { +void JingleChromotocolConnection::SetState(State new_state) { if (new_state != state_) { state_ = new_state; if (!closed_ && state_change_callback_.get()) diff --git a/remoting/protocol/jingle_chromoting_connection.h b/remoting/protocol/jingle_chromotocol_connection.h index 736d11e..d139aef 100644 --- a/remoting/protocol/jingle_chromoting_connection.h +++ b/remoting/protocol/jingle_chromotocol_connection.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_CHROMOTING_CONNECTION_H_ -#define REMOTING_PROTOCOL_JINGLE_CHROMOTING_CONNECTION_H_ +#ifndef REMOTING_PROTOCOL_JINGLE_CHROMOTOCOL_CONNECTION_H_ +#define REMOTING_PROTOCOL_JINGLE_CHROMOTOCOL_CONNECTION_H_ #include "base/lock.h" #include "base/ref_counted.h" -#include "remoting/protocol/chromoting_connection.h" +#include "remoting/protocol/chromotocol_connection.h" #include "third_party/libjingle/source/talk/base/sigslot.h" #include "third_party/libjingle/source/talk/p2p/base/session.h" @@ -21,29 +21,29 @@ class Socket; namespace remoting { -class JingleChromotingServer; +class JingleChromotocolServer; class StreamSocketAdapter; class TransportChannelSocketAdapter; -// Implements ChromotingConnection that work over libjingle session (the +// Implements ChromotocolConnection that work over libjingle session (the // cricket::Session object is passed to Init() method). Created -// by JingleChromotingServer for incoming and outgoing connections. -class JingleChromotingConnection : public ChromotingConnection, +// by JingleChromotocolServer for incoming and outgoing connections. +class JingleChromotocolConnection : public ChromotocolConnection, public sigslot::has_slots<> { public: static const char kChromotingContentName[]; - explicit JingleChromotingConnection(JingleChromotingServer* client); + explicit JingleChromotocolConnection(JingleChromotocolServer* client); - // ChromotingConnection interface. + // ChromotocolConnection interface. virtual void SetStateChangeCallback(StateChangeCallback* callback); - virtual net::Socket* GetControlChannel(); - virtual net::Socket* GetEventChannel(); - virtual net::Socket* GetVideoChannel(); + virtual net::Socket* control_channel(); + virtual net::Socket* event_channel(); + virtual net::Socket* video_channel(); - virtual net::Socket* GetVideoRtpChannel(); - virtual net::Socket* GetVideoRtcpChannel(); + virtual net::Socket* video_rtp_channel(); + virtual net::Socket* video_rtcp_channel(); virtual const std::string& jid(); virtual MessageLoop* message_loop(); @@ -56,12 +56,12 @@ class JingleChromotingConnection : public ChromotingConnection, virtual void Close(Task* closed_task); protected: - virtual ~JingleChromotingConnection(); + virtual ~JingleChromotocolConnection(); private: - friend class JingleChromotingServer; + friend class JingleChromotocolServer; - // Called by JingleChromotingServer. + // Called by JingleChromotocolServer. void set_candidate_config(const CandidateChromotocolConfig* candidate_config); void Init(cricket::Session* session); bool HasSession(cricket::Session* session); @@ -77,8 +77,8 @@ class JingleChromotingConnection : public ChromotingConnection, void SetState(State new_state); - // JingleChromotingServer that created this connection. - scoped_refptr<JingleChromotingServer> server_; + // JingleChromotocolServer that created this connection. + scoped_refptr<JingleChromotocolServer> server_; State state_; scoped_ptr<StateChangeCallback> state_change_callback_; @@ -104,9 +104,9 @@ class JingleChromotingConnection : public ChromotingConnection, scoped_ptr<TransportChannelSocketAdapter> video_rtp_channel_; scoped_ptr<TransportChannelSocketAdapter> video_rtcp_channel_; - DISALLOW_COPY_AND_ASSIGN(JingleChromotingConnection); + DISALLOW_COPY_AND_ASSIGN(JingleChromotocolConnection); }; } // namespace remoting -#endif // REMOTING_PROTOCOL_JINGLE_CHROMOTING_CONNECTION_H_ +#endif // REMOTING_PROTOCOL_JINGLE_CHROMOTOCOL_CONNECTION_H_ diff --git a/remoting/protocol/jingle_chromoting_connection_unittest.cc b/remoting/protocol/jingle_chromotocol_connection_unittest.cc index bb16967..d8f12cd 100644 --- a/remoting/protocol/jingle_chromoting_connection_unittest.cc +++ b/remoting/protocol/jingle_chromotocol_connection_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_chromoting_connection.h" -#include "remoting/protocol/jingle_chromoting_server.h" +#include "remoting/protocol/jingle_chromotocol_connection.h" +#include "remoting/protocol/jingle_chromotocol_server.h" #include "remoting/protocol/session_manager_pair.h" #include "remoting/jingle_glue/jingle_thread.h" #include "testing/gmock/include/gmock/gmock.h" @@ -27,10 +27,10 @@ using testing::SetArgumentPointee; using testing::WithArg; namespace remoting { -class JingleChromotingConnectionTest; +class JingleChromotocolConnectionTest; } // namespace remoting -DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::JingleChromotingConnectionTest); +DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::JingleChromotocolConnectionTest); namespace remoting { @@ -45,19 +45,20 @@ const int kUdpWriteDelayMs = 10; class MockServerCallback { public: - MOCK_METHOD2(OnNewConnection, void(ChromotingConnection*, - ChromotingServer::NewConnectionResponse*)); + MOCK_METHOD2(OnIncomingConnection, + void(ChromotocolConnection*, + ChromotocolServer::IncomingConnectionResponse*)); }; class MockConnectionCallback { public: - MOCK_METHOD1(OnStateChange, void(ChromotingConnection::State)); + MOCK_METHOD1(OnStateChange, void(ChromotocolConnection::State)); }; -class JingleChromotingConnectionTest : public testing::Test { +class JingleChromotocolConnectionTest : public testing::Test { public: // Helper method to copy to set value of client_connection_. - void SetHostConnection(ChromotingConnection* connection) { + void SetHostConnection(ChromotocolConnection* connection) { DCHECK(connection); host_connection_ = connection; host_connection_->SetStateChangeCallback( @@ -77,11 +78,11 @@ class JingleChromotingConnectionTest : public testing::Test { if (host_server_) { host_server_->Close(NewRunnableFunction( - &JingleChromotingConnectionTest::DoNothing)); + &JingleChromotocolConnectionTest::DoNothing)); } if (client_server_) { client_server_->Close(NewRunnableFunction( - &JingleChromotingConnectionTest::DoNothing)); + &JingleChromotocolConnectionTest::DoNothing)); } thread_.Stop(); } @@ -90,18 +91,18 @@ class JingleChromotingConnectionTest : public testing::Test { // SessionManagerPair must be initialized on the jingle thread. thread_.message_loop()->PostTask( FROM_HERE, NewRunnableMethod( - this, &JingleChromotingConnectionTest::DoCreateServerPair)); + this, &JingleChromotocolConnectionTest::DoCreateServerPair)); SyncWithJingleThread(); } void CloseConnections() { if (host_connection_) { host_connection_->Close(NewRunnableFunction( - &JingleChromotingConnectionTest::DoNothing)); + &JingleChromotocolConnectionTest::DoNothing)); } if (client_connection_) { client_connection_->Close(NewRunnableFunction( - &JingleChromotingConnectionTest::DoNothing)); + &JingleChromotocolConnectionTest::DoNothing)); } SyncWithJingleThread(); } @@ -109,53 +110,53 @@ class JingleChromotingConnectionTest : public testing::Test { void DoCreateServerPair() { session_manager_pair_ = new SessionManagerPair(&thread_); session_manager_pair_->Init(); - host_server_ = new JingleChromotingServer(thread_.message_loop()); + host_server_ = new JingleChromotocolServer(&thread_); host_server_->set_allow_local_ips(true); host_server_->Init(SessionManagerPair::kHostJid, session_manager_pair_->host_session_manager(), NewCallback(&host_server_callback_, - &MockServerCallback::OnNewConnection)); - client_server_ = new JingleChromotingServer(thread_.message_loop()); + &MockServerCallback::OnIncomingConnection)); + client_server_ = new JingleChromotocolServer(&thread_); client_server_->set_allow_local_ips(true); client_server_->Init(SessionManagerPair::kClientJid, session_manager_pair_->client_session_manager(), NewCallback(&client_server_callback_, - &MockServerCallback::OnNewConnection)); + &MockServerCallback::OnIncomingConnection)); } - void InitiateConnection() { - EXPECT_CALL(host_server_callback_, OnNewConnection(_, _)) + bool InitiateConnection() { + EXPECT_CALL(host_server_callback_, OnIncomingConnection(_, _)) .WillOnce(DoAll( WithArg<0>(Invoke( - this, &JingleChromotingConnectionTest::SetHostConnection)), - SetArgumentPointee<1>(ChromotingServer::ACCEPT))); + this, &JingleChromotocolConnectionTest::SetHostConnection)), + SetArgumentPointee<1>(ChromotocolServer::ACCEPT))); base::WaitableEvent host_connected_event(false, false); EXPECT_CALL(host_connection_callback_, - OnStateChange(ChromotingConnection::CONNECTING)) + OnStateChange(ChromotocolConnection::CONNECTING)) .Times(1); EXPECT_CALL(host_connection_callback_, - OnStateChange(ChromotingConnection::CONNECTED)) + OnStateChange(ChromotocolConnection::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(ChromotingConnection::CLOSED)) + OnStateChange(ChromotocolConnection::CLOSED)) .Times(1); base::WaitableEvent client_connected_event(false, false); EXPECT_CALL(client_connection_callback_, - OnStateChange(ChromotingConnection::CONNECTING)) + OnStateChange(ChromotocolConnection::CONNECTING)) .Times(1); EXPECT_CALL(client_connection_callback_, - OnStateChange(ChromotingConnection::CONNECTED)) + OnStateChange(ChromotocolConnection::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(ChromotingConnection::CLOSED)) + OnStateChange(ChromotocolConnection::CLOSED)) .Times(1); client_connection_ = client_server_->Connect( @@ -164,12 +165,10 @@ class JingleChromotingConnectionTest : public testing::Test { NewCallback(&client_connection_callback_, &MockConnectionCallback::OnStateChange)); - ASSERT_TRUE( - host_connected_event.TimedWait(base::TimeDelta::FromMilliseconds( - TestTimeouts::action_max_timeout_ms()))); - ASSERT_TRUE( + return host_connected_event.TimedWait(base::TimeDelta::FromMilliseconds( + TestTimeouts::action_max_timeout_ms())) && client_connected_event.TimedWait(base::TimeDelta::FromMilliseconds( - TestTimeouts::action_max_timeout_ms()))); + TestTimeouts::action_max_timeout_ms())); } static void SignalEvent(base::WaitableEvent* event) { @@ -187,14 +186,14 @@ class JingleChromotingConnectionTest : public testing::Test { JingleThread thread_; scoped_refptr<SessionManagerPair> session_manager_pair_; - scoped_refptr<JingleChromotingServer> host_server_; + scoped_refptr<JingleChromotocolServer> host_server_; MockServerCallback host_server_callback_; - scoped_refptr<JingleChromotingServer> client_server_; + scoped_refptr<JingleChromotocolServer> client_server_; MockServerCallback client_server_callback_; - scoped_refptr<ChromotingConnection> host_connection_; + scoped_refptr<ChromotocolConnection> host_connection_; MockConnectionCallback host_connection_callback_; - scoped_refptr<ChromotingConnection> client_connection_; + scoped_refptr<ChromotocolConnection> client_connection_; MockConnectionCallback client_connection_callback_; }; @@ -209,8 +208,8 @@ class ChannelTesterBase : public base::RefCountedThreadSafe<ChannelTesterBase> { }; ChannelTesterBase(MessageLoop* message_loop, - ChromotingConnection* host_connection, - ChromotingConnection* client_connection) + ChromotocolConnection* host_connection, + ChromotocolConnection* client_connection) : message_loop_(message_loop), host_connection_(host_connection), client_connection_(client_connection), @@ -225,10 +224,9 @@ class ChannelTesterBase : public base::RefCountedThreadSafe<ChannelTesterBase> { channel)); } - void WaitFinished() { - ASSERT_TRUE( - done_event_.TimedWait(base::TimeDelta::FromMilliseconds( - TestTimeouts::action_max_timeout_ms()))); + bool WaitFinished() { + return done_event_.TimedWait(base::TimeDelta::FromMilliseconds( + TestTimeouts::action_max_timeout_ms())); } virtual void CheckResults() = 0; @@ -247,19 +245,19 @@ class ChannelTesterBase : public base::RefCountedThreadSafe<ChannelTesterBase> { virtual void DoWrite() = 0; virtual void DoRead() = 0; - net::Socket* SelectChannel(ChromotingConnection* connection, + net::Socket* SelectChannel(ChromotocolConnection* connection, ChannelType channel) { switch (channel) { case CONTROL: - return connection->GetControlChannel(); + return connection->control_channel(); case EVENT: - return connection->GetEventChannel(); + return connection->event_channel(); case VIDEO: - return connection->GetVideoChannel(); + return connection->video_channel(); case VIDEO_RTP: - return connection->GetVideoRtpChannel(); + return connection->video_rtp_channel(); case VIDEO_RTCP: - return connection->GetVideoRtcpChannel(); + return connection->video_rtcp_channel(); default: NOTREACHED(); return NULL; @@ -267,8 +265,8 @@ class ChannelTesterBase : public base::RefCountedThreadSafe<ChannelTesterBase> { } MessageLoop* message_loop_; - scoped_refptr<ChromotingConnection> host_connection_; - scoped_refptr<ChromotingConnection> client_connection_; + scoped_refptr<ChromotocolConnection> host_connection_; + scoped_refptr<ChromotocolConnection> client_connection_; net::Socket* socket_1_; net::Socket* socket_2_; base::WaitableEvent done_event_; @@ -277,8 +275,8 @@ class ChannelTesterBase : public base::RefCountedThreadSafe<ChannelTesterBase> { class TCPChannelTester : public ChannelTesterBase { public: TCPChannelTester(MessageLoop* message_loop, - ChromotingConnection* host_connection, - ChromotingConnection* client_connection) + ChromotocolConnection* host_connection, + ChromotocolConnection* client_connection) : ChannelTesterBase(message_loop, host_connection, client_connection), ALLOW_THIS_IN_INITIALIZER_LIST( write_cb_(this, &TCPChannelTester::OnWritten)), @@ -386,8 +384,8 @@ class TCPChannelTester : public ChannelTesterBase { class UDPChannelTester : public ChannelTesterBase { public: UDPChannelTester(MessageLoop* message_loop, - ChromotingConnection* host_connection, - ChromotingConnection* client_connection) + ChromotocolConnection* host_connection, + ChromotocolConnection* client_connection) : ChannelTesterBase(message_loop, host_connection, client_connection), ALLOW_THIS_IN_INITIALIZER_LIST( write_cb_(this, &UDPChannelTester::OnWritten)), @@ -510,25 +508,25 @@ class UDPChannelTester : public ChannelTesterBase { }; // Verify that we can create and destory server objects without a connection. -TEST_F(JingleChromotingConnectionTest, CreateAndDestoy) { +TEST_F(JingleChromotocolConnectionTest, CreateAndDestoy) { CreateServerPair(); } // Verify that incoming connection can be rejected, and that the status // of the connection is set to CLOSED in this case. -TEST_F(JingleChromotingConnectionTest, RejectConnection) { +TEST_F(JingleChromotocolConnectionTest, RejectConnection) { CreateServerPair(); // Reject incoming connection. - EXPECT_CALL(host_server_callback_, OnNewConnection(_, _)) - .WillOnce(SetArgumentPointee<1>(ChromotingServer::DECLINE)); + EXPECT_CALL(host_server_callback_, OnIncomingConnection(_, _)) + .WillOnce(SetArgumentPointee<1>(ChromotocolServer::DECLINE)); base::WaitableEvent done_event(false, false); EXPECT_CALL(client_connection_callback_, - OnStateChange(ChromotingConnection::CONNECTING)) + OnStateChange(ChromotocolConnection::CONNECTING)) .Times(1); EXPECT_CALL(client_connection_callback_, - OnStateChange(ChromotingConnection::CLOSED)) + OnStateChange(ChromotocolConnection::CLOSED)) .Times(1) .WillOnce(InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)); @@ -544,20 +542,20 @@ TEST_F(JingleChromotingConnectionTest, RejectConnection) { } // Verify that we can connect two endpoints. -TEST_F(JingleChromotingConnectionTest, Connect) { +TEST_F(JingleChromotocolConnectionTest, Connect) { CreateServerPair(); - InitiateConnection(); + ASSERT_TRUE(InitiateConnection()); } // Verify that data can be transmitted over the event channel. -TEST_F(JingleChromotingConnectionTest, TestControlChannel) { +TEST_F(JingleChromotocolConnectionTest, TestControlChannel) { CreateServerPair(); - InitiateConnection(); + ASSERT_TRUE(InitiateConnection()); scoped_refptr<TCPChannelTester> tester = new TCPChannelTester(thread_.message_loop(), host_connection_, client_connection_); tester->Start(ChannelTesterBase::CONTROL); - tester->WaitFinished(); + ASSERT_TRUE(tester->WaitFinished()); tester->CheckResults(); // Connections must be closed while |tester| still exists. @@ -566,14 +564,14 @@ TEST_F(JingleChromotingConnectionTest, TestControlChannel) { // Verify that data can be transmitted over the video channel. -TEST_F(JingleChromotingConnectionTest, TestVideoChannel) { +TEST_F(JingleChromotocolConnectionTest, TestVideoChannel) { CreateServerPair(); - InitiateConnection(); + ASSERT_TRUE(InitiateConnection()); scoped_refptr<TCPChannelTester> tester = new TCPChannelTester(thread_.message_loop(), host_connection_, client_connection_); tester->Start(ChannelTesterBase::VIDEO); - tester->WaitFinished(); + ASSERT_TRUE(tester->WaitFinished()); tester->CheckResults(); // Connections must be closed while |tester| still exists. @@ -581,14 +579,14 @@ TEST_F(JingleChromotingConnectionTest, TestVideoChannel) { } // Verify that data can be transmitted over the event channel. -TEST_F(JingleChromotingConnectionTest, TestEventChannel) { +TEST_F(JingleChromotocolConnectionTest, TestEventChannel) { CreateServerPair(); - InitiateConnection(); + ASSERT_TRUE(InitiateConnection()); scoped_refptr<TCPChannelTester> tester = new TCPChannelTester(thread_.message_loop(), host_connection_, client_connection_); tester->Start(ChannelTesterBase::EVENT); - tester->WaitFinished(); + ASSERT_TRUE(tester->WaitFinished()); tester->CheckResults(); // Connections must be closed while |tester| still exists. @@ -596,14 +594,14 @@ TEST_F(JingleChromotingConnectionTest, TestEventChannel) { } // Verify that data can be transmitted over the video RTP channel. -TEST_F(JingleChromotingConnectionTest, TestVideoRtpChannel) { +TEST_F(JingleChromotocolConnectionTest, TestVideoRtpChannel) { CreateServerPair(); - InitiateConnection(); + ASSERT_TRUE(InitiateConnection()); scoped_refptr<UDPChannelTester> tester = new UDPChannelTester(thread_.message_loop(), host_connection_, client_connection_); tester->Start(ChannelTesterBase::VIDEO_RTP); - tester->WaitFinished(); + ASSERT_TRUE(tester->WaitFinished()); tester->CheckResults(); // Connections must be closed while |tester| still exists. diff --git a/remoting/protocol/jingle_chromoting_server.cc b/remoting/protocol/jingle_chromotocol_server.cc index 802689d..796c63b 100644 --- a/remoting/protocol/jingle_chromoting_server.cc +++ b/remoting/protocol/jingle_chromotocol_server.cc @@ -2,11 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "remoting/protocol/jingle_chromoting_server.h" +#include "remoting/protocol/jingle_chromotocol_server.h" #include "base/message_loop.h" #include "base/string_number_conversions.h" #include "remoting/base/constants.h" +#include "remoting/jingle_glue/jingle_thread.h" #include "third_party/libjingle/source/talk/p2p/base/constants.h" #include "third_party/libjingle/source/talk/p2p/base/transport.h" #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" @@ -149,51 +150,51 @@ bool ParseChannelConfig(const XmlElement* element, bool codec_required, } // namespace -ChromotingContentDescription::ChromotingContentDescription( +ChromotocolContentDescription::ChromotocolContentDescription( const CandidateChromotocolConfig* config) : candidate_config_(config) { } -ChromotingContentDescription::~ChromotingContentDescription() { } +ChromotocolContentDescription::~ChromotocolContentDescription() { } -JingleChromotingServer::JingleChromotingServer( - MessageLoop* message_loop) - : message_loop_(message_loop), +JingleChromotocolServer::JingleChromotocolServer( + JingleThread* jingle_thread) + : jingle_thread_(jingle_thread), session_manager_(NULL), allow_local_ips_(false), closed_(false) { - DCHECK(message_loop_); + DCHECK(jingle_thread_); } -void JingleChromotingServer::Init( +void JingleChromotocolServer::Init( const std::string& local_jid, cricket::SessionManager* session_manager, - NewConnectionCallback* new_connection_callback) { + IncomingConnectionCallback* incoming_connection_callback) { if (MessageLoop::current() != message_loop()) { message_loop()->PostTask( FROM_HERE, NewRunnableMethod( - this, &JingleChromotingServer::Init, - local_jid, session_manager, new_connection_callback)); + this, &JingleChromotocolServer::Init, + local_jid, session_manager, incoming_connection_callback)); return; } DCHECK(session_manager); - DCHECK(new_connection_callback); + DCHECK(incoming_connection_callback); local_jid_ = local_jid; - new_connection_callback_.reset(new_connection_callback); + incoming_connection_callback_.reset(incoming_connection_callback); session_manager_ = session_manager; session_manager_->AddClient(kChromotingXmlNamespace, this); } -JingleChromotingServer::~JingleChromotingServer() { +JingleChromotocolServer::~JingleChromotocolServer() { DCHECK(closed_); } -void JingleChromotingServer::Close(Task* closed_task) { +void JingleChromotocolServer::Close(Task* closed_task) { if (MessageLoop::current() != message_loop()) { message_loop()->PostTask( - FROM_HERE, NewRunnableMethod(this, &JingleChromotingServer::Close, + FROM_HERE, NewRunnableMethod(this, &JingleChromotocolServer::Close, closed_task)); return; } @@ -213,29 +214,29 @@ void JingleChromotingServer::Close(Task* closed_task) { delete closed_task; } -void JingleChromotingServer::set_allow_local_ips(bool allow_local_ips) { +void JingleChromotocolServer::set_allow_local_ips(bool allow_local_ips) { allow_local_ips_ = allow_local_ips; } -scoped_refptr<ChromotingConnection> JingleChromotingServer::Connect( +scoped_refptr<ChromotocolConnection> JingleChromotocolServer::Connect( const std::string& jid, CandidateChromotocolConfig* chromotocol_config, - ChromotingConnection::StateChangeCallback* state_change_callback) { + ChromotocolConnection::StateChangeCallback* state_change_callback) { // Can be called from any thread. - scoped_refptr<JingleChromotingConnection> connection = - new JingleChromotingConnection(this); + scoped_refptr<JingleChromotocolConnection> connection = + new JingleChromotocolConnection(this); connection->set_candidate_config(chromotocol_config); message_loop()->PostTask( - FROM_HERE, NewRunnableMethod(this, &JingleChromotingServer::DoConnect, + FROM_HERE, NewRunnableMethod(this, &JingleChromotocolServer::DoConnect, connection, jid, state_change_callback)); return connection; } -void JingleChromotingServer::DoConnect( - scoped_refptr<JingleChromotingConnection> connection, +void JingleChromotocolServer::DoConnect( + scoped_refptr<JingleChromotocolConnection> connection, const std::string& jid, - ChromotingConnection::StateChangeCallback* state_change_callback) { + ChromotocolConnection::StateChangeCallback* state_change_callback) { DCHECK_EQ(message_loop(), MessageLoop::current()); Session* session = session_manager_->CreateSession( local_jid_, kChromotingXmlNamespace); @@ -249,11 +250,15 @@ void JingleChromotingServer::DoConnect( jid, CreateSessionDescription(connection->candidate_config()->Clone())); } -MessageLoop* JingleChromotingServer::message_loop() { - return message_loop_; +JingleThread* JingleChromotocolServer::jingle_thread() { + return jingle_thread_; } -void JingleChromotingServer::OnSessionCreate( +MessageLoop* JingleChromotocolServer::message_loop() { + return jingle_thread_->message_loop(); +} + +void JingleChromotocolServer::OnSessionCreate( Session* session, bool incoming) { DCHECK_EQ(message_loop(), MessageLoop::current()); @@ -263,17 +268,17 @@ void JingleChromotingServer::OnSessionCreate( // If this is an outcoming session the connection object is already // created. if (incoming) { - JingleChromotingConnection* connection = - new JingleChromotingConnection(this); + JingleChromotocolConnection* connection = + new JingleChromotocolConnection(this); connections_.push_back(connection); connection->Init(session); } } -void JingleChromotingServer::OnSessionDestroy(Session* session) { +void JingleChromotocolServer::OnSessionDestroy(Session* session) { DCHECK_EQ(message_loop(), MessageLoop::current()); - std::list<scoped_refptr<JingleChromotingConnection> >::iterator it; + std::list<scoped_refptr<JingleChromotocolConnection> >::iterator it; for (it = connections_.begin(); it != connections_.end(); ++it) { if ((*it)->HasSession(session)) { (*it)->ReleaseSession(); @@ -283,8 +288,8 @@ void JingleChromotingServer::OnSessionDestroy(Session* session) { } } -void JingleChromotingServer::AcceptConnection( - JingleChromotingConnection* connection, +void JingleChromotocolServer::AcceptConnection( + JingleChromotocolConnection* connection, Session* session) { DCHECK_EQ(message_loop(), MessageLoop::current()); @@ -301,18 +306,18 @@ void JingleChromotingServer::AcceptConnection( CHECK(content); - const ChromotingContentDescription* content_description = - static_cast<const ChromotingContentDescription*>(content->description); + const ChromotocolContentDescription* content_description = + static_cast<const ChromotocolContentDescription*>(content->description); connection->set_candidate_config(content_description->config()->Clone()); - NewConnectionResponse response = ChromotingServer::DECLINE; + IncomingConnectionResponse response = ChromotocolServer::DECLINE; // Always reject connection if there is no callback. - if (new_connection_callback_.get()) - new_connection_callback_->Run(connection, &response); + if (incoming_connection_callback_.get()) + incoming_connection_callback_->Run(connection, &response); switch (response) { - case ChromotingServer::ACCEPT: { + case ChromotocolServer::ACCEPT: { // Connection must be configured by the callback. DCHECK(connection->config()); CandidateChromotocolConfig* candidate_config = @@ -321,12 +326,12 @@ void JingleChromotingServer::AcceptConnection( break; } - case ChromotingServer::INCOMPATIBLE: { + case ChromotocolServer::INCOMPATIBLE: { session->Reject(cricket::STR_TERMINATE_INCOMPATIBLE_PARAMETERS); break; } - case ChromotingServer::DECLINE: { + case ChromotocolServer::DECLINE: { session->Reject(cricket::STR_TERMINATE_DECLINE); break; } @@ -338,7 +343,7 @@ void JingleChromotingServer::AcceptConnection( } // Parse content description generated by WriteContent(). -bool JingleChromotingServer::ParseContent( +bool JingleChromotocolServer::ParseContent( cricket::SignalingProtocol protocol, const XmlElement* element, const cricket::ContentDescription** content, @@ -400,7 +405,7 @@ bool JingleChromotingServer::ParseContent( config->SetInitialResolution(resolution); - *content = new ChromotingContentDescription(config.release()); + *content = new ChromotocolContentDescription(config.release()); return true; } LOG(ERROR) << "Invalid description: " << element->Str(); @@ -416,13 +421,13 @@ bool JingleChromotingServer::ParseContent( // <initial-resolution width="800" height="600" /> // </description> // -bool JingleChromotingServer::WriteContent( +bool JingleChromotocolServer::WriteContent( cricket::SignalingProtocol protocol, const cricket::ContentDescription* content, XmlElement** elem, cricket::WriteError* error) { - const ChromotingContentDescription* desc = - static_cast<const ChromotingContentDescription*>(content); + const ChromotocolContentDescription* desc = + static_cast<const ChromotocolContentDescription*>(content); XmlElement* root = new XmlElement( QName(kChromotingXmlNamespace, kDescriptionTag), true); @@ -459,12 +464,12 @@ bool JingleChromotingServer::WriteContent( return true; } -SessionDescription* JingleChromotingServer::CreateSessionDescription( +SessionDescription* JingleChromotocolServer::CreateSessionDescription( const CandidateChromotocolConfig* config) { SessionDescription* desc = new SessionDescription(); - desc->AddContent(JingleChromotingConnection::kChromotingContentName, + desc->AddContent(JingleChromotocolConnection::kChromotingContentName, kChromotingXmlNamespace, - new ChromotingContentDescription(config)); + new ChromotocolContentDescription(config)); return desc; } diff --git a/remoting/protocol/jingle_chromoting_server.h b/remoting/protocol/jingle_chromotocol_server.h index b802057..84f7697 100644 --- a/remoting/protocol/jingle_chromoting_server.h +++ b/remoting/protocol/jingle_chromotocol_server.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_CHROMOTING_SERVER_H_ -#define REMOTING_PROTOCOL_JINGLE_CHROMOTING_SERVER_H_ +#ifndef REMOTING_PROTOCOL_JINGLE_CHROMOTOCOL_SERVER_H_ +#define REMOTING_PROTOCOL_JINGLE_CHROMOTOCOL_SERVER_H_ #include <list> #include <string> #include "base/lock.h" #include "base/ref_counted.h" -#include "remoting/protocol/chromoting_server.h" -#include "remoting/protocol/jingle_chromoting_connection.h" +#include "remoting/protocol/chromotocol_server.h" +#include "remoting/protocol/jingle_chromotocol_connection.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" @@ -24,15 +24,17 @@ class SessionManager; namespace remoting { +class JingleThread; + // ContentDescription used for chromoting sessions. It simply wraps // CandidateChromotocolConfig. CandidateChromotocolConfig doesn't inherit // from ContentDescription to avoid dependency on libjingle in -// ChromotingConnection interface. -class ChromotingContentDescription : public cricket::ContentDescription { +// ChromotocolConnection interface. +class ChromotocolContentDescription : public cricket::ContentDescription { public: - explicit ChromotingContentDescription( + explicit ChromotocolContentDescription( const CandidateChromotocolConfig* config); - ~ChromotingContentDescription(); + ~ChromotocolContentDescription(); const CandidateChromotocolConfig* config() const { return candidate_config_.get(); @@ -45,45 +47,48 @@ class ChromotingContentDescription : 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 JingleChromotingServer - : public ChromotingServer, +class JingleChromotocolServer + : public ChromotocolServer, public cricket::SessionClient { public: - explicit JingleChromotingServer(MessageLoop* message_loop); + explicit JingleChromotocolServer(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, - NewConnectionCallback* new_connection_callback); + IncomingConnectionCallback* incoming_connection_callback); - // ChromotingServer interface. - virtual scoped_refptr<ChromotingConnection> Connect( + // ChromotocolServer interface. + virtual scoped_refptr<ChromotocolConnection> Connect( const std::string& jid, CandidateChromotocolConfig* chromotocol_config, - ChromotingConnection::StateChangeCallback* state_change_callback); + ChromotocolConnection::StateChangeCallback* state_change_callback); virtual void Close(Task* closed_task); void set_allow_local_ips(bool allow_local_ips); protected: - virtual ~JingleChromotingServer(); + virtual ~JingleChromotocolServer(); private: - friend class JingleChromotingConnection; + friend class JingleChromotocolConnection; + + // The jingle thread used by this object. + JingleThread* jingle_thread(); - // Message loop used by this session client. + // Message loop that corresponds to jingle_thread(). MessageLoop* message_loop(); - // Called by JingleChromotingConnection when a new connection is initiated. - void AcceptConnection(JingleChromotingConnection* connection, + // Called by JingleChromotocolConnection when a new connection is initiated. + void AcceptConnection(JingleChromotocolConnection* connection, cricket::Session* session); void DoConnect( - scoped_refptr<JingleChromotingConnection> connection, + scoped_refptr<JingleChromotocolConnection> connection, const std::string& jid, - ChromotingConnection::StateChangeCallback* state_change_callback); + ChromotocolConnection::StateChangeCallback* state_change_callback); // Creates outgoing session description for an incoming connection. cricket::SessionDescription* CreateSessionDescription( @@ -104,18 +109,18 @@ class JingleChromotingServer cricket::WriteError* error); std::string local_jid_; - MessageLoop* message_loop_; + JingleThread* jingle_thread_; cricket::SessionManager* session_manager_; - scoped_ptr<NewConnectionCallback> new_connection_callback_; + scoped_ptr<IncomingConnectionCallback> incoming_connection_callback_; bool allow_local_ips_; bool closed_; - std::list<scoped_refptr<JingleChromotingConnection> > connections_; + std::list<scoped_refptr<JingleChromotocolConnection> > connections_; - DISALLOW_COPY_AND_ASSIGN(JingleChromotingServer); + DISALLOW_COPY_AND_ASSIGN(JingleChromotocolServer); }; } // namespace remoting -#endif // REMOTING_PROTOCOL_JINGLE_CHROMOTING_SERVER_H_ +#endif // REMOTING_PROTOCOL_JINGLE_CHROMOTOCOL_SERVER_H_ diff --git a/remoting/protocol/protocol_test_client.cc b/remoting/protocol/protocol_test_client.cc index 946931a..8113db7 100644 --- a/remoting/protocol/protocol_test_client.cc +++ b/remoting/protocol/protocol_test_client.cc @@ -24,7 +24,7 @@ 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_chromoting_server.h" +#include "remoting/protocol/jingle_chromotocol_server.h" using remoting::kChromotingTokenServiceName; @@ -51,13 +51,13 @@ class ProtocolTestConnection closed_event_(true, false) { } - void Init(ChromotingConnection* connection); + void Init(ChromotocolConnection* connection); void Write(const std::string& str); void Read(); void Close(); - // ChromotingConnection::Callback interface. - virtual void OnStateChange(ChromotingConnection::State state); + // ChromotocolConnection::Callback interface. + virtual void OnStateChange(ChromotocolConnection::State state); private: void DoWrite(scoped_refptr<net::IOBuffer> buf, int size); void DoRead(); @@ -71,7 +71,7 @@ class ProtocolTestConnection ProtocolTestClient* client_; MessageLoop* message_loop_; - scoped_refptr<ChromotingConnection> connection_; + scoped_refptr<ChromotocolConnection> connection_; net::CompletionCallbackImpl<ProtocolTestConnection> write_cb_; bool pending_write_; net::CompletionCallbackImpl<ProtocolTestConnection> read_cb_; @@ -97,10 +97,10 @@ class ProtocolTestClient // JingleClient::Callback interface. virtual void OnStateChange(JingleClient* client, JingleClient::State state); - // callback for JingleChromotingServer interface. + // callback for JingleChromotocolServer interface. virtual void OnNewChromotocolConnection( - ChromotingConnection* connection, - ChromotingServer::NewConnectionResponse* response); + ChromotocolConnection* connection, + ChromotocolServer::IncomingConnectionResponse* response); private: typedef std::list<scoped_refptr<ProtocolTestConnection> > ConnectionsList; @@ -110,14 +110,14 @@ class ProtocolTestClient std::string host_jid_; scoped_refptr<JingleClient> client_; - scoped_refptr<JingleChromotingServer> server_; + scoped_refptr<JingleChromotocolServer> server_; ConnectionsList connections_; Lock connections_lock_; base::WaitableEvent closed_event_; }; -void ProtocolTestConnection::Init(ChromotingConnection* connection) { +void ProtocolTestConnection::Init(ChromotocolConnection* connection) { connection_ = connection; } @@ -139,7 +139,7 @@ void ProtocolTestConnection::DoWrite( return; } - net::Socket* channel = connection_->GetEventChannel(); + net::Socket* channel = connection_->event_channel(); if (channel != NULL) { int result = channel->Write(buf, size, &write_cb_); if (result < 0) { @@ -162,7 +162,7 @@ void ProtocolTestConnection::Read() { void ProtocolTestConnection::DoRead() { read_buffer_ = new net::IOBuffer(kBufferSize); while (true) { - int result = connection_->GetEventChannel()->Read( + int result = connection_->event_channel()->Read( read_buffer_, kBufferSize, &read_cb_); if (result < 0) { if (result != net::ERR_IO_PENDING) @@ -185,12 +185,12 @@ void ProtocolTestConnection::OnFinishedClosing() { } void ProtocolTestConnection::OnStateChange( - ChromotingConnection::State state) { + ChromotocolConnection::State state) { LOG(INFO) << "State of " << connection_->jid() << " changed to " << state; - if (state == ChromotingConnection::CONNECTED) { + if (state == ChromotocolConnection::CONNECTED) { // Start reading after we've connected. Read(); - } else if (state == ChromotingConnection::CLOSED) { + } else if (state == ChromotocolConnection::CLOSED) { std::cerr << "Connection to " << connection_->jid() << " closed" << std::endl; client_->OnConnectionClosed(this); @@ -226,7 +226,7 @@ void ProtocolTestClient::Run(const std::string& username, client_ = new JingleClient(&jingle_thread); client_->Init(username, auth_token, kChromotingTokenServiceName, this); - server_ = new JingleChromotingServer(jingle_thread.message_loop()); + server_ = new JingleChromotocolServer(&jingle_thread); host_jid_ = host_jid; @@ -296,12 +296,12 @@ void ProtocolTestClient::OnStateChange( } void ProtocolTestClient::OnNewChromotocolConnection( - ChromotingConnection* connection, - ChromotingServer::NewConnectionResponse* response) { + ChromotocolConnection* connection, + ChromotocolServer::IncomingConnectionResponse* response) { std::cerr << "Accepting connection from " << connection->jid() << std::endl; connection->set_config(ChromotocolConfig::CreateDefault()); - *response = ChromotingServer::ACCEPT; + *response = ChromotocolServer::ACCEPT; ProtocolTestConnection* test_connection = new ProtocolTestConnection(this, client_->message_loop()); diff --git a/remoting/protocol/session_manager_pair.h b/remoting/protocol/session_manager_pair.h index a8f99d2..f3e4f37f 100644 --- a/remoting/protocol/session_manager_pair.h +++ b/remoting/protocol/session_manager_pair.h @@ -4,7 +4,7 @@ // SessionManagerPair class is used by unittests to create a pair of session // managers connected to each other. These session managers are then can be -// passed to a pair of JingleChromotingConnection objects, so that it is +// passed to a pair of JingleChromotocolConnection objects, so that it is // possible to simulate connection between host and client. #ifndef REMOTING_PROTOCOL_MOCK_SESSION_MANAGER_H_ diff --git a/remoting/protocol/stream_writer.cc b/remoting/protocol/stream_writer.cc index 7650edf..ce91650 100644 --- a/remoting/protocol/stream_writer.cc +++ b/remoting/protocol/stream_writer.cc @@ -5,7 +5,7 @@ #include "remoting/protocol/stream_writer.h" #include "base/message_loop.h" -#include "remoting/protocol/chromoting_connection.h" +#include "remoting/protocol/chromotocol_connection.h" #include "remoting/protocol/util.h" namespace remoting { |