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" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 std::string xmpp_login; | 86 std::string xmpp_login; |
| 87 std::string xmpp_auth_token; | 87 std::string xmpp_auth_token; |
| 88 std::string xmpp_auth_service; | 88 std::string xmpp_auth_service; |
| 89 if (!config_->GetString(kXmppLoginConfigPath, &xmpp_login) || | 89 if (!config_->GetString(kXmppLoginConfigPath, &xmpp_login) || |
| 90 !config_->GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token) || | 90 !config_->GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token) || |
| 91 !config_->GetString(kXmppAuthServiceConfigPath, &xmpp_auth_service)) { | 91 !config_->GetString(kXmppAuthServiceConfigPath, &xmpp_auth_service)) { |
| 92 LOG(ERROR) << "XMPP credentials are not defined in the config."; | 92 LOG(ERROR) << "XMPP credentials are not defined in the config."; |
| 93 return; | 93 return; |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Create and start XMPP connection. | |
| 96 signal_strategy_.reset( | 97 signal_strategy_.reset( |
| 97 new XmppSignalStrategy(context_->jingle_thread(), xmpp_login, | 98 new XmppSignalStrategy(context_->jingle_thread(), xmpp_login, |
| 98 xmpp_auth_token, | 99 xmpp_auth_token, xmpp_auth_service)); |
| 99 xmpp_auth_service)); | 100 signal_strategy_->AddListener(this); |
| 100 signal_strategy_->Init(this); | 101 signal_strategy_->Connect(); |
| 102 | |
| 103 // Create and start session manager. | |
| 104 session_manager_.reset( | |
| 105 new protocol::JingleSessionManager(context_->network_message_loop())); | |
| 106 session_manager_->Init(signal_strategy_.get(), | |
| 107 this, allow_nat_traversal_); | |
|
Wez
2011/12/21 23:35:30
nit: We should replace Init() with an AcceptConnec
Sergey Ulanov
2011/12/22 21:45:10
Init() must be called before Connect() even if we
| |
| 101 } | 108 } |
| 102 | 109 |
| 103 // This method is called when we need to destroy the host process. | 110 // This method is called when we need to destroy the host process. |
| 104 void ChromotingHost::Shutdown(const base::Closure& shutdown_task) { | 111 void ChromotingHost::Shutdown(const base::Closure& shutdown_task) { |
| 105 if (!context_->network_message_loop()->BelongsToCurrentThread()) { | 112 if (!context_->network_message_loop()->BelongsToCurrentThread()) { |
| 106 context_->network_message_loop()->PostTask( | 113 context_->network_message_loop()->PostTask( |
| 107 FROM_HERE, base::Bind(&ChromotingHost::Shutdown, this, shutdown_task)); | 114 FROM_HERE, base::Bind(&ChromotingHost::Shutdown, this, shutdown_task)); |
| 108 return; | 115 return; |
| 109 } | 116 } |
| 110 | 117 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 133 // this method may be invoked in response to a libjingle event and | 140 // this method may be invoked in response to a libjingle event and |
| 134 // libjingle's sigslot doesn't handle it properly, so postpone the | 141 // libjingle's sigslot doesn't handle it properly, so postpone the |
| 135 // deletion. | 142 // deletion. |
| 136 context_->network_message_loop()->DeleteSoon( | 143 context_->network_message_loop()->DeleteSoon( |
| 137 FROM_HERE, session_manager_.release()); | 144 FROM_HERE, session_manager_.release()); |
| 138 have_shared_secret_ = false; | 145 have_shared_secret_ = false; |
| 139 } | 146 } |
| 140 | 147 |
| 141 // Stop XMPP connection synchronously. | 148 // Stop XMPP connection synchronously. |
| 142 if (signal_strategy_.get()) { | 149 if (signal_strategy_.get()) { |
| 143 signal_strategy_->Close(); | 150 signal_strategy_->Disconnect(); |
| 151 signal_strategy_->RemoveListener(this); | |
| 144 signal_strategy_.reset(); | 152 signal_strategy_.reset(); |
| 145 | |
| 146 for (StatusObserverList::iterator it = status_observers_.begin(); | |
| 147 it != status_observers_.end(); ++it) { | |
| 148 (*it)->OnSignallingDisconnected(); | |
| 149 } | |
| 150 } | 153 } |
| 151 | 154 |
| 152 if (recorder_.get()) { | 155 if (recorder_.get()) { |
| 153 StopScreenRecorder(); | 156 StopScreenRecorder(); |
| 154 } else { | 157 } else { |
| 155 ShutdownFinish(); | 158 ShutdownFinish(); |
| 156 } | 159 } |
| 157 } | 160 } |
| 158 | 161 |
| 159 void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) { | 162 void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) { |
| 160 DCHECK_EQ(state_, kInitial); | 163 DCHECK_EQ(state_, kInitial); |
| 161 status_observers_.push_back(observer); | 164 status_observers_.push_back(observer); |
| 162 } | 165 } |
| 163 | 166 |
| 164 void ChromotingHost::SetSharedSecret(const std::string& shared_secret) { | 167 void ChromotingHost::SetSharedSecret(const std::string& shared_secret) { |
| 165 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 168 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| 166 shared_secret_ = shared_secret; | 169 session_manager_->set_authenticator_factory( |
| 167 have_shared_secret_ = true; | 170 new protocol::V1HostAuthenticatorFactory( |
| 168 if (session_manager_.get()) { | 171 key_pair_.GenerateCertificate(), key_pair_.private_key(), |
| 169 session_manager_->set_authenticator_factory( | 172 shared_secret)); |
| 170 new protocol::V1HostAuthenticatorFactory( | |
| 171 key_pair_.GenerateCertificate(), key_pair_.private_key(), | |
| 172 shared_secret_)); | |
| 173 } | |
| 174 } | 173 } |
| 175 | 174 |
| 176 //////////////////////////////////////////////////////////////////////////// | 175 //////////////////////////////////////////////////////////////////////////// |
| 177 // protocol::ClientSession::EventHandler implementation. | 176 // protocol::ClientSession::EventHandler implementation. |
| 178 void ChromotingHost::OnSessionAuthenticated(ClientSession* client) { | 177 void ChromotingHost::OnSessionAuthenticated(ClientSession* client) { |
| 179 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 178 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| 180 | 179 |
| 181 // Disconnect all other clients. | 180 // Disconnect all other clients. |
| 182 // Iterate over a copy of the list of clients, to avoid mutating the list | 181 // Iterate over a copy of the list of clients, to avoid mutating the list |
| 183 // while iterating over it. | 182 // while iterating over it. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 | 249 |
| 251 void ChromotingHost::OnSessionSequenceNumber(ClientSession* session, | 250 void ChromotingHost::OnSessionSequenceNumber(ClientSession* session, |
| 252 int64 sequence_number) { | 251 int64 sequence_number) { |
| 253 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 252 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| 254 if (recorder_.get()) | 253 if (recorder_.get()) |
| 255 recorder_->UpdateSequenceNumber(sequence_number); | 254 recorder_->UpdateSequenceNumber(sequence_number); |
| 256 } | 255 } |
| 257 | 256 |
| 258 //////////////////////////////////////////////////////////////////////////// | 257 //////////////////////////////////////////////////////////////////////////// |
| 259 // SignalStrategy::StatusObserver implementations | 258 // SignalStrategy::StatusObserver implementations |
| 260 void ChromotingHost::OnStateChange( | 259 void ChromotingHost::OnSignalStrategyStateChange( |
| 261 SignalStrategy::StatusObserver::State state) { | 260 SignalStrategy::State state) { |
| 262 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 261 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| 263 | 262 |
| 264 if (state == SignalStrategy::StatusObserver::CONNECTED) { | 263 if (state == SignalStrategy::CONNECTED) { |
| 265 LOG(INFO) << "Host connected as " << local_jid_; | 264 LOG(INFO) << "Host connected as " << signal_strategy_->GetLocalJid(); |
| 266 | |
| 267 // Create and start session manager. | |
| 268 protocol::JingleSessionManager* server = | |
| 269 new protocol::JingleSessionManager(context_->network_message_loop()); | |
| 270 | |
| 271 server->Init(local_jid_, signal_strategy_.get(), | |
| 272 this, allow_nat_traversal_); | |
| 273 | |
| 274 session_manager_.reset(server); | |
| 275 if (have_shared_secret_) { | |
| 276 session_manager_->set_authenticator_factory( | |
| 277 new protocol::V1HostAuthenticatorFactory( | |
| 278 key_pair_.GenerateCertificate(), key_pair_.private_key(), | |
| 279 shared_secret_)); | |
| 280 } | |
| 281 | 265 |
| 282 for (StatusObserverList::iterator it = status_observers_.begin(); | 266 for (StatusObserverList::iterator it = status_observers_.begin(); |
| 283 it != status_observers_.end(); ++it) { | 267 it != status_observers_.end(); ++it) { |
| 284 (*it)->OnSignallingConnected(signal_strategy_.get(), local_jid_); | 268 (*it)->OnSignallingConnected(signal_strategy_.get()); |
| 285 } | 269 } |
| 286 } else if (state == SignalStrategy::StatusObserver::CLOSED) { | 270 } else if (state == SignalStrategy::CLOSED) { |
| 287 LOG(INFO) << "Host disconnected from talk network."; | 271 LOG(INFO) << "Host disconnected from talk network."; |
| 288 for (StatusObserverList::iterator it = status_observers_.begin(); | 272 for (StatusObserverList::iterator it = status_observers_.begin(); |
| 289 it != status_observers_.end(); ++it) { | 273 it != status_observers_.end(); ++it) { |
| 290 (*it)->OnSignallingDisconnected(); | 274 (*it)->OnSignallingDisconnected(); |
| 291 } | 275 } |
| 292 } | 276 } |
| 293 } | 277 } |
| 294 | 278 |
| 295 void ChromotingHost::OnJidChange(const std::string& full_jid) { | 279 bool ChromotingHost::OnSignalStrategyIncomingStanza( |
| 296 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 280 const buzz::XmlElement* stanza) { |
| 297 local_jid_ = full_jid; | 281 return false; |
| 298 } | 282 } |
| 299 | 283 |
| 300 void ChromotingHost::OnSessionManagerInitialized() { | 284 void ChromotingHost::OnSessionManagerReady() { |
| 301 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 285 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| 302 // Don't need to do anything here, just wait for incoming | 286 // Don't need to do anything here, just wait for incoming |
| 303 // connections. | 287 // connections. |
| 304 } | 288 } |
| 305 | 289 |
| 306 void ChromotingHost::OnIncomingSession( | 290 void ChromotingHost::OnIncomingSession( |
| 307 protocol::Session* session, | 291 protocol::Session* session, |
| 308 protocol::SessionManager::IncomingSessionResponse* response) { | 292 protocol::SessionManager::IncomingSessionResponse* response) { |
| 309 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 293 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| 310 | 294 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 } | 443 } |
| 460 | 444 |
| 461 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin(); | 445 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin(); |
| 462 it != shutdown_tasks_.end(); ++it) { | 446 it != shutdown_tasks_.end(); ++it) { |
| 463 it->Run(); | 447 it->Run(); |
| 464 } | 448 } |
| 465 shutdown_tasks_.clear(); | 449 shutdown_tasks_.clear(); |
| 466 } | 450 } |
| 467 | 451 |
| 468 } // namespace remoting | 452 } // namespace remoting |
| OLD | NEW |