[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "remoting/host/client_session.h" |
| 6 | |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 7 | #include "base/task.h" |
[email protected] | 4ea2c7c | 2011-03-31 14:20:06 | [diff] [blame] | 8 | #include "media/base/callback.h" |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 9 | #include "remoting/host/user_authenticator.h" |
| 10 | #include "remoting/proto/auth.pb.h" |
| 11 | |
| 12 | namespace remoting { |
| 13 | |
| 14 | ClientSession::ClientSession( |
| 15 | EventHandler* event_handler, |
[email protected] | 0b7e428 | 2011-04-04 22:44:11 | [diff] [blame] | 16 | UserAuthenticator* user_authenticator, |
[email protected] | 4ea2c7c | 2011-03-31 14:20:06 | [diff] [blame] | 17 | scoped_refptr<protocol::ConnectionToClient> connection, |
| 18 | protocol::InputStub* input_stub) |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 19 | : event_handler_(event_handler), |
[email protected] | 0b7e428 | 2011-04-04 22:44:11 | [diff] [blame] | 20 | user_authenticator_(user_authenticator), |
[email protected] | 4ea2c7c | 2011-03-31 14:20:06 | [diff] [blame] | 21 | connection_(connection), |
| 22 | input_stub_(input_stub), |
| 23 | authenticated_(false) { |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | ClientSession::~ClientSession() { |
| 27 | } |
| 28 | |
| 29 | void ClientSession::SuggestResolution( |
| 30 | const protocol::SuggestResolutionRequest* msg, Task* done) { |
[email protected] | 4ea2c7c | 2011-03-31 14:20:06 | [diff] [blame] | 31 | 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] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void ClientSession::BeginSessionRequest( |
| 41 | const protocol::LocalLoginCredentials* credentials, Task* done) { |
| 42 | DCHECK(event_handler_); |
| 43 | |
[email protected] | 4ea2c7c | 2011-03-31 14:20:06 | [diff] [blame] | 44 | media::AutoTaskRunner done_runner(done); |
| 45 | |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 46 | bool success = false; |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 47 | switch (credentials->type()) { |
| 48 | case protocol::PASSWORD: |
[email protected] | 0b7e428 | 2011-04-04 22:44:11 | [diff] [blame] | 49 | success = user_authenticator_->Authenticate(credentials->username(), |
| 50 | credentials->credential()); |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 51 | break; |
| 52 | |
| 53 | default: |
| 54 | LOG(ERROR) << "Invalid credentials type " << credentials->type(); |
| 55 | break; |
| 56 | } |
| 57 | |
| 58 | if (success) { |
[email protected] | 4ea2c7c | 2011-03-31 14:20:06 | [diff] [blame] | 59 | authenticated_ = true; |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 60 | 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] | 4ea2c7c | 2011-03-31 14:20:06 | [diff] [blame] | 65 | } |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 66 | |
[email protected] | 4ea2c7c | 2011-03-31 14:20:06 | [diff] [blame] | 67 | void 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 | |
| 76 | void 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] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | void ClientSession::Disconnect() { |
| 86 | connection_->Disconnect(); |
[email protected] | 4ea2c7c | 2011-03-31 14:20:06 | [diff] [blame] | 87 | authenticated_ = false; |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | } // namespace remoting |