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