Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(631)

Side by Side Diff: remoting/host/chromoting_host.cc

Issue 6724033: Remove authenticated_ fields from stubs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix .gyp file for unit tests. Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/chromoting_host.h" 5 #include "remoting/host/chromoting_host.h"
6 6
7 #include "base/bind.h"
7 #include "base/stl_util-inl.h" 8 #include "base/stl_util-inl.h"
8 #include "base/task.h" 9 #include "base/task.h"
9 #include "build/build_config.h" 10 #include "build/build_config.h"
10 #include "remoting/base/constants.h" 11 #include "remoting/base/constants.h"
11 #include "remoting/base/encoder.h" 12 #include "remoting/base/encoder.h"
12 #include "remoting/base/encoder_row_based.h" 13 #include "remoting/base/encoder_row_based.h"
13 #include "remoting/base/encoder_vp8.h" 14 #include "remoting/base/encoder_vp8.h"
14 #include "remoting/host/capturer.h" 15 #include "remoting/host/capturer.h"
15 #include "remoting/host/chromoting_host_context.h" 16 #include "remoting/host/chromoting_host_context.h"
16 #include "remoting/host/desktop_environment.h" 17 #include "remoting/host/desktop_environment.h"
17 #include "remoting/host/event_executor.h" 18 #include "remoting/host/event_executor.h"
18 #include "remoting/host/host_config.h" 19 #include "remoting/host/host_config.h"
19 #include "remoting/host/host_key_pair.h" 20 #include "remoting/host/host_key_pair.h"
20 #include "remoting/host/screen_recorder.h" 21 #include "remoting/host/screen_recorder.h"
22 #include "remoting/host/user_authenticator.h"
21 #include "remoting/proto/auth.pb.h" 23 #include "remoting/proto/auth.pb.h"
22 #include "remoting/protocol/connection_to_client.h" 24 #include "remoting/protocol/connection_to_client.h"
23 #include "remoting/protocol/client_stub.h" 25 #include "remoting/protocol/client_stub.h"
24 #include "remoting/protocol/host_stub.h" 26 #include "remoting/protocol/host_stub.h"
25 #include "remoting/protocol/input_stub.h" 27 #include "remoting/protocol/input_stub.h"
26 #include "remoting/protocol/jingle_session_manager.h" 28 #include "remoting/protocol/jingle_session_manager.h"
27 #include "remoting/protocol/session_config.h" 29 #include "remoting/protocol/session_config.h"
28 30
29 using remoting::protocol::ConnectionToClient; 31 using remoting::protocol::ConnectionToClient;
30 using remoting::protocol::InputStub; 32 using remoting::protocol::InputStub;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } 172 }
171 173
172 // This method is called when a client connects. 174 // This method is called when a client connects.
173 void ChromotingHost::OnClientConnected(ConnectionToClient* connection) { 175 void ChromotingHost::OnClientConnected(ConnectionToClient* connection) {
174 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); 176 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current());
175 } 177 }
176 178
177 void ChromotingHost::OnClientDisconnected(ConnectionToClient* connection) { 179 void ChromotingHost::OnClientDisconnected(ConnectionToClient* connection) {
178 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); 180 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current());
179 181
182 // Find the client session corresponding to the given connection.
183 std::vector<scoped_refptr<ClientSession> >::iterator client;
184 for (client = clients_.begin(); client != clients_.end(); ++client) {
185 if (client->get()->connection() == connection)
186 break;
187 }
188 if (client == clients_.end())
189 return;
190
180 // Remove the connection from the session manager and stop the session. 191 // Remove the connection from the session manager and stop the session.
181 // TODO(hclam): Stop only if the last connection disconnected. 192 // TODO(hclam): Stop only if the last connection disconnected.
182 if (recorder_.get()) { 193 if (recorder_.get()) {
183 recorder_->RemoveConnection(connection); 194 recorder_->RemoveConnection(connection);
184 // The recorder only exists to serve the unique authenticated client. 195 // The recorder only exists to serve the unique authenticated client.
185 // If that client has disconnected, then we can kill the recorder. 196 // If that client has disconnected, then we can kill the recorder.
186 if (connection->client_authenticated()) { 197 if (client->get()->authenticated()) {
187 recorder_->Stop(NULL); 198 recorder_->Stop(NULL);
188 recorder_ = NULL; 199 recorder_ = NULL;
189 } 200 }
190 } 201 }
191 202
192 // Close the connection to connection just to be safe. 203 // Close the connection to connection just to be safe.
193 connection->Disconnect(); 204 connection->Disconnect();
194 205
195 // Also remove reference to ConnectionToClient from this object. 206 // Also remove reference to ConnectionToClient from this object.
196 std::vector<scoped_refptr<ClientSession> >::iterator it; 207 clients_.erase(client);
197 for (it = clients_.begin(); it != clients_.end(); ++it) {
198 if (it->get()->connection() == connection) {
199 clients_.erase(it);
200 break;
201 }
202 }
203 } 208 }
204 209
205 //////////////////////////////////////////////////////////////////////////// 210 ////////////////////////////////////////////////////////////////////////////
206 // protocol::ConnectionToClient::EventHandler implementations 211 // protocol::ConnectionToClient::EventHandler implementations
207 void ChromotingHost::OnConnectionOpened(ConnectionToClient* connection) { 212 void ChromotingHost::OnConnectionOpened(ConnectionToClient* connection) {
208 DCHECK_EQ(context_->network_message_loop(), MessageLoop::current()); 213 DCHECK_EQ(context_->network_message_loop(), MessageLoop::current());
209 214
210 // Completes the connection to the client. 215 // Completes the connection to the client.
211 VLOG(1) << "Connection to client established."; 216 VLOG(1) << "Connection to client established.";
212 context_->main_message_loop()->PostTask( 217 context_->main_message_loop()->PostTask(
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 session->set_config(config); 314 session->set_config(config);
310 session->set_receiver_token( 315 session->set_receiver_token(
311 GenerateHostAuthToken(session->initiator_token())); 316 GenerateHostAuthToken(session->initiator_token()));
312 317
313 *response = protocol::SessionManager::ACCEPT; 318 *response = protocol::SessionManager::ACCEPT;
314 319
315 VLOG(1) << "Client connected: " << session->jid(); 320 VLOG(1) << "Client connected: " << session->jid();
316 321
317 // We accept the connection, so create a connection object. 322 // We accept the connection, so create a connection object.
318 ConnectionToClient* connection = new ConnectionToClient( 323 ConnectionToClient* connection = new ConnectionToClient(
319 context_->network_message_loop(), 324 context_->network_message_loop(), this);
320 this,
321 desktop_environment_->input_stub());
322 325
323 // Create a client object. 326 // Create a client object.
324 ClientSession* client = new ClientSession(this, connection); 327 ClientSession* client = new ClientSession(
328 this,
329 base::Bind(UserAuthenticator::Create),
330 connection,
331 desktop_environment_->input_stub());
325 connection->set_host_stub(client); 332 connection->set_host_stub(client);
333 connection->set_input_stub(client);
326 334
327 connection->Init(session); 335 connection->Init(session);
328 336
329 clients_.push_back(client); 337 clients_.push_back(client);
330 } 338 }
331 339
332 void ChromotingHost::set_protocol_config( 340 void ChromotingHost::set_protocol_config(
333 protocol::CandidateSessionConfig* config) { 341 protocol::CandidateSessionConfig* config) {
334 DCHECK(config_.get()); 342 DCHECK(config_.get());
335 DCHECK_EQ(state_, kInitial); 343 DCHECK_EQ(state_, kInitial);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 &ChromotingHost::LocalLoginSucceeded, 386 &ChromotingHost::LocalLoginSucceeded,
379 connection)); 387 connection));
380 return; 388 return;
381 } 389 }
382 390
383 protocol::LocalLoginStatus* status = new protocol::LocalLoginStatus(); 391 protocol::LocalLoginStatus* status = new protocol::LocalLoginStatus();
384 status->set_success(true); 392 status->set_success(true);
385 connection->client_stub()->BeginSessionResponse( 393 connection->client_stub()->BeginSessionResponse(
386 status, new DeleteTask<protocol::LocalLoginStatus>(status)); 394 status, new DeleteTask<protocol::LocalLoginStatus>(status));
387 395
388 connection->OnClientAuthenticated();
389
390 // Disconnect all other clients. 396 // Disconnect all other clients.
391 // Iterate over a copy of the list of clients, to avoid mutating the list 397 // Iterate over a copy of the list of clients, to avoid mutating the list
392 // while iterating over it. 398 // while iterating over it.
393 std::vector<scoped_refptr<ClientSession> > clients_copy(clients_); 399 std::vector<scoped_refptr<ClientSession> > clients_copy(clients_);
394 std::vector<scoped_refptr<ClientSession> >::const_iterator client; 400 std::vector<scoped_refptr<ClientSession> >::const_iterator client;
395 for (client = clients_copy.begin(); client != clients_copy.end(); client++) { 401 for (client = clients_copy.begin(); client != clients_copy.end(); client++) {
396 ConnectionToClient* connection_other = client->get()->connection(); 402 ConnectionToClient* connection_other = client->get()->connection();
397 if (connection_other != connection) { 403 if (connection_other != connection) {
398 OnClientDisconnected(connection_other); 404 OnClientDisconnected(connection_other);
399 } 405 }
(...skipping 28 matching lines...) Expand all
428 return; 434 return;
429 } 435 }
430 436
431 protocol::LocalLoginStatus* status = new protocol::LocalLoginStatus(); 437 protocol::LocalLoginStatus* status = new protocol::LocalLoginStatus();
432 status->set_success(false); 438 status->set_success(false);
433 connection->client_stub()->BeginSessionResponse( 439 connection->client_stub()->BeginSessionResponse(
434 status, new DeleteTask<protocol::LocalLoginStatus>(status)); 440 status, new DeleteTask<protocol::LocalLoginStatus>(status));
435 } 441 }
436 442
437 } // namespace remoting 443 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | remoting/host/chromoting_host_unittest.cc » ('j') | remoting/host/chromoting_host_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698