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/message_loop_proxy.h" | |
9 #include "base/task.h" | 10 #include "base/task.h" |
10 #include "remoting/host/capturer.h" | 11 #include "remoting/host/capturer.h" |
11 #include "remoting/proto/event.pb.h" | 12 #include "remoting/proto/event.pb.h" |
12 | 13 |
13 // 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 |
14 // "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 |
15 // 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 |
16 // any echoes are detected. | 17 // any echoes are detected. |
17 static const unsigned int kNumRemoteMousePositions = 50; | 18 static const unsigned int kNumRemoteMousePositions = 50; |
18 | 19 |
(...skipping 12 matching lines...) Expand all Loading... | |
31 protocol::InputStub* input_stub, | 32 protocol::InputStub* input_stub, |
32 Capturer* capturer) | 33 Capturer* capturer) |
33 : event_handler_(event_handler), | 34 : event_handler_(event_handler), |
34 connection_(connection), | 35 connection_(connection), |
35 client_jid_(connection->session()->jid()), | 36 client_jid_(connection->session()->jid()), |
36 input_stub_(input_stub), | 37 input_stub_(input_stub), |
37 capturer_(capturer), | 38 capturer_(capturer), |
38 authenticated_(false), | 39 authenticated_(false), |
39 awaiting_continue_approval_(false), | 40 awaiting_continue_approval_(false), |
40 remote_mouse_button_state_(0) { | 41 remote_mouse_button_state_(0) { |
42 connection_->SetEventHandler(this); | |
43 connection_->set_host_stub(this); | |
44 connection_->set_input_stub(this); | |
41 } | 45 } |
42 | 46 |
43 ClientSession::~ClientSession() { | 47 ClientSession::~ClientSession() { |
44 } | 48 } |
45 | 49 |
46 void ClientSession::OnAuthenticationComplete() { | |
47 authenticated_ = true; | |
48 event_handler_->OnAuthenticationComplete(connection_.get()); | |
49 } | |
50 | |
51 void ClientSession::InjectKeyEvent(const KeyEvent& event) { | 50 void ClientSession::InjectKeyEvent(const KeyEvent& event) { |
52 if (authenticated_ && !ShouldIgnoreRemoteKeyboardInput(event)) { | 51 if (authenticated_ && !ShouldIgnoreRemoteKeyboardInput(event)) { |
53 RecordKeyEvent(event); | 52 RecordKeyEvent(event); |
54 input_stub_->InjectKeyEvent(event); | 53 input_stub_->InjectKeyEvent(event); |
55 } | 54 } |
56 } | 55 } |
57 | 56 |
58 void ClientSession::InjectMouseEvent(const MouseEvent& event) { | 57 void ClientSession::InjectMouseEvent(const MouseEvent& event) { |
59 if (authenticated_ && !ShouldIgnoreRemoteMouseInput(event)) { | 58 if (authenticated_ && !ShouldIgnoreRemoteMouseInput(event)) { |
60 RecordMouseButtonState(event); | 59 RecordMouseButtonState(event); |
(...skipping 18 matching lines...) Expand all Loading... | |
79 injected_mouse_positions_.push_back(pos); | 78 injected_mouse_positions_.push_back(pos); |
80 if (injected_mouse_positions_.size() > kNumRemoteMousePositions) { | 79 if (injected_mouse_positions_.size() > kNumRemoteMousePositions) { |
81 VLOG(1) << "Injected mouse positions queue full."; | 80 VLOG(1) << "Injected mouse positions queue full."; |
82 injected_mouse_positions_.pop_front(); | 81 injected_mouse_positions_.pop_front(); |
83 } | 82 } |
84 } | 83 } |
85 input_stub_->InjectMouseEvent(event_to_inject); | 84 input_stub_->InjectMouseEvent(event_to_inject); |
86 } | 85 } |
87 } | 86 } |
88 | 87 |
89 void ClientSession::OnDisconnected() { | 88 void ClientSession::OnConnectionOpened( |
89 protocol::ConnectionToClient* connection) { | |
90 DCHECK_EQ(connection_.get(), connection); | |
91 // TODO(sergeyu): Acutally authenticate the session. | |
Wez
2011/11/09 01:35:07
typo: Acutally.
Clarify what level of authenticati
Sergey Ulanov
2011/11/09 19:26:13
Removed this TODO for now. The intention is that C
| |
92 authenticated_ = true; | |
93 event_handler_->OnSessionAuthenticated(this); | |
94 } | |
95 | |
96 void ClientSession::OnConnectionClosed( | |
97 protocol::ConnectionToClient* connection) { | |
98 DCHECK_EQ(connection_.get(), connection); | |
99 scoped_refptr<ClientSession> self = this; | |
100 event_handler_->OnSessionClosed(this); | |
101 Disconnect(); | |
Wez
2011/11/09 01:35:07
Could OnSessionClosed() be dispatched from Disconn
Sergey Ulanov
2011/11/09 19:26:13
No. In any case I removed this line in one of the
| |
102 } | |
103 | |
104 void ClientSession::OnConnectionFailed( | |
105 protocol::ConnectionToClient* connection) { | |
Wez
2011/11/09 01:35:07
Fetch and log some reason for the "failure"?
Sergey Ulanov
2011/11/09 19:26:13
Added TODO for this.
| |
106 DCHECK_EQ(connection_.get(), connection); | |
107 scoped_refptr<ClientSession> self = this; | |
108 event_handler_->OnSessionClosed(this); | |
109 Disconnect(); | |
110 } | |
111 | |
112 void ClientSession::OnSequenceNumberUpdated( | |
113 protocol::ConnectionToClient* connection, int64 sequence_number) { | |
114 DCHECK_EQ(connection_.get(), connection); | |
115 event_handler_->OnSessionSequenceNumber(this, sequence_number); | |
116 } | |
117 | |
118 void ClientSession::Disconnect() { | |
119 connection_->Disconnect(); | |
120 authenticated_ = false; | |
Wez
2011/11/09 01:35:07
Rather than keeping a separate |authenticated_| fl
Sergey Ulanov
2011/11/09 19:26:13
I agree it would be better, but currently Connecti
| |
90 RestoreEventState(); | 121 RestoreEventState(); |
91 authenticated_ = false; | |
92 } | 122 } |
93 | 123 |
94 void ClientSession::LocalMouseMoved(const SkIPoint& mouse_pos) { | 124 void ClientSession::LocalMouseMoved(const SkIPoint& mouse_pos) { |
95 // If this is a genuine local input event (rather than an echo of a remote | 125 // If this is a genuine local input event (rather than an echo of a remote |
96 // input event that we've just injected), then ignore remote inputs for a | 126 // input event that we've just injected), then ignore remote inputs for a |
97 // short time. | 127 // short time. |
98 std::list<SkIPoint>::iterator found_position = | 128 std::list<SkIPoint>::iterator found_position = |
99 std::find(injected_mouse_positions_.begin(), | 129 std::find(injected_mouse_positions_.begin(), |
100 injected_mouse_positions_.end(), mouse_pos); | 130 injected_mouse_positions_.end(), mouse_pos); |
101 if (found_position != injected_mouse_positions_.end()) { | 131 if (found_position != injected_mouse_positions_.end()) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 mouse.set_y(remote_mouse_pos_.y()); | 216 mouse.set_y(remote_mouse_pos_.y()); |
187 mouse.set_button((MouseEvent::MouseButton)i); | 217 mouse.set_button((MouseEvent::MouseButton)i); |
188 mouse.set_button_down(false); | 218 mouse.set_button_down(false); |
189 input_stub_->InjectMouseEvent(mouse); | 219 input_stub_->InjectMouseEvent(mouse); |
190 } | 220 } |
191 } | 221 } |
192 remote_mouse_button_state_ = 0; | 222 remote_mouse_button_state_ = 0; |
193 } | 223 } |
194 | 224 |
195 } // namespace remoting | 225 } // namespace remoting |
OLD | NEW |