summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-13 18:17:30 +0000
committerlambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-13 18:17:30 +0000
commitb25ff3b40b859a512f38106bd04010dac9412bd6 (patch)
treed14ef420f85b380bd99756ce5d5d6668237477fd
parentd4fe2317514900f7a70cb61da28bc3fced7da974 (diff)
downloadchromium_src-b25ff3b40b859a512f38106bd04010dac9412bd6.zip
chromium_src-b25ff3b40b859a512f38106bd04010dac9412bd6.tar.gz
chromium_src-b25ff3b40b859a512f38106bd04010dac9412bd6.tar.bz2
Refactor InputStub interface to pass events by value (const reference).
This will make it much easier to inject modified key/mouse events, for example, restricting mouse-coordinates to the screen area. BUG=None TEST=Manual Review URL: http://codereview.chromium.org/7803004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100939 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--remoting/client/input_handler.cc27
-rw-r--r--remoting/host/client_session.cc48
-rw-r--r--remoting/host/client_session.h10
-rw-r--r--remoting/host/client_session_unittest.cc53
-rw-r--r--remoting/host/event_executor_linux.cc58
-rw-r--r--remoting/host/event_executor_mac.cc46
-rw-r--r--remoting/host/event_executor_win.cc53
-rw-r--r--remoting/host/host_mock_objects.cc1
-rw-r--r--remoting/host/host_mock_objects.h6
-rw-r--r--remoting/protocol/host_message_dispatcher.cc10
-rw-r--r--remoting/protocol/input_sender.cc18
-rw-r--r--remoting/protocol/input_sender.h4
-rw-r--r--remoting/protocol/input_stub.h4
-rw-r--r--remoting/protocol/protocol_mock_objects.h4
14 files changed, 159 insertions, 183 deletions
diff --git a/remoting/client/input_handler.cc b/remoting/client/input_handler.cc
index 690ce04..7b48d89 100644
--- a/remoting/client/input_handler.cc
+++ b/remoting/client/input_handler.cc
@@ -34,22 +34,20 @@ void InputHandler::SendKeyEvent(bool press, int keycode) {
pressed_keys_.erase(keycode);
}
- KeyEvent* event = new KeyEvent();
- event->set_keycode(keycode);
- event->set_pressed(press);
-
- stub->InjectKeyEvent(event, new DeleteTask<KeyEvent>(event));
+ KeyEvent event;
+ event.set_keycode(keycode);
+ event.set_pressed(press);
+ stub->InjectKeyEvent(event);
}
}
void InputHandler::SendMouseMoveEvent(int x, int y) {
protocol::InputStub* stub = connection_->input_stub();
if (stub) {
- MouseEvent* event = new MouseEvent();
- event->set_x(x);
- event->set_y(y);
-
- stub->InjectMouseEvent(event, new DeleteTask<MouseEvent>(event));
+ MouseEvent event;
+ event.set_x(x);
+ event.set_y(y);
+ stub->InjectMouseEvent(event);
}
}
@@ -57,11 +55,10 @@ void InputHandler::SendMouseButtonEvent(bool button_down,
MouseEvent::MouseButton button) {
protocol::InputStub* stub = connection_->input_stub();
if (stub) {
- MouseEvent* event = new MouseEvent();
- event->set_button(button);
- event->set_button_down(button_down);
-
- stub->InjectMouseEvent(event, new DeleteTask<MouseEvent>(event));
+ MouseEvent event;
+ event.set_button(button);
+ event.set_button_down(button_down);
+ stub->InjectMouseEvent(event);
}
}
diff --git a/remoting/host/client_session.cc b/remoting/host/client_session.cc
index 72666fb..9a8002e 100644
--- a/remoting/host/client_session.cc
+++ b/remoting/host/client_session.cc
@@ -24,6 +24,7 @@ static const int64 kRemoteBlockTimeoutMillis = 2000;
namespace remoting {
using protocol::KeyEvent;
+using protocol::MouseEvent;
ClientSession::ClientSession(
EventHandler* event_handler,
@@ -74,37 +75,34 @@ void ClientSession::OnAuthorizationComplete(bool success) {
}
}
-void ClientSession::InjectKeyEvent(const KeyEvent* event, Task* done) {
- base::ScopedTaskRunner done_runner(done);
+void ClientSession::InjectKeyEvent(const KeyEvent& event) {
if (authenticated_ && !ShouldIgnoreRemoteKeyboardInput(event)) {
RecordKeyEvent(event);
- input_stub_->InjectKeyEvent(event, done_runner.Release());
+ input_stub_->InjectKeyEvent(event);
}
}
-void ClientSession::InjectMouseEvent(const protocol::MouseEvent* event,
- Task* done) {
- base::ScopedTaskRunner done_runner(done);
+void ClientSession::InjectMouseEvent(const MouseEvent& event) {
if (authenticated_ && !ShouldIgnoreRemoteMouseInput(event)) {
- if (event->has_button() && event->has_button_down()) {
- if (event->button() >= 1 && event->button() < 32) {
- uint32 button_change = 1 << (event->button() - 1);
- if (event->button_down()) {
+ if (event.has_button() && event.has_button_down()) {
+ if (event.button() >= 1 && event.button() < 32) {
+ uint32 button_change = 1 << (event.button() - 1);
+ if (event.button_down()) {
remote_mouse_button_state_ |= button_change;
} else {
remote_mouse_button_state_ &= ~button_change;
}
}
}
- if (event->has_x() && event->has_y()) {
- gfx::Point pos(event->x(), event->y());
+ if (event.has_x() && event.has_y()) {
+ gfx::Point pos(event.x(), event.y());
injected_mouse_positions_.push_back(pos);
if (injected_mouse_positions_.size() > kNumRemoteMousePositions) {
VLOG(1) << "Injected mouse positions queue full.";
injected_mouse_positions_.pop_front();
}
}
- input_stub_->InjectMouseEvent(event, done_runner.Release());
+ input_stub_->InjectMouseEvent(event);
}
}
@@ -138,7 +136,7 @@ void ClientSession::LocalMouseMoved(const gfx::Point& mouse_pos) {
}
bool ClientSession::ShouldIgnoreRemoteMouseInput(
- const protocol::MouseEvent* event) const {
+ const protocol::MouseEvent& event) const {
// If the last remote input event was a click or a drag, then it's not safe
// to block remote mouse events. For example, it might result in the host
// missing the mouse-up event and being stuck with the button pressed.
@@ -157,32 +155,32 @@ bool ClientSession::ShouldIgnoreRemoteMouseInput(
}
bool ClientSession::ShouldIgnoreRemoteKeyboardInput(
- const KeyEvent* event) const {
+ const KeyEvent& event) const {
// If the host user has not yet approved the continuation of the connection,
// then all remote keyboard input is ignored, except to release keys that
// were already pressed.
if (awaiting_continue_approval_) {
- return event->pressed() ||
- (pressed_keys_.find(event->keycode()) == pressed_keys_.end());
+ return event.pressed() ||
+ (pressed_keys_.find(event.keycode()) == pressed_keys_.end());
}
return false;
}
-void ClientSession::RecordKeyEvent(const KeyEvent* event) {
- if (event->pressed()) {
- pressed_keys_.insert(event->keycode());
+void ClientSession::RecordKeyEvent(const KeyEvent& event) {
+ if (event.pressed()) {
+ pressed_keys_.insert(event.keycode());
} else {
- pressed_keys_.erase(event->keycode());
+ pressed_keys_.erase(event.keycode());
}
}
void ClientSession::UnpressKeys() {
std::set<int>::iterator i;
for (i = pressed_keys_.begin(); i != pressed_keys_.end(); ++i) {
- KeyEvent* key = new KeyEvent();
- key->set_keycode(*i);
- key->set_pressed(false);
- input_stub_->InjectKeyEvent(key, new DeleteTask<KeyEvent>(key));
+ KeyEvent key;
+ key.set_keycode(*i);
+ key.set_pressed(false);
+ input_stub_->InjectKeyEvent(key);
}
pressed_keys_.clear();
}
diff --git a/remoting/host/client_session.h b/remoting/host/client_session.h
index d9cd337..9ff7b93 100644
--- a/remoting/host/client_session.h
+++ b/remoting/host/client_session.h
@@ -51,8 +51,8 @@ class ClientSession : public protocol::HostStub,
const protocol::LocalLoginCredentials* credentials, Task* done);
// protocol::InputStub interface.
- virtual void InjectKeyEvent(const protocol::KeyEvent* event, Task* done);
- virtual void InjectMouseEvent(const protocol::MouseEvent* event, Task* done);
+ virtual void InjectKeyEvent(const protocol::KeyEvent& event);
+ virtual void InjectMouseEvent(const protocol::MouseEvent& event);
// Disconnect this client session.
void Disconnect();
@@ -79,8 +79,8 @@ class ClientSession : public protocol::HostStub,
// have the upper hand in 'pointer wars'.
void LocalMouseMoved(const gfx::Point& new_pos);
- bool ShouldIgnoreRemoteMouseInput(const protocol::MouseEvent* event) const;
- bool ShouldIgnoreRemoteKeyboardInput(const protocol::KeyEvent* event) const;
+ bool ShouldIgnoreRemoteMouseInput(const protocol::MouseEvent& event) const;
+ bool ShouldIgnoreRemoteKeyboardInput(const protocol::KeyEvent& event) const;
private:
friend class base::RefCountedThreadSafe<ClientSession>;
@@ -89,7 +89,7 @@ class ClientSession : public protocol::HostStub,
// Keep track of keydowns and keyups so that we can clean up the keyboard
// state when the user disconnects.
- void RecordKeyEvent(const protocol::KeyEvent* event);
+ void RecordKeyEvent(const protocol::KeyEvent& event);
// Synthesize KeyUp events for keys that have been pressed but not released.
// This should be used when the client has disconnected to clear out any
diff --git a/remoting/host/client_session_unittest.cc b/remoting/host/client_session_unittest.cc
index 07b2e92..ef80941 100644
--- a/remoting/host/client_session_unittest.cc
+++ b/remoting/host/client_session_unittest.cc
@@ -50,9 +50,6 @@ class ClientSessionTest : public testing::Test {
user_authenticator_,
connection_,
&input_stub_);
-
- ON_CALL(input_stub_, InjectKeyEvent(_, _)).WillByDefault(DeleteArg<1>());
- ON_CALL(input_stub_, InjectMouseEvent(_, _)).WillByDefault(DeleteArg<1>());
}
protected:
@@ -68,6 +65,14 @@ class ClientSessionTest : public testing::Test {
scoped_refptr<ClientSession> client_session_;
};
+MATCHER_P2(EqualsKeyEvent, keycode, pressed, "") {
+ return arg.keycode() == keycode && arg.pressed() == pressed;
+}
+
+MATCHER_P2(EqualsMouseEvent, x, y, "") {
+ return arg.x() == x && arg.y() == y;
+}
+
TEST_F(ClientSessionTest, InputStubFilter) {
protocol::KeyEvent key_event1;
key_event1.set_pressed(true);
@@ -106,25 +111,25 @@ TEST_F(ClientSessionTest, InputStubFilter) {
EXPECT_CALL(*user_authenticator_, Authenticate(_, _))
.WillOnce(Return(true));
EXPECT_CALL(session_event_handler_, LocalLoginSucceeded(_));
- EXPECT_CALL(input_stub_, InjectKeyEvent(&key_event2_down, _));
- EXPECT_CALL(input_stub_, InjectKeyEvent(&key_event2_up, _));
- EXPECT_CALL(input_stub_, InjectMouseEvent(&mouse_event2, _));
+ EXPECT_CALL(input_stub_, InjectKeyEvent(EqualsKeyEvent(2, true)));
+ EXPECT_CALL(input_stub_, InjectKeyEvent(EqualsKeyEvent(2, false)));
+ EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201)));
EXPECT_CALL(*connection_.get(), Disconnect());
// These events should not get through to the input stub,
// because the client isn't authenticated yet.
- client_session_->InjectKeyEvent(&key_event1, new DummyTask());
- client_session_->InjectMouseEvent(&mouse_event1, new DummyTask());
+ client_session_->InjectKeyEvent(key_event1);
+ client_session_->InjectMouseEvent(mouse_event1);
client_session_->BeginSessionRequest(&credentials, new DummyTask());
// These events should get through to the input stub.
- client_session_->InjectKeyEvent(&key_event2_down, new DummyTask());
- client_session_->InjectKeyEvent(&key_event2_up, new DummyTask());
- client_session_->InjectMouseEvent(&mouse_event2, new DummyTask());
+ client_session_->InjectKeyEvent(key_event2_down);
+ client_session_->InjectKeyEvent(key_event2_up);
+ client_session_->InjectMouseEvent(mouse_event2);
client_session_->Disconnect();
// These events should not get through to the input stub,
// because the client has disconnected.
- client_session_->InjectKeyEvent(&key_event3, new DummyTask());
- client_session_->InjectMouseEvent(&mouse_event3, new DummyTask());
+ client_session_->InjectKeyEvent(key_event3);
+ client_session_->InjectMouseEvent(mouse_event3);
}
TEST_F(ClientSessionTest, LocalInputTest) {
@@ -147,28 +152,24 @@ TEST_F(ClientSessionTest, LocalInputTest) {
EXPECT_CALL(*user_authenticator_, Authenticate(_, _))
.WillOnce(Return(true));
EXPECT_CALL(session_event_handler_, LocalLoginSucceeded(_));
- EXPECT_CALL(input_stub_, InjectMouseEvent(&mouse_event1, _));
- EXPECT_CALL(input_stub_, InjectMouseEvent(&mouse_event2, _));
+ EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent(100, 101)));
+ EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201)));
EXPECT_CALL(*connection_.get(), Disconnect());
client_session_->BeginSessionRequest(&credentials, new DummyTask());
// This event should get through to the input stub.
- client_session_->InjectMouseEvent(&mouse_event1, new DummyTask());
+ client_session_->InjectMouseEvent(mouse_event1);
// This one should too because the local event echoes the remote one.
client_session_->LocalMouseMoved(gfx::Point(mouse_event1.x(),
mouse_event1.y()));
- client_session_->InjectMouseEvent(&mouse_event2, new DummyTask());
+ client_session_->InjectMouseEvent(mouse_event2);
// This one should not.
client_session_->LocalMouseMoved(gfx::Point(mouse_event1.x(),
mouse_event1.y()));
- client_session_->InjectMouseEvent(&mouse_event3, new DummyTask());
+ client_session_->InjectMouseEvent(mouse_event3);
// TODO(jamiewalch): Verify that remote inputs are re-enabled eventually
// (via dependency injection, not sleep!)
client_session_->Disconnect();
- }
-
-MATCHER_P(IsMatchingKeyUp, k, "") {
- return !arg->pressed() && arg->keycode() == k->keycode();
}
TEST_F(ClientSessionTest, UnpressKeys) {
@@ -180,11 +181,11 @@ TEST_F(ClientSessionTest, UnpressKeys) {
key2.set_pressed(true);
key2.set_keycode(2);
- client_session_->RecordKeyEvent(&key1);
- client_session_->RecordKeyEvent(&key2);
+ client_session_->RecordKeyEvent(key1);
+ client_session_->RecordKeyEvent(key2);
- EXPECT_CALL(input_stub_, InjectKeyEvent(IsMatchingKeyUp(&key1), _));
- EXPECT_CALL(input_stub_, InjectKeyEvent(IsMatchingKeyUp(&key2), _));
+ EXPECT_CALL(input_stub_, InjectKeyEvent(EqualsKeyEvent(1, false)));
+ EXPECT_CALL(input_stub_, InjectKeyEvent(EqualsKeyEvent(2, false)));
client_session_->UnpressKeys();
}
diff --git a/remoting/host/event_executor_linux.cc b/remoting/host/event_executor_linux.cc
index 6867c66..56ac3e4 100644
--- a/remoting/host/event_executor_linux.cc
+++ b/remoting/host/event_executor_linux.cc
@@ -10,6 +10,7 @@
#include <X11/extensions/XTest.h>
#include "base/basictypes.h"
+#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/message_loop.h"
@@ -31,8 +32,8 @@ class EventExecutorLinux : public EventExecutor {
bool Init();
- virtual void InjectKeyEvent(const KeyEvent* event, Task* done) OVERRIDE;
- virtual void InjectMouseEvent(const MouseEvent* event, Task* done) OVERRIDE;
+ virtual void InjectKeyEvent(const KeyEvent& event) OVERRIDE;
+ virtual void InjectMouseEvent(const MouseEvent& event) OVERRIDE;
private:
MessageLoop* message_loop_;
@@ -276,22 +277,20 @@ bool EventExecutorLinux::Init() {
return true;
}
-void EventExecutorLinux::InjectKeyEvent(const KeyEvent* event, Task* done) {
- base::ScopedTaskRunner done_runner(done);
-
+void EventExecutorLinux::InjectKeyEvent(const KeyEvent& event) {
if (MessageLoop::current() != message_loop_) {
message_loop_->PostTask(
FROM_HERE,
- NewRunnableMethod(this, &EventExecutorLinux::InjectKeyEvent,
- event, done_runner.Release()));
+ base::Bind(&EventExecutorLinux::InjectKeyEvent, base::Unretained(this),
+ event));
return;
}
// TODO(ajwong): This will only work for QWERTY keyboards.
- int keysym = ChromotocolKeycodeToX11Keysym(event->keycode());
+ int keysym = ChromotocolKeycodeToX11Keysym(event.keycode());
if (keysym == -1) {
- LOG(WARNING) << "Ignoring unknown key: " << event->keycode();
+ LOG(WARNING) << "Ignoring unknown key: " << event.keycode();
return;
}
@@ -299,63 +298,60 @@ void EventExecutorLinux::InjectKeyEvent(const KeyEvent* event, Task* done) {
int keycode = XKeysymToKeycode(display_, keysym);
if (keycode == 0) {
LOG(WARNING) << "Ignoring undefined keysym: " << keysym
- << " for key: " << event->keycode();
+ << " for key: " << event.keycode();
return;
}
- VLOG(3) << "Got pepper key: " << event->keycode()
+ VLOG(3) << "Got pepper key: " << event.keycode()
<< " sending keysym: " << keysym
<< " to keycode: " << keycode;
- XTestFakeKeyEvent(display_, keycode, event->pressed(), CurrentTime);
+ XTestFakeKeyEvent(display_, keycode, event.pressed(), CurrentTime);
XFlush(display_);
}
-void EventExecutorLinux::InjectMouseEvent(const MouseEvent* event,
- Task* done) {
- base::ScopedTaskRunner done_runner(done);
-
+void EventExecutorLinux::InjectMouseEvent(const MouseEvent& event) {
if (MessageLoop::current() != message_loop_) {
message_loop_->PostTask(
FROM_HERE,
- NewRunnableMethod(this, &EventExecutorLinux::InjectMouseEvent,
- event, done_runner.Release()));
+ base::Bind(&EventExecutorLinux::InjectMouseEvent,
+ base::Unretained(this), event));
return;
}
- if (event->has_x() && event->has_y()) {
- if (event->x() < 0 || event->y() < 0 ||
- event->x() > width_ || event->y() > height_) {
+ if (event.has_x() && event.has_y()) {
+ if (event.x() < 0 || event.y() < 0 ||
+ event.x() > width_ || event.y() > height_) {
// A misbehaving client may send these. Drop events that are out of range.
// TODO(ajwong): How can we log this sanely? We don't want to DOS the
// server with a misbehaving client by logging like crazy.
return;
}
- VLOG(3) << "Moving mouse to " << event->x()
- << "," << event->y();
+ VLOG(3) << "Moving mouse to " << event.x()
+ << "," << event.y();
XTestFakeMotionEvent(display_, DefaultScreen(display_),
- event->x(), event->y(),
+ event.x(), event.y(),
CurrentTime);
XFlush(display_);
}
- if (event->has_button() && event->has_button_down()) {
- int button_number = MouseButtonToX11ButtonNumber(event->button());
+ if (event.has_button() && event.has_button_down()) {
+ int button_number = MouseButtonToX11ButtonNumber(event.button());
if (button_number < 0) {
LOG(WARNING) << "Ignoring unknown button type: "
- << event->button();
+ << event.button();
return;
}
- VLOG(3) << "Button " << event->button()
+ VLOG(3) << "Button " << event.button()
<< " received, sending down " << button_number;
- XTestFakeButtonEvent(display_, button_number, event->button_down(),
+ XTestFakeButtonEvent(display_, button_number, event.button_down(),
CurrentTime);
XFlush(display_);
}
- if (event->has_wheel_offset_x() && event->has_wheel_offset_y()) {
+ if (event.has_wheel_offset_x() && event.has_wheel_offset_y()) {
NOTIMPLEMENTED() << "No scroll wheel support yet.";
}
}
@@ -373,5 +369,3 @@ EventExecutor* EventExecutor::Create(MessageLoop* message_loop,
}
} // namespace remoting
-
-DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::EventExecutorLinux);
diff --git a/remoting/host/event_executor_mac.cc b/remoting/host/event_executor_mac.cc
index be782a2..0ca50af 100644
--- a/remoting/host/event_executor_mac.cc
+++ b/remoting/host/event_executor_mac.cc
@@ -29,8 +29,8 @@ class EventExecutorMac : public EventExecutor {
EventExecutorMac(MessageLoop* message_loop, Capturer* capturer);
virtual ~EventExecutorMac() {}
- virtual void InjectKeyEvent(const KeyEvent* event, Task* done) OVERRIDE;
- virtual void InjectMouseEvent(const MouseEvent* event, Task* done) OVERRIDE;
+ virtual void InjectKeyEvent(const KeyEvent& event) OVERRIDE;
+ virtual void InjectMouseEvent(const MouseEvent& event) OVERRIDE;
private:
MessageLoop* message_loop_;
@@ -212,50 +212,46 @@ const int kUsVkeyToKeysym[256] = {
/* VKEY_NONAME */ -1, /* VKEY_PA1 */ -1, /* VKEY_OEM_CLEAR */ -1, -1
};
-void EventExecutorMac::InjectKeyEvent(const KeyEvent* event, Task* done) {
- base::ScopedTaskRunner done_runner(done);
-
- int key_code = event->keycode();
+void EventExecutorMac::InjectKeyEvent(const KeyEvent& event) {
+ int key_code = event.keycode();
if (key_code >= 0 && key_code < 256) {
int key_sym = kUsVkeyToKeysym[key_code];
if (key_sym != -1) {
// We use the deprecated event injection API because the new one doesn't
// work with switched-out sessions (curtain mode).
- CGPostKeyboardEvent(0, key_sym, event->pressed());
+ CGPostKeyboardEvent(0, key_sym, event.pressed());
}
}
}
-void EventExecutorMac::InjectMouseEvent(const MouseEvent* event, Task* done) {
- base::ScopedTaskRunner done_runner(done);
-
- if (event->has_x() && event->has_y()) {
+void EventExecutorMac::InjectMouseEvent(const MouseEvent& event) {
+ if (event.has_x() && event.has_y()) {
// TODO(wez): Checking the validity of the MouseEvent should be done in core
// cross-platform code, not here!
// TODO(wez): This code assumes that MouseEvent(0,0) (top-left of client view)
// corresponds to local (0,0) (top-left of primary monitor). That won't in
// general be true on multi-monitor systems, though.
gfx::Size size = capturer_->size_most_recent();
- if (event->x() >= 0 || event->y() >= 0 ||
- event->x() < size.width() || event->y() < size.height()) {
- VLOG(3) << "Moving mouse to " << event->x() << "," << event->y();
- last_x_ = event->x();
- last_y_ = event->y();
+ if (event.x() >= 0 || event.y() >= 0 ||
+ event.x() < size.width() || event.y() < size.height()) {
+ VLOG(3) << "Moving mouse to " << event.x() << "," << event.y();
+ last_x_ = event.x();
+ last_y_ = event.y();
} else {
- VLOG(1) << "Invalid mouse position " << event->x() << "," << event->y();
+ VLOG(1) << "Invalid mouse position " << event.x() << "," << event.y();
}
}
- if (event->has_button() && event->has_button_down()) {
- if (event->button() >= 1 && event->button() <= 3) {
- VLOG(2) << "Button " << event->button()
- << (event->button_down() ? " down" : " up");
- int button_change = 1 << (event->button() - 1);
- if (event->button_down())
+ if (event.has_button() && event.has_button_down()) {
+ if (event.button() >= 1 && event.button() <= 3) {
+ VLOG(2) << "Button " << event.button()
+ << (event.button_down() ? " down" : " up");
+ int button_change = 1 << (event.button() - 1);
+ if (event.button_down())
mouse_buttons_ |= button_change;
else
mouse_buttons_ &= ~button_change;
} else {
- VLOG(1) << "Unknown mouse button: " << event->button();
+ VLOG(1) << "Unknown mouse button: " << event.button();
}
}
// We use the deprecated CGPostMouseEvent API because we receive low-level
@@ -275,7 +271,7 @@ void EventExecutorMac::InjectMouseEvent(const MouseEvent* event, Task* done) {
(mouse_buttons_ & RightBit) != 0,
(mouse_buttons_ & MiddleBit) != 0);
- if (event->has_wheel_offset_x() && event->has_wheel_offset_y()) {
+ if (event.has_wheel_offset_x() && event.has_wheel_offset_y()) {
// TODO(jamiewalch): Use either CGPostScrollWheelEvent() or
// CGEventCreateScrollWheelEvent() to inject scroll events.
NOTIMPLEMENTED() << "No scroll wheel support yet.";
diff --git a/remoting/host/event_executor_win.cc b/remoting/host/event_executor_win.cc
index 2f7e737..c4283e4 100644
--- a/remoting/host/event_executor_win.cc
+++ b/remoting/host/event_executor_win.cc
@@ -6,6 +6,7 @@
#include <windows.h>
+#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/message_loop.h"
#include "media/base/callback.h"
@@ -26,12 +27,12 @@ class EventExecutorWin : public EventExecutor {
EventExecutorWin(MessageLoop* message_loop, Capturer* capturer);
virtual ~EventExecutorWin() {}
- virtual void InjectKeyEvent(const KeyEvent* event, Task* done) OVERRIDE;
- virtual void InjectMouseEvent(const MouseEvent* event, Task* done) OVERRIDE;
+ virtual void InjectKeyEvent(const KeyEvent& event) OVERRIDE;
+ virtual void InjectMouseEvent(const MouseEvent& event) OVERRIDE;
private:
- void HandleKey(const KeyEvent* event);
- void HandleMouse(const MouseEvent* event);
+ void HandleKey(const KeyEvent& event);
+ void HandleMouse(const MouseEvent& event);
MessageLoop* message_loop_;
Capturer* capturer_;
@@ -45,37 +46,33 @@ EventExecutorWin::EventExecutorWin(MessageLoop* message_loop,
capturer_(capturer) {
}
-void EventExecutorWin::InjectKeyEvent(const KeyEvent* event, Task* done) {
- base::ScopedTaskRunner done_runner(done);
-
+void EventExecutorWin::InjectKeyEvent(const KeyEvent& event) {
if (MessageLoop::current() != message_loop_) {
message_loop_->PostTask(
FROM_HERE,
- NewRunnableMethod(this, &EventExecutorWin::InjectKeyEvent,
- event, done_runner.Release()));
+ base::Bind(&EventExecutorWin::InjectKeyEvent, base::Unretained(this),
+ event));
return;
}
HandleKey(event);
}
-void EventExecutorWin::InjectMouseEvent(const MouseEvent* event, Task* done) {
- base::ScopedTaskRunner done_runner(done);
-
+void EventExecutorWin::InjectMouseEvent(const MouseEvent& event) {
if (MessageLoop::current() != message_loop_) {
message_loop_->PostTask(
FROM_HERE,
- NewRunnableMethod(this, &EventExecutorWin::InjectMouseEvent,
- event, done_runner.Release()));
+ base::Bind(&EventExecutorWin::InjectMouseEvent, base::Unretained(this),
+ event));
return;
}
HandleMouse(event);
}
-void EventExecutorWin::HandleKey(const KeyEvent* event) {
- int key = event->keycode();
- bool down = event->pressed();
+void EventExecutorWin::HandleKey(const KeyEvent& event) {
+ int key = event.keycode();
+ bool down = event.pressed();
// Calculate scan code from virtual key.
HKL hkl = GetKeyboardLayout(0);
@@ -103,12 +100,12 @@ void EventExecutorWin::HandleKey(const KeyEvent* event) {
SendInput(1, &input, sizeof(INPUT));
}
-void EventExecutorWin::HandleMouse(const MouseEvent* event) {
+void EventExecutorWin::HandleMouse(const MouseEvent& event) {
// TODO(garykac) Collapse mouse (x,y) and button events into a single
// input event when possible.
- if (event->has_x() && event->has_y()) {
- int x = event->x();
- int y = event->y();
+ if (event.has_x() && event.has_y()) {
+ int x = event.x();
+ int y = event.y();
INPUT input;
input.type = INPUT_MOUSE;
@@ -122,13 +119,13 @@ void EventExecutorWin::HandleMouse(const MouseEvent* event) {
}
}
- if (event->has_wheel_offset_x() && event->has_wheel_offset_y()) {
+ if (event.has_wheel_offset_x() && event.has_wheel_offset_y()) {
INPUT wheel;
wheel.type = INPUT_MOUSE;
wheel.mi.time = 0;
- int dx = event->wheel_offset_x();
- int dy = event->wheel_offset_y();
+ int dx = event.wheel_offset_x();
+ int dy = event.wheel_offset_y();
if (dx != 0) {
wheel.mi.mouseData = dx;
@@ -142,15 +139,15 @@ void EventExecutorWin::HandleMouse(const MouseEvent* event) {
}
}
- if (event->has_button() && event->has_button_down()) {
+ if (event.has_button() && event.has_button_down()) {
INPUT button_event;
button_event.type = INPUT_MOUSE;
button_event.mi.time = 0;
button_event.mi.dx = 0;
button_event.mi.dy = 0;
- MouseEvent::MouseButton button = event->button();
- bool down = event->button_down();
+ MouseEvent::MouseButton button = event.button();
+ bool down = event.button_down();
if (button == MouseEvent::BUTTON_LEFT) {
button_event.mi.dwFlags =
down ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP;
@@ -177,5 +174,3 @@ EventExecutor* EventExecutor::Create(MessageLoop* message_loop,
}
} // namespace remoting
-
-DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::EventExecutorWin);
diff --git a/remoting/host/host_mock_objects.cc b/remoting/host/host_mock_objects.cc
index 1af08ee..3fd1e36 100644
--- a/remoting/host/host_mock_objects.cc
+++ b/remoting/host/host_mock_objects.cc
@@ -5,6 +5,7 @@
#include "remoting/host/host_mock_objects.h"
#include "base/message_loop_proxy.h"
+#include "remoting/proto/event.pb.h"
namespace remoting {
diff --git a/remoting/host/host_mock_objects.h b/remoting/host/host_mock_objects.h
index 67aed7c..5503ca8 100644
--- a/remoting/host/host_mock_objects.h
+++ b/remoting/host/host_mock_objects.h
@@ -109,10 +109,8 @@ class MockEventExecutor : public EventExecutor {
MockEventExecutor();
virtual ~MockEventExecutor();
- MOCK_METHOD2(InjectKeyEvent, void(const protocol::KeyEvent* event,
- Task* done));
- MOCK_METHOD2(InjectMouseEvent, void(const protocol::MouseEvent* event,
- Task* done));
+ MOCK_METHOD1(InjectKeyEvent, void(const protocol::KeyEvent& event));
+ MOCK_METHOD1(InjectMouseEvent, void(const protocol::MouseEvent& event));
private:
DISALLOW_COPY_AND_ASSIGN(MockEventExecutor);
diff --git a/remoting/protocol/host_message_dispatcher.cc b/remoting/protocol/host_message_dispatcher.cc
index c2b6423..1e395da 100644
--- a/remoting/protocol/host_message_dispatcher.cc
+++ b/remoting/protocol/host_message_dispatcher.cc
@@ -67,22 +67,22 @@ void HostMessageDispatcher::OnControlMessageReceived(
void HostMessageDispatcher::OnEventMessageReceived(
EventMessage* message, Task* done_task) {
+ base::ScopedTaskRunner done_runner(done_task);
+
connection_->UpdateSequenceNumber(message->sequence_number());
if (message->has_key_event()) {
const KeyEvent& event = message->key_event();
if (event.has_keycode() && event.has_pressed()) {
- input_stub_->InjectKeyEvent(&event, done_task);
+ input_stub_->InjectKeyEvent(event);
return;
}
} else if (message->has_mouse_event()) {
- input_stub_->InjectMouseEvent(&message->mouse_event(), done_task);
+ input_stub_->InjectMouseEvent(message->mouse_event());
return;
}
- LOG(WARNING) << "Invalid event message received.";
- done_task->Run();
- delete done_task;
+ LOG(WARNING) << "Unknown event message received.";
}
} // namespace protocol
diff --git a/remoting/protocol/input_sender.cc b/remoting/protocol/input_sender.cc
index ff45ce2..2d725c6 100644
--- a/remoting/protocol/input_sender.cc
+++ b/remoting/protocol/input_sender.cc
@@ -3,7 +3,7 @@
// found in the LICENSE file.
// This stub is thread safe because of the use of BufferedSocketWriter.
-// BufferedSocketWriter buffers messages and send them on them right thread.
+// BufferedSocketWriter buffers messages and send them on the right thread.
#include "remoting/protocol/input_sender.h"
@@ -27,22 +27,18 @@ InputSender::InputSender(base::MessageLoopProxy* message_loop,
InputSender::~InputSender() {
}
-void InputSender::InjectKeyEvent(const KeyEvent* event, Task* done) {
- DCHECK(done);
-
+void InputSender::InjectKeyEvent(const KeyEvent& event) {
EventMessage message;
message.set_sequence_number(base::Time::Now().ToInternalValue());
- message.mutable_key_event()->CopyFrom(*event);
- buffered_writer_->Write(SerializeAndFrameMessage(message), done);
+ message.mutable_key_event()->CopyFrom(event);
+ buffered_writer_->Write(SerializeAndFrameMessage(message), NULL);
}
-void InputSender::InjectMouseEvent(const MouseEvent* event, Task* done) {
- DCHECK(done);
-
+void InputSender::InjectMouseEvent(const MouseEvent& event) {
EventMessage message;
message.set_sequence_number(base::Time::Now().ToInternalValue());
- message.mutable_mouse_event()->CopyFrom(*event);
- buffered_writer_->Write(SerializeAndFrameMessage(message), done);
+ message.mutable_mouse_event()->CopyFrom(event);
+ buffered_writer_->Write(SerializeAndFrameMessage(message), NULL);
}
void InputSender::Close() {
diff --git a/remoting/protocol/input_sender.h b/remoting/protocol/input_sender.h
index 464237f..1733b11 100644
--- a/remoting/protocol/input_sender.h
+++ b/remoting/protocol/input_sender.h
@@ -43,8 +43,8 @@ class InputSender : public InputStub {
virtual ~InputSender();
// InputStub implementation.
- virtual void InjectKeyEvent(const KeyEvent* event, Task* done);
- virtual void InjectMouseEvent(const MouseEvent* event, Task* done);
+ virtual void InjectKeyEvent(const KeyEvent& event);
+ virtual void InjectMouseEvent(const MouseEvent& event);
// Stop writing. Must be called on the network thread when the
// underlying socket is being destroyed.
diff --git a/remoting/protocol/input_stub.h b/remoting/protocol/input_stub.h
index 464454f..5db53ee 100644
--- a/remoting/protocol/input_stub.h
+++ b/remoting/protocol/input_stub.h
@@ -23,8 +23,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) = 0;
+ virtual void InjectMouseEvent(const MouseEvent& event) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(InputStub);
diff --git a/remoting/protocol/protocol_mock_objects.h b/remoting/protocol/protocol_mock_objects.h
index 7186467..4af7584 100644
--- a/remoting/protocol/protocol_mock_objects.h
+++ b/remoting/protocol/protocol_mock_objects.h
@@ -57,8 +57,8 @@ class MockInputStub : public InputStub {
MockInputStub();
virtual ~MockInputStub();
- MOCK_METHOD2(InjectKeyEvent, void(const KeyEvent* event, Task* done));
- MOCK_METHOD2(InjectMouseEvent, void(const MouseEvent* event, Task* done));
+ MOCK_METHOD1(InjectKeyEvent, void(const KeyEvent& event));
+ MOCK_METHOD1(InjectMouseEvent, void(const MouseEvent& event));
private:
DISALLOW_COPY_AND_ASSIGN(MockInputStub);