Chromium Code Reviews| 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/chromoting_host.h" | 5 #include "remoting/host/chromoting_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "remoting/base/constants.h" | 12 #include "remoting/base/constants.h" |
| 13 #include "remoting/base/encoder.h" | 13 #include "remoting/base/encoder.h" |
| 14 #include "remoting/base/encoder_row_based.h" | 14 #include "remoting/base/encoder_row_based.h" |
| 15 #include "remoting/base/encoder_vp8.h" | 15 #include "remoting/base/encoder_vp8.h" |
| 16 #include "remoting/host/chromoting_host_context.h" | 16 #include "remoting/host/chromoting_host_context.h" |
| 17 #include "remoting/host/curtain.h" | |
| 18 #include "remoting/host/desktop_environment.h" | 17 #include "remoting/host/desktop_environment.h" |
| 19 #include "remoting/host/event_executor.h" | 18 #include "remoting/host/event_executor.h" |
| 20 #include "remoting/host/host_config.h" | 19 #include "remoting/host/host_config.h" |
| 21 #include "remoting/host/host_key_pair.h" | 20 #include "remoting/host/host_key_pair.h" |
| 22 #include "remoting/host/screen_recorder.h" | 21 #include "remoting/host/screen_recorder.h" |
| 23 #include "remoting/host/user_authenticator.h" | 22 #include "remoting/host/user_authenticator.h" |
| 24 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | 23 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
| 25 #include "remoting/protocol/connection_to_client.h" | 24 #include "remoting/protocol/connection_to_client.h" |
| 26 #include "remoting/protocol/client_stub.h" | 25 #include "remoting/protocol/client_stub.h" |
| 27 #include "remoting/protocol/host_stub.h" | 26 #include "remoting/protocol/host_stub.h" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 50 AccessVerifier* access_verifier, | 49 AccessVerifier* access_verifier, |
| 51 bool allow_nat_traversal) | 50 bool allow_nat_traversal) |
| 52 : context_(context), | 51 : context_(context), |
| 53 desktop_environment_(environment), | 52 desktop_environment_(environment), |
| 54 config_(config), | 53 config_(config), |
| 55 access_verifier_(access_verifier), | 54 access_verifier_(access_verifier), |
| 56 allow_nat_traversal_(allow_nat_traversal), | 55 allow_nat_traversal_(allow_nat_traversal), |
| 57 stopping_recorders_(0), | 56 stopping_recorders_(0), |
| 58 state_(kInitial), | 57 state_(kInitial), |
| 59 protocol_config_(protocol::CandidateSessionConfig::CreateDefault()), | 58 protocol_config_(protocol::CandidateSessionConfig::CreateDefault()), |
| 60 is_curtained_(false), | |
| 61 is_it2me_(false) { | 59 is_it2me_(false) { |
| 62 DCHECK(desktop_environment_); | 60 DCHECK(desktop_environment_); |
| 63 desktop_environment_->set_host(this); | 61 desktop_environment_->set_host(this); |
| 64 } | 62 } |
| 65 | 63 |
| 66 ChromotingHost::~ChromotingHost() { | 64 ChromotingHost::~ChromotingHost() { |
| 67 DCHECK(clients_.empty()); | 65 DCHECK(clients_.empty()); |
| 68 } | 66 } |
| 69 | 67 |
| 70 void ChromotingHost::Start() { | 68 void ChromotingHost::Start() { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 // Immediately add the connection and start the session. | 191 // Immediately add the connection and start the session. |
| 194 recorder_->AddConnection(client->connection()); | 192 recorder_->AddConnection(client->connection()); |
| 195 recorder_->Start(); | 193 recorder_->Start(); |
| 196 | 194 |
| 197 // Notify observers that there is at least one authenticated client. | 195 // Notify observers that there is at least one authenticated client. |
| 198 const std::string& jid = client->connection()->session()->jid(); | 196 const std::string& jid = client->connection()->session()->jid(); |
| 199 for (StatusObserverList::iterator it = status_observers_.begin(); | 197 for (StatusObserverList::iterator it = status_observers_.begin(); |
| 200 it != status_observers_.end(); ++it) { | 198 it != status_observers_.end(); ++it) { |
| 201 (*it)->OnClientAuthenticated(jid); | 199 (*it)->OnClientAuthenticated(jid); |
| 202 } | 200 } |
| 203 // TODO(jamiewalch): Tidy up actions to be taken on connect/disconnect, | |
| 204 // including closing the connection on failure of a critical operation. | |
| 205 EnableCurtainMode(true); | |
| 206 | |
| 207 std::string username = jid.substr(0, jid.find('/')); | |
| 208 desktop_environment_->OnConnect(username); | |
| 209 } | 201 } |
| 210 | 202 |
| 211 void ChromotingHost::OnSessionClosed(ClientSession* client) { | 203 void ChromotingHost::OnSessionClosed(ClientSession* client) { |
| 212 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 204 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| 213 | 205 |
| 214 scoped_ptr<ClientSession> client_destroyer(client); | 206 scoped_ptr<ClientSession> client_destroyer(client); |
| 215 | 207 |
| 216 ClientList::iterator it = std::find(clients_.begin(), clients_.end(), client); | 208 ClientList::iterator it = std::find(clients_.begin(), clients_.end(), client); |
| 217 CHECK(it != clients_.end()); | 209 CHECK(it != clients_.end()); |
| 218 clients_.erase(it); | 210 clients_.erase(it); |
| 219 | 211 |
| 220 if (recorder_.get()) { | 212 if (recorder_.get()) { |
| 221 recorder_->RemoveConnection(client->connection()); | 213 recorder_->RemoveConnection(client->connection()); |
| 222 } | 214 } |
| 223 | 215 |
| 224 for (StatusObserverList::iterator it = status_observers_.begin(); | 216 for (StatusObserverList::iterator it = status_observers_.begin(); |
| 225 it != status_observers_.end(); ++it) { | 217 it != status_observers_.end(); ++it) { |
| 226 (*it)->OnClientDisconnected(client->client_jid()); | 218 (*it)->OnClientDisconnected(client->client_jid()); |
| 227 } | 219 } |
| 228 | 220 |
| 229 if (AuthenticatedClientsCount() == 0) { | 221 if (AuthenticatedClientsCount() == 0) { |
| 230 if (recorder_.get()) { | 222 if (recorder_.get()) { |
| 231 // Stop the recorder if there are no more clients. | 223 // Stop the recorder if there are no more clients. |
| 232 StopScreenRecorder(); | 224 StopScreenRecorder(); |
| 233 } | 225 } |
| 234 | |
| 235 // Disable the "curtain" if there are no more active clients. | |
| 236 EnableCurtainMode(false); | |
| 237 desktop_environment_->OnLastDisconnect(); | |
| 238 } | 226 } |
| 239 } | 227 } |
| 240 | 228 |
| 241 void ChromotingHost::OnSessionSequenceNumber(ClientSession* session, | 229 void ChromotingHost::OnSessionSequenceNumber(ClientSession* session, |
| 242 int64 sequence_number) { | 230 int64 sequence_number) { |
| 243 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 231 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| 244 if (recorder_.get()) | 232 if (recorder_.get()) |
| 245 recorder_->UpdateSequenceNumber(sequence_number); | 233 recorder_->UpdateSequenceNumber(sequence_number); |
| 246 } | 234 } |
| 247 | 235 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 // Notify observers. | 301 // Notify observers. |
| 314 for (StatusObserverList::iterator it = status_observers_.begin(); | 302 for (StatusObserverList::iterator it = status_observers_.begin(); |
| 315 it != status_observers_.end(); ++it) { | 303 it != status_observers_.end(); ++it) { |
| 316 (*it)->OnAccessDenied(); | 304 (*it)->OnAccessDenied(); |
| 317 } | 305 } |
| 318 return; | 306 return; |
| 319 } | 307 } |
| 320 | 308 |
| 321 // If we are running Me2Mom and already have an authenticated client then | 309 // If we are running Me2Mom and already have an authenticated client then |
| 322 // one of the connections may be an attacker, so both are suspect. | 310 // one of the connections may be an attacker, so both are suspect. |
| 323 if (is_it2me_ && AuthenticatedClientsCount() > 0) { | 311 if (is_it2me_ && AuthenticatedClientsCount() > 0) { |
|
Sergey Ulanov
2011/11/30 21:24:37
I think we can remove is_it2me_ flag now. Here we
Lambros
2011/11/30 22:09:41
I will address this in a followup CL. Dealing wit
| |
| 324 *response = protocol::SessionManager::DECLINE; | 312 *response = protocol::SessionManager::DECLINE; |
| 325 | 313 |
| 326 // Close existing sessions and shutdown the host. | 314 // Close existing sessions and shutdown the host. |
| 327 Shutdown(base::Closure()); | 315 Shutdown(base::Closure()); |
| 328 return; | 316 return; |
| 329 } | 317 } |
| 330 | 318 |
| 331 // TODO(simonmorris): The resolution is set in the video stream now, | 319 // TODO(simonmorris): The resolution is set in the video stream now, |
| 332 // so it doesn't need to be set here. | 320 // so it doesn't need to be set here. |
| 333 *protocol_config_->mutable_initial_resolution() = | 321 *protocol_config_->mutable_initial_resolution() = |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 if (!context_->network_message_loop()->BelongsToCurrentThread()) { | 374 if (!context_->network_message_loop()->BelongsToCurrentThread()) { |
| 387 context_->network_message_loop()->PostTask( | 375 context_->network_message_loop()->PostTask( |
| 388 FROM_HERE, base::Bind(&ChromotingHost::PauseSession, this, pause)); | 376 FROM_HERE, base::Bind(&ChromotingHost::PauseSession, this, pause)); |
| 389 return; | 377 return; |
| 390 } | 378 } |
| 391 | 379 |
| 392 ClientList::iterator client; | 380 ClientList::iterator client; |
| 393 for (client = clients_.begin(); client != clients_.end(); ++client) { | 381 for (client = clients_.begin(); client != clients_.end(); ++client) { |
| 394 (*client)->set_awaiting_continue_approval(pause); | 382 (*client)->set_awaiting_continue_approval(pause); |
| 395 } | 383 } |
| 396 desktop_environment_->OnPause(pause); | |
| 397 } | 384 } |
| 398 | 385 |
| 399 void ChromotingHost::SetUiStrings(const UiStrings& ui_strings) { | 386 void ChromotingHost::SetUiStrings(const UiStrings& ui_strings) { |
| 400 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); | 387 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); |
| 401 DCHECK_EQ(state_, kInitial); | 388 DCHECK_EQ(state_, kInitial); |
| 402 | 389 |
| 403 ui_strings_ = ui_strings; | 390 ui_strings_ = ui_strings; |
| 404 } | 391 } |
| 405 | 392 |
| 406 // TODO(sergeyu): Move this to SessionManager? | 393 // TODO(sergeyu): Move this to SessionManager? |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 429 | 416 |
| 430 int authenticated_clients = 0; | 417 int authenticated_clients = 0; |
| 431 for (ClientList::const_iterator it = clients_.begin(); it != clients_.end(); | 418 for (ClientList::const_iterator it = clients_.begin(); it != clients_.end(); |
| 432 ++it) { | 419 ++it) { |
| 433 if ((*it)->authenticated()) | 420 if ((*it)->authenticated()) |
| 434 ++authenticated_clients; | 421 ++authenticated_clients; |
| 435 } | 422 } |
| 436 return authenticated_clients; | 423 return authenticated_clients; |
| 437 } | 424 } |
| 438 | 425 |
| 439 void ChromotingHost::EnableCurtainMode(bool enable) { | |
| 440 // TODO(jamiewalch): This will need to be more sophisticated when we think | |
| 441 // about proper crash recovery and daemon mode. | |
| 442 // TODO(wez): CurtainMode shouldn't be driven directly by ChromotingHost. | |
| 443 if (is_it2me_ || enable == is_curtained_) | |
| 444 return; | |
| 445 desktop_environment_->curtain()->EnableCurtainMode(enable); | |
| 446 is_curtained_ = enable; | |
| 447 } | |
| 448 | |
| 449 void ChromotingHost::StopScreenRecorder() { | 426 void ChromotingHost::StopScreenRecorder() { |
| 450 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 427 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| 451 DCHECK(recorder_.get()); | 428 DCHECK(recorder_.get()); |
| 452 | 429 |
| 453 ++stopping_recorders_; | 430 ++stopping_recorders_; |
| 454 scoped_refptr<ScreenRecorder> recorder = recorder_; | 431 scoped_refptr<ScreenRecorder> recorder = recorder_; |
| 455 recorder_ = NULL; | 432 recorder_ = NULL; |
| 456 recorder->Stop(base::Bind(&ChromotingHost::OnScreenRecorderStopped, this)); | 433 recorder->Stop(base::Bind(&ChromotingHost::OnScreenRecorderStopped, this)); |
| 457 } | 434 } |
| 458 | 435 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 486 } | 463 } |
| 487 | 464 |
| 488 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin(); | 465 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin(); |
| 489 it != shutdown_tasks_.end(); ++it) { | 466 it != shutdown_tasks_.end(); ++it) { |
| 490 it->Run(); | 467 it->Run(); |
| 491 } | 468 } |
| 492 shutdown_tasks_.clear(); | 469 shutdown_tasks_.clear(); |
| 493 } | 470 } |
| 494 | 471 |
| 495 } // namespace remoting | 472 } // namespace remoting |
| OLD | NEW |