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
|
// 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.
#include "remoting/host/client_session.h"
#include "base/task.h"
#include "remoting/host/user_authenticator.h"
#include "remoting/proto/auth.pb.h"
namespace remoting {
ClientSession::ClientSession(
EventHandler* event_handler,
UserAuthenticator* user_authenticator,
scoped_refptr<protocol::ConnectionToClient> connection,
protocol::InputStub* input_stub)
: event_handler_(event_handler),
user_authenticator_(user_authenticator),
connection_(connection),
input_stub_(input_stub),
authenticated_(false) {
}
ClientSession::~ClientSession() {
}
void ClientSession::SuggestResolution(
const protocol::SuggestResolutionRequest* msg, Task* done) {
base::ScopedTaskRunner done_runner(done);
if (!authenticated_) {
LOG(WARNING) << "Invalid control message received "
<< "(client not authenticated).";
return;
}
}
void ClientSession::BeginSessionRequest(
const protocol::LocalLoginCredentials* credentials, Task* done) {
DCHECK(event_handler_);
base::ScopedTaskRunner done_runner(done);
bool success = false;
switch (credentials->type()) {
case protocol::PASSWORD:
success = user_authenticator_->Authenticate(credentials->username(),
credentials->credential());
break;
default:
LOG(ERROR) << "Invalid credentials type " << credentials->type();
break;
}
OnAuthorizationComplete(success);
}
void ClientSession::OnAuthorizationComplete(bool success) {
if (success) {
authenticated_ = true;
event_handler_->LocalLoginSucceeded(connection_.get());
} else {
LOG(WARNING) << "Login failed";
event_handler_->LocalLoginFailed(connection_.get());
}
}
void ClientSession::InjectKeyEvent(const protocol::KeyEvent* event,
Task* done) {
base::ScopedTaskRunner done_runner(done);
if (authenticated_) {
input_stub_->InjectKeyEvent(event, done_runner.Release());
}
}
void ClientSession::InjectMouseEvent(const protocol::MouseEvent* event,
Task* done) {
base::ScopedTaskRunner done_runner(done);
if (authenticated_) {
input_stub_->InjectMouseEvent(event, done_runner.Release());
}
}
void ClientSession::Disconnect() {
connection_->Disconnect();
authenticated_ = false;
}
} // namespace remoting
|