| 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 "build/build_config.h" | 11 #include "build/build_config.h" |
| 11 #include "remoting/base/constants.h" | 12 #include "remoting/base/constants.h" |
| 12 #include "remoting/base/encoder.h" | 13 #include "remoting/base/encoder.h" |
| 13 #include "remoting/base/encoder_row_based.h" | 14 #include "remoting/base/encoder_row_based.h" |
| 14 #include "remoting/base/encoder_vp8.h" | 15 #include "remoting/base/encoder_vp8.h" |
| 15 #include "remoting/host/chromoting_host_context.h" | 16 #include "remoting/host/chromoting_host_context.h" |
| 16 #include "remoting/host/curtain.h" | 17 #include "remoting/host/curtain.h" |
| 17 #include "remoting/host/desktop_environment.h" | 18 #include "remoting/host/desktop_environment.h" |
| 18 #include "remoting/host/event_executor.h" | 19 #include "remoting/host/event_executor.h" |
| 19 #include "remoting/host/host_config.h" | 20 #include "remoting/host/host_config.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 is_curtained_(false), | 60 is_curtained_(false), |
| 60 is_it2me_(false) { | 61 is_it2me_(false) { |
| 61 DCHECK(desktop_environment_); | 62 DCHECK(desktop_environment_); |
| 62 desktop_environment_->set_host(this); | 63 desktop_environment_->set_host(this); |
| 63 } | 64 } |
| 64 | 65 |
| 65 ChromotingHost::~ChromotingHost() { | 66 ChromotingHost::~ChromotingHost() { |
| 66 } | 67 } |
| 67 | 68 |
| 68 void ChromotingHost::Start() { | 69 void ChromotingHost::Start() { |
| 69 if (MessageLoop::current() != context_->network_message_loop()) { | 70 if (!context_->network_message_loop()->BelongsToCurrentThread()) { |
| 70 context_->network_message_loop()->PostTask( | 71 context_->network_message_loop()->PostTask( |
| 71 FROM_HERE, base::Bind(&ChromotingHost::Start, this)); | 72 FROM_HERE, base::Bind(&ChromotingHost::Start, this)); |
| 72 return; | 73 return; |
| 73 } | 74 } |
| 74 | 75 |
| 75 LOG(INFO) << "Starting host"; | 76 LOG(INFO) << "Starting host"; |
| 76 DCHECK(!signal_strategy_.get()); | 77 DCHECK(!signal_strategy_.get()); |
| 77 DCHECK(access_verifier_.get()); | 78 DCHECK(access_verifier_.get()); |
| 78 | 79 |
| 79 // Make sure this object is not started. | 80 // Make sure this object is not started. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 } | 146 } |
| 146 | 147 |
| 147 void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) { | 148 void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) { |
| 148 DCHECK_EQ(state_, kInitial); | 149 DCHECK_EQ(state_, kInitial); |
| 149 status_observers_.push_back(observer); | 150 status_observers_.push_back(observer); |
| 150 } | 151 } |
| 151 | 152 |
| 152 //////////////////////////////////////////////////////////////////////////// | 153 //////////////////////////////////////////////////////////////////////////// |
| 153 // protocol::ConnectionToClient::EventHandler implementations | 154 // protocol::ConnectionToClient::EventHandler implementations |
| 154 void ChromotingHost::OnConnectionOpened(ConnectionToClient* connection) { | 155 void ChromotingHost::OnConnectionOpened(ConnectionToClient* connection) { |
| 155 DCHECK_EQ(context_->network_message_loop(), MessageLoop::current()); | 156 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| 156 VLOG(1) << "Connection to client established."; | 157 VLOG(1) << "Connection to client established."; |
| 157 // TODO(wez): ChromotingHost shouldn't need to know about Me2Mom. | 158 // TODO(wez): ChromotingHost shouldn't need to know about Me2Mom. |
| 158 if (is_it2me_) { | 159 if (is_it2me_) { |
| 159 context_->main_message_loop()->PostTask( | 160 context_->main_message_loop()->PostTask( |
| 160 FROM_HERE, base::Bind(&ChromotingHost::ProcessPreAuthentication, this, | 161 FROM_HERE, base::Bind(&ChromotingHost::ProcessPreAuthentication, this, |
| 161 make_scoped_refptr(connection))); | 162 make_scoped_refptr(connection))); |
| 162 } | 163 } |
| 163 } | 164 } |
| 164 | 165 |
| 165 void ChromotingHost::OnConnectionClosed(ConnectionToClient* connection) { | 166 void ChromotingHost::OnConnectionClosed(ConnectionToClient* connection) { |
| 166 DCHECK_EQ(context_->network_message_loop(), MessageLoop::current()); | 167 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| 167 | 168 |
| 168 VLOG(1) << "Connection to client closed."; | 169 VLOG(1) << "Connection to client closed."; |
| 169 context_->main_message_loop()->PostTask( | 170 context_->main_message_loop()->PostTask( |
| 170 FROM_HERE, base::Bind(&ChromotingHost::OnClientDisconnected, this, | 171 FROM_HERE, base::Bind(&ChromotingHost::OnClientDisconnected, this, |
| 171 make_scoped_refptr(connection))); | 172 make_scoped_refptr(connection))); |
| 172 } | 173 } |
| 173 | 174 |
| 174 void ChromotingHost::OnConnectionFailed(ConnectionToClient* connection) { | 175 void ChromotingHost::OnConnectionFailed(ConnectionToClient* connection) { |
| 175 DCHECK_EQ(context_->network_message_loop(), MessageLoop::current()); | 176 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| 176 | 177 |
| 177 LOG(ERROR) << "Connection failed unexpectedly."; | 178 LOG(ERROR) << "Connection failed unexpectedly."; |
| 178 context_->main_message_loop()->PostTask( | 179 context_->main_message_loop()->PostTask( |
| 179 FROM_HERE, base::Bind(&ChromotingHost::OnClientDisconnected, this, | 180 FROM_HERE, base::Bind(&ChromotingHost::OnClientDisconnected, this, |
| 180 make_scoped_refptr(connection))); | 181 make_scoped_refptr(connection))); |
| 181 } | 182 } |
| 182 | 183 |
| 183 void ChromotingHost::OnSequenceNumberUpdated(ConnectionToClient* connection, | 184 void ChromotingHost::OnSequenceNumberUpdated(ConnectionToClient* connection, |
| 184 int64 sequence_number) { | 185 int64 sequence_number) { |
| 185 // Update the sequence number in ScreenRecorder. | 186 // Update the sequence number in ScreenRecorder. |
| 186 if (MessageLoop::current() != context_->main_message_loop()) { | 187 if (MessageLoop::current() != context_->main_message_loop()) { |
| 187 context_->main_message_loop()->PostTask( | 188 context_->main_message_loop()->PostTask( |
| 188 FROM_HERE, base::Bind(&ChromotingHost::OnSequenceNumberUpdated, this, | 189 FROM_HERE, base::Bind(&ChromotingHost::OnSequenceNumberUpdated, this, |
| 189 make_scoped_refptr(connection), sequence_number)); | 190 make_scoped_refptr(connection), sequence_number)); |
| 190 return; | 191 return; |
| 191 } | 192 } |
| 192 | 193 |
| 193 if (recorder_.get()) | 194 if (recorder_.get()) |
| 194 recorder_->UpdateSequenceNumber(sequence_number); | 195 recorder_->UpdateSequenceNumber(sequence_number); |
| 195 } | 196 } |
| 196 | 197 |
| 197 //////////////////////////////////////////////////////////////////////////// | 198 //////////////////////////////////////////////////////////////////////////// |
| 198 // SignalStrategy::StatusObserver implementations | 199 // SignalStrategy::StatusObserver implementations |
| 199 void ChromotingHost::OnStateChange( | 200 void ChromotingHost::OnStateChange( |
| 200 SignalStrategy::StatusObserver::State state) { | 201 SignalStrategy::StatusObserver::State state) { |
| 201 DCHECK_EQ(MessageLoop::current(), context_->network_message_loop()); | 202 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| 202 | 203 |
| 203 if (state == SignalStrategy::StatusObserver::CONNECTED) { | 204 if (state == SignalStrategy::StatusObserver::CONNECTED) { |
| 204 LOG(INFO) << "Host connected as " << local_jid_; | 205 LOG(INFO) << "Host connected as " << local_jid_; |
| 205 | 206 |
| 206 // Create and start session manager. | 207 // Create and start session manager. |
| 207 protocol::JingleSessionManager* server = | 208 protocol::JingleSessionManager* server = |
| 208 protocol::JingleSessionManager::CreateNotSandboxed(); | 209 protocol::JingleSessionManager::CreateNotSandboxed( |
| 210 context_->network_message_loop()); |
| 209 // TODO(ajwong): Make this a command switch when we're more stable. | 211 // TODO(ajwong): Make this a command switch when we're more stable. |
| 210 server->set_allow_local_ips(true); | 212 server->set_allow_local_ips(true); |
| 211 | 213 |
| 212 // Assign key and certificate to server. | 214 // Assign key and certificate to server. |
| 213 HostKeyPair key_pair; | 215 HostKeyPair key_pair; |
| 214 CHECK(key_pair.Load(config_)) | 216 CHECK(key_pair.Load(config_)) |
| 215 << "Failed to load server authentication data"; | 217 << "Failed to load server authentication data"; |
| 216 | 218 |
| 217 server->Init(local_jid_, signal_strategy_.get(), this, | 219 server->Init(local_jid_, signal_strategy_.get(), this, |
| 218 key_pair.CopyPrivateKey(), key_pair.GenerateCertificate(), | 220 key_pair.CopyPrivateKey(), key_pair.GenerateCertificate(), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 231 (*it)->OnSignallingDisconnected(); | 233 (*it)->OnSignallingDisconnected(); |
| 232 } | 234 } |
| 233 // TODO(sergeyu): Don't shutdown the host and let the upper level | 235 // TODO(sergeyu): Don't shutdown the host and let the upper level |
| 234 // decide what needs to be done when signalling channel is | 236 // decide what needs to be done when signalling channel is |
| 235 // disconnected. | 237 // disconnected. |
| 236 Shutdown(NULL); | 238 Shutdown(NULL); |
| 237 } | 239 } |
| 238 } | 240 } |
| 239 | 241 |
| 240 void ChromotingHost::OnJidChange(const std::string& full_jid) { | 242 void ChromotingHost::OnJidChange(const std::string& full_jid) { |
| 241 DCHECK_EQ(MessageLoop::current(), context_->network_message_loop()); | 243 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| 242 local_jid_ = full_jid; | 244 local_jid_ = full_jid; |
| 243 } | 245 } |
| 244 | 246 |
| 245 void ChromotingHost::OnSessionManagerInitialized() { | 247 void ChromotingHost::OnSessionManagerInitialized() { |
| 246 DCHECK_EQ(MessageLoop::current(), context_->network_message_loop()); | 248 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| 247 // Don't need to do anything here, just wait for incoming | 249 // Don't need to do anything here, just wait for incoming |
| 248 // connections. | 250 // connections. |
| 249 } | 251 } |
| 250 | 252 |
| 251 void ChromotingHost::OnIncomingSession( | 253 void ChromotingHost::OnIncomingSession( |
| 252 protocol::Session* session, | 254 protocol::Session* session, |
| 253 protocol::SessionManager::IncomingSessionResponse* response) { | 255 protocol::SessionManager::IncomingSessionResponse* response) { |
| 254 DCHECK_EQ(MessageLoop::current(), context_->network_message_loop()); | 256 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| 255 | 257 |
| 256 base::AutoLock auto_lock(lock_); | 258 base::AutoLock auto_lock(lock_); |
| 257 if (state_ != kStarted) { | 259 if (state_ != kStarted) { |
| 258 *response = protocol::SessionManager::DECLINE; | 260 *response = protocol::SessionManager::DECLINE; |
| 259 return; | 261 return; |
| 260 } | 262 } |
| 261 | 263 |
| 262 // If we are running Me2Mom and already have an authenticated client then | 264 // If we are running Me2Mom and already have an authenticated client then |
| 263 // reject the connection immediately. | 265 // reject the connection immediately. |
| 264 if (is_it2me_ && AuthenticatedClientsCount() > 0) { | 266 if (is_it2me_ && AuthenticatedClientsCount() > 0) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 } | 326 } |
| 325 | 327 |
| 326 void ChromotingHost::set_protocol_config( | 328 void ChromotingHost::set_protocol_config( |
| 327 protocol::CandidateSessionConfig* config) { | 329 protocol::CandidateSessionConfig* config) { |
| 328 DCHECK(config_.get()); | 330 DCHECK(config_.get()); |
| 329 DCHECK_EQ(state_, kInitial); | 331 DCHECK_EQ(state_, kInitial); |
| 330 protocol_config_.reset(config); | 332 protocol_config_.reset(config); |
| 331 } | 333 } |
| 332 | 334 |
| 333 void ChromotingHost::LocalMouseMoved(const gfx::Point& new_pos) { | 335 void ChromotingHost::LocalMouseMoved(const gfx::Point& new_pos) { |
| 334 if (MessageLoop::current() != context_->network_message_loop()) { | 336 if (!context_->network_message_loop()->BelongsToCurrentThread()) { |
| 335 context_->network_message_loop()->PostTask( | 337 context_->network_message_loop()->PostTask( |
| 336 FROM_HERE, base::Bind(&ChromotingHost::LocalMouseMoved, this, new_pos)); | 338 FROM_HERE, base::Bind(&ChromotingHost::LocalMouseMoved, this, new_pos)); |
| 337 return; | 339 return; |
| 338 } | 340 } |
| 339 ClientList::iterator client; | 341 ClientList::iterator client; |
| 340 for (client = clients_.begin(); client != clients_.end(); ++client) { | 342 for (client = clients_.begin(); client != clients_.end(); ++client) { |
| 341 client->get()->LocalMouseMoved(new_pos); | 343 client->get()->LocalMouseMoved(new_pos); |
| 342 } | 344 } |
| 343 } | 345 } |
| 344 | 346 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 ClientList::iterator client; | 538 ClientList::iterator client; |
| 537 for (client = clients_.begin(); client != clients_.end(); ++client) { | 539 for (client = clients_.begin(); client != clients_.end(); ++client) { |
| 538 if (client->get()->connection() == connection) | 540 if (client->get()->connection() == connection) |
| 539 break; | 541 break; |
| 540 } | 542 } |
| 541 CHECK(client != clients_.end()); | 543 CHECK(client != clients_.end()); |
| 542 client->get()->OnAuthorizationComplete(true); | 544 client->get()->OnAuthorizationComplete(true); |
| 543 } | 545 } |
| 544 | 546 |
| 545 void ChromotingHost::ShutdownNetwork() { | 547 void ChromotingHost::ShutdownNetwork() { |
| 546 if (MessageLoop::current() != context_->network_message_loop()) { | 548 if (!context_->network_message_loop()->BelongsToCurrentThread()) { |
| 547 context_->network_message_loop()->PostTask( | 549 context_->network_message_loop()->PostTask( |
| 548 FROM_HERE, base::Bind(&ChromotingHost::ShutdownNetwork, this)); | 550 FROM_HERE, base::Bind(&ChromotingHost::ShutdownNetwork, this)); |
| 549 return; | 551 return; |
| 550 } | 552 } |
| 551 | 553 |
| 552 // Stop chromotocol session manager. | 554 // Stop chromotocol session manager. |
| 553 if (session_manager_.get()) { | 555 if (session_manager_.get()) { |
| 554 session_manager_->Close(); | 556 session_manager_->Close(); |
| 555 session_manager_.reset(); | 557 session_manager_.reset(); |
| 556 } | 558 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 | 605 |
| 604 for (std::vector<Task*>::iterator it = shutdown_tasks_.begin(); | 606 for (std::vector<Task*>::iterator it = shutdown_tasks_.begin(); |
| 605 it != shutdown_tasks_.end(); ++it) { | 607 it != shutdown_tasks_.end(); ++it) { |
| 606 (*it)->Run(); | 608 (*it)->Run(); |
| 607 delete *it; | 609 delete *it; |
| 608 } | 610 } |
| 609 shutdown_tasks_.clear(); | 611 shutdown_tasks_.clear(); |
| 610 } | 612 } |
| 611 | 613 |
| 612 } // namespace remoting | 614 } // namespace remoting |
| OLD | NEW |