| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/it2me/it2me_host.h" | 5 #include "remoting/host/it2me/it2me_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> |
| 10 |
| 9 #include "base/bind.h" | 11 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 11 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 12 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
| 13 #include "net/socket/client_socket_factory.h" | 15 #include "net/socket/client_socket_factory.h" |
| 14 #include "net/url_request/url_request_context_getter.h" | 16 #include "net/url_request/url_request_context_getter.h" |
| 15 #include "policy/policy_constants.h" | 17 #include "policy/policy_constants.h" |
| 16 #include "remoting/base/auto_thread.h" | 18 #include "remoting/base/auto_thread.h" |
| 17 #include "remoting/base/logging.h" | 19 #include "remoting/base/logging.h" |
| 18 #include "remoting/base/rsa_key_pair.h" | 20 #include "remoting/base/rsa_key_pair.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 43 | 45 |
| 44 } // namespace | 46 } // namespace |
| 45 | 47 |
| 46 It2MeHost::It2MeHost( | 48 It2MeHost::It2MeHost( |
| 47 scoped_ptr<ChromotingHostContext> host_context, | 49 scoped_ptr<ChromotingHostContext> host_context, |
| 48 scoped_ptr<PolicyWatcher> policy_watcher, | 50 scoped_ptr<PolicyWatcher> policy_watcher, |
| 49 scoped_ptr<It2MeConfirmationDialogFactory> confirmation_dialog_factory, | 51 scoped_ptr<It2MeConfirmationDialogFactory> confirmation_dialog_factory, |
| 50 base::WeakPtr<It2MeHost::Observer> observer, | 52 base::WeakPtr<It2MeHost::Observer> observer, |
| 51 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | 53 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, |
| 52 const std::string& directory_bot_jid) | 54 const std::string& directory_bot_jid) |
| 53 : host_context_(host_context.Pass()), | 55 : host_context_(std::move(host_context)), |
| 54 task_runner_(host_context_->ui_task_runner()), | 56 task_runner_(host_context_->ui_task_runner()), |
| 55 observer_(observer), | 57 observer_(observer), |
| 56 xmpp_server_config_(xmpp_server_config), | 58 xmpp_server_config_(xmpp_server_config), |
| 57 directory_bot_jid_(directory_bot_jid), | 59 directory_bot_jid_(directory_bot_jid), |
| 58 state_(kDisconnected), | 60 state_(kDisconnected), |
| 59 failed_login_attempts_(0), | 61 failed_login_attempts_(0), |
| 60 policy_watcher_(policy_watcher.Pass()), | 62 policy_watcher_(std::move(policy_watcher)), |
| 61 confirmation_dialog_factory_(confirmation_dialog_factory.Pass()), | 63 confirmation_dialog_factory_(std::move(confirmation_dialog_factory)), |
| 62 nat_traversal_enabled_(false), | 64 nat_traversal_enabled_(false), |
| 63 policy_received_(false) { | 65 policy_received_(false) { |
| 64 DCHECK(task_runner_->BelongsToCurrentThread()); | 66 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 65 } | 67 } |
| 66 | 68 |
| 67 void It2MeHost::Connect() { | 69 void It2MeHost::Connect() { |
| 68 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) { | 70 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) { |
| 69 DCHECK(task_runner_->BelongsToCurrentThread()); | 71 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 70 host_context_->ui_task_runner()->PostTask( | 72 host_context_->ui_task_runner()->PostTask( |
| 71 FROM_HERE, base::Bind(&It2MeHost::Connect, this)); | 73 FROM_HERE, base::Bind(&It2MeHost::Connect, this)); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 confirmation_dialog_factory_->Create(); | 140 confirmation_dialog_factory_->Create(); |
| 139 | 141 |
| 140 // TODO(dcaiafa): Remove after dialog implementations for all platforms exist. | 142 // TODO(dcaiafa): Remove after dialog implementations for all platforms exist. |
| 141 if (!confirmation_dialog) { | 143 if (!confirmation_dialog) { |
| 142 ReadPolicyAndConnect(); | 144 ReadPolicyAndConnect(); |
| 143 return; | 145 return; |
| 144 } | 146 } |
| 145 | 147 |
| 146 confirmation_dialog_proxy_.reset( | 148 confirmation_dialog_proxy_.reset( |
| 147 new It2MeConfirmationDialogProxy(host_context_->ui_task_runner(), | 149 new It2MeConfirmationDialogProxy(host_context_->ui_task_runner(), |
| 148 confirmation_dialog.Pass())); | 150 std::move(confirmation_dialog))); |
| 149 | 151 |
| 150 confirmation_dialog_proxy_->Show( | 152 confirmation_dialog_proxy_->Show( |
| 151 base::Bind(&It2MeHost::OnConfirmationResult, base::Unretained(this))); | 153 base::Bind(&It2MeHost::OnConfirmationResult, base::Unretained(this))); |
| 152 } | 154 } |
| 153 | 155 |
| 154 void It2MeHost::OnConfirmationResult(It2MeConfirmationDialog::Result result) { | 156 void It2MeHost::OnConfirmationResult(It2MeConfirmationDialog::Result result) { |
| 155 switch (result) { | 157 switch (result) { |
| 156 case It2MeConfirmationDialog::Result::OK: | 158 case It2MeConfirmationDialog::Result::OK: |
| 157 ReadPolicyAndConnect(); | 159 ReadPolicyAndConnect(); |
| 158 break; | 160 break; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 xmpp_server_config_)); | 212 xmpp_server_config_)); |
| 211 | 213 |
| 212 // Request registration of the host for support. | 214 // Request registration of the host for support. |
| 213 scoped_ptr<RegisterSupportHostRequest> register_request( | 215 scoped_ptr<RegisterSupportHostRequest> register_request( |
| 214 new RegisterSupportHostRequest( | 216 new RegisterSupportHostRequest( |
| 215 signal_strategy.get(), host_key_pair_, directory_bot_jid_, | 217 signal_strategy.get(), host_key_pair_, directory_bot_jid_, |
| 216 base::Bind(&It2MeHost::OnReceivedSupportID, | 218 base::Bind(&It2MeHost::OnReceivedSupportID, |
| 217 base::Unretained(this)))); | 219 base::Unretained(this)))); |
| 218 | 220 |
| 219 // Beyond this point nothing can fail, so save the config and request. | 221 // Beyond this point nothing can fail, so save the config and request. |
| 220 signal_strategy_ = signal_strategy.Pass(); | 222 signal_strategy_ = std::move(signal_strategy); |
| 221 register_request_ = register_request.Pass(); | 223 register_request_ = std::move(register_request); |
| 222 | 224 |
| 223 // If NAT traversal is off then limit port range to allow firewall pin-holing. | 225 // If NAT traversal is off then limit port range to allow firewall pin-holing. |
| 224 HOST_LOG << "NAT state: " << nat_traversal_enabled_; | 226 HOST_LOG << "NAT state: " << nat_traversal_enabled_; |
| 225 protocol::NetworkSettings network_settings( | 227 protocol::NetworkSettings network_settings( |
| 226 nat_traversal_enabled_ ? | 228 nat_traversal_enabled_ ? |
| 227 protocol::NetworkSettings::NAT_TRAVERSAL_FULL : | 229 protocol::NetworkSettings::NAT_TRAVERSAL_FULL : |
| 228 protocol::NetworkSettings::NAT_TRAVERSAL_DISABLED); | 230 protocol::NetworkSettings::NAT_TRAVERSAL_DISABLED); |
| 229 if (!nat_traversal_enabled_) { | 231 if (!nat_traversal_enabled_) { |
| 230 network_settings.port_range.min_port = | 232 network_settings.port_range.min_port = |
| 231 protocol::NetworkSettings::kDefaultMinPort; | 233 protocol::NetworkSettings::kDefaultMinPort; |
| 232 network_settings.port_range.max_port = | 234 network_settings.port_range.max_port = |
| 233 protocol::NetworkSettings::kDefaultMaxPort; | 235 protocol::NetworkSettings::kDefaultMaxPort; |
| 234 } | 236 } |
| 235 | 237 |
| 236 scoped_ptr<protocol::TransportFactory> transport_factory( | 238 scoped_ptr<protocol::TransportFactory> transport_factory( |
| 237 new protocol::IceTransportFactory(new protocol::TransportContext( | 239 new protocol::IceTransportFactory(new protocol::TransportContext( |
| 238 signal_strategy_.get(), | 240 signal_strategy_.get(), |
| 239 make_scoped_ptr(new protocol::ChromiumPortAllocatorFactory( | 241 make_scoped_ptr(new protocol::ChromiumPortAllocatorFactory( |
| 240 host_context_->url_request_context_getter())), | 242 host_context_->url_request_context_getter())), |
| 241 network_settings, protocol::TransportRole::SERVER))); | 243 network_settings, protocol::TransportRole::SERVER))); |
| 242 | 244 |
| 243 scoped_ptr<protocol::SessionManager> session_manager( | 245 scoped_ptr<protocol::SessionManager> session_manager( |
| 244 new protocol::JingleSessionManager(transport_factory.Pass(), | 246 new protocol::JingleSessionManager(std::move(transport_factory), |
| 245 signal_strategy.get())); | 247 signal_strategy.get())); |
| 246 | 248 |
| 247 scoped_ptr<protocol::CandidateSessionConfig> protocol_config = | 249 scoped_ptr<protocol::CandidateSessionConfig> protocol_config = |
| 248 protocol::CandidateSessionConfig::CreateDefault(); | 250 protocol::CandidateSessionConfig::CreateDefault(); |
| 249 // Disable audio by default. | 251 // Disable audio by default. |
| 250 // TODO(sergeyu): Add UI to enable it. | 252 // TODO(sergeyu): Add UI to enable it. |
| 251 protocol_config->DisableAudioChannel(); | 253 protocol_config->DisableAudioChannel(); |
| 252 session_manager->set_protocol_config(protocol_config.Pass()); | 254 session_manager->set_protocol_config(std::move(protocol_config)); |
| 253 | 255 |
| 254 // Create the host. | 256 // Create the host. |
| 255 host_.reset(new ChromotingHost( | 257 host_.reset(new ChromotingHost( |
| 256 desktop_environment_factory_.get(), | 258 desktop_environment_factory_.get(), std::move(session_manager), |
| 257 session_manager.Pass(), host_context_->audio_task_runner(), | 259 host_context_->audio_task_runner(), host_context_->input_task_runner(), |
| 258 host_context_->input_task_runner(), | |
| 259 host_context_->video_capture_task_runner(), | 260 host_context_->video_capture_task_runner(), |
| 260 host_context_->video_encode_task_runner(), | 261 host_context_->video_encode_task_runner(), |
| 261 host_context_->network_task_runner(), host_context_->ui_task_runner())); | 262 host_context_->network_task_runner(), host_context_->ui_task_runner())); |
| 262 host_->AddStatusObserver(this); | 263 host_->AddStatusObserver(this); |
| 263 host_status_logger_.reset( | 264 host_status_logger_.reset( |
| 264 new HostStatusLogger(host_->AsWeakPtr(), ServerLogEntry::IT2ME, | 265 new HostStatusLogger(host_->AsWeakPtr(), ServerLogEntry::IT2ME, |
| 265 signal_strategy_.get(), directory_bot_jid_)); | 266 signal_strategy_.get(), directory_bot_jid_)); |
| 266 | 267 |
| 267 // Create event logger. | 268 // Create event logger. |
| 268 host_event_logger_ = | 269 host_event_logger_ = |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 std::string error_message = "Failed to generate host certificate."; | 453 std::string error_message = "Failed to generate host certificate."; |
| 453 LOG(ERROR) << error_message; | 454 LOG(ERROR) << error_message; |
| 454 SetState(kError, error_message); | 455 SetState(kError, error_message); |
| 455 Shutdown(); | 456 Shutdown(); |
| 456 return; | 457 return; |
| 457 } | 458 } |
| 458 | 459 |
| 459 scoped_ptr<protocol::AuthenticatorFactory> factory( | 460 scoped_ptr<protocol::AuthenticatorFactory> factory( |
| 460 new protocol::It2MeHostAuthenticatorFactory( | 461 new protocol::It2MeHostAuthenticatorFactory( |
| 461 local_certificate, host_key_pair_, access_code)); | 462 local_certificate, host_key_pair_, access_code)); |
| 462 host_->SetAuthenticatorFactory(factory.Pass()); | 463 host_->SetAuthenticatorFactory(std::move(factory)); |
| 463 | 464 |
| 464 // Pass the Access Code to the script object before changing state. | 465 // Pass the Access Code to the script object before changing state. |
| 465 task_runner_->PostTask( | 466 task_runner_->PostTask( |
| 466 FROM_HERE, base::Bind(&It2MeHost::Observer::OnStoreAccessCode, | 467 FROM_HERE, base::Bind(&It2MeHost::Observer::OnStoreAccessCode, |
| 467 observer_, access_code, lifetime)); | 468 observer_, access_code, lifetime)); |
| 468 | 469 |
| 469 SetState(kReceivedAccessCode, ""); | 470 SetState(kReceivedAccessCode, ""); |
| 470 } | 471 } |
| 471 | 472 |
| 472 It2MeHostFactory::It2MeHostFactory() : policy_service_(nullptr) { | 473 It2MeHostFactory::It2MeHostFactory() : policy_service_(nullptr) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 485 scoped_ptr<ChromotingHostContext> context, | 486 scoped_ptr<ChromotingHostContext> context, |
| 486 base::WeakPtr<It2MeHost::Observer> observer, | 487 base::WeakPtr<It2MeHost::Observer> observer, |
| 487 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | 488 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, |
| 488 const std::string& directory_bot_jid) { | 489 const std::string& directory_bot_jid) { |
| 489 DCHECK(context->ui_task_runner()->BelongsToCurrentThread()); | 490 DCHECK(context->ui_task_runner()->BelongsToCurrentThread()); |
| 490 | 491 |
| 491 scoped_ptr<It2MeConfirmationDialogFactory> confirmation_dialog_factory( | 492 scoped_ptr<It2MeConfirmationDialogFactory> confirmation_dialog_factory( |
| 492 new It2MeConfirmationDialogFactory()); | 493 new It2MeConfirmationDialogFactory()); |
| 493 scoped_ptr<PolicyWatcher> policy_watcher = | 494 scoped_ptr<PolicyWatcher> policy_watcher = |
| 494 PolicyWatcher::Create(policy_service_, context->file_task_runner()); | 495 PolicyWatcher::Create(policy_service_, context->file_task_runner()); |
| 495 return new It2MeHost(context.Pass(), policy_watcher.Pass(), | 496 return new It2MeHost(std::move(context), std::move(policy_watcher), |
| 496 confirmation_dialog_factory.Pass(), | 497 std::move(confirmation_dialog_factory), observer, |
| 497 observer, xmpp_server_config, directory_bot_jid); | 498 xmpp_server_config, directory_bot_jid); |
| 498 } | 499 } |
| 499 | 500 |
| 500 } // namespace remoting | 501 } // namespace remoting |
| OLD | NEW |