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/screen_recorder.h" | 20 #include "remoting/host/screen_recorder.h" |
22 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | 21 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
23 #include "remoting/protocol/connection_to_client.h" | 22 #include "remoting/protocol/connection_to_client.h" |
24 #include "remoting/protocol/client_stub.h" | 23 #include "remoting/protocol/client_stub.h" |
25 #include "remoting/protocol/host_stub.h" | 24 #include "remoting/protocol/host_stub.h" |
26 #include "remoting/protocol/input_stub.h" | 25 #include "remoting/protocol/input_stub.h" |
27 #include "remoting/protocol/jingle_session_manager.h" | 26 #include "remoting/protocol/jingle_session_manager.h" |
(...skipping 17 matching lines...) Expand all Loading... |
45 MutableHostConfig* config, | 44 MutableHostConfig* config, |
46 DesktopEnvironment* environment, | 45 DesktopEnvironment* environment, |
47 bool allow_nat_traversal) | 46 bool allow_nat_traversal) |
48 : context_(context), | 47 : context_(context), |
49 desktop_environment_(environment), | 48 desktop_environment_(environment), |
50 config_(config), | 49 config_(config), |
51 allow_nat_traversal_(allow_nat_traversal), | 50 allow_nat_traversal_(allow_nat_traversal), |
52 stopping_recorders_(0), | 51 stopping_recorders_(0), |
53 state_(kInitial), | 52 state_(kInitial), |
54 protocol_config_(protocol::CandidateSessionConfig::CreateDefault()), | 53 protocol_config_(protocol::CandidateSessionConfig::CreateDefault()), |
55 is_curtained_(false), | |
56 is_it2me_(false) { | 54 is_it2me_(false) { |
57 DCHECK(desktop_environment_); | 55 DCHECK(desktop_environment_); |
58 desktop_environment_->set_host(this); | 56 desktop_environment_->set_host(this); |
59 } | 57 } |
60 | 58 |
61 ChromotingHost::~ChromotingHost() { | 59 ChromotingHost::~ChromotingHost() { |
62 DCHECK(clients_.empty()); | 60 DCHECK(clients_.empty()); |
63 } | 61 } |
64 | 62 |
65 void ChromotingHost::Start() { | 63 void ChromotingHost::Start() { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 // Immediately add the connection and start the session. | 199 // Immediately add the connection and start the session. |
202 recorder_->AddConnection(client->connection()); | 200 recorder_->AddConnection(client->connection()); |
203 recorder_->Start(); | 201 recorder_->Start(); |
204 | 202 |
205 // Notify observers that there is at least one authenticated client. | 203 // Notify observers that there is at least one authenticated client. |
206 const std::string& jid = client->connection()->session()->jid(); | 204 const std::string& jid = client->connection()->session()->jid(); |
207 for (StatusObserverList::iterator it = status_observers_.begin(); | 205 for (StatusObserverList::iterator it = status_observers_.begin(); |
208 it != status_observers_.end(); ++it) { | 206 it != status_observers_.end(); ++it) { |
209 (*it)->OnClientAuthenticated(jid); | 207 (*it)->OnClientAuthenticated(jid); |
210 } | 208 } |
211 // TODO(jamiewalch): Tidy up actions to be taken on connect/disconnect, | |
212 // including closing the connection on failure of a critical operation. | |
213 EnableCurtainMode(true); | |
214 | |
215 std::string username = jid.substr(0, jid.find('/')); | |
216 desktop_environment_->OnConnect(username); | |
217 } | 209 } |
218 | 210 |
219 void ChromotingHost::OnSessionAuthenticationFailed(ClientSession* client) { | 211 void ChromotingHost::OnSessionAuthenticationFailed(ClientSession* client) { |
220 // Notify observers. | 212 // Notify observers. |
221 for (StatusObserverList::iterator it = status_observers_.begin(); | 213 for (StatusObserverList::iterator it = status_observers_.begin(); |
222 it != status_observers_.end(); ++it) { | 214 it != status_observers_.end(); ++it) { |
223 (*it)->OnAccessDenied(); | 215 (*it)->OnAccessDenied(); |
224 } | 216 } |
225 } | 217 } |
226 | 218 |
(...skipping 13 matching lines...) Expand all Loading... |
240 for (StatusObserverList::iterator it = status_observers_.begin(); | 232 for (StatusObserverList::iterator it = status_observers_.begin(); |
241 it != status_observers_.end(); ++it) { | 233 it != status_observers_.end(); ++it) { |
242 (*it)->OnClientDisconnected(client->client_jid()); | 234 (*it)->OnClientDisconnected(client->client_jid()); |
243 } | 235 } |
244 | 236 |
245 if (AuthenticatedClientsCount() == 0) { | 237 if (AuthenticatedClientsCount() == 0) { |
246 if (recorder_.get()) { | 238 if (recorder_.get()) { |
247 // Stop the recorder if there are no more clients. | 239 // Stop the recorder if there are no more clients. |
248 StopScreenRecorder(); | 240 StopScreenRecorder(); |
249 } | 241 } |
250 | |
251 // Disable the "curtain" if there are no more active clients. | |
252 EnableCurtainMode(false); | |
253 desktop_environment_->OnLastDisconnect(); | |
254 } | 242 } |
255 } | 243 } |
256 | 244 |
257 void ChromotingHost::OnSessionSequenceNumber(ClientSession* session, | 245 void ChromotingHost::OnSessionSequenceNumber(ClientSession* session, |
258 int64 sequence_number) { | 246 int64 sequence_number) { |
259 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 247 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
260 if (recorder_.get()) | 248 if (recorder_.get()) |
261 recorder_->UpdateSequenceNumber(sequence_number); | 249 recorder_->UpdateSequenceNumber(sequence_number); |
262 } | 250 } |
263 | 251 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 if (!context_->network_message_loop()->BelongsToCurrentThread()) { | 364 if (!context_->network_message_loop()->BelongsToCurrentThread()) { |
377 context_->network_message_loop()->PostTask( | 365 context_->network_message_loop()->PostTask( |
378 FROM_HERE, base::Bind(&ChromotingHost::PauseSession, this, pause)); | 366 FROM_HERE, base::Bind(&ChromotingHost::PauseSession, this, pause)); |
379 return; | 367 return; |
380 } | 368 } |
381 | 369 |
382 ClientList::iterator client; | 370 ClientList::iterator client; |
383 for (client = clients_.begin(); client != clients_.end(); ++client) { | 371 for (client = clients_.begin(); client != clients_.end(); ++client) { |
384 (*client)->set_awaiting_continue_approval(pause); | 372 (*client)->set_awaiting_continue_approval(pause); |
385 } | 373 } |
386 desktop_environment_->OnPause(pause); | |
387 } | 374 } |
388 | 375 |
389 void ChromotingHost::SetUiStrings(const UiStrings& ui_strings) { | 376 void ChromotingHost::SetUiStrings(const UiStrings& ui_strings) { |
390 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); | 377 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); |
391 DCHECK_EQ(state_, kInitial); | 378 DCHECK_EQ(state_, kInitial); |
392 | 379 |
393 ui_strings_ = ui_strings; | 380 ui_strings_ = ui_strings; |
394 } | 381 } |
395 | 382 |
396 // TODO(sergeyu): Move this to SessionManager? | 383 // TODO(sergeyu): Move this to SessionManager? |
(...skipping 16 matching lines...) Expand all Loading... |
413 | 400 |
414 int authenticated_clients = 0; | 401 int authenticated_clients = 0; |
415 for (ClientList::const_iterator it = clients_.begin(); it != clients_.end(); | 402 for (ClientList::const_iterator it = clients_.begin(); it != clients_.end(); |
416 ++it) { | 403 ++it) { |
417 if ((*it)->authenticated()) | 404 if ((*it)->authenticated()) |
418 ++authenticated_clients; | 405 ++authenticated_clients; |
419 } | 406 } |
420 return authenticated_clients; | 407 return authenticated_clients; |
421 } | 408 } |
422 | 409 |
423 void ChromotingHost::EnableCurtainMode(bool enable) { | |
424 // TODO(jamiewalch): This will need to be more sophisticated when we think | |
425 // about proper crash recovery and daemon mode. | |
426 // TODO(wez): CurtainMode shouldn't be driven directly by ChromotingHost. | |
427 if (is_it2me_ || enable == is_curtained_) | |
428 return; | |
429 desktop_environment_->curtain()->EnableCurtainMode(enable); | |
430 is_curtained_ = enable; | |
431 } | |
432 | |
433 void ChromotingHost::StopScreenRecorder() { | 410 void ChromotingHost::StopScreenRecorder() { |
434 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 411 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
435 DCHECK(recorder_.get()); | 412 DCHECK(recorder_.get()); |
436 | 413 |
437 ++stopping_recorders_; | 414 ++stopping_recorders_; |
438 scoped_refptr<ScreenRecorder> recorder = recorder_; | 415 scoped_refptr<ScreenRecorder> recorder = recorder_; |
439 recorder_ = NULL; | 416 recorder_ = NULL; |
440 recorder->Stop(base::Bind(&ChromotingHost::OnScreenRecorderStopped, this)); | 417 recorder->Stop(base::Bind(&ChromotingHost::OnScreenRecorderStopped, this)); |
441 } | 418 } |
442 | 419 |
(...skipping 27 matching lines...) Expand all Loading... |
470 } | 447 } |
471 | 448 |
472 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin(); | 449 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin(); |
473 it != shutdown_tasks_.end(); ++it) { | 450 it != shutdown_tasks_.end(); ++it) { |
474 it->Run(); | 451 it->Run(); |
475 } | 452 } |
476 shutdown_tasks_.clear(); | 453 shutdown_tasks_.clear(); |
477 } | 454 } |
478 | 455 |
479 } // namespace remoting | 456 } // namespace remoting |
OLD | NEW |