blob: 1e678ffeb46a0d2c455e016993e37994a8befea0 [file] [log] [blame]
[email protected]44f60762011-03-23 12:13:351// 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
3// found in the LICENSE file.
4
5#include "remoting/host/client_session.h"
6
[email protected]44f60762011-03-23 12:13:357#include "base/task.h"
[email protected]4ea2c7c2011-03-31 14:20:068#include "media/base/callback.h"
[email protected]44f60762011-03-23 12:13:359#include "remoting/host/user_authenticator.h"
10#include "remoting/proto/auth.pb.h"
11
12namespace remoting {
13
14ClientSession::ClientSession(
15 EventHandler* event_handler,
[email protected]0b7e4282011-04-04 22:44:1116 UserAuthenticator* user_authenticator,
[email protected]4ea2c7c2011-03-31 14:20:0617 scoped_refptr<protocol::ConnectionToClient> connection,
18 protocol::InputStub* input_stub)
[email protected]44f60762011-03-23 12:13:3519 : event_handler_(event_handler),
[email protected]0b7e4282011-04-04 22:44:1120 user_authenticator_(user_authenticator),
[email protected]4ea2c7c2011-03-31 14:20:0621 connection_(connection),
22 input_stub_(input_stub),
23 authenticated_(false) {
[email protected]44f60762011-03-23 12:13:3524}
25
26ClientSession::~ClientSession() {
27}
28
29void ClientSession::SuggestResolution(
30 const protocol::SuggestResolutionRequest* msg, Task* done) {
[email protected]4ea2c7c2011-03-31 14:20:0631 media::AutoTaskRunner done_runner(done);
32
33 if (!authenticated_) {
34 LOG(WARNING) << "Invalid control message received "
35 << "(client not authenticated).";
36 return;
37 }
[email protected]44f60762011-03-23 12:13:3538}
39
40void ClientSession::BeginSessionRequest(
41 const protocol::LocalLoginCredentials* credentials, Task* done) {
42 DCHECK(event_handler_);
43
[email protected]4ea2c7c2011-03-31 14:20:0644 media::AutoTaskRunner done_runner(done);
45
[email protected]44f60762011-03-23 12:13:3546 bool success = false;
[email protected]44f60762011-03-23 12:13:3547 switch (credentials->type()) {
48 case protocol::PASSWORD:
[email protected]0b7e4282011-04-04 22:44:1149 success = user_authenticator_->Authenticate(credentials->username(),
50 credentials->credential());
[email protected]44f60762011-03-23 12:13:3551 break;
52
53 default:
54 LOG(ERROR) << "Invalid credentials type " << credentials->type();
55 break;
56 }
57
58 if (success) {
[email protected]4ea2c7c2011-03-31 14:20:0659 authenticated_ = true;
[email protected]44f60762011-03-23 12:13:3560 event_handler_->LocalLoginSucceeded(connection_.get());
61 } else {
62 LOG(WARNING) << "Login failed for user " << credentials->username();
63 event_handler_->LocalLoginFailed(connection_.get());
64 }
[email protected]4ea2c7c2011-03-31 14:20:0665}
[email protected]44f60762011-03-23 12:13:3566
[email protected]4ea2c7c2011-03-31 14:20:0667void ClientSession::InjectKeyEvent(const protocol::KeyEvent* event,
68 Task* done) {
69 media::AutoTaskRunner done_runner(done);
70 if (authenticated_) {
71 done_runner.release();
72 input_stub_->InjectKeyEvent(event, done);
73 }
74}
75
76void ClientSession::InjectMouseEvent(const protocol::MouseEvent* event,
77 Task* done) {
78 media::AutoTaskRunner done_runner(done);
79 if (authenticated_) {
80 done_runner.release();
81 input_stub_->InjectMouseEvent(event, done);
82 }
[email protected]44f60762011-03-23 12:13:3583}
84
85void ClientSession::Disconnect() {
86 connection_->Disconnect();
[email protected]4ea2c7c2011-03-31 14:20:0687 authenticated_ = false;
[email protected]44f60762011-03-23 12:13:3588}
89
90} // namespace remoting