| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/host/client_session.h" | 5 #include "remoting/host/client_session.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/task.h" | 9 #include "base/task.h" |
| 10 #include "remoting/host/user_authenticator.h" | 10 #include "remoting/host/user_authenticator.h" |
| 11 #include "remoting/proto/auth.pb.h" | 11 #include "remoting/proto/auth.pb.h" |
| 12 #include "remoting/proto/event.pb.h" | 12 #include "remoting/proto/event.pb.h" |
| 13 | 13 |
| 14 // The number of remote mouse events to record for the purpose of eliminating | 14 // The number of remote mouse events to record for the purpose of eliminating |
| 15 // "echoes" detected by the local input detector. The value should be large | 15 // "echoes" detected by the local input detector. The value should be large |
| 16 // enough to cope with the fact that multiple events might be injected before | 16 // enough to cope with the fact that multiple events might be injected before |
| 17 // any echoes are detected. | 17 // any echoes are detected. |
| 18 static const unsigned int kNumRemoteMousePositions = 50; | 18 static const unsigned int kNumRemoteMousePositions = 50; |
| 19 | 19 |
| 20 // The number of milliseconds for which to block remote input when local input | 20 // The number of milliseconds for which to block remote input when local input |
| 21 // is received. | 21 // is received. |
| 22 static const int64 kRemoteBlockTimeoutMillis = 2000; | 22 static const int64 kRemoteBlockTimeoutMillis = 2000; |
| 23 | 23 |
| 24 namespace remoting { | 24 namespace remoting { |
| 25 | 25 |
| 26 using protocol::KeyEvent; |
| 27 |
| 26 ClientSession::ClientSession( | 28 ClientSession::ClientSession( |
| 27 EventHandler* event_handler, | 29 EventHandler* event_handler, |
| 28 UserAuthenticator* user_authenticator, | 30 UserAuthenticator* user_authenticator, |
| 29 scoped_refptr<protocol::ConnectionToClient> connection, | 31 scoped_refptr<protocol::ConnectionToClient> connection, |
| 30 protocol::InputStub* input_stub) | 32 protocol::InputStub* input_stub) |
| 31 : event_handler_(event_handler), | 33 : event_handler_(event_handler), |
| 32 user_authenticator_(user_authenticator), | 34 user_authenticator_(user_authenticator), |
| 33 connection_(connection), | 35 connection_(connection), |
| 34 input_stub_(input_stub), | 36 input_stub_(input_stub), |
| 35 authenticated_(false), | 37 authenticated_(false), |
| (...skipping 28 matching lines...) Expand all Loading... |
| 64 void ClientSession::OnAuthorizationComplete(bool success) { | 66 void ClientSession::OnAuthorizationComplete(bool success) { |
| 65 if (success) { | 67 if (success) { |
| 66 authenticated_ = true; | 68 authenticated_ = true; |
| 67 event_handler_->LocalLoginSucceeded(connection_.get()); | 69 event_handler_->LocalLoginSucceeded(connection_.get()); |
| 68 } else { | 70 } else { |
| 69 LOG(WARNING) << "Login failed"; | 71 LOG(WARNING) << "Login failed"; |
| 70 event_handler_->LocalLoginFailed(connection_.get()); | 72 event_handler_->LocalLoginFailed(connection_.get()); |
| 71 } | 73 } |
| 72 } | 74 } |
| 73 | 75 |
| 74 void ClientSession::InjectKeyEvent(const protocol::KeyEvent* event, | 76 void ClientSession::InjectKeyEvent(const KeyEvent* event, Task* done) { |
| 75 Task* done) { | |
| 76 base::ScopedTaskRunner done_runner(done); | 77 base::ScopedTaskRunner done_runner(done); |
| 77 if (authenticated_ && !ShouldIgnoreRemoteKeyboardInput(event)) { | 78 if (authenticated_ && !ShouldIgnoreRemoteKeyboardInput(event)) { |
| 78 RecordKeyEvent(event); | 79 RecordKeyEvent(event); |
| 79 input_stub_->InjectKeyEvent(event, done_runner.Release()); | 80 input_stub_->InjectKeyEvent(event, done_runner.Release()); |
| 80 } | 81 } |
| 81 } | 82 } |
| 82 | 83 |
| 83 void ClientSession::InjectMouseEvent(const protocol::MouseEvent* event, | 84 void ClientSession::InjectMouseEvent(const protocol::MouseEvent* event, |
| 84 Task* done) { | 85 Task* done) { |
| 85 base::ScopedTaskRunner done_runner(done); | 86 base::ScopedTaskRunner done_runner(done); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 return true; | 149 return true; |
| 149 // Otherwise, ignore remote mouse events if the local mouse moved recently. | 150 // Otherwise, ignore remote mouse events if the local mouse moved recently. |
| 150 int64 millis = (base::Time::Now() - latest_local_input_time_) | 151 int64 millis = (base::Time::Now() - latest_local_input_time_) |
| 151 .InMilliseconds(); | 152 .InMilliseconds(); |
| 152 if (millis < kRemoteBlockTimeoutMillis) | 153 if (millis < kRemoteBlockTimeoutMillis) |
| 153 return true; | 154 return true; |
| 154 return false; | 155 return false; |
| 155 } | 156 } |
| 156 | 157 |
| 157 bool ClientSession::ShouldIgnoreRemoteKeyboardInput( | 158 bool ClientSession::ShouldIgnoreRemoteKeyboardInput( |
| 158 const protocol::KeyEvent* event) const { | 159 const KeyEvent* event) const { |
| 159 // If the host user has not yet approved the continuation of the connection, | 160 // If the host user has not yet approved the continuation of the connection, |
| 160 // then all remote keyboard input is ignored, except to release keys that | 161 // then all remote keyboard input is ignored, except to release keys that |
| 161 // were already pressed. | 162 // were already pressed. |
| 162 if (awaiting_continue_approval_) { | 163 if (awaiting_continue_approval_) { |
| 163 return event->pressed() || | 164 return event->pressed() || |
| 164 (pressed_keys_.find(event->keycode()) == pressed_keys_.end()); | 165 (pressed_keys_.find(event->keycode()) == pressed_keys_.end()); |
| 165 } | 166 } |
| 166 return false; | 167 return false; |
| 167 } | 168 } |
| 168 | 169 |
| 169 void ClientSession::RecordKeyEvent(const protocol::KeyEvent* event) { | 170 void ClientSession::RecordKeyEvent(const KeyEvent* event) { |
| 170 if (event->pressed()) { | 171 if (event->pressed()) { |
| 171 pressed_keys_.insert(event->keycode()); | 172 pressed_keys_.insert(event->keycode()); |
| 172 } else { | 173 } else { |
| 173 pressed_keys_.erase(event->keycode()); | 174 pressed_keys_.erase(event->keycode()); |
| 174 } | 175 } |
| 175 } | 176 } |
| 176 | 177 |
| 177 void ClientSession::UnpressKeys() { | 178 void ClientSession::UnpressKeys() { |
| 178 std::set<int>::iterator i; | 179 std::set<int>::iterator i; |
| 179 for (i = pressed_keys_.begin(); i != pressed_keys_.end(); ++i) { | 180 for (i = pressed_keys_.begin(); i != pressed_keys_.end(); ++i) { |
| 180 protocol::KeyEvent key; | 181 KeyEvent* key = new KeyEvent(); |
| 181 key.set_keycode(*i); | 182 key->set_keycode(*i); |
| 182 key.set_pressed(false); | 183 key->set_pressed(false); |
| 183 input_stub_->InjectKeyEvent(&key, NULL); | 184 input_stub_->InjectKeyEvent(key, new DeleteTask<KeyEvent>(key)); |
| 184 } | 185 } |
| 185 pressed_keys_.clear(); | 186 pressed_keys_.clear(); |
| 186 } | 187 } |
| 187 | 188 |
| 188 } // namespace remoting | 189 } // namespace remoting |
| OLD | NEW |