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> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 13 #include "base/memory/ptr_util.h" |
13 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
14 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
15 #include "net/socket/client_socket_factory.h" | 16 #include "net/socket/client_socket_factory.h" |
16 #include "net/url_request/url_request_context_getter.h" | 17 #include "net/url_request/url_request_context_getter.h" |
17 #include "policy/policy_constants.h" | 18 #include "policy/policy_constants.h" |
18 #include "remoting/base/auto_thread.h" | 19 #include "remoting/base/auto_thread.h" |
19 #include "remoting/base/chromium_url_request.h" | 20 #include "remoting/base/chromium_url_request.h" |
20 #include "remoting/base/logging.h" | 21 #include "remoting/base/logging.h" |
21 #include "remoting/base/rsa_key_pair.h" | 22 #include "remoting/base/rsa_key_pair.h" |
22 #include "remoting/host/chromoting_host.h" | 23 #include "remoting/host/chromoting_host.h" |
(...skipping 19 matching lines...) Expand all Loading... |
42 | 43 |
43 namespace { | 44 namespace { |
44 | 45 |
45 // This is used for tagging system event logs. | 46 // This is used for tagging system event logs. |
46 const char kApplicationName[] = "chromoting"; | 47 const char kApplicationName[] = "chromoting"; |
47 const int kMaxLoginAttempts = 5; | 48 const int kMaxLoginAttempts = 5; |
48 | 49 |
49 } // namespace | 50 } // namespace |
50 | 51 |
51 It2MeHost::It2MeHost( | 52 It2MeHost::It2MeHost( |
52 scoped_ptr<ChromotingHostContext> host_context, | 53 std::unique_ptr<ChromotingHostContext> host_context, |
53 scoped_ptr<PolicyWatcher> policy_watcher, | 54 std::unique_ptr<PolicyWatcher> policy_watcher, |
54 scoped_ptr<It2MeConfirmationDialogFactory> confirmation_dialog_factory, | 55 std::unique_ptr<It2MeConfirmationDialogFactory> confirmation_dialog_factory, |
55 base::WeakPtr<It2MeHost::Observer> observer, | 56 base::WeakPtr<It2MeHost::Observer> observer, |
56 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | 57 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, |
57 const std::string& directory_bot_jid) | 58 const std::string& directory_bot_jid) |
58 : host_context_(std::move(host_context)), | 59 : host_context_(std::move(host_context)), |
59 task_runner_(host_context_->ui_task_runner()), | 60 task_runner_(host_context_->ui_task_runner()), |
60 observer_(observer), | 61 observer_(observer), |
61 xmpp_server_config_(xmpp_server_config), | 62 xmpp_server_config_(xmpp_server_config), |
62 directory_bot_jid_(directory_bot_jid), | 63 directory_bot_jid_(directory_bot_jid), |
63 state_(kDisconnected), | 64 state_(kDisconnected), |
64 failed_login_attempts_(0), | 65 failed_login_attempts_(0), |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 133 |
133 if (policy_received_) | 134 if (policy_received_) |
134 UpdateNatPolicy(nat_traversal_enabled_); | 135 UpdateNatPolicy(nat_traversal_enabled_); |
135 } | 136 } |
136 | 137 |
137 void It2MeHost::ShowConfirmationPrompt() { | 138 void It2MeHost::ShowConfirmationPrompt() { |
138 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 139 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
139 | 140 |
140 SetState(kStarting, ""); | 141 SetState(kStarting, ""); |
141 | 142 |
142 scoped_ptr<It2MeConfirmationDialog> confirmation_dialog = | 143 std::unique_ptr<It2MeConfirmationDialog> confirmation_dialog = |
143 confirmation_dialog_factory_->Create(); | 144 confirmation_dialog_factory_->Create(); |
144 | 145 |
145 // TODO(dcaiafa): Remove after dialog implementations for all platforms exist. | 146 // TODO(dcaiafa): Remove after dialog implementations for all platforms exist. |
146 if (!confirmation_dialog) { | 147 if (!confirmation_dialog) { |
147 ReadPolicyAndConnect(); | 148 ReadPolicyAndConnect(); |
148 return; | 149 return; |
149 } | 150 } |
150 | 151 |
151 confirmation_dialog_proxy_.reset( | 152 confirmation_dialog_proxy_.reset( |
152 new It2MeConfirmationDialogProxy(host_context_->ui_task_runner(), | 153 new It2MeConfirmationDialogProxy(host_context_->ui_task_runner(), |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 base::CompareCase::INSENSITIVE_ASCII)) { | 203 base::CompareCase::INSENSITIVE_ASCII)) { |
203 SetState(kInvalidDomainError, ""); | 204 SetState(kInvalidDomainError, ""); |
204 return; | 205 return; |
205 } | 206 } |
206 | 207 |
207 // Generate a key pair for the Host to use. | 208 // Generate a key pair for the Host to use. |
208 // TODO(wez): Move this to the worker thread. | 209 // TODO(wez): Move this to the worker thread. |
209 host_key_pair_ = RsaKeyPair::Generate(); | 210 host_key_pair_ = RsaKeyPair::Generate(); |
210 | 211 |
211 // Create XMPP connection. | 212 // Create XMPP connection. |
212 scoped_ptr<SignalStrategy> signal_strategy( | 213 std::unique_ptr<SignalStrategy> signal_strategy(new XmppSignalStrategy( |
213 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), | 214 net::ClientSocketFactory::GetDefaultFactory(), |
214 host_context_->url_request_context_getter(), | 215 host_context_->url_request_context_getter(), xmpp_server_config_)); |
215 xmpp_server_config_)); | |
216 | 216 |
217 // Request registration of the host for support. | 217 // Request registration of the host for support. |
218 scoped_ptr<RegisterSupportHostRequest> register_request( | 218 std::unique_ptr<RegisterSupportHostRequest> register_request( |
219 new RegisterSupportHostRequest( | 219 new RegisterSupportHostRequest( |
220 signal_strategy.get(), host_key_pair_, directory_bot_jid_, | 220 signal_strategy.get(), host_key_pair_, directory_bot_jid_, |
221 base::Bind(&It2MeHost::OnReceivedSupportID, | 221 base::Bind(&It2MeHost::OnReceivedSupportID, base::Unretained(this)))); |
222 base::Unretained(this)))); | |
223 | 222 |
224 // Beyond this point nothing can fail, so save the config and request. | 223 // Beyond this point nothing can fail, so save the config and request. |
225 signal_strategy_ = std::move(signal_strategy); | 224 signal_strategy_ = std::move(signal_strategy); |
226 register_request_ = std::move(register_request); | 225 register_request_ = std::move(register_request); |
227 | 226 |
228 // If NAT traversal is off then limit port range to allow firewall pin-holing. | 227 // If NAT traversal is off then limit port range to allow firewall pin-holing. |
229 HOST_LOG << "NAT state: " << nat_traversal_enabled_; | 228 HOST_LOG << "NAT state: " << nat_traversal_enabled_; |
230 protocol::NetworkSettings network_settings( | 229 protocol::NetworkSettings network_settings( |
231 nat_traversal_enabled_ ? | 230 nat_traversal_enabled_ ? |
232 protocol::NetworkSettings::NAT_TRAVERSAL_FULL : | 231 protocol::NetworkSettings::NAT_TRAVERSAL_FULL : |
233 protocol::NetworkSettings::NAT_TRAVERSAL_DISABLED); | 232 protocol::NetworkSettings::NAT_TRAVERSAL_DISABLED); |
234 if (!nat_traversal_enabled_) { | 233 if (!nat_traversal_enabled_) { |
235 network_settings.port_range.min_port = | 234 network_settings.port_range.min_port = |
236 protocol::NetworkSettings::kDefaultMinPort; | 235 protocol::NetworkSettings::kDefaultMinPort; |
237 network_settings.port_range.max_port = | 236 network_settings.port_range.max_port = |
238 protocol::NetworkSettings::kDefaultMaxPort; | 237 protocol::NetworkSettings::kDefaultMaxPort; |
239 } | 238 } |
240 | 239 |
241 scoped_refptr<protocol::TransportContext> transport_context = | 240 scoped_refptr<protocol::TransportContext> transport_context = |
242 new protocol::TransportContext( | 241 new protocol::TransportContext( |
243 signal_strategy_.get(), | 242 signal_strategy_.get(), |
244 make_scoped_ptr(new protocol::ChromiumPortAllocatorFactory()), | 243 base::WrapUnique(new protocol::ChromiumPortAllocatorFactory()), |
245 make_scoped_ptr(new ChromiumUrlRequestFactory( | 244 base::WrapUnique(new ChromiumUrlRequestFactory( |
246 host_context_->url_request_context_getter())), | 245 host_context_->url_request_context_getter())), |
247 network_settings, protocol::TransportRole::SERVER); | 246 network_settings, protocol::TransportRole::SERVER); |
248 transport_context->set_ice_config_url( | 247 transport_context->set_ice_config_url( |
249 ServiceUrls::GetInstance()->ice_config_url()); | 248 ServiceUrls::GetInstance()->ice_config_url()); |
250 | 249 |
251 scoped_ptr<protocol::SessionManager> session_manager( | 250 std::unique_ptr<protocol::SessionManager> session_manager( |
252 new protocol::JingleSessionManager(signal_strategy_.get())); | 251 new protocol::JingleSessionManager(signal_strategy_.get())); |
253 | 252 |
254 scoped_ptr<protocol::CandidateSessionConfig> protocol_config = | 253 std::unique_ptr<protocol::CandidateSessionConfig> protocol_config = |
255 protocol::CandidateSessionConfig::CreateDefault(); | 254 protocol::CandidateSessionConfig::CreateDefault(); |
256 // Disable audio by default. | 255 // Disable audio by default. |
257 // TODO(sergeyu): Add UI to enable it. | 256 // TODO(sergeyu): Add UI to enable it. |
258 protocol_config->DisableAudioChannel(); | 257 protocol_config->DisableAudioChannel(); |
259 session_manager->set_protocol_config(std::move(protocol_config)); | 258 session_manager->set_protocol_config(std::move(protocol_config)); |
260 | 259 |
261 // Create the host. | 260 // Create the host. |
262 host_.reset(new ChromotingHost(desktop_environment_factory_.get(), | 261 host_.reset(new ChromotingHost(desktop_environment_factory_.get(), |
263 std::move(session_manager), transport_context, | 262 std::move(session_manager), transport_context, |
264 host_context_->audio_task_runner(), | 263 host_context_->audio_task_runner(), |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 | 309 |
311 SetState(kConnected, ""); | 310 SetState(kConnected, ""); |
312 } | 311 } |
313 | 312 |
314 void It2MeHost::OnClientDisconnected(const std::string& jid) { | 313 void It2MeHost::OnClientDisconnected(const std::string& jid) { |
315 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 314 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
316 | 315 |
317 Shutdown(); | 316 Shutdown(); |
318 } | 317 } |
319 | 318 |
320 void It2MeHost::OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) { | 319 void It2MeHost::OnPolicyUpdate( |
| 320 std::unique_ptr<base::DictionaryValue> policies) { |
321 // The policy watcher runs on the |ui_task_runner|. | 321 // The policy watcher runs on the |ui_task_runner|. |
322 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { | 322 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { |
323 host_context_->network_task_runner()->PostTask( | 323 host_context_->network_task_runner()->PostTask( |
324 FROM_HERE, | 324 FROM_HERE, |
325 base::Bind(&It2MeHost::OnPolicyUpdate, this, base::Passed(&policies))); | 325 base::Bind(&It2MeHost::OnPolicyUpdate, this, base::Passed(&policies))); |
326 return; | 326 return; |
327 } | 327 } |
328 | 328 |
329 bool nat_policy; | 329 bool nat_policy; |
330 if (policies->GetBoolean(policy::key::kRemoteAccessHostFirewallTraversal, | 330 if (policies->GetBoolean(policy::key::kRemoteAccessHostFirewallTraversal, |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 | 473 |
474 std::string local_certificate = host_key_pair_->GenerateCertificate(); | 474 std::string local_certificate = host_key_pair_->GenerateCertificate(); |
475 if (local_certificate.empty()) { | 475 if (local_certificate.empty()) { |
476 std::string error_message = "Failed to generate host certificate."; | 476 std::string error_message = "Failed to generate host certificate."; |
477 LOG(ERROR) << error_message; | 477 LOG(ERROR) << error_message; |
478 SetState(kError, error_message); | 478 SetState(kError, error_message); |
479 Shutdown(); | 479 Shutdown(); |
480 return; | 480 return; |
481 } | 481 } |
482 | 482 |
483 scoped_ptr<protocol::AuthenticatorFactory> factory( | 483 std::unique_ptr<protocol::AuthenticatorFactory> factory( |
484 new protocol::It2MeHostAuthenticatorFactory( | 484 new protocol::It2MeHostAuthenticatorFactory( |
485 local_certificate, host_key_pair_, access_code_hash, | 485 local_certificate, host_key_pair_, access_code_hash, |
486 required_client_domain_)); | 486 required_client_domain_)); |
487 host_->SetAuthenticatorFactory(std::move(factory)); | 487 host_->SetAuthenticatorFactory(std::move(factory)); |
488 | 488 |
489 // Pass the Access Code to the script object before changing state. | 489 // Pass the Access Code to the script object before changing state. |
490 task_runner_->PostTask( | 490 task_runner_->PostTask( |
491 FROM_HERE, base::Bind(&It2MeHost::Observer::OnStoreAccessCode, | 491 FROM_HERE, base::Bind(&It2MeHost::Observer::OnStoreAccessCode, |
492 observer_, access_code, lifetime)); | 492 observer_, access_code, lifetime)); |
493 | 493 |
494 SetState(kReceivedAccessCode, ""); | 494 SetState(kReceivedAccessCode, ""); |
495 } | 495 } |
496 | 496 |
497 It2MeHostFactory::It2MeHostFactory() : policy_service_(nullptr) { | 497 It2MeHostFactory::It2MeHostFactory() : policy_service_(nullptr) { |
498 } | 498 } |
499 | 499 |
500 It2MeHostFactory::~It2MeHostFactory() {} | 500 It2MeHostFactory::~It2MeHostFactory() {} |
501 | 501 |
502 void It2MeHostFactory::set_policy_service( | 502 void It2MeHostFactory::set_policy_service( |
503 policy::PolicyService* policy_service) { | 503 policy::PolicyService* policy_service) { |
504 DCHECK(policy_service); | 504 DCHECK(policy_service); |
505 DCHECK(!policy_service_) << "|policy_service| can only be set once."; | 505 DCHECK(!policy_service_) << "|policy_service| can only be set once."; |
506 policy_service_ = policy_service; | 506 policy_service_ = policy_service; |
507 } | 507 } |
508 | 508 |
509 scoped_refptr<It2MeHost> It2MeHostFactory::CreateIt2MeHost( | 509 scoped_refptr<It2MeHost> It2MeHostFactory::CreateIt2MeHost( |
510 scoped_ptr<ChromotingHostContext> context, | 510 std::unique_ptr<ChromotingHostContext> context, |
511 base::WeakPtr<It2MeHost::Observer> observer, | 511 base::WeakPtr<It2MeHost::Observer> observer, |
512 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | 512 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, |
513 const std::string& directory_bot_jid) { | 513 const std::string& directory_bot_jid) { |
514 DCHECK(context->ui_task_runner()->BelongsToCurrentThread()); | 514 DCHECK(context->ui_task_runner()->BelongsToCurrentThread()); |
515 | 515 |
516 scoped_ptr<It2MeConfirmationDialogFactory> confirmation_dialog_factory( | 516 std::unique_ptr<It2MeConfirmationDialogFactory> confirmation_dialog_factory( |
517 new It2MeConfirmationDialogFactory()); | 517 new It2MeConfirmationDialogFactory()); |
518 scoped_ptr<PolicyWatcher> policy_watcher = | 518 std::unique_ptr<PolicyWatcher> policy_watcher = |
519 PolicyWatcher::Create(policy_service_, context->file_task_runner()); | 519 PolicyWatcher::Create(policy_service_, context->file_task_runner()); |
520 return new It2MeHost(std::move(context), std::move(policy_watcher), | 520 return new It2MeHost(std::move(context), std::move(policy_watcher), |
521 std::move(confirmation_dialog_factory), observer, | 521 std::move(confirmation_dialog_factory), observer, |
522 xmpp_server_config, directory_bot_jid); | 522 xmpp_server_config, directory_bot_jid); |
523 } | 523 } |
524 | 524 |
525 } // namespace remoting | 525 } // namespace remoting |
OLD | NEW |