summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--remoting/host/chromoting_host.cc61
-rw-r--r--remoting/host/chromoting_host.h34
-rw-r--r--remoting/host/mock_objects.h34
-rw-r--r--remoting/host/session_manager.cc76
-rw-r--r--remoting/host/session_manager.h32
-rw-r--r--remoting/host/session_manager_unittest.cc15
-rw-r--r--remoting/protocol/connection_to_client.cc (renamed from remoting/host/client_connection.cc)47
-rw-r--r--remoting/protocol/connection_to_client.h (renamed from remoting/host/client_connection.h)31
-rw-r--r--remoting/protocol/connection_to_client_unittest.cc (renamed from remoting/host/client_connection_unittest.cc)25
-rw-r--r--remoting/protocol/mock_objects.h50
-rw-r--r--remoting/remoting.gyp12
11 files changed, 225 insertions, 192 deletions
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc
index 89389a6..9e265fb 100644
--- a/remoting/host/chromoting_host.cc
+++ b/remoting/host/chromoting_host.cc
@@ -19,6 +19,9 @@
#include "remoting/host/session_manager.h"
#include "remoting/protocol/chromotocol_config.h"
#include "remoting/protocol/jingle_session_manager.h"
+#include "remoting/protocol/connection_to_client.h"
+
+using remoting::protocol::ConnectionToClient;
namespace remoting {
@@ -103,12 +106,12 @@ void ChromotingHost::Shutdown() {
// Tell the session to pause and then disconnect all clients.
if (session_.get()) {
session_->Pause();
- session_->RemoveAllClients();
+ session_->RemoveAllConnections();
}
- // Disconnect all clients.
- if (client_) {
- client_->Disconnect();
+ // Disconnect the client.
+ if (connection_) {
+ connection_->Disconnect();
}
// Stop the heartbeat sender.
@@ -133,8 +136,8 @@ void ChromotingHost::Shutdown() {
}
}
-// This method is called if a client is connected to this object.
-void ChromotingHost::OnClientConnected(protocol::ClientConnection* client) {
+// This method is called when a client connects.
+void ChromotingHost::OnClientConnected(ConnectionToClient* connection) {
DCHECK_EQ(context_->main_message_loop(), MessageLoop::current());
// Create a new RecordSession if there was none.
@@ -143,7 +146,7 @@ void ChromotingHost::OnClientConnected(protocol::ClientConnection* client) {
// it should run on.
DCHECK(capturer_.get());
- Encoder* encoder = CreateEncoder(client->session()->config());
+ Encoder* encoder = CreateEncoder(connection->session()->config());
session_ = new SessionManager(context_->capture_message_loop(),
context_->encode_message_loop(),
@@ -152,32 +155,32 @@ void ChromotingHost::OnClientConnected(protocol::ClientConnection* client) {
encoder);
}
- // Immediately add the client and start the session.
- session_->AddClient(client);
+ // Immediately add the connection and start the session.
+ session_->AddConnection(connection);
session_->Start();
VLOG(1) << "Session manager started";
}
-void ChromotingHost::OnClientDisconnected(protocol::ClientConnection* client) {
+void ChromotingHost::OnClientDisconnected(ConnectionToClient* connection) {
DCHECK_EQ(context_->main_message_loop(), MessageLoop::current());
- // Remove the client from the session manager and pause the session.
- // TODO(hclam): Pause only if the last client disconnected.
+ // Remove the connection from the session manager and pause the session.
+ // TODO(hclam): Pause only if the last connection disconnected.
if (session_.get()) {
- session_->RemoveClient(client);
+ session_->RemoveConnection(connection);
session_->Pause();
}
- // Close the connection to client just to be safe.
- client->Disconnect();
+ // Close the connection to connection just to be safe.
+ connection->Disconnect();
- // Also remove reference to ClientConnection from this object.
- client_ = NULL;
+ // Also remove reference to ConnectionToClient from this object.
+ connection_ = NULL;
}
////////////////////////////////////////////////////////////////////////////
-// protocol::ClientConnection::EventHandler implementations
-void ChromotingHost::HandleMessage(protocol::ClientConnection* client,
+// protocol::ConnectionToClient::EventHandler implementations
+void ChromotingHost::HandleMessage(ConnectionToClient* connection,
ChromotingClientMessage* message) {
DCHECK_EQ(context_->main_message_loop(), MessageLoop::current());
@@ -187,26 +190,26 @@ void ChromotingHost::HandleMessage(protocol::ClientConnection* client,
executor_->HandleInputEvent(message);
}
-void ChromotingHost::OnConnectionOpened(protocol::ClientConnection* client) {
+void ChromotingHost::OnConnectionOpened(ConnectionToClient* connection) {
DCHECK_EQ(context_->main_message_loop(), MessageLoop::current());
- // Completes the client connection.
+ // Completes the connection to the client.
VLOG(1) << "Connection to client established.";
- OnClientConnected(client_.get());
+ OnClientConnected(connection_.get());
}
-void ChromotingHost::OnConnectionClosed(protocol::ClientConnection* client) {
+void ChromotingHost::OnConnectionClosed(ConnectionToClient* connection) {
DCHECK_EQ(context_->main_message_loop(), MessageLoop::current());
VLOG(1) << "Connection to client closed.";
- OnClientDisconnected(client_.get());
+ OnClientDisconnected(connection_.get());
}
-void ChromotingHost::OnConnectionFailed(protocol::ClientConnection* client) {
+void ChromotingHost::OnConnectionFailed(ConnectionToClient* connection) {
DCHECK_EQ(context_->main_message_loop(), MessageLoop::current());
LOG(ERROR) << "Connection failed unexpectedly.";
- OnClientDisconnected(client_.get());
+ OnClientDisconnected(connection_.get());
}
////////////////////////////////////////////////////////////////////////////
@@ -246,7 +249,7 @@ void ChromotingHost::OnNewClientSession(
protocol::SessionManager::IncomingSessionResponse* response) {
AutoLock auto_lock(lock_);
// TODO(hclam): Allow multiple clients to connect to the host.
- if (client_.get() || state_ != kStarted) {
+ if (connection_.get() || state_ != kStarted) {
*response = protocol::SessionManager::DECLINE;
return;
}
@@ -281,8 +284,8 @@ void ChromotingHost::OnNewClientSession(
// If we accept the connected then create a client object and set the
// callback.
- client_ = new protocol::ClientConnection(context_->main_message_loop(), this);
- client_->Init(session);
+ connection_ = new ConnectionToClient(context_->main_message_loop(), this);
+ connection_->Init(session);
}
void ChromotingHost::OnServerClosed() {
diff --git a/remoting/host/chromoting_host.h b/remoting/host/chromoting_host.h
index 04b0d2b..2fdcadb 100644
--- a/remoting/host/chromoting_host.h
+++ b/remoting/host/chromoting_host.h
@@ -11,17 +11,21 @@
#include "remoting/base/encoder.h"
#include "remoting/host/access_verifier.h"
#include "remoting/host/capturer.h"
-#include "remoting/host/client_connection.h"
#include "remoting/host/event_executor.h"
#include "remoting/host/heartbeat_sender.h"
#include "remoting/jingle_glue/jingle_client.h"
#include "remoting/jingle_glue/jingle_thread.h"
#include "remoting/protocol/session_manager.h"
+#include "remoting/protocol/connection_to_client.h"
class Task;
namespace remoting {
+namespace protocol {
+class ConnectionToClient;
+} // namespace protocol
+
class Capturer;
class ChromotingHostContext;
class ChromotocolConfig;
@@ -39,11 +43,11 @@ class SessionManager;
// and register the host.
//
// 2. We listen for incoming connection using libjingle. We will create
-// a ClientConnection object that wraps around linjingle for transport. Also
-// create a SessionManager with appropriate Encoder and Capturer and
-// add the ClientConnection to this SessionManager for transporting the
+// a ConnectionToClient object that wraps around linjingle for transport.
+// Also create a SessionManager with appropriate Encoder and Capturer and
+// add the ConnectionToClient to this SessionManager for transporting the
// screen captures. A EventExecutor is created and registered with the
-// ClientConnection to receive mouse / keyboard events from the remote
+// ConnectionToClient to receive mouse / keyboard events from the remote
// client.
// This is also the right time to create multiple threads to host
// the above objects. After we have done all the initialization
@@ -56,7 +60,7 @@ class SessionManager;
// return to the idle state. We then go to step (2) if there a new
// incoming connection.
class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>,
- public protocol::ClientConnection::EventHandler,
+ public protocol::ConnectionToClient::EventHandler,
public JingleClient::Callback {
public:
ChromotingHost(ChromotingHostContext* context, MutableHostConfig* config,
@@ -78,18 +82,18 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>,
void Shutdown();
// This method is called if a client is connected to this object.
- void OnClientConnected(protocol::ClientConnection* client);
+ void OnClientConnected(protocol::ConnectionToClient* client);
// This method is called if a client is disconnected from the host.
- void OnClientDisconnected(protocol::ClientConnection* client);
+ void OnClientDisconnected(protocol::ConnectionToClient* client);
////////////////////////////////////////////////////////////////////////////
- // protocol::ClientConnection::EventHandler implementations
- virtual void HandleMessage(protocol::ClientConnection* client,
+ // protocol::ConnectionToClient::EventHandler implementations
+ virtual void HandleMessage(protocol::ConnectionToClient* client,
ChromotingClientMessage* message);
- virtual void OnConnectionOpened(protocol::ClientConnection* client);
- virtual void OnConnectionClosed(protocol::ClientConnection* client);
- virtual void OnConnectionFailed(protocol::ClientConnection* client);
+ virtual void OnConnectionOpened(protocol::ConnectionToClient* client);
+ virtual void OnConnectionClosed(protocol::ConnectionToClient* client);
+ virtual void OnConnectionFailed(protocol::ConnectionToClient* client);
////////////////////////////////////////////////////////////////////////////
// JingleClient::Callback implementations
@@ -143,9 +147,9 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>,
AccessVerifier access_verifier_;
- // A ClientConnection manages the connectino to a remote client.
+ // A ConnectionToClient manages the connectino to a remote client.
// TODO(hclam): Expand this to a list of clients.
- scoped_refptr<protocol::ClientConnection> client_;
+ scoped_refptr<protocol::ConnectionToClient> connection_;
// Session manager for the host process.
scoped_refptr<SessionManager> session_;
diff --git a/remoting/host/mock_objects.h b/remoting/host/mock_objects.h
index a28f32d..8541d62 100644
--- a/remoting/host/mock_objects.h
+++ b/remoting/host/mock_objects.h
@@ -6,7 +6,6 @@
#define REMOTING_HOST_MOCK_OBJECTS_H_
#include "remoting/host/capturer.h"
-#include "remoting/host/client_connection.h"
#include "remoting/host/event_executor.h"
#include "remoting/proto/internal.pb.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -41,39 +40,6 @@ class MockEventExecutor : public EventExecutor {
DISALLOW_COPY_AND_ASSIGN(MockEventExecutor);
};
-namespace protocol {
-
-class MockClientConnection : public ClientConnection {
- public:
- MockClientConnection(){}
-
- MOCK_METHOD1(Init, void(ChromotocolConnection* connection));
- MOCK_METHOD2(SendInitClientMessage, void(int width, int height));
- MOCK_METHOD1(SendVideoPacket, void(const VideoPacket& packet));
- MOCK_METHOD0(GetPendingUpdateStreamMessages, int());
- MOCK_METHOD0(Disconnect, void());
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MockClientConnection);
-};
-
-class MockClientConnectionEventHandler : public ClientConnection::EventHandler {
- public:
- MockClientConnectionEventHandler() {}
-
- MOCK_METHOD2(HandleMessage,
- void(ClientConnection* viewer,
- ChromotingClientMessage* message));
- MOCK_METHOD1(OnConnectionOpened, void(ClientConnection* viewer));
- MOCK_METHOD1(OnConnectionClosed, void(ClientConnection* viewer));
- MOCK_METHOD1(OnConnectionFailed, void(ClientConnection* viewer));
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MockClientConnectionEventHandler);
-};
-
-} // namespace protocol
-
} // namespace remoting
#endif // REMOTING_HOST_MOCK_OBJECTS_H_
diff --git a/remoting/host/session_manager.cc b/remoting/host/session_manager.cc
index 68458bc..b9726a7 100644
--- a/remoting/host/session_manager.cc
+++ b/remoting/host/session_manager.cc
@@ -11,9 +11,11 @@
#include "base/stl_util-inl.h"
#include "remoting/base/capture_data.h"
#include "remoting/base/tracer.h"
-#include "remoting/host/client_connection.h"
+#include "remoting/protocol/connection_to_client.h"
#include "remoting/protocol/message_decoder.h"
+using remoting::protocol::ConnectionToClient;
+
namespace remoting {
// By default we capture 20 times a second. This number is obtained by
@@ -54,7 +56,7 @@ SessionManager::SessionManager(
}
SessionManager::~SessionManager() {
- clients_.clear();
+ connections_.clear();
}
// Public methods --------------------------------------------------------------
@@ -74,22 +76,22 @@ void SessionManager::SetMaxRate(double rate) {
FROM_HERE, NewTracedMethod(this, &SessionManager::DoSetMaxRate, rate));
}
-void SessionManager::AddClient(
- scoped_refptr<protocol::ClientConnection> client) {
- // Gets the init information for the client.
+void SessionManager::AddConnection(
+ scoped_refptr<ConnectionToClient> connection) {
+ // Gets the init information for the connection.
capture_loop_->PostTask(
FROM_HERE,
- NewTracedMethod(this, &SessionManager::DoGetInitInfo, client));
+ NewTracedMethod(this, &SessionManager::DoGetInitInfo, connection));
}
-void SessionManager::RemoveClient(
- scoped_refptr<protocol::ClientConnection> client) {
+void SessionManager::RemoveConnection(
+ scoped_refptr<ConnectionToClient> connection) {
network_loop_->PostTask(
FROM_HERE,
- NewTracedMethod(this, &SessionManager::DoRemoveClient, client));
+ NewTracedMethod(this, &SessionManager::DoRemoveClient, connection));
}
-void SessionManager::RemoveAllClients() {
+void SessionManager::RemoveAllConnections() {
network_loop_->PostTask(
FROM_HERE,
NewTracedMethod(this, &SessionManager::DoRemoveAllClients));
@@ -246,23 +248,23 @@ void SessionManager::DoFinishEncode() {
}
void SessionManager::DoGetInitInfo(
- scoped_refptr<protocol::ClientConnection> client) {
+ scoped_refptr<ConnectionToClient> connection) {
DCHECK_EQ(capture_loop_, MessageLoop::current());
ScopedTracer tracer("init");
- // Sends the init message to the client.
+ // Sends the init message to the connection.
network_loop_->PostTask(
FROM_HERE,
- NewTracedMethod(this, &SessionManager::DoSendInit, client,
+ NewTracedMethod(this, &SessionManager::DoSendInit, connection,
capturer()->width(), capturer()->height()));
- // And then add the client to the list so it can receive update stream.
- // It is important we do so in such order or the client will receive
+ // And then add the connection to the list so it can receive update stream.
+ // It is important we do so in such order or the connection will receive
// update stream before init message.
network_loop_->PostTask(
FROM_HERE,
- NewTracedMethod(this, &SessionManager::DoAddClient, client));
+ NewTracedMethod(this, &SessionManager::DoAddClient, connection));
}
// Network thread --------------------------------------------------------------
@@ -304,10 +306,10 @@ void SessionManager::DoRateControl() {
return;
int max_pending_update_streams = 0;
- for (size_t i = 0; i < clients_.size(); ++i) {
+ for (size_t i = 0; i < connections_.size(); ++i) {
max_pending_update_streams =
std::max(max_pending_update_streams,
- clients_[i]->GetPendingUpdateStreamMessages());
+ connections_[i]->GetPendingUpdateStreamMessages());
}
// If |slow_down| equals zero, we have no slow down.
@@ -336,8 +338,8 @@ void SessionManager::DoSendVideoPacket(VideoPacket* packet) {
TraceContext::tracer()->PrintString("DoSendUpdate");
- for (ClientConnectionList::const_iterator i = clients_.begin();
- i < clients_.end(); ++i) {
+ for (ConnectionToClientList::const_iterator i = connections_.begin();
+ i < connections_.end(); ++i) {
(*i)->SendVideoPacket(*packet);
}
delete packet;
@@ -345,40 +347,38 @@ void SessionManager::DoSendVideoPacket(VideoPacket* packet) {
TraceContext::tracer()->PrintString("DoSendUpdate done");
}
-void SessionManager::DoSendInit(
- scoped_refptr<protocol::ClientConnection> client,
- int width, int height) {
+void SessionManager::DoSendInit(scoped_refptr<ConnectionToClient> connection,
+ int width, int height) {
DCHECK_EQ(network_loop_, MessageLoop::current());
- // Sends the client init information.
- client->SendInitClientMessage(width, height);
+ // Sends the connection init information.
+ connection->SendInitClientMessage(width, height);
}
-void SessionManager::DoAddClient(
- scoped_refptr<protocol::ClientConnection> client) {
+void SessionManager::DoAddClient(scoped_refptr<ConnectionToClient> connection) {
DCHECK_EQ(network_loop_, MessageLoop::current());
// TODO(hclam): Force a full frame for next encode.
- clients_.push_back(client);
+ connections_.push_back(connection);
}
void SessionManager::DoRemoveClient(
- scoped_refptr<protocol::ClientConnection> client) {
+ scoped_refptr<ConnectionToClient> connection) {
DCHECK_EQ(network_loop_, MessageLoop::current());
// TODO(hclam): Is it correct to do to a scoped_refptr?
- ClientConnectionList::iterator it
- = std::find(clients_.begin(), clients_.end(), client);
- if (it != clients_.end()) {
- clients_.erase(it);
+ ConnectionToClientList::iterator it
+ = std::find(connections_.begin(), connections_.end(), connection);
+ if (it != connections_.end()) {
+ connections_.erase(it);
}
}
void SessionManager::DoRemoveAllClients() {
DCHECK_EQ(network_loop_, MessageLoop::current());
- // Clear the list of clients.
- clients_.clear();
+ // Clear the list of connections.
+ connections_.clear();
}
// Encoder thread --------------------------------------------------------------
@@ -395,7 +395,7 @@ void SessionManager::DoEncode(
return;
}
- // TODO(hclam): Enable |force_refresh| if a new client was
+ // TODO(hclam): Enable |force_refresh| if a new connection was
// added.
TraceContext::tracer()->PrintString("Encode start");
encoder_->Encode(capture_data, false,
@@ -408,10 +408,10 @@ void SessionManager::EncodeDataAvailableTask(VideoPacket* packet) {
bool last = (packet->flags() & VideoPacket::LAST_PACKET) != 0;
- // Before a new encode task starts, notify clients a new update
+ // Before a new encode task starts, notify connected clients a new update
// stream is coming.
// Notify this will keep a reference to the DataBuffer in the
- // task. The ownership will eventually pass to the ClientConnections.
+ // task. The ownership will eventually pass to the ConnectionToClients.
network_loop_->PostTask(
FROM_HERE,
NewTracedMethod(this, &SessionManager::DoSendVideoPacket, packet));
diff --git a/remoting/host/session_manager.h b/remoting/host/session_manager.h
index c58ef32..e5a12d2 100644
--- a/remoting/host/session_manager.h
+++ b/remoting/host/session_manager.h
@@ -18,12 +18,12 @@
namespace remoting {
-class CaptureData;
-
namespace protocol {
-class ClientConnection;
+class ConnectionToClient;
} // namespace protocol
+class CaptureData;
+
// A class for controlling and coordinate Capturer, Encoder
// and NetworkChannel in a record session.
//
@@ -86,14 +86,14 @@ class SessionManager : public base::RefCountedThreadSafe<SessionManager> {
// This method should be called before Start() is called.
void SetMaxRate(double rate);
- // Add a client to this recording session.
- void AddClient(scoped_refptr<protocol::ClientConnection> client);
+ // Add a connection to this recording session.
+ void AddConnection(scoped_refptr<protocol::ConnectionToClient> connection);
- // Remove a client from receiving screen updates.
- void RemoveClient(scoped_refptr<protocol::ClientConnection> client);
+ // Remove a connection from receiving screen updates.
+ void RemoveConnection(scoped_refptr<protocol::ConnectionToClient> connection);
- // Remove all clients.
- void RemoveAllClients();
+ // Remove all connections.
+ void RemoveAllConnections();
private:
// Getters for capturer and encoder.
@@ -115,7 +115,7 @@ class SessionManager : public base::RefCountedThreadSafe<SessionManager> {
void CaptureDoneCallback(scoped_refptr<CaptureData> capture_data);
void DoFinishEncode();
- void DoGetInitInfo(scoped_refptr<protocol::ClientConnection> client);
+ void DoGetInitInfo(scoped_refptr<protocol::ConnectionToClient> client);
// Network thread -----------------------------------------------------------
@@ -129,11 +129,11 @@ class SessionManager : public base::RefCountedThreadSafe<SessionManager> {
// DoSendUpdate takes ownership of header and is responsible for deleting it.
void DoSendVideoPacket(VideoPacket* packet);
- void DoSendInit(scoped_refptr<protocol::ClientConnection> client,
+ void DoSendInit(scoped_refptr<protocol::ConnectionToClient> connection,
int width, int height);
- void DoAddClient(scoped_refptr<protocol::ClientConnection> client);
- void DoRemoveClient(scoped_refptr<protocol::ClientConnection> client);
+ void DoAddClient(scoped_refptr<protocol::ConnectionToClient> connection);
+ void DoRemoveClient(scoped_refptr<protocol::ConnectionToClient> connection);
void DoRemoveAllClients();
// Encoder thread -----------------------------------------------------------
@@ -161,9 +161,9 @@ class SessionManager : public base::RefCountedThreadSafe<SessionManager> {
// This member is always accessed on the NETWORK thread.
// TODO(hclam): Have to scoped_refptr the clients since they have a shorter
// lifetime than this object.
- typedef std::vector<scoped_refptr<protocol::ClientConnection> >
- ClientConnectionList;
- ClientConnectionList clients_;
+ typedef std::vector<scoped_refptr<protocol::ConnectionToClient> >
+ ConnectionToClientList;
+ ConnectionToClientList connections_;
// The following members are accessed on the capture thread.
double rate_; // Number of captures to perform every second.
diff --git a/remoting/host/session_manager_unittest.cc b/remoting/host/session_manager_unittest.cc
index 7291c3e..2fc59e6 100644
--- a/remoting/host/session_manager_unittest.cc
+++ b/remoting/host/session_manager_unittest.cc
@@ -7,9 +7,12 @@
#include "remoting/base/mock_objects.h"
#include "remoting/host/mock_objects.h"
#include "remoting/host/session_manager.h"
+#include "remoting/protocol/mock_objects.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+using ::remoting::protocol::MockConnectionToClient;
+
using ::testing::_;
using ::testing::AtLeast;
using ::testing::NotNull;
@@ -32,7 +35,7 @@ class SessionManagerTest : public testing::Test {
void Init() {
capturer_ = new MockCapturer();
encoder_ = new MockEncoder();
- client_ = new protocol::MockClientConnection();
+ connection_ = new MockConnectionToClient();
record_ = new SessionManager(&message_loop_,
&message_loop_,
&message_loop_,
@@ -41,7 +44,7 @@ class SessionManagerTest : public testing::Test {
}
scoped_refptr<SessionManager> record_;
- scoped_refptr<protocol::MockClientConnection> client_;
+ scoped_refptr<MockConnectionToClient> connection_;
MockCapturer* capturer_;
MockEncoder* encoder_;
MessageLoop message_loop_;
@@ -88,8 +91,8 @@ TEST_F(SessionManagerTest, DISABLED_OneRecordCycle) {
// Add the mock client connection to the session.
EXPECT_CALL(*capturer_, width()).WillRepeatedly(Return(kWidth));
EXPECT_CALL(*capturer_, height()).WillRepeatedly(Return(kHeight));
- EXPECT_CALL(*client_, SendInitClientMessage(kWidth, kHeight));
- record_->AddClient(client_);
+ EXPECT_CALL(*connection_, SendInitClientMessage(kWidth, kHeight));
+ record_->AddConnection(connection_);
// First the capturer is called.
EXPECT_CALL(*capturer_, CaptureInvalidRects(NotNull()))
@@ -101,8 +104,8 @@ TEST_F(SessionManagerTest, DISABLED_OneRecordCycle) {
.WillOnce(FinishEncode(packet));
// Expect the client be notified.
- EXPECT_CALL(*client_, SendVideoPacket(_));
- EXPECT_CALL(*client_, GetPendingUpdateStreamMessages())
+ EXPECT_CALL(*connection_, SendVideoPacket(_));
+ EXPECT_CALL(*connection_, GetPendingUpdateStreamMessages())
.Times(AtLeast(0))
.WillRepeatedly(Return(0));
diff --git a/remoting/host/client_connection.cc b/remoting/protocol/connection_to_client.cc
index 779e630..9925648 100644
--- a/remoting/host/client_connection.cc
+++ b/remoting/protocol/connection_to_client.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.
-// TODO(hclam): Remove this header once MessageDispatcher is used.
-#include "remoting/base/multiple_array_input_stream.h"
-#include "remoting/host/client_connection.h"
+#include "remoting/protocol/connection_to_client.h"
#include "google/protobuf/message.h"
#include "net/base/io_buffer.h"
#include "remoting/protocol/util.h"
+// TODO(hclam): Remove this header once MessageDispatcher is used.
+#include "remoting/base/multiple_array_input_stream.h"
+
namespace remoting {
namespace protocol {
@@ -17,32 +18,32 @@ namespace protocol {
// average update stream.
static const size_t kAverageUpdateStream = 10;
-ClientConnection::ClientConnection(MessageLoop* message_loop,
- EventHandler* handler)
+ConnectionToClient::ConnectionToClient(MessageLoop* message_loop,
+ EventHandler* handler)
: loop_(message_loop),
handler_(handler) {
DCHECK(loop_);
DCHECK(handler_);
}
-ClientConnection::~ClientConnection() {
+ConnectionToClient::~ConnectionToClient() {
// TODO(hclam): When we shut down the viewer we may have to close the
// connection.
}
-void ClientConnection::Init(protocol::Session* session) {
+void ConnectionToClient::Init(protocol::Session* session) {
DCHECK_EQ(session->message_loop(), MessageLoop::current());
session_ = session;
session_->SetStateChangeCallback(
- NewCallback(this, &ClientConnection::OnSessionStateChange));
+ NewCallback(this, &ConnectionToClient::OnSessionStateChange));
}
-protocol::Session* ClientConnection::session() {
+protocol::Session* ConnectionToClient::session() {
return session_;
}
-void ClientConnection::SendInitClientMessage(int width, int height) {
+void ConnectionToClient::SendInitClientMessage(int width, int height) {
DCHECK_EQ(loop_, MessageLoop::current());
// If we are disconnected then return.
@@ -56,7 +57,7 @@ void ClientConnection::SendInitClientMessage(int width, int height) {
control_writer_.SendMessage(msg);
}
-void ClientConnection::SendVideoPacket(const VideoPacket& packet) {
+void ConnectionToClient::SendVideoPacket(const VideoPacket& packet) {
DCHECK_EQ(loop_, MessageLoop::current());
// If we are disconnected then return.
@@ -66,45 +67,45 @@ void ClientConnection::SendVideoPacket(const VideoPacket& packet) {
video_writer_->SendPacket(packet);
}
-int ClientConnection::GetPendingUpdateStreamMessages() {
+int ConnectionToClient::GetPendingUpdateStreamMessages() {
DCHECK_EQ(loop_, MessageLoop::current());
return video_writer_->GetPendingPackets();
}
-void ClientConnection::Disconnect() {
+void ConnectionToClient::Disconnect() {
DCHECK_EQ(loop_, MessageLoop::current());
// If there is a channel then close it and release the reference.
if (session_) {
- session_->Close(NewRunnableMethod(this, &ClientConnection::OnClosed));
+ session_->Close(NewRunnableMethod(this, &ConnectionToClient::OnClosed));
session_ = NULL;
}
}
-ClientConnection::ClientConnection() {}
+ConnectionToClient::ConnectionToClient() {}
-void ClientConnection::OnSessionStateChange(
+void ConnectionToClient::OnSessionStateChange(
protocol::Session::State state) {
if (state == protocol::Session::CONNECTED) {
control_writer_.Init(session_->control_channel());
event_reader_.Init<ChromotingClientMessage>(
session_->event_channel(),
- NewCallback(this, &ClientConnection::OnMessageReceived));
+ NewCallback(this, &ConnectionToClient::OnMessageReceived));
video_writer_.reset(VideoWriter::Create(session_->config()));
video_writer_->Init(session_);
}
loop_->PostTask(FROM_HERE,
- NewRunnableMethod(this, &ClientConnection::StateChangeTask, state));
+ NewRunnableMethod(this, &ConnectionToClient::StateChangeTask, state));
}
-void ClientConnection::OnMessageReceived(ChromotingClientMessage* message) {
+void ConnectionToClient::OnMessageReceived(ChromotingClientMessage* message) {
loop_->PostTask(FROM_HERE,
- NewRunnableMethod(this, &ClientConnection::MessageReceivedTask,
+ NewRunnableMethod(this, &ConnectionToClient::MessageReceivedTask,
message));
}
-void ClientConnection::StateChangeTask(protocol::Session::State state) {
+void ConnectionToClient::StateChangeTask(protocol::Session::State state) {
DCHECK_EQ(loop_, MessageLoop::current());
DCHECK(handler_);
@@ -127,14 +128,14 @@ void ClientConnection::StateChangeTask(protocol::Session::State state) {
}
}
-void ClientConnection::MessageReceivedTask(ChromotingClientMessage* message) {
+void ConnectionToClient::MessageReceivedTask(ChromotingClientMessage* message) {
DCHECK_EQ(loop_, MessageLoop::current());
DCHECK(handler_);
handler_->HandleMessage(this, message);
}
// OnClosed() is used as a callback for protocol::Session::Close().
-void ClientConnection::OnClosed() {
+void ConnectionToClient::OnClosed() {
}
} // namespace protocol
diff --git a/remoting/host/client_connection.h b/remoting/protocol/connection_to_client.h
index 50589e69..ee8b1d7 100644
--- a/remoting/host/client_connection.h
+++ b/remoting/protocol/connection_to_client.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_HOST_CLIENT_CONNECTION_H_
-#define REMOTING_HOST_CLIENT_CONNECTION_H_
+#ifndef REMOTING_PROTOCOL_CONNECTION_TO_CLIENT_H_
+#define REMOTING_PROTOCOL_CONNECTION_TO_CLIENT_H_
#include <deque>
#include <vector>
@@ -25,37 +25,38 @@ namespace protocol {
// screen updates and other messages to the remote viewer. It is also
// responsible for receiving and parsing data from the remote viewer and
// delegating events to the event handler.
-class ClientConnection : public base::RefCountedThreadSafe<ClientConnection> {
+class ConnectionToClient :
+ public base::RefCountedThreadSafe<ConnectionToClient> {
public:
class EventHandler {
public:
virtual ~EventHandler() {}
- // Handles an event received by the ClientConnection. Receiver will own the
- // ClientMessages in ClientMessageList and needs to delete them.
+ // Handles an event received by the ConnectionToClient. Receiver will own
+ // the ClientMessages in ClientMessageList and needs to delete them.
// Note that the sender of messages will not reference messages
// again so it is okay to clear |messages| in this method.
- virtual void HandleMessage(ClientConnection* viewer,
+ virtual void HandleMessage(ConnectionToClient* connection,
ChromotingClientMessage* message) = 0;
// Called when the network connection is opened.
- virtual void OnConnectionOpened(ClientConnection* viewer) = 0;
+ virtual void OnConnectionOpened(ConnectionToClient* connection) = 0;
// Called when the network connection is closed.
- virtual void OnConnectionClosed(ClientConnection* viewer) = 0;
+ virtual void OnConnectionClosed(ConnectionToClient* connection) = 0;
// Called when the network connection has failed.
- virtual void OnConnectionFailed(ClientConnection* viewer) = 0;
+ virtual void OnConnectionFailed(ConnectionToClient* connection) = 0;
};
- // Constructs a ClientConnection object. |message_loop| is the message loop
+ // Constructs a ConnectionToClient object. |message_loop| is the message loop
// that this object runs on. A viewer object receives events and messages from
// a libjingle channel, these events are delegated to |handler|.
// It is guranteed that |handler| is called only on the |message_loop|.
- ClientConnection(MessageLoop* message_loop,
+ ConnectionToClient(MessageLoop* message_loop,
EventHandler* handler);
- virtual ~ClientConnection();
+ virtual ~ConnectionToClient();
virtual void Init(protocol::Session* session);
@@ -82,7 +83,7 @@ class ClientConnection : public base::RefCountedThreadSafe<ClientConnection> {
protected:
// Protected constructor used by unit test.
- ClientConnection();
+ ConnectionToClient();
private:
// Callback for protocol Session.
@@ -112,10 +113,10 @@ class ClientConnection : public base::RefCountedThreadSafe<ClientConnection> {
// Event handler for handling events sent from this object.
EventHandler* handler_;
- DISALLOW_COPY_AND_ASSIGN(ClientConnection);
+ DISALLOW_COPY_AND_ASSIGN(ConnectionToClient);
};
} // namespace protocol
} // namespace remoting
-#endif // REMOTING_HOST_CLIENT_CONNECTION_H_
+#endif // REMOTING_PROTOCOL_CONNECTION_TO_CLIENT_H_
diff --git a/remoting/host/client_connection_unittest.cc b/remoting/protocol/connection_to_client_unittest.cc
index 8f522db..45b9143 100644
--- a/remoting/host/client_connection_unittest.cc
+++ b/remoting/protocol/connection_to_client_unittest.cc
@@ -4,9 +4,10 @@
#include "base/message_loop.h"
#include "remoting/base/mock_objects.h"
-#include "remoting/host/client_connection.h"
#include "remoting/host/mock_objects.h"
#include "remoting/protocol/fake_session.h"
+#include "remoting/protocol/connection_to_client.h"
+#include "remoting/protocol/mock_objects.h"
#include "testing/gmock/include/gmock/gmock.h"
using ::testing::_;
@@ -14,10 +15,11 @@ using ::testing::NotNull;
using ::testing::StrictMock;
namespace remoting {
+namespace protocol {
-class ClientConnectionTest : public testing::Test {
+class ConnectionToClientTest : public testing::Test {
public:
- ClientConnectionTest() {
+ ConnectionToClientTest() {
}
protected:
@@ -26,7 +28,7 @@ class ClientConnectionTest : public testing::Test {
session_->set_message_loop(&message_loop_);
// Allocate a ClientConnection object with the mock objects.
- viewer_ = new protocol::ClientConnection(&message_loop_, &handler_);
+ viewer_ = new ConnectionToClient(&message_loop_, &handler_);
viewer_->Init(session_);
EXPECT_CALL(handler_, OnConnectionOpened(viewer_.get()));
session_->state_change_callback()->Run(
@@ -35,21 +37,21 @@ class ClientConnectionTest : public testing::Test {
}
MessageLoop message_loop_;
- protocol::MockClientConnectionEventHandler handler_;
- scoped_refptr<protocol::ClientConnection> viewer_;
+ MockConnectionToClientEventHandler handler_;
+ scoped_refptr<ConnectionToClient> viewer_;
scoped_refptr<protocol::FakeSession> session_;
private:
- DISALLOW_COPY_AND_ASSIGN(ClientConnectionTest);
+ DISALLOW_COPY_AND_ASSIGN(ConnectionToClientTest);
};
-TEST_F(ClientConnectionTest, SendUpdateStream) {
+TEST_F(ConnectionToClientTest, SendUpdateStream) {
// Then send the actual data.
VideoPacket packet;
viewer_->SendVideoPacket(packet);
- // And then close the connection to ClientConnection.
+ // And then close the connection to ConnectionToClient.
viewer_->Disconnect();
message_loop_.RunAllPending();
@@ -59,7 +61,7 @@ TEST_F(ClientConnectionTest, SendUpdateStream) {
EXPECT_GT(session_->video_channel()->written_data().size(), 0u);
}
-TEST_F(ClientConnectionTest, StateChange) {
+TEST_F(ConnectionToClientTest, StateChange) {
EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get()));
session_->state_change_callback()->Run(protocol::Session::CLOSED);
message_loop_.RunAllPending();
@@ -71,7 +73,7 @@ TEST_F(ClientConnectionTest, StateChange) {
// Test that we can close client connection more than once and operations
// after the connection is closed has no effect.
-TEST_F(ClientConnectionTest, Close) {
+TEST_F(ConnectionToClientTest, Close) {
viewer_->Disconnect();
message_loop_.RunAllPending();
EXPECT_TRUE(session_->is_closed());
@@ -85,4 +87,5 @@ TEST_F(ClientConnectionTest, Close) {
EXPECT_EQ(session_->video_channel()->written_data().size(), 0u);
}
+} // namespace protocol
} // namespace remoting
diff --git a/remoting/protocol/mock_objects.h b/remoting/protocol/mock_objects.h
new file mode 100644
index 0000000..5acb131
--- /dev/null
+++ b/remoting/protocol/mock_objects.h
@@ -0,0 +1,50 @@
+// 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_MOCK_OBJECTS_H_
+#define REMOTING_PROTOCOL_MOCK_OBJECTS_H_
+
+#include "remoting/proto/internal.pb.h"
+#include "remoting/protocol/connection_to_client.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace remoting {
+namespace protocol {
+
+class ChromotocolConnection;
+
+class MockConnectionToClient : public ConnectionToClient {
+ public:
+ MockConnectionToClient() {}
+
+ MOCK_METHOD1(Init, void(ChromotocolConnection* connection));
+ MOCK_METHOD2(SendInitClientMessage, void(int width, int height));
+ MOCK_METHOD1(SendVideoPacket, void(const VideoPacket& packet));
+ MOCK_METHOD0(GetPendingUpdateStreamMessages, int());
+ MOCK_METHOD0(Disconnect, void());
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockConnectionToClient);
+};
+
+class MockConnectionToClientEventHandler :
+ public ConnectionToClient::EventHandler {
+ public:
+ MockConnectionToClientEventHandler() {}
+
+ MOCK_METHOD2(HandleMessage,
+ void(ConnectionToClient* viewer,
+ ChromotingClientMessage* message));
+ MOCK_METHOD1(OnConnectionOpened, void(ConnectionToClient* connection));
+ MOCK_METHOD1(OnConnectionClosed, void(ConnectionToClient* connection));
+ MOCK_METHOD1(OnConnectionFailed, void(ConnectionToClient* connection));
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockConnectionToClientEventHandler);
+};
+
+} // namespace protocol
+} // namespace remoting
+
+#endif // REMOTING_PROTOCOL_MOCK_OBJECTS_H_
diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp
index f4e7079..628504f 100644
--- a/remoting/remoting.gyp
+++ b/remoting/remoting.gyp
@@ -193,8 +193,6 @@
'host/chromoting_host.h',
'host/chromoting_host_context.cc',
'host/chromoting_host_context.h',
- 'host/client_connection.cc',
- 'host/client_connection.h',
'host/differ.h',
'host/differ.cc',
'host/differ_block.h',
@@ -365,6 +363,8 @@
'protocol/buffered_socket_writer.h',
'protocol/chromotocol_config.cc',
'protocol/chromotocol_config.h',
+ 'protocol/connection_to_client.cc',
+ 'protocol/connection_to_client.h',
'protocol/host_control_message_handler.h',
'protocol/host_event_message_handler.h',
'protocol/host_message_dispatcher.cc',
@@ -455,7 +455,6 @@
'client/mock_objects.h',
'host/access_verifier_unittest.cc',
'host/chromoting_host_context_unittest.cc',
- 'host/client_connection_unittest.cc',
'host/differ_unittest.cc',
'host/differ_block_unittest.cc',
'host/heartbeat_sender_unittest.cc',
@@ -470,10 +469,13 @@
'jingle_glue/iq_request_unittest.cc',
'jingle_glue/mock_objects.h',
'jingle_glue/stream_socket_adapter_unittest.cc',
- 'protocol/jingle_session_unittest.cc',
- 'protocol/message_decoder_unittest.cc',
+ 'protocol/connection_to_client_unittest.cc',
'protocol/fake_session.cc',
'protocol/fake_session.h',
+ 'protocol/jingle_session_unittest.cc',
+ 'protocol/message_decoder_unittest.cc',
+ 'protocol/message_decoder_unittest.cc',
+ 'protocol/mock_objects.h',
'protocol/session_manager_pair.cc',
'protocol/session_manager_pair.h',
'run_all_unittests.cc',