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/capturer.h" | 10 #include "remoting/host/capturer.h" |
11 #include "remoting/host/user_authenticator.h" | |
12 #include "remoting/proto/auth.pb.h" | |
13 #include "remoting/proto/event.pb.h" | 11 #include "remoting/proto/event.pb.h" |
14 | 12 |
15 // The number of remote mouse events to record for the purpose of eliminating | 13 // The number of remote mouse events to record for the purpose of eliminating |
16 // "echoes" detected by the local input detector. The value should be large | 14 // "echoes" detected by the local input detector. The value should be large |
17 // enough to cope with the fact that multiple events might be injected before | 15 // enough to cope with the fact that multiple events might be injected before |
18 // any echoes are detected. | 16 // any echoes are detected. |
19 static const unsigned int kNumRemoteMousePositions = 50; | 17 static const unsigned int kNumRemoteMousePositions = 50; |
20 | 18 |
21 // The number of milliseconds for which to block remote input when local input | 19 // The number of milliseconds for which to block remote input when local input |
22 // is received. | 20 // is received. |
23 static const int64 kRemoteBlockTimeoutMillis = 2000; | 21 static const int64 kRemoteBlockTimeoutMillis = 2000; |
24 | 22 |
25 namespace remoting { | 23 namespace remoting { |
26 | 24 |
27 using protocol::KeyEvent; | 25 using protocol::KeyEvent; |
28 using protocol::MouseEvent; | 26 using protocol::MouseEvent; |
29 | 27 |
30 ClientSession::ClientSession( | 28 ClientSession::ClientSession( |
31 EventHandler* event_handler, | 29 EventHandler* event_handler, |
32 UserAuthenticator* user_authenticator, | |
33 scoped_refptr<protocol::ConnectionToClient> connection, | 30 scoped_refptr<protocol::ConnectionToClient> connection, |
34 protocol::InputStub* input_stub, | 31 protocol::InputStub* input_stub, |
35 Capturer* capturer) | 32 Capturer* capturer) |
36 : event_handler_(event_handler), | 33 : event_handler_(event_handler), |
37 user_authenticator_(user_authenticator), | |
38 connection_(connection), | 34 connection_(connection), |
39 client_jid_(connection->session()->jid()), | 35 client_jid_(connection->session()->jid()), |
40 input_stub_(input_stub), | 36 input_stub_(input_stub), |
41 capturer_(capturer), | 37 capturer_(capturer), |
42 authenticated_(false), | 38 authenticated_(false), |
43 awaiting_continue_approval_(false), | 39 awaiting_continue_approval_(false), |
44 remote_mouse_button_state_(0) { | 40 remote_mouse_button_state_(0) { |
45 } | 41 } |
46 | 42 |
47 ClientSession::~ClientSession() { | 43 ClientSession::~ClientSession() { |
48 } | 44 } |
49 | 45 |
50 void ClientSession::BeginSessionRequest( | 46 void ClientSession::OnAuthorizationComplete() { |
51 const protocol::LocalLoginCredentials* credentials, | 47 authenticated_ = true; |
52 const base::Closure& done) { | 48 event_handler_->OnAuthorizationComplete(connection_.get()); |
53 DCHECK(event_handler_); | |
54 | |
55 base::ScopedClosureRunner done_runner(done); | |
56 | |
57 bool success = false; | |
58 switch (credentials->type()) { | |
59 case protocol::PASSWORD: | |
60 success = user_authenticator_->Authenticate(credentials->username(), | |
61 credentials->credential()); | |
62 break; | |
63 | |
64 default: | |
65 LOG(ERROR) << "Invalid credentials type " << credentials->type(); | |
66 break; | |
67 } | |
68 | |
69 OnAuthorizationComplete(success); | |
70 } | |
71 | |
72 void ClientSession::OnAuthorizationComplete(bool success) { | |
73 if (success) { | |
74 authenticated_ = true; | |
75 event_handler_->LocalLoginSucceeded(connection_.get()); | |
76 } else { | |
77 LOG(WARNING) << "Login failed"; | |
78 event_handler_->LocalLoginFailed(connection_.get()); | |
79 } | |
80 } | 49 } |
81 | 50 |
82 void ClientSession::InjectKeyEvent(const KeyEvent& event) { | 51 void ClientSession::InjectKeyEvent(const KeyEvent& event) { |
83 if (authenticated_ && !ShouldIgnoreRemoteKeyboardInput(event)) { | 52 if (authenticated_ && !ShouldIgnoreRemoteKeyboardInput(event)) { |
84 RecordKeyEvent(event); | 53 RecordKeyEvent(event); |
85 input_stub_->InjectKeyEvent(event); | 54 input_stub_->InjectKeyEvent(event); |
86 } | 55 } |
87 } | 56 } |
88 | 57 |
89 void ClientSession::InjectMouseEvent(const MouseEvent& event) { | 58 void ClientSession::InjectMouseEvent(const MouseEvent& event) { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 mouse.set_y(remote_mouse_pos_.y()); | 186 mouse.set_y(remote_mouse_pos_.y()); |
218 mouse.set_button((MouseEvent::MouseButton)i); | 187 mouse.set_button((MouseEvent::MouseButton)i); |
219 mouse.set_button_down(false); | 188 mouse.set_button_down(false); |
220 input_stub_->InjectMouseEvent(mouse); | 189 input_stub_->InjectMouseEvent(mouse); |
221 } | 190 } |
222 } | 191 } |
223 remote_mouse_button_state_ = 0; | 192 remote_mouse_button_state_ = 0; |
224 } | 193 } |
225 | 194 |
226 } // namespace remoting | 195 } // namespace remoting |
OLD | NEW |