| 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 "base/task.h" | 7 #include "base/task.h" |
| 8 #include "media/base/callback.h" |
| 8 #include "remoting/host/user_authenticator.h" | 9 #include "remoting/host/user_authenticator.h" |
| 9 #include "remoting/proto/auth.pb.h" | 10 #include "remoting/proto/auth.pb.h" |
| 10 | 11 |
| 11 namespace remoting { | 12 namespace remoting { |
| 12 | 13 |
| 13 ClientSession::ClientSession( | 14 ClientSession::ClientSession( |
| 14 EventHandler* event_handler, | 15 EventHandler* event_handler, |
| 15 UserAuthenticator* user_authenticator, | 16 UserAuthenticator* user_authenticator, |
| 16 scoped_refptr<protocol::ConnectionToClient> connection, | 17 scoped_refptr<protocol::ConnectionToClient> connection, |
| 17 protocol::InputStub* input_stub) | 18 protocol::InputStub* input_stub) |
| 18 : event_handler_(event_handler), | 19 : event_handler_(event_handler), |
| 19 user_authenticator_(user_authenticator), | 20 user_authenticator_(user_authenticator), |
| 20 connection_(connection), | 21 connection_(connection), |
| 21 input_stub_(input_stub), | 22 input_stub_(input_stub), |
| 22 authenticated_(false) { | 23 authenticated_(false) { |
| 23 } | 24 } |
| 24 | 25 |
| 25 ClientSession::~ClientSession() { | 26 ClientSession::~ClientSession() { |
| 26 } | 27 } |
| 27 | 28 |
| 28 void ClientSession::SuggestResolution( | 29 void ClientSession::SuggestResolution( |
| 29 const protocol::SuggestResolutionRequest* msg, Task* done) { | 30 const protocol::SuggestResolutionRequest* msg, Task* done) { |
| 30 base::ScopedTaskRunner done_runner(done); | 31 media::AutoTaskRunner done_runner(done); |
| 31 | 32 |
| 32 if (!authenticated_) { | 33 if (!authenticated_) { |
| 33 LOG(WARNING) << "Invalid control message received " | 34 LOG(WARNING) << "Invalid control message received " |
| 34 << "(client not authenticated)."; | 35 << "(client not authenticated)."; |
| 35 return; | 36 return; |
| 36 } | 37 } |
| 37 } | 38 } |
| 38 | 39 |
| 39 void ClientSession::BeginSessionRequest( | 40 void ClientSession::BeginSessionRequest( |
| 40 const protocol::LocalLoginCredentials* credentials, Task* done) { | 41 const protocol::LocalLoginCredentials* credentials, Task* done) { |
| 41 DCHECK(event_handler_); | 42 DCHECK(event_handler_); |
| 42 | 43 |
| 43 base::ScopedTaskRunner done_runner(done); | 44 media::AutoTaskRunner done_runner(done); |
| 44 | 45 |
| 45 bool success = false; | 46 bool success = false; |
| 46 switch (credentials->type()) { | 47 switch (credentials->type()) { |
| 47 case protocol::PASSWORD: | 48 case protocol::PASSWORD: |
| 48 success = user_authenticator_->Authenticate(credentials->username(), | 49 success = user_authenticator_->Authenticate(credentials->username(), |
| 49 credentials->credential()); | 50 credentials->credential()); |
| 50 break; | 51 break; |
| 51 | 52 |
| 52 default: | 53 default: |
| 53 LOG(ERROR) << "Invalid credentials type " << credentials->type(); | 54 LOG(ERROR) << "Invalid credentials type " << credentials->type(); |
| 54 break; | 55 break; |
| 55 } | 56 } |
| 56 | 57 |
| 57 OnAuthorizationComplete(success); | 58 OnAuthorizationComplete(success); |
| 58 } | 59 } |
| 59 | 60 |
| 60 void ClientSession::OnAuthorizationComplete(bool success) { | 61 void ClientSession::OnAuthorizationComplete(bool success) { |
| 61 if (success) { | 62 if (success) { |
| 62 authenticated_ = true; | 63 authenticated_ = true; |
| 63 event_handler_->LocalLoginSucceeded(connection_.get()); | 64 event_handler_->LocalLoginSucceeded(connection_.get()); |
| 64 } else { | 65 } else { |
| 65 LOG(WARNING) << "Login failed"; | 66 LOG(WARNING) << "Login failed"; |
| 66 event_handler_->LocalLoginFailed(connection_.get()); | 67 event_handler_->LocalLoginFailed(connection_.get()); |
| 67 } | 68 } |
| 68 } | 69 } |
| 69 | 70 |
| 70 void ClientSession::InjectKeyEvent(const protocol::KeyEvent* event, | 71 void ClientSession::InjectKeyEvent(const protocol::KeyEvent* event, |
| 71 Task* done) { | 72 Task* done) { |
| 72 base::ScopedTaskRunner done_runner(done); | 73 media::AutoTaskRunner done_runner(done); |
| 73 if (authenticated_) { | 74 if (authenticated_) { |
| 74 input_stub_->InjectKeyEvent(event, done_runner.Release()); | 75 done_runner.release(); |
| 76 input_stub_->InjectKeyEvent(event, done); |
| 75 } | 77 } |
| 76 } | 78 } |
| 77 | 79 |
| 78 void ClientSession::InjectMouseEvent(const protocol::MouseEvent* event, | 80 void ClientSession::InjectMouseEvent(const protocol::MouseEvent* event, |
| 79 Task* done) { | 81 Task* done) { |
| 80 base::ScopedTaskRunner done_runner(done); | 82 media::AutoTaskRunner done_runner(done); |
| 81 if (authenticated_) { | 83 if (authenticated_) { |
| 82 input_stub_->InjectMouseEvent(event, done_runner.Release()); | 84 done_runner.release(); |
| 85 input_stub_->InjectMouseEvent(event, done); |
| 83 } | 86 } |
| 84 } | 87 } |
| 85 | 88 |
| 86 void ClientSession::Disconnect() { | 89 void ClientSession::Disconnect() { |
| 87 connection_->Disconnect(); | 90 connection_->Disconnect(); |
| 88 authenticated_ = false; | 91 authenticated_ = false; |
| 89 } | 92 } |
| 90 | 93 |
| 91 } // namespace remoting | 94 } // namespace remoting |
| OLD | NEW |