summaryrefslogtreecommitdiffstats
path: root/remoting/host/client_session.cc
diff options
context:
space:
mode:
authorjamiewalch@google.com <jamiewalch@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-13 22:42:38 +0000
committerjamiewalch@google.com <jamiewalch@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-13 22:42:38 +0000
commitc78669c954f21f73734a1a484943d19525a58a5b (patch)
tree5a1ddd659dd13d1296692694d78e8b03fd9939ab /remoting/host/client_session.cc
parent244d7c5866e4c7406251a499272abd76204fa005 (diff)
downloadchromium_src-c78669c954f21f73734a1a484943d19525a58a5b.zip
chromium_src-c78669c954f21f73734a1a484943d19525a58a5b.tar.gz
chromium_src-c78669c954f21f73734a1a484943d19525a58a5b.tar.bz2
Block remote mouse inputs for a short time when local input is received.
BUG= TEST= Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=88878 Review URL: http://codereview.chromium.org/7134048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88915 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host/client_session.cc')
-rw-r--r--remoting/host/client_session.cc58
1 files changed, 56 insertions, 2 deletions
diff --git a/remoting/host/client_session.cc b/remoting/host/client_session.cc
index 1aae53c..0ebd0c5 100644
--- a/remoting/host/client_session.cc
+++ b/remoting/host/client_session.cc
@@ -7,6 +7,17 @@
#include "base/task.h"
#include "remoting/host/user_authenticator.h"
#include "remoting/proto/auth.pb.h"
+#include "remoting/proto/event.pb.h"
+
+// The number of remote mouse events to record for the purpose of eliminating
+// "echoes" detected by the local input detector. The value should be large
+// enough to cope with the fact that multiple events might be injected before
+// any echoes are detected.
+static const unsigned int kNumRemoteMousePositions = 10;
+
+// The number of milliseconds for which to block remote input when local input
+// is received.
+static const int64 kRemoteBlockTimeoutMillis = 2000;
namespace remoting {
@@ -19,7 +30,8 @@ ClientSession::ClientSession(
user_authenticator_(user_authenticator),
connection_(connection),
input_stub_(input_stub),
- authenticated_(false) {
+ authenticated_(false),
+ remote_mouse_button_state_(0) {
}
ClientSession::~ClientSession() {
@@ -78,7 +90,24 @@ void ClientSession::InjectKeyEvent(const protocol::KeyEvent* event,
void ClientSession::InjectMouseEvent(const protocol::MouseEvent* event,
Task* done) {
base::ScopedTaskRunner done_runner(done);
- if (authenticated_) {
+ if (authenticated_ && !ShouldIgnoreRemoteInput()) {
+ 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());
+ recent_remote_mouse_positions_.push_back(pos);
+ if (recent_remote_mouse_positions_.size() > kNumRemoteMousePositions) {
+ recent_remote_mouse_positions_.pop_front();
+ }
+ }
input_stub_->InjectMouseEvent(event, done_runner.Release());
}
}
@@ -88,4 +117,29 @@ void ClientSession::Disconnect() {
authenticated_ = false;
}
+void ClientSession::LocalMouseMoved(const gfx::Point& mouse_pos) {
+ // If this is a genuine local input event (rather than an echo of a remote
+ // input event that we've just injected), then ignore remote inputs for a
+ // short time.
+ if (!recent_remote_mouse_positions_.empty() &&
+ mouse_pos == *recent_remote_mouse_positions_.begin()) {
+ recent_remote_mouse_positions_.pop_front();
+ } else {
+ latest_local_input_time_ = base::Time::Now();
+ }
+}
+
+bool ClientSession::ShouldIgnoreRemoteInput() const {
+ // If the last remote input event was a click or a drag, then it's not safe
+ // to block remote input. For example, it might result in the host missing
+ // the mouse-up event and being stuck with the button pressed.
+ if (remote_mouse_button_state_ != 0)
+ return false;
+ int64 millis = (base::Time::Now() - latest_local_input_time_)
+ .InMilliseconds();
+ if (millis < kRemoteBlockTimeoutMillis)
+ return true;
+ return false;
+}
+
} // namespace remoting