Chromium Code Reviews| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/synchronization/waitable_event.h" | |
| 10 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
| 11 #include "net/socket/client_socket_factory.h" | 10 #include "net/socket/client_socket_factory.h" |
| 12 #include "remoting/base/auto_thread.h" | 11 #include "remoting/base/auto_thread.h" |
| 13 #include "remoting/base/logging.h" | 12 #include "remoting/base/logging.h" |
| 14 #include "remoting/base/rsa_key_pair.h" | 13 #include "remoting/base/rsa_key_pair.h" |
| 15 #include "remoting/host/chromoting_host.h" | 14 #include "remoting/host/chromoting_host.h" |
| 16 #include "remoting/host/chromoting_host_context.h" | 15 #include "remoting/host/chromoting_host_context.h" |
| 17 #include "remoting/host/host_event_logger.h" | 16 #include "remoting/host/host_event_logger.h" |
| 18 #include "remoting/host/host_secret.h" | 17 #include "remoting/host/host_secret.h" |
| 19 #include "remoting/host/host_status_logger.h" | 18 #include "remoting/host/host_status_logger.h" |
| 20 #include "remoting/host/it2me_desktop_environment.h" | 19 #include "remoting/host/it2me_desktop_environment.h" |
| 21 #include "remoting/host/policy_hack/policy_watcher.h" | 20 #include "remoting/host/policy_hack/policy_watcher.h" |
| 22 #include "remoting/host/register_support_host_request.h" | 21 #include "remoting/host/register_support_host_request.h" |
| 23 #include "remoting/host/session_manager_factory.h" | 22 #include "remoting/host/session_manager_factory.h" |
| 24 #include "remoting/protocol/it2me_host_authenticator_factory.h" | 23 #include "remoting/protocol/it2me_host_authenticator_factory.h" |
| 25 #include "remoting/protocol/network_settings.h" | 24 #include "remoting/protocol/network_settings.h" |
| 26 #include "remoting/signaling/server_log_entry.h" | 25 #include "remoting/signaling/server_log_entry.h" |
| 27 | 26 |
| 28 namespace remoting { | 27 namespace remoting { |
| 29 | 28 |
| 30 namespace { | 29 namespace { |
| 31 | 30 |
| 32 // This is used for tagging system event logs. | 31 // This is used for tagging system event logs. |
| 33 const char kApplicationName[] = "chromoting"; | 32 const char kApplicationName[] = "chromoting"; |
| 34 const int kMaxLoginAttempts = 5; | 33 const int kMaxLoginAttempts = 5; |
| 35 | 34 |
| 36 } // namespace | 35 } // namespace |
| 37 | 36 |
| 38 It2MeHost::It2MeHost( | 37 It2MeHost::It2MeHost( |
| 39 ChromotingHostContext* host_context, | 38 scoped_ptr<ChromotingHostContext> host_context, |
| 40 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 39 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher, |
| 41 base::WeakPtr<It2MeHost::Observer> observer, | 40 base::WeakPtr<It2MeHost::Observer> observer, |
| 42 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | 41 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, |
| 43 const std::string& directory_bot_jid) | 42 const std::string& directory_bot_jid) |
| 44 : host_context_(host_context), | 43 : host_context_(host_context.Pass()), |
| 45 task_runner_(task_runner), | 44 task_runner_(host_context_->ui_task_runner()), |
| 46 observer_(observer), | 45 observer_(observer), |
| 47 xmpp_server_config_(xmpp_server_config), | 46 xmpp_server_config_(xmpp_server_config), |
| 48 directory_bot_jid_(directory_bot_jid), | 47 directory_bot_jid_(directory_bot_jid), |
| 49 state_(kDisconnected), | 48 state_(kDisconnected), |
| 50 failed_login_attempts_(0), | 49 failed_login_attempts_(0), |
| 50 policy_watcher_(policy_watcher.Pass()), | |
| 51 nat_traversal_enabled_(false), | 51 nat_traversal_enabled_(false), |
| 52 policy_received_(false) { | 52 policy_received_(false) { |
| 53 DCHECK(task_runner_->BelongsToCurrentThread()); | 53 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void It2MeHost::Connect() { | 56 void It2MeHost::Connect() { |
| 57 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) { | 57 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) { |
| 58 DCHECK(task_runner_->BelongsToCurrentThread()); | 58 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 59 host_context_->ui_task_runner()->PostTask( | 59 host_context_->ui_task_runner()->PostTask( |
| 60 FROM_HERE, base::Bind(&It2MeHost::Connect, this)); | 60 FROM_HERE, base::Bind(&It2MeHost::Connect, this)); |
| 61 return; | 61 return; |
| 62 } | 62 } |
| 63 | 63 |
| 64 desktop_environment_factory_.reset(new It2MeDesktopEnvironmentFactory( | 64 desktop_environment_factory_.reset(new It2MeDesktopEnvironmentFactory( |
| 65 host_context_->network_task_runner(), | 65 host_context_->network_task_runner(), |
| 66 host_context_->input_task_runner(), | 66 host_context_->input_task_runner(), |
| 67 host_context_->ui_task_runner())); | 67 host_context_->ui_task_runner())); |
| 68 | 68 |
| 69 // Start monitoring configured policies. | 69 // Start monitoring configured policies. |
| 70 policy_watcher_.reset( | 70 policy_watcher_->StartWatching(base::Bind(&It2MeHost::OnPolicyUpdate, this)); |
| 71 policy_hack::PolicyWatcher::Create(host_context_->network_task_runner())); | |
| 72 policy_watcher_->StartWatching( | |
| 73 base::Bind(&It2MeHost::OnPolicyUpdate, this)); | |
| 74 | 71 |
| 75 // Switch to the network thread to start the actual connection. | 72 // Switch to the network thread to start the actual connection. |
| 76 host_context_->network_task_runner()->PostTask( | 73 host_context_->network_task_runner()->PostTask( |
| 77 FROM_HERE, base::Bind(&It2MeHost::ReadPolicyAndConnect, this)); | 74 FROM_HERE, base::Bind(&It2MeHost::ReadPolicyAndConnect, this)); |
| 78 } | 75 } |
| 79 | 76 |
| 80 void It2MeHost::Disconnect() { | 77 void It2MeHost::Disconnect() { |
| 81 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { | 78 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { |
| 82 DCHECK(task_runner_->BelongsToCurrentThread()); | 79 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 83 host_context_->network_task_runner()->PostTask( | 80 host_context_->network_task_runner()->PostTask( |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 } | 247 } |
| 251 | 248 |
| 252 void It2MeHost::ShutdownOnUiThread() { | 249 void It2MeHost::ShutdownOnUiThread() { |
| 253 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread()); | 250 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread()); |
| 254 | 251 |
| 255 // Destroy the DesktopEnvironmentFactory, to free thread references. | 252 // Destroy the DesktopEnvironmentFactory, to free thread references. |
| 256 desktop_environment_factory_.reset(); | 253 desktop_environment_factory_.reset(); |
| 257 | 254 |
| 258 // Stop listening for policy updates. | 255 // Stop listening for policy updates. |
| 259 if (policy_watcher_.get()) { | 256 if (policy_watcher_.get()) { |
| 260 base::WaitableEvent policy_watcher_stopped_(true, false); | 257 policy_watcher_->StopWatching( |
| 261 policy_watcher_->StopWatching(&policy_watcher_stopped_); | 258 base::Bind(&It2MeHost::OnPolicyWatcherShutdown, this)); |
| 262 policy_watcher_stopped_.Wait(); | 259 return; |
| 263 policy_watcher_.reset(); | |
| 264 } | 260 } |
| 265 } | 261 } |
| 266 | 262 |
| 263 void It2MeHost::OnPolicyWatcherShutdown() { | |
| 264 policy_watcher_.reset(); | |
| 265 } | |
| 266 | |
| 267 void It2MeHost::OnAccessDenied(const std::string& jid) { | 267 void It2MeHost::OnAccessDenied(const std::string& jid) { |
| 268 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 268 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
| 269 | 269 |
| 270 ++failed_login_attempts_; | 270 ++failed_login_attempts_; |
| 271 if (failed_login_attempts_ == kMaxLoginAttempts) { | 271 if (failed_login_attempts_ == kMaxLoginAttempts) { |
| 272 Disconnect(); | 272 Disconnect(); |
| 273 } | 273 } |
| 274 } | 274 } |
| 275 | 275 |
| 276 void It2MeHost::OnClientAuthenticated(const std::string& jid) { | 276 void It2MeHost::OnClientAuthenticated(const std::string& jid) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 304 SetState(kConnected); | 304 SetState(kConnected); |
| 305 } | 305 } |
| 306 | 306 |
| 307 void It2MeHost::OnClientDisconnected(const std::string& jid) { | 307 void It2MeHost::OnClientDisconnected(const std::string& jid) { |
| 308 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 308 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
| 309 | 309 |
| 310 Disconnect(); | 310 Disconnect(); |
| 311 } | 311 } |
| 312 | 312 |
| 313 void It2MeHost::OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) { | 313 void It2MeHost::OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) { |
| 314 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 314 // The policy watcher runs on the |ui_task_runner| on ChromeOS and the |
| 315 // |network_task_runner| on other platforms. | |
|
Wez
2014/10/29 18:27:51
That's just an implementation detail of the CrOS p
kelvinp
2014/10/29 22:20:17
Unfortunately, We can't. In ChromeOS, |task_runne
Wez
2014/10/30 01:08:59
No it isn't - it's still passed the network task r
| |
| 316 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { | |
| 317 host_context_->network_task_runner()->PostTask( | |
| 318 FROM_HERE, | |
| 319 base::Bind(&It2MeHost::OnPolicyUpdate, this, base::Passed(&policies))); | |
| 320 return; | |
| 321 } | |
| 315 | 322 |
| 316 bool nat_policy; | 323 bool nat_policy; |
| 317 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName, | 324 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName, |
| 318 &nat_policy)) { | 325 &nat_policy)) { |
| 319 UpdateNatPolicy(nat_policy); | 326 UpdateNatPolicy(nat_policy); |
| 320 } | 327 } |
| 321 std::string host_domain; | 328 std::string host_domain; |
| 322 if (policies->GetString(policy_hack::PolicyWatcher::kHostDomainPolicyName, | 329 if (policies->GetString(policy_hack::PolicyWatcher::kHostDomainPolicyName, |
| 323 &host_domain)) { | 330 &host_domain)) { |
| 324 UpdateHostDomainPolicy(host_domain); | 331 UpdateHostDomainPolicy(host_domain); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 host_->SetAuthenticatorFactory(factory.Pass()); | 459 host_->SetAuthenticatorFactory(factory.Pass()); |
| 453 | 460 |
| 454 // Pass the Access Code to the script object before changing state. | 461 // Pass the Access Code to the script object before changing state. |
| 455 task_runner_->PostTask( | 462 task_runner_->PostTask( |
| 456 FROM_HERE, base::Bind(&It2MeHost::Observer::OnStoreAccessCode, | 463 FROM_HERE, base::Bind(&It2MeHost::Observer::OnStoreAccessCode, |
| 457 observer_, access_code, lifetime)); | 464 observer_, access_code, lifetime)); |
| 458 | 465 |
| 459 SetState(kReceivedAccessCode); | 466 SetState(kReceivedAccessCode); |
| 460 } | 467 } |
| 461 | 468 |
| 462 It2MeHostFactory::It2MeHostFactory() {} | 469 It2MeHostFactory::It2MeHostFactory(policy::PolicyService* policy_service) |
| 470 : policy_service_(policy_service) { | |
| 471 } | |
| 463 | 472 |
| 464 It2MeHostFactory::~It2MeHostFactory() {} | 473 It2MeHostFactory::~It2MeHostFactory() {} |
| 465 | 474 |
| 466 scoped_refptr<It2MeHost> It2MeHostFactory::CreateIt2MeHost( | 475 scoped_refptr<It2MeHost> It2MeHostFactory::CreateIt2MeHost( |
| 467 ChromotingHostContext* context, | 476 scoped_ptr<ChromotingHostContext> context, |
| 468 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
| 469 base::WeakPtr<It2MeHost::Observer> observer, | 477 base::WeakPtr<It2MeHost::Observer> observer, |
| 470 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | 478 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, |
| 471 const std::string& directory_bot_jid) { | 479 const std::string& directory_bot_jid) { |
| 472 return new It2MeHost( | 480 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher = |
| 473 context, task_runner, observer, xmpp_server_config, directory_bot_jid); | 481 policy_hack::PolicyWatcher::Create(policy_service_, |
| 482 context->network_task_runner()); | |
| 483 return new It2MeHost(context.Pass(), policy_watcher.Pass(), observer, | |
| 484 xmpp_server_config, directory_bot_jid); | |
| 474 } | 485 } |
| 475 | 486 |
| 476 } // namespace remoting | 487 } // namespace remoting |
| OLD | NEW |