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 task_runner(done); |
27 delete done; | 33 |
34 if (!authenticated_) { | |
35 LOG(WARNING) << "Invalid control message received " | |
36 << "(client not authenticated)."; | |
37 return; | |
38 } | |
Wez
2011/03/30 20:24:57
If the client sends unexpected messages before hav
simonmorris
2011/03/31 11:14:00
Could be good, in another CL.
| |
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 |
34 bool success = false; | 45 bool success = false; |
35 scoped_ptr<UserAuthenticator> authenticator(UserAuthenticator::Create()); | 46 scoped_ptr<UserAuthenticator> authenticator(auth_factory_.Run()); |
36 switch (credentials->type()) { | 47 switch (credentials->type()) { |
37 case protocol::PASSWORD: | 48 case protocol::PASSWORD: |
38 success = authenticator->Authenticate(credentials->username(), | 49 success = authenticator->Authenticate(credentials->username(), |
39 credentials->credential()); | 50 credentials->credential()); |
40 break; | 51 break; |
41 | 52 |
42 default: | 53 default: |
43 LOG(ERROR) << "Invalid credentials type " << credentials->type(); | 54 LOG(ERROR) << "Invalid credentials type " << credentials->type(); |
44 break; | 55 break; |
45 } | 56 } |
46 | 57 |
47 if (success) { | 58 if (success) { |
59 authenticated_ = true; | |
48 event_handler_->LocalLoginSucceeded(connection_.get()); | 60 event_handler_->LocalLoginSucceeded(connection_.get()); |
49 } else { | 61 } else { |
50 LOG(WARNING) << "Login failed for user " << credentials->username(); | 62 LOG(WARNING) << "Login failed for user " << credentials->username(); |
51 event_handler_->LocalLoginFailed(connection_.get()); | 63 event_handler_->LocalLoginFailed(connection_.get()); |
52 } | 64 } |
53 | 65 |
54 done->Run(); | 66 done->Run(); |
55 delete done; | 67 delete done; |
56 } | 68 } |
57 | 69 |
70 void ClientSession::InjectKeyEvent(const protocol::KeyEvent* event, | |
71 Task* done) { | |
72 if (authenticated_) { | |
73 input_stub_->InjectKeyEvent(event, done); | |
74 return; | |
75 } | |
76 done->Run(); | |
garykac
2011/03/30 20:04:03
nit: The
media::AutoTaskRunner task_runner(done)
simonmorris
2011/03/31 11:14:00
Done.
| |
77 delete done; | |
78 } | |
79 | |
80 void ClientSession::InjectMouseEvent(const protocol::MouseEvent* event, | |
81 Task* done) { | |
82 if (authenticated_) { | |
83 input_stub_->InjectMouseEvent(event, done); | |
84 return; | |
85 } | |
86 done->Run(); | |
garykac
2011/03/30 20:04:03
nit: AutoTaskRunner
Wez
2011/03/30 20:24:57
As above, it's not valid for the client to send in
simonmorris
2011/03/31 11:14:00
Done.
simonmorris
2011/03/31 11:14:00
Could be good, in another CL.
| |
87 delete done; | |
88 } | |
89 | |
58 void ClientSession::Disconnect() { | 90 void ClientSession::Disconnect() { |
59 connection_->Disconnect(); | 91 connection_->Disconnect(); |
60 } | 92 authenticated_ = false; |
61 | |
62 protocol::ConnectionToClient* ClientSession::connection() const { | |
63 return connection_.get(); | |
64 } | 93 } |
65 | 94 |
66 } // namespace remoting | 95 } // namespace remoting |
OLD | NEW |