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/desktop_environment.h" | 17 #include "remoting/host/desktop_environment.h" |
| 18 #include "remoting/host/event_executor.h" | 18 #include "remoting/host/event_executor.h" |
| 19 #include "remoting/host/host_config.h" | 19 #include "remoting/host/host_config.h" |
| 20 #include "remoting/host/screen_recorder.h" | 20 #include "remoting/host/screen_recorder.h" |
| 21 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | |
| 22 #include "remoting/protocol/connection_to_client.h" | 21 #include "remoting/protocol/connection_to_client.h" |
| 23 #include "remoting/protocol/client_stub.h" | 22 #include "remoting/protocol/client_stub.h" |
| 24 #include "remoting/protocol/host_stub.h" | 23 #include "remoting/protocol/host_stub.h" |
| 25 #include "remoting/protocol/input_stub.h" | 24 #include "remoting/protocol/input_stub.h" |
| 26 #include "remoting/protocol/jingle_session_manager.h" | 25 #include "remoting/protocol/jingle_session_manager.h" |
| 27 #include "remoting/protocol/session_config.h" | 26 #include "remoting/protocol/session_config.h" |
| 28 #include "remoting/protocol/v1_authenticator.h" | 27 #include "remoting/protocol/v1_authenticator.h" |
| 29 | 28 |
| 30 using remoting::protocol::ConnectionToClient; | 29 using remoting::protocol::ConnectionToClient; |
| 31 using remoting::protocol::InputStub; | 30 using remoting::protocol::InputStub; |
| 32 | 31 |
| 33 namespace remoting { | 32 namespace remoting { |
| 34 | 33 |
| 35 // static | |
| 36 ChromotingHost* ChromotingHost::Create(ChromotingHostContext* context, | |
| 37 MutableHostConfig* config, | |
| 38 DesktopEnvironment* environment, | |
| 39 bool allow_nat_traversal) { | |
| 40 return new ChromotingHost(context, config, environment, allow_nat_traversal); | |
| 41 } | |
| 42 | |
| 43 ChromotingHost::ChromotingHost(ChromotingHostContext* context, | 34 ChromotingHost::ChromotingHost(ChromotingHostContext* context, |
| 44 MutableHostConfig* config, | 35 MutableHostConfig* config, |
| 36 SignalStrategy* signal_strategy, | |
| 45 DesktopEnvironment* environment, | 37 DesktopEnvironment* environment, |
| 46 bool allow_nat_traversal) | 38 bool allow_nat_traversal) |
| 47 : context_(context), | 39 : context_(context), |
| 48 desktop_environment_(environment), | 40 desktop_environment_(environment), |
| 49 config_(config), | 41 config_(config), |
| 50 allow_nat_traversal_(allow_nat_traversal), | 42 allow_nat_traversal_(allow_nat_traversal), |
| 51 have_shared_secret_(false), | 43 have_shared_secret_(false), |
| 44 signal_strategy_(signal_strategy), | |
| 52 stopping_recorders_(0), | 45 stopping_recorders_(0), |
| 53 state_(kInitial), | 46 state_(kInitial), |
| 54 protocol_config_(protocol::CandidateSessionConfig::CreateDefault()), | 47 protocol_config_(protocol::CandidateSessionConfig::CreateDefault()), |
| 55 is_it2me_(false) { | 48 is_it2me_(false) { |
| 56 DCHECK(desktop_environment_); | 49 DCHECK(desktop_environment_); |
|
Wez
2012/01/03 16:25:04
nit: Do we touch any of the other objects we are p
Sergey Ulanov
2012/01/03 21:51:02
Done.
| |
| 57 desktop_environment_->set_host(this); | 50 desktop_environment_->set_host(this); |
| 58 } | 51 } |
| 59 | 52 |
| 60 ChromotingHost::~ChromotingHost() { | 53 ChromotingHost::~ChromotingHost() { |
| 61 DCHECK(clients_.empty()); | 54 DCHECK(clients_.empty()); |
| 62 } | 55 } |
| 63 | 56 |
| 64 void ChromotingHost::Start() { | 57 void ChromotingHost::Start() { |
| 65 if (!context_->network_message_loop()->BelongsToCurrentThread()) { | 58 if (!context_->network_message_loop()->BelongsToCurrentThread()) { |
| 66 context_->network_message_loop()->PostTask( | 59 context_->network_message_loop()->PostTask( |
| 67 FROM_HERE, base::Bind(&ChromotingHost::Start, this)); | 60 FROM_HERE, base::Bind(&ChromotingHost::Start, this)); |
| 68 return; | 61 return; |
| 69 } | 62 } |
| 70 | 63 |
| 71 LOG(INFO) << "Starting host"; | 64 LOG(INFO) << "Starting host"; |
| 72 DCHECK(!signal_strategy_.get()); | |
| 73 | 65 |
| 74 // Make sure this object is not started. | 66 // Make sure this object is not started. |
| 75 if (state_ != kInitial) | 67 if (state_ != kInitial) |
| 76 return; | 68 return; |
| 77 state_ = kStarted; | 69 state_ = kStarted; |
| 78 | 70 |
| 79 // Assign key and certificate to server. | 71 // Assign key and certificate to server. |
| 80 if (!key_pair_.Load(config_)) { | 72 if (!key_pair_.Load(config_)) { |
| 81 LOG(ERROR) << "Failed to load key pair for the host."; | 73 LOG(ERROR) << "Failed to load key pair for the host."; |
| 82 return; | 74 return; |
| 83 } | 75 } |
| 84 | 76 |
| 85 // Use an XMPP connection to the Talk network for session signalling. | |
| 86 std::string xmpp_login; | |
| 87 std::string xmpp_auth_token; | |
| 88 std::string xmpp_auth_service; | |
| 89 if (!config_->GetString(kXmppLoginConfigPath, &xmpp_login) || | |
| 90 !config_->GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token) || | |
| 91 !config_->GetString(kXmppAuthServiceConfigPath, &xmpp_auth_service)) { | |
| 92 LOG(ERROR) << "XMPP credentials are not defined in the config."; | |
| 93 return; | |
| 94 } | |
| 95 | |
| 96 // Create and start XMPP connection. | |
| 97 signal_strategy_.reset( | |
| 98 new XmppSignalStrategy(context_->jingle_thread(), xmpp_login, | |
| 99 xmpp_auth_token, xmpp_auth_service)); | |
| 100 signal_strategy_->AddListener(this); | |
| 101 signal_strategy_->Connect(); | |
| 102 | |
| 103 // Create and start session manager. | 77 // Create and start session manager. |
| 104 session_manager_.reset( | 78 session_manager_.reset( |
| 105 new protocol::JingleSessionManager(context_->network_message_loop())); | 79 new protocol::JingleSessionManager(context_->network_message_loop())); |
| 106 session_manager_->Init(signal_strategy_.get(), | 80 session_manager_->Init(signal_strategy_, this, allow_nat_traversal_); |
| 107 this, allow_nat_traversal_); | |
| 108 } | 81 } |
| 109 | 82 |
| 110 // This method is called when we need to destroy the host process. | 83 // This method is called when we need to destroy the host process. |
| 111 void ChromotingHost::Shutdown(const base::Closure& shutdown_task) { | 84 void ChromotingHost::Shutdown(const base::Closure& shutdown_task) { |
| 112 if (!context_->network_message_loop()->BelongsToCurrentThread()) { | 85 if (!context_->network_message_loop()->BelongsToCurrentThread()) { |
| 113 context_->network_message_loop()->PostTask( | 86 context_->network_message_loop()->PostTask( |
| 114 FROM_HERE, base::Bind(&ChromotingHost::Shutdown, this, shutdown_task)); | 87 FROM_HERE, base::Bind(&ChromotingHost::Shutdown, this, shutdown_task)); |
| 115 return; | 88 return; |
| 116 } | 89 } |
| 117 | 90 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 138 session_manager_->Close(); | 111 session_manager_->Close(); |
| 139 // It may not be safe to delete |session_manager_| here becase | 112 // It may not be safe to delete |session_manager_| here becase |
| 140 // this method may be invoked in response to a libjingle event and | 113 // this method may be invoked in response to a libjingle event and |
| 141 // libjingle's sigslot doesn't handle it properly, so postpone the | 114 // libjingle's sigslot doesn't handle it properly, so postpone the |
| 142 // deletion. | 115 // deletion. |
| 143 context_->network_message_loop()->DeleteSoon( | 116 context_->network_message_loop()->DeleteSoon( |
| 144 FROM_HERE, session_manager_.release()); | 117 FROM_HERE, session_manager_.release()); |
| 145 have_shared_secret_ = false; | 118 have_shared_secret_ = false; |
| 146 } | 119 } |
| 147 | 120 |
| 148 // Stop XMPP connection synchronously. | |
| 149 if (signal_strategy_.get()) { | |
| 150 signal_strategy_->Disconnect(); | |
| 151 signal_strategy_->RemoveListener(this); | |
| 152 signal_strategy_.reset(); | |
| 153 } | |
| 154 | |
| 155 if (recorder_.get()) { | 121 if (recorder_.get()) { |
| 156 StopScreenRecorder(); | 122 StopScreenRecorder(); |
| 157 } else { | 123 } else { |
| 158 ShutdownFinish(); | 124 ShutdownFinish(); |
| 159 } | 125 } |
| 160 } | 126 } |
| 161 | 127 |
| 162 void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) { | 128 void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) { |
| 163 DCHECK_EQ(state_, kInitial); | 129 DCHECK_EQ(state_, kInitial); |
| 164 status_observers_.push_back(observer); | 130 status_observers_.push_back(observer); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 } | 213 } |
| 248 } | 214 } |
| 249 | 215 |
| 250 void ChromotingHost::OnSessionSequenceNumber(ClientSession* session, | 216 void ChromotingHost::OnSessionSequenceNumber(ClientSession* session, |
| 251 int64 sequence_number) { | 217 int64 sequence_number) { |
| 252 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 218 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| 253 if (recorder_.get()) | 219 if (recorder_.get()) |
| 254 recorder_->UpdateSequenceNumber(sequence_number); | 220 recorder_->UpdateSequenceNumber(sequence_number); |
| 255 } | 221 } |
| 256 | 222 |
| 257 //////////////////////////////////////////////////////////////////////////// | |
| 258 // SignalStrategy::StatusObserver implementations | |
| 259 void ChromotingHost::OnSignalStrategyStateChange( | |
| 260 SignalStrategy::State state) { | |
| 261 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | |
| 262 | |
| 263 if (state == SignalStrategy::CONNECTED) { | |
| 264 LOG(INFO) << "Host connected as " << signal_strategy_->GetLocalJid(); | |
| 265 | |
| 266 for (StatusObserverList::iterator it = status_observers_.begin(); | |
| 267 it != status_observers_.end(); ++it) { | |
| 268 (*it)->OnSignallingConnected(signal_strategy_.get()); | |
| 269 } | |
| 270 } else if (state == SignalStrategy::DISCONNECTED) { | |
| 271 LOG(INFO) << "Host disconnected from talk network."; | |
| 272 for (StatusObserverList::iterator it = status_observers_.begin(); | |
| 273 it != status_observers_.end(); ++it) { | |
| 274 (*it)->OnSignallingDisconnected(); | |
| 275 } | |
| 276 } | |
| 277 } | |
| 278 | |
| 279 void ChromotingHost::OnSessionManagerReady() { | 223 void ChromotingHost::OnSessionManagerReady() { |
| 280 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 224 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| 281 // Don't need to do anything here, just wait for incoming | 225 // Don't need to do anything here, just wait for incoming |
| 282 // connections. | 226 // connections. |
| 283 } | 227 } |
| 284 | 228 |
| 285 void ChromotingHost::OnIncomingSession( | 229 void ChromotingHost::OnIncomingSession( |
| 286 protocol::Session* session, | 230 protocol::Session* session, |
| 287 protocol::SessionManager::IncomingSessionResponse* response) { | 231 protocol::SessionManager::IncomingSessionResponse* response) { |
| 288 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 232 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 438 } | 382 } |
| 439 | 383 |
| 440 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin(); | 384 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin(); |
| 441 it != shutdown_tasks_.end(); ++it) { | 385 it != shutdown_tasks_.end(); ++it) { |
| 442 it->Run(); | 386 it->Run(); |
| 443 } | 387 } |
| 444 shutdown_tasks_.clear(); | 388 shutdown_tasks_.clear(); |
| 445 } | 389 } |
| 446 | 390 |
| 447 } // namespace remoting | 391 } // namespace remoting |
| OLD | NEW |