| 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 <cstdint> | 7 #include <cstdint> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "remoting/base/logging.h" | 21 #include "remoting/base/logging.h" |
| 22 #include "remoting/base/rsa_key_pair.h" | 22 #include "remoting/base/rsa_key_pair.h" |
| 23 #include "remoting/base/service_urls.h" | 23 #include "remoting/base/service_urls.h" |
| 24 #include "remoting/host/chromoting_host.h" | 24 #include "remoting/host/chromoting_host.h" |
| 25 #include "remoting/host/chromoting_host_context.h" | 25 #include "remoting/host/chromoting_host_context.h" |
| 26 #include "remoting/host/host_event_logger.h" | 26 #include "remoting/host/host_event_logger.h" |
| 27 #include "remoting/host/host_secret.h" | 27 #include "remoting/host/host_secret.h" |
| 28 #include "remoting/host/host_status_logger.h" | 28 #include "remoting/host/host_status_logger.h" |
| 29 #include "remoting/host/it2me/it2me_confirmation_dialog.h" | 29 #include "remoting/host/it2me/it2me_confirmation_dialog.h" |
| 30 #include "remoting/host/it2me_desktop_environment.h" | 30 #include "remoting/host/it2me_desktop_environment.h" |
| 31 #include "remoting/host/policy_watcher.h" | |
| 32 #include "remoting/host/register_support_host_request.h" | 31 #include "remoting/host/register_support_host_request.h" |
| 33 #include "remoting/protocol/auth_util.h" | 32 #include "remoting/protocol/auth_util.h" |
| 34 #include "remoting/protocol/chromium_port_allocator_factory.h" | 33 #include "remoting/protocol/chromium_port_allocator_factory.h" |
| 35 #include "remoting/protocol/ice_transport.h" | 34 #include "remoting/protocol/ice_transport.h" |
| 36 #include "remoting/protocol/it2me_host_authenticator_factory.h" | 35 #include "remoting/protocol/it2me_host_authenticator_factory.h" |
| 37 #include "remoting/protocol/jingle_session_manager.h" | 36 #include "remoting/protocol/jingle_session_manager.h" |
| 38 #include "remoting/protocol/network_settings.h" | 37 #include "remoting/protocol/network_settings.h" |
| 39 #include "remoting/protocol/transport_context.h" | 38 #include "remoting/protocol/transport_context.h" |
| 40 #include "remoting/protocol/validating_authenticator.h" | 39 #include "remoting/protocol/validating_authenticator.h" |
| 41 #include "remoting/signaling/jid_util.h" | 40 #include "remoting/signaling/jid_util.h" |
| 42 #include "remoting/signaling/server_log_entry.h" | 41 #include "remoting/signaling/server_log_entry.h" |
| 43 | 42 |
| 44 namespace remoting { | 43 namespace remoting { |
| 45 | 44 |
| 46 namespace { | 45 namespace { |
| 47 | 46 |
| 48 // This is used for tagging system event logs. | 47 // This is used for tagging system event logs. |
| 49 const char kApplicationName[] = "chromoting"; | 48 const char kApplicationName[] = "chromoting"; |
| 50 const int kMaxLoginAttempts = 5; | 49 const int kMaxLoginAttempts = 5; |
| 51 | 50 |
| 52 using protocol::ValidatingAuthenticator; | 51 using protocol::ValidatingAuthenticator; |
| 53 typedef ValidatingAuthenticator::Result ValidationResult; | 52 typedef ValidatingAuthenticator::Result ValidationResult; |
| 54 typedef ValidatingAuthenticator::ValidationCallback ValidationCallback; | 53 typedef ValidatingAuthenticator::ValidationCallback ValidationCallback; |
| 55 typedef ValidatingAuthenticator::ResultCallback ValidationResultCallback; | 54 typedef ValidatingAuthenticator::ResultCallback ValidationResultCallback; |
| 56 | 55 |
| 57 } // namespace | 56 } // namespace |
| 58 | 57 |
| 59 It2MeHost::It2MeHost( | 58 It2MeHost::It2MeHost( |
| 60 std::unique_ptr<ChromotingHostContext> host_context, | 59 std::unique_ptr<ChromotingHostContext> host_context, |
| 61 std::unique_ptr<PolicyWatcher> policy_watcher, | |
| 62 std::unique_ptr<It2MeConfirmationDialogFactory> dialog_factory, | 60 std::unique_ptr<It2MeConfirmationDialogFactory> dialog_factory, |
| 63 base::WeakPtr<It2MeHost::Observer> observer, | 61 base::WeakPtr<It2MeHost::Observer> observer, |
| 64 std::unique_ptr<SignalStrategy> signal_strategy, | 62 std::unique_ptr<SignalStrategy> signal_strategy, |
| 65 const std::string& username, | 63 const std::string& username, |
| 66 const std::string& directory_bot_jid) | 64 const std::string& directory_bot_jid) |
| 67 : host_context_(std::move(host_context)), | 65 : host_context_(std::move(host_context)), |
| 68 observer_(observer), | 66 observer_(observer), |
| 69 signal_strategy_(std::move(signal_strategy)), | 67 signal_strategy_(std::move(signal_strategy)), |
| 70 username_(username), | 68 username_(username), |
| 71 directory_bot_jid_(directory_bot_jid), | 69 directory_bot_jid_(directory_bot_jid), |
| 72 policy_watcher_(std::move(policy_watcher)), | |
| 73 confirmation_dialog_factory_(std::move(dialog_factory)) { | 70 confirmation_dialog_factory_(std::move(dialog_factory)) { |
| 74 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread()); | 71 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread()); |
| 75 } | 72 } |
| 76 | 73 |
| 77 It2MeHost::~It2MeHost() { | 74 It2MeHost::~It2MeHost() { |
| 78 // Check that resources that need to be torn down on the UI thread are gone. | 75 // Check that resources that need to be torn down on the UI thread are gone. |
| 79 DCHECK(!desktop_environment_factory_.get()); | 76 DCHECK(!desktop_environment_factory_.get()); |
| 80 DCHECK(!policy_watcher_.get()); | |
| 81 } | 77 } |
| 82 | 78 |
| 83 void It2MeHost::Connect() { | 79 void It2MeHost::Connect() { |
| 84 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) { | 80 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) { |
| 85 host_context_->ui_task_runner()->PostTask( | 81 host_context_->ui_task_runner()->PostTask( |
| 86 FROM_HERE, base::Bind(&It2MeHost::Connect, this)); | 82 FROM_HERE, base::Bind(&It2MeHost::Connect, this)); |
| 87 return; | 83 return; |
| 88 } | 84 } |
| 89 | 85 |
| 90 desktop_environment_factory_.reset(new It2MeDesktopEnvironmentFactory( | 86 desktop_environment_factory_.reset(new It2MeDesktopEnvironmentFactory( |
| 91 host_context_->network_task_runner(), | 87 host_context_->network_task_runner(), |
| 92 host_context_->video_capture_task_runner(), | 88 host_context_->video_capture_task_runner(), |
| 93 host_context_->input_task_runner(), host_context_->ui_task_runner())); | 89 host_context_->input_task_runner(), host_context_->ui_task_runner())); |
| 94 | 90 |
| 95 // Start monitoring configured policies. | |
| 96 policy_watcher_->StartWatching( | |
| 97 base::Bind(&It2MeHost::OnPolicyUpdate, this), | |
| 98 base::Bind(&It2MeHost::OnPolicyError, this)); | |
| 99 | |
| 100 // Switch to the network thread to start the actual connection. | 91 // Switch to the network thread to start the actual connection. |
| 101 host_context_->network_task_runner()->PostTask( | 92 host_context_->network_task_runner()->PostTask( |
| 102 FROM_HERE, base::Bind(&It2MeHost::ReadPolicyAndConnect, this)); | 93 FROM_HERE, base::Bind(&It2MeHost::ReadPolicyAndConnect, this)); |
| 103 } | 94 } |
| 104 | 95 |
| 105 void It2MeHost::Disconnect() { | 96 void It2MeHost::Disconnect() { |
| 106 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread()); | 97 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread()); |
| 107 host_context_->network_task_runner()->PostTask( | 98 host_context_->network_task_runner()->PostTask( |
| 108 FROM_HERE, base::Bind(&It2MeHost::DisconnectOnNetworkThread, this)); | 99 FROM_HERE, base::Bind(&It2MeHost::DisconnectOnNetworkThread, this)); |
| 109 } | 100 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 125 host_.reset(); | 116 host_.reset(); |
| 126 } | 117 } |
| 127 | 118 |
| 128 register_request_.reset(); | 119 register_request_.reset(); |
| 129 host_status_logger_.reset(); | 120 host_status_logger_.reset(); |
| 130 signal_strategy_.reset(); | 121 signal_strategy_.reset(); |
| 131 | 122 |
| 132 // Post tasks to delete UI objects on the UI thread. | 123 // Post tasks to delete UI objects on the UI thread. |
| 133 host_context_->ui_task_runner()->DeleteSoon( | 124 host_context_->ui_task_runner()->DeleteSoon( |
| 134 FROM_HERE, desktop_environment_factory_.release()); | 125 FROM_HERE, desktop_environment_factory_.release()); |
| 135 host_context_->ui_task_runner()->DeleteSoon(FROM_HERE, | |
| 136 policy_watcher_.release()); | |
| 137 | 126 |
| 138 SetState(kDisconnected, ""); | 127 SetState(kDisconnected, ""); |
| 139 } | 128 } |
| 140 | 129 |
| 141 void It2MeHost::RequestNatPolicy() { | 130 void It2MeHost::RequestNatPolicy() { |
| 142 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { | 131 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { |
| 143 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread()); | 132 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread()); |
| 144 host_context_->network_task_runner()->PostTask( | 133 host_context_->network_task_runner()->PostTask( |
| 145 FROM_HERE, base::Bind(&It2MeHost::RequestNatPolicy, this)); | 134 FROM_HERE, base::Bind(&It2MeHost::RequestNatPolicy, this)); |
| 146 return; | 135 return; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 UpdateClientDomainPolicy(client_domain); | 313 UpdateClientDomainPolicy(client_domain); |
| 325 } | 314 } |
| 326 | 315 |
| 327 policy_received_ = true; | 316 policy_received_ = true; |
| 328 | 317 |
| 329 if (!pending_connect_.is_null()) { | 318 if (!pending_connect_.is_null()) { |
| 330 base::ResetAndReturn(&pending_connect_).Run(); | 319 base::ResetAndReturn(&pending_connect_).Run(); |
| 331 } | 320 } |
| 332 } | 321 } |
| 333 | 322 |
| 334 void It2MeHost::OnPolicyError() { | |
| 335 // TODO(lukasza): Report the policy error to the user. crbug.com/433009 | |
| 336 NOTIMPLEMENTED(); | |
| 337 } | |
| 338 | |
| 339 void It2MeHost::UpdateNatPolicy(bool nat_traversal_enabled) { | 323 void It2MeHost::UpdateNatPolicy(bool nat_traversal_enabled) { |
| 340 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 324 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
| 341 | 325 |
| 342 VLOG(2) << "UpdateNatPolicy: " << nat_traversal_enabled; | 326 VLOG(2) << "UpdateNatPolicy: " << nat_traversal_enabled; |
| 343 | 327 |
| 344 // When transitioning from enabled to disabled, force disconnect any | 328 // When transitioning from enabled to disabled, force disconnect any |
| 345 // existing session. | 329 // existing session. |
| 346 if (nat_traversal_enabled_ && !nat_traversal_enabled && IsRunning()) { | 330 if (nat_traversal_enabled_ && !nat_traversal_enabled && IsRunning()) { |
| 347 DisconnectOnNetworkThread(); | 331 DisconnectOnNetworkThread(); |
| 348 } | 332 } |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 It2MeHostFactory::~It2MeHostFactory() {} | 544 It2MeHostFactory::~It2MeHostFactory() {} |
| 561 | 545 |
| 562 scoped_refptr<It2MeHost> It2MeHostFactory::CreateIt2MeHost( | 546 scoped_refptr<It2MeHost> It2MeHostFactory::CreateIt2MeHost( |
| 563 std::unique_ptr<ChromotingHostContext> context, | 547 std::unique_ptr<ChromotingHostContext> context, |
| 564 policy::PolicyService* policy_service, | 548 policy::PolicyService* policy_service, |
| 565 base::WeakPtr<It2MeHost::Observer> observer, | 549 base::WeakPtr<It2MeHost::Observer> observer, |
| 566 std::unique_ptr<SignalStrategy> signal_strategy, | 550 std::unique_ptr<SignalStrategy> signal_strategy, |
| 567 const std::string& username, | 551 const std::string& username, |
| 568 const std::string& directory_bot_jid) { | 552 const std::string& directory_bot_jid) { |
| 569 DCHECK(context->ui_task_runner()->BelongsToCurrentThread()); | 553 DCHECK(context->ui_task_runner()->BelongsToCurrentThread()); |
| 570 | 554 return new It2MeHost( |
| 571 std::unique_ptr<PolicyWatcher> policy_watcher = | 555 std::move(context), base::MakeUnique<It2MeConfirmationDialogFactory>(), |
| 572 PolicyWatcher::Create(policy_service, context->file_task_runner()); | 556 observer, std::move(signal_strategy), username, directory_bot_jid); |
| 573 return new It2MeHost(std::move(context), std::move(policy_watcher), | |
| 574 base::MakeUnique<It2MeConfirmationDialogFactory>(), | |
| 575 observer, std::move(signal_strategy), username, | |
| 576 directory_bot_jid); | |
| 577 } | 557 } |
| 578 | 558 |
| 579 } // namespace remoting | 559 } // namespace remoting |
| OLD | NEW |