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 |
| 44 // TODO(sergeyu): Currently ConnectionToClient expects stubs to be |
| 45 // set before channels are connected. Make it possible to set stubs |
| 46 // later and set them only when connection is authenticated. |
| 47 connection_->set_host_stub(this); |
| 48 connection_->set_input_stub(this); |
41 } | 49 } |
42 | 50 |
43 ClientSession::~ClientSession() { | 51 ClientSession::~ClientSession() { |
44 } | 52 } |
45 | 53 |
46 void ClientSession::OnAuthenticationComplete() { | |
47 authenticated_ = true; | |
48 event_handler_->OnAuthenticationComplete(connection_.get()); | |
49 } | |
50 | |
51 void ClientSession::InjectKeyEvent(const KeyEvent& event) { | 54 void ClientSession::InjectKeyEvent(const KeyEvent& event) { |
52 if (authenticated_ && !ShouldIgnoreRemoteKeyboardInput(event)) { | 55 if (authenticated_ && !ShouldIgnoreRemoteKeyboardInput(event)) { |
53 RecordKeyEvent(event); | 56 RecordKeyEvent(event); |
54 input_stub_->InjectKeyEvent(event); | 57 input_stub_->InjectKeyEvent(event); |
55 } | 58 } |
56 } | 59 } |
57 | 60 |
58 void ClientSession::InjectMouseEvent(const MouseEvent& event) { | 61 void ClientSession::InjectMouseEvent(const MouseEvent& event) { |
59 if (authenticated_ && !ShouldIgnoreRemoteMouseInput(event)) { | 62 if (authenticated_ && !ShouldIgnoreRemoteMouseInput(event)) { |
60 RecordMouseButtonState(event); | 63 RecordMouseButtonState(event); |
(...skipping 18 matching lines...) Expand all Loading... |
79 injected_mouse_positions_.push_back(pos); | 82 injected_mouse_positions_.push_back(pos); |
80 if (injected_mouse_positions_.size() > kNumRemoteMousePositions) { | 83 if (injected_mouse_positions_.size() > kNumRemoteMousePositions) { |
81 VLOG(1) << "Injected mouse positions queue full."; | 84 VLOG(1) << "Injected mouse positions queue full."; |
82 injected_mouse_positions_.pop_front(); | 85 injected_mouse_positions_.pop_front(); |
83 } | 86 } |
84 } | 87 } |
85 input_stub_->InjectMouseEvent(event_to_inject); | 88 input_stub_->InjectMouseEvent(event_to_inject); |
86 } | 89 } |
87 } | 90 } |
88 | 91 |
89 void ClientSession::OnDisconnected() { | 92 void ClientSession::OnConnectionOpened( |
| 93 protocol::ConnectionToClient* connection) { |
| 94 DCHECK_EQ(connection_.get(), connection); |
| 95 authenticated_ = true; |
| 96 event_handler_->OnSessionAuthenticated(this); |
| 97 } |
| 98 |
| 99 void ClientSession::OnConnectionClosed( |
| 100 protocol::ConnectionToClient* connection) { |
| 101 DCHECK_EQ(connection_.get(), connection); |
| 102 scoped_refptr<ClientSession> self = this; |
| 103 event_handler_->OnSessionClosed(this); |
| 104 Disconnect(); |
| 105 } |
| 106 |
| 107 void ClientSession::OnConnectionFailed( |
| 108 protocol::ConnectionToClient* connection) { |
| 109 DCHECK_EQ(connection_.get(), connection); |
| 110 // TODO(sergeyu): Log failure reason? |
| 111 scoped_refptr<ClientSession> self = this; |
| 112 event_handler_->OnSessionClosed(this); |
| 113 Disconnect(); |
| 114 } |
| 115 |
| 116 void ClientSession::OnSequenceNumberUpdated( |
| 117 protocol::ConnectionToClient* connection, int64 sequence_number) { |
| 118 DCHECK_EQ(connection_.get(), connection); |
| 119 event_handler_->OnSessionSequenceNumber(this, sequence_number); |
| 120 } |
| 121 |
| 122 void ClientSession::Disconnect() { |
| 123 connection_->Disconnect(); |
| 124 authenticated_ = false; |
90 RestoreEventState(); | 125 RestoreEventState(); |
91 authenticated_ = false; | |
92 } | 126 } |
93 | 127 |
94 void ClientSession::LocalMouseMoved(const SkIPoint& mouse_pos) { | 128 void ClientSession::LocalMouseMoved(const SkIPoint& mouse_pos) { |
95 // If this is a genuine local input event (rather than an echo of a remote | 129 // 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 | 130 // input event that we've just injected), then ignore remote inputs for a |
97 // short time. | 131 // short time. |
98 std::list<SkIPoint>::iterator found_position = | 132 std::list<SkIPoint>::iterator found_position = |
99 std::find(injected_mouse_positions_.begin(), | 133 std::find(injected_mouse_positions_.begin(), |
100 injected_mouse_positions_.end(), mouse_pos); | 134 injected_mouse_positions_.end(), mouse_pos); |
101 if (found_position != injected_mouse_positions_.end()) { | 135 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()); | 220 mouse.set_y(remote_mouse_pos_.y()); |
187 mouse.set_button((MouseEvent::MouseButton)i); | 221 mouse.set_button((MouseEvent::MouseButton)i); |
188 mouse.set_button_down(false); | 222 mouse.set_button_down(false); |
189 input_stub_->InjectMouseEvent(mouse); | 223 input_stub_->InjectMouseEvent(mouse); |
190 } | 224 } |
191 } | 225 } |
192 remote_mouse_button_state_ = 0; | 226 remote_mouse_button_state_ = 0; |
193 } | 227 } |
194 | 228 |
195 } // namespace remoting | 229 } // namespace remoting |
OLD | NEW |