forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_session.h
131 lines (98 loc) · 4.35 KB
/
client_session.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef REMOTING_HOST_CLIENT_SESSION_H_
#define REMOTING_HOST_CLIENT_SESSION_H_
#include <list>
#include <set>
#include "base/time.h"
#include "remoting/protocol/connection_to_client.h"
#include "remoting/protocol/host_stub.h"
#include "remoting/protocol/input_stub.h"
#include "ui/gfx/point.h"
namespace remoting {
class UserAuthenticator;
// A ClientSession keeps a reference to a connection to a client, and maintains
// per-client state.
class ClientSession : public protocol::HostStub,
public protocol::InputStub,
public base::RefCountedThreadSafe<ClientSession> {
public:
// Callback interface for passing events to the ChromotingHost.
class EventHandler {
public:
virtual ~EventHandler() {}
// Called to signal that local login has succeeded and ChromotingHost can
// proceed with the next step.
virtual void LocalLoginSucceeded(
scoped_refptr<protocol::ConnectionToClient> client) = 0;
// Called to signal that local login has failed.
virtual void LocalLoginFailed(
scoped_refptr<protocol::ConnectionToClient> client) = 0;
};
// Takes ownership of |user_authenticator|. Does not take ownership of
// |event_handler| or |input_stub|.
ClientSession(EventHandler* event_handler,
UserAuthenticator* user_authenticator,
scoped_refptr<protocol::ConnectionToClient> connection,
protocol::InputStub* input_stub);
// protocol::HostStub interface.
virtual void BeginSessionRequest(
const protocol::LocalLoginCredentials* credentials, Task* done);
// protocol::InputStub interface.
virtual void InjectKeyEvent(const protocol::KeyEvent* event, Task* done);
virtual void InjectMouseEvent(const protocol::MouseEvent* event, Task* done);
// Disconnect this client session.
void Disconnect();
// Set the authenticated flag or log a failure message as appropriate.
void OnAuthorizationComplete(bool success);
protocol::ConnectionToClient* connection() const {
return connection_.get();
}
bool authenticated() const {
return authenticated_;
}
void set_awaiting_continue_approval(bool awaiting) {
awaiting_continue_approval_ = awaiting;
}
// Indicate that local mouse activity has been detected. This causes remote
// inputs to be ignored for a short time so that the local user will always
// have the upper hand in 'pointer wars'.
void LocalMouseMoved(const gfx::Point& new_pos);
bool ShouldIgnoreRemoteMouseInput(const protocol::MouseEvent* event) const;
bool ShouldIgnoreRemoteKeyboardInput(const protocol::KeyEvent* event) const;
private:
friend class base::RefCountedThreadSafe<ClientSession>;
friend class ClientSessionTest_UnpressKeys_Test;
virtual ~ClientSession();
// Keep track of keydowns and keyups so that we can clean up the keyboard
// state when the user disconnects.
void RecordKeyEvent(const protocol::KeyEvent* event);
// Synthesize KeyUp events for keys that have been pressed but not released.
// This should be used when the client has disconnected to clear out any
// pending key events.
void UnpressKeys();
EventHandler* event_handler_;
// A factory for user authenticators.
scoped_ptr<UserAuthenticator> user_authenticator_;
// The connection to the client.
scoped_refptr<protocol::ConnectionToClient> connection_;
// The input stub to which this object delegates.
protocol::InputStub* input_stub_;
// Whether this client is authenticated.
bool authenticated_;
// Whether or not inputs from this client are blocked pending approval from
// the host user to continue the connection.
bool awaiting_continue_approval_;
// State to control remote input blocking while the local pointer is in use.
uint32 remote_mouse_button_state_;
// Queue of recently-injected mouse positions. This is used to detect whether
// mouse events from the local input monitor are echoes of injected positions,
// or genuine mouse movements of a local input device.
std::list<gfx::Point> injected_mouse_positions_;
base::Time latest_local_input_time_;
std::set<int> pressed_keys_;
DISALLOW_COPY_AND_ASSIGN(ClientSession);
};
} // namespace remoting
#endif // REMOTING_HOST_CLIENT_SESSION_H_