summaryrefslogtreecommitdiffstats
path: root/remoting/protocol
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-16 19:53:35 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-16 19:53:35 +0000
commit6fd3d6a1648a754d8023924074612d55c187b4cf (patch)
tree102ac605e52b8cf1a4e423b5403a0302a5ee9f76 /remoting/protocol
parent3e4155c723ab73c8f754a82d81f0eb247c83536f (diff)
downloadchromium_src-6fd3d6a1648a754d8023924074612d55c187b4cf.zip
chromium_src-6fd3d6a1648a754d8023924074612d55c187b4cf.tar.gz
chromium_src-6fd3d6a1648a754d8023924074612d55c187b4cf.tar.bz2
Implement input stub in the host side for chromoting
Implement InputStub for the host. BUG=None TEST=None Review URL: http://codereview.chromium.org/4726003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66314 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/protocol')
-rw-r--r--remoting/protocol/connection_to_client.cc27
-rw-r--r--remoting/protocol/connection_to_client.h33
-rw-r--r--remoting/protocol/connection_to_client_unittest.cc5
-rw-r--r--remoting/protocol/connection_to_host.h1
-rw-r--r--remoting/protocol/host_message_dispatcher.cc16
-rw-r--r--remoting/protocol/host_message_dispatcher.h4
-rw-r--r--remoting/protocol/host_stub.h2
-rw-r--r--remoting/protocol/input_stub.h4
-rw-r--r--remoting/protocol/mock_objects.h24
9 files changed, 72 insertions, 44 deletions
diff --git a/remoting/protocol/connection_to_client.cc b/remoting/protocol/connection_to_client.cc
index c3c695d..0661be3 100644
--- a/remoting/protocol/connection_to_client.cc
+++ b/remoting/protocol/connection_to_client.cc
@@ -7,6 +7,7 @@
#include "google/protobuf/message.h"
#include "net/base/io_buffer.h"
#include "remoting/protocol/client_control_sender.h"
+#include "remoting/protocol/host_message_dispatcher.h"
// TODO(hclam): Remove this header once MessageDispatcher is used.
#include "remoting/base/compound_buffer.h"
@@ -19,9 +20,13 @@ namespace protocol {
static const size_t kAverageUpdateStream = 10;
ConnectionToClient::ConnectionToClient(MessageLoop* message_loop,
- EventHandler* handler)
+ EventHandler* handler,
+ HostStub* host_stub,
+ InputStub* input_stub)
: loop_(message_loop),
- handler_(handler) {
+ handler_(handler),
+ host_stub_(host_stub),
+ input_stub_(input_stub) {
DCHECK(loop_);
DCHECK(handler_);
}
@@ -74,23 +79,17 @@ void ConnectionToClient::OnSessionStateChange(
protocol::Session::State state) {
if (state == protocol::Session::CONNECTED) {
client_stub_.reset(new ClientControlSender(session_->control_channel()));
- event_reader_.Init<ChromotingClientMessage>(
- session_->event_channel(),
- NewCallback(this, &ConnectionToClient::OnMessageReceived));
video_writer_.reset(VideoWriter::Create(session_->config()));
video_writer_->Init(session_);
+
+ dispatcher_.reset(new HostMessageDispatcher());
+ dispatcher_->Initialize(session_.get(), host_stub_, input_stub_);
}
loop_->PostTask(FROM_HERE,
NewRunnableMethod(this, &ConnectionToClient::StateChangeTask, state));
}
-void ConnectionToClient::OnMessageReceived(ChromotingClientMessage* message) {
- loop_->PostTask(FROM_HERE,
- NewRunnableMethod(this, &ConnectionToClient::MessageReceivedTask,
- message));
-}
-
void ConnectionToClient::StateChangeTask(protocol::Session::State state) {
DCHECK_EQ(loop_, MessageLoop::current());
@@ -114,12 +113,6 @@ void ConnectionToClient::StateChangeTask(protocol::Session::State state) {
}
}
-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 ConnectionToClient::OnClosed() {
}
diff --git a/remoting/protocol/connection_to_client.h b/remoting/protocol/connection_to_client.h
index 769b0a8..546db76 100644
--- a/remoting/protocol/connection_to_client.h
+++ b/remoting/protocol/connection_to_client.h
@@ -11,7 +11,6 @@
#include "base/message_loop.h"
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
-#include "remoting/protocol/message_reader.h"
#include "remoting/protocol/session.h"
#include "remoting/protocol/stream_writer.h"
#include "remoting/protocol/video_writer.h"
@@ -20,6 +19,9 @@ namespace remoting {
namespace protocol {
class ClientStub;
+class HostStub;
+class InputStub;
+class HostMessageDispatcher;
// This class represents a remote viewer connected to the chromoting host
// through a libjingle connection. A viewer object is responsible for sending
@@ -27,19 +29,12 @@ class ClientStub;
// responsible for receiving and parsing data from the remote viewer and
// delegating events to the event handler.
class ConnectionToClient :
- public base::RefCountedThreadSafe<ConnectionToClient> {
+ public base::RefCountedThreadSafe<ConnectionToClient> {
public:
class EventHandler {
public:
virtual ~EventHandler() {}
- // 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(ConnectionToClient* connection,
- ChromotingClientMessage* message) = 0;
-
// Called when the network connection is opened.
virtual void OnConnectionOpened(ConnectionToClient* connection) = 0;
@@ -55,7 +50,9 @@ class ConnectionToClient :
// a libjingle channel, these events are delegated to |handler|.
// It is guranteed that |handler| is called only on the |message_loop|.
ConnectionToClient(MessageLoop* message_loop,
- EventHandler* handler);
+ EventHandler* handler,
+ HostStub* host_stub,
+ InputStub* input_stub);
virtual ~ConnectionToClient();
@@ -90,21 +87,14 @@ class ConnectionToClient :
// Callback for protocol Session.
void OnSessionStateChange(protocol::Session::State state);
- // Callback for MessageReader.
- void OnMessageReceived(ChromotingClientMessage* message);
-
// Process a libjingle state change event on the |loop_|.
void StateChangeTask(protocol::Session::State state);
- // Process a data buffer received from libjingle.
- void MessageReceivedTask(ChromotingClientMessage* message);
-
void OnClosed();
// The libjingle channel used to send and receive data from the remote client.
scoped_refptr<protocol::Session> session_;
- MessageReader event_reader_;
scoped_ptr<VideoWriter> video_writer_;
// ClientStub for sending messages to the client.
@@ -116,6 +106,15 @@ class ConnectionToClient :
// Event handler for handling events sent from this object.
EventHandler* handler_;
+ // HostStub for receiving control events from the client.
+ HostStub* host_stub_;
+
+ // InputStub for receiving input events from the client.
+ InputStub* input_stub_;
+
+ // Dispatcher for submitting messages to stubs.
+ scoped_ptr<HostMessageDispatcher> dispatcher_;
+
DISALLOW_COPY_AND_ASSIGN(ConnectionToClient);
};
diff --git a/remoting/protocol/connection_to_client_unittest.cc b/remoting/protocol/connection_to_client_unittest.cc
index e199c12..eaea342 100644
--- a/remoting/protocol/connection_to_client_unittest.cc
+++ b/remoting/protocol/connection_to_client_unittest.cc
@@ -27,7 +27,8 @@ class ConnectionToClientTest : public testing::Test {
session_->set_message_loop(&message_loop_);
// Allocate a ClientConnection object with the mock objects.
- viewer_ = new ConnectionToClient(&message_loop_, &handler_);
+ viewer_ = new ConnectionToClient(&message_loop_, &handler_,
+ &host_stub_, &input_stub_);
viewer_->Init(session_);
EXPECT_CALL(handler_, OnConnectionOpened(viewer_.get()));
session_->state_change_callback()->Run(
@@ -37,6 +38,8 @@ class ConnectionToClientTest : public testing::Test {
MessageLoop message_loop_;
MockConnectionToClientEventHandler handler_;
+ MockHostStub host_stub_;
+ MockInputStub input_stub_;
scoped_refptr<ConnectionToClient> viewer_;
scoped_refptr<protocol::FakeSession> session_;
diff --git a/remoting/protocol/connection_to_host.h b/remoting/protocol/connection_to_host.h
index e2b0ce2..d34b9ee 100644
--- a/remoting/protocol/connection_to_host.h
+++ b/remoting/protocol/connection_to_host.h
@@ -10,7 +10,6 @@
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
#include "remoting/proto/internal.pb.h"
-#include "remoting/protocol/message_decoder.h"
namespace remoting {
namespace protocol {
diff --git a/remoting/protocol/host_message_dispatcher.cc b/remoting/protocol/host_message_dispatcher.cc
index 7ad9cac..13fa803 100644
--- a/remoting/protocol/host_message_dispatcher.cc
+++ b/remoting/protocol/host_message_dispatcher.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/ref_counted.h"
#include "net/base/io_buffer.h"
#include "remoting/proto/control.pb.h"
#include "remoting/proto/event.pb.h"
@@ -77,13 +78,24 @@ void HostMessageDispatcher::OnControlMessageReceived(ControlMessage* message) {
new RefCountedMessage<ControlMessage>(message);
if (message->has_suggest_resolution()) {
host_stub_->SuggestResolution(
- message->suggest_resolution(), NewDeleteTask(ref_msg));
+ &message->suggest_resolution(), NewDeleteTask(ref_msg));
}
}
void HostMessageDispatcher::OnEventMessageReceived(
EventMessage* message) {
- // TODO(hclam): Implement.
+ scoped_refptr<RefCountedMessage<EventMessage> > ref_msg =
+ new RefCountedMessage<EventMessage>(message);
+ for (int i = 0; i < message->event_size(); ++i) {
+ if (message->event(i).has_key()) {
+ input_stub_->InjectKeyEvent(
+ &message->event(i).key(), NewDeleteTask(ref_msg));
+ }
+ if (message->event(i).has_mouse()) {
+ input_stub_->InjectMouseEvent(
+ &message->event(i).mouse(), NewDeleteTask(ref_msg));
+ }
+ }
}
} // namespace protocol
diff --git a/remoting/protocol/host_message_dispatcher.h b/remoting/protocol/host_message_dispatcher.h
index cd95b26..c8b7a39 100644
--- a/remoting/protocol/host_message_dispatcher.h
+++ b/remoting/protocol/host_message_dispatcher.h
@@ -6,7 +6,6 @@
#define REMOTING_PROTOCOL_HOST_MESSAGE_DISPATCHER_H_
#include "base/basictypes.h"
-#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
#include "base/task.h"
@@ -32,8 +31,7 @@ class Session;
//
// Object of this class is owned by ChromotingHost to dispatch messages
// to itself.
-class HostMessageDispatcher :
- public base::RefCountedThreadSafe<HostMessageDispatcher> {
+class HostMessageDispatcher {
public:
// Construct a message dispatcher.
HostMessageDispatcher();
diff --git a/remoting/protocol/host_stub.h b/remoting/protocol/host_stub.h
index a9e2fa5..cf14daa 100644
--- a/remoting/protocol/host_stub.h
+++ b/remoting/protocol/host_stub.h
@@ -24,7 +24,7 @@ class HostStub {
virtual ~HostStub() {};
virtual void SuggestResolution(
- const SuggestResolutionRequest& msg, Task* done) = 0;
+ const SuggestResolutionRequest* msg, Task* done) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(HostStub);
diff --git a/remoting/protocol/input_stub.h b/remoting/protocol/input_stub.h
index 201dda3..c36ff07 100644
--- a/remoting/protocol/input_stub.h
+++ b/remoting/protocol/input_stub.h
@@ -22,8 +22,8 @@ class InputStub {
InputStub() {}
virtual ~InputStub() {}
- virtual void InjectKeyEvent(const KeyEvent& event, Task* done) = 0;
- virtual void InjectMouseEvent(const MouseEvent& event, Task* done) = 0;
+ virtual void InjectKeyEvent(const KeyEvent* event, Task* done) = 0;
+ virtual void InjectMouseEvent(const MouseEvent* event, Task* done) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(InputStub);
diff --git a/remoting/protocol/mock_objects.h b/remoting/protocol/mock_objects.h
index 5acb131..b10c139 100644
--- a/remoting/protocol/mock_objects.h
+++ b/remoting/protocol/mock_objects.h
@@ -7,6 +7,8 @@
#include "remoting/proto/internal.pb.h"
#include "remoting/protocol/connection_to_client.h"
+#include "remoting/protocol/host_stub.h"
+#include "remoting/protocol/input_stub.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace remoting {
@@ -44,6 +46,28 @@ class MockConnectionToClientEventHandler :
DISALLOW_COPY_AND_ASSIGN(MockConnectionToClientEventHandler);
};
+class MockInputStub : public InputStub {
+ public:
+ MockInputStub() {}
+
+ MOCK_METHOD2(InjectKeyEvent, void(const KeyEvent* event, Task* done));
+ MOCK_METHOD2(InjectMouseEvent, void(const MouseEvent* event, Task* done));
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockInputStub);
+};
+
+class MockHostStub : public HostStub {
+ public:
+ MockHostStub() {}
+
+ MOCK_METHOD2(SuggestResolution, void(const SuggestResolutionRequest* msg,
+ Task* done));
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockHostStub);
+};
+
} // namespace protocol
} // namespace remoting