| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/plugin/host_script_object.h" | 5 #include "remoting/host/plugin/host_script_object.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
| 14 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
| 18 #include "remoting/base/auto_thread_task_runner.h" | 18 #include "remoting/base/auto_thread_task_runner.h" |
| 19 #include "remoting/base/auth_token_util.h" | 19 #include "remoting/base/auth_token_util.h" |
| 20 #include "remoting/host/chromoting_host.h" | 20 #include "remoting/host/chromoting_host.h" |
| 21 #include "remoting/host/chromoting_host_context.h" | 21 #include "remoting/host/chromoting_host_context.h" |
| 22 #include "remoting/host/desktop_environment.h" | 22 #include "remoting/host/desktop_environment_factory.h" |
| 23 #include "remoting/host/host_config.h" | 23 #include "remoting/host/host_config.h" |
| 24 #include "remoting/host/host_event_logger.h" | 24 #include "remoting/host/host_event_logger.h" |
| 25 #include "remoting/host/host_key_pair.h" | 25 #include "remoting/host/host_key_pair.h" |
| 26 #include "remoting/host/host_secret.h" | 26 #include "remoting/host/host_secret.h" |
| 27 #include "remoting/host/it2me_host_user_interface.h" | 27 #include "remoting/host/it2me_host_user_interface.h" |
| 28 #include "remoting/host/network_settings.h" | 28 #include "remoting/host/network_settings.h" |
| 29 #include "remoting/host/pin_hash.h" | 29 #include "remoting/host/pin_hash.h" |
| 30 #include "remoting/host/plugin/daemon_controller.h" | 30 #include "remoting/host/plugin/daemon_controller.h" |
| 31 #include "remoting/host/plugin/host_log_handler.h" | 31 #include "remoting/host/plugin/host_log_handler.h" |
| 32 #include "remoting/host/policy_hack/policy_watcher.h" | 32 #include "remoting/host/policy_hack/policy_watcher.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 NPP plugin, | 86 NPP plugin, |
| 87 NPObject* parent, | 87 NPObject* parent, |
| 88 PluginThreadTaskRunner::Delegate* plugin_thread_delegate) | 88 PluginThreadTaskRunner::Delegate* plugin_thread_delegate) |
| 89 : plugin_(plugin), | 89 : plugin_(plugin), |
| 90 parent_(parent), | 90 parent_(parent), |
| 91 am_currently_logging_(false), | 91 am_currently_logging_(false), |
| 92 state_(kDisconnected), | 92 state_(kDisconnected), |
| 93 np_thread_id_(base::PlatformThread::CurrentId()), | 93 np_thread_id_(base::PlatformThread::CurrentId()), |
| 94 plugin_task_runner_( | 94 plugin_task_runner_( |
| 95 new PluginThreadTaskRunner(plugin_thread_delegate)), | 95 new PluginThreadTaskRunner(plugin_thread_delegate)), |
| 96 desktop_environment_factory_(new DesktopEnvironmentFactory()), |
| 96 failed_login_attempts_(0), | 97 failed_login_attempts_(0), |
| 97 disconnected_event_(true, false), | 98 disconnected_event_(true, false), |
| 98 nat_traversal_enabled_(false), | 99 nat_traversal_enabled_(false), |
| 99 policy_received_(false), | 100 policy_received_(false), |
| 100 daemon_controller_(DaemonController::Create()), | 101 daemon_controller_(DaemonController::Create()), |
| 101 worker_thread_("RemotingHostPlugin") { | 102 worker_thread_("RemotingHostPlugin") { |
| 102 worker_thread_.Start(); | 103 worker_thread_.Start(); |
| 103 } | 104 } |
| 104 | 105 |
| 105 HostNPScriptObject::~HostNPScriptObject() { | 106 HostNPScriptObject::~HostNPScriptObject() { |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 &HostNPScriptObject::ReadPolicyAndConnect, base::Unretained(this), | 505 &HostNPScriptObject::ReadPolicyAndConnect, base::Unretained(this), |
| 505 uid, auth_token, auth_service)); | 506 uid, auth_token, auth_service)); |
| 506 return; | 507 return; |
| 507 } | 508 } |
| 508 | 509 |
| 509 SetState(kStarting); | 510 SetState(kStarting); |
| 510 | 511 |
| 511 // Only proceed to FinishConnect() if at least one policy update has been | 512 // Only proceed to FinishConnect() if at least one policy update has been |
| 512 // received. | 513 // received. |
| 513 if (policy_received_) { | 514 if (policy_received_) { |
| 514 FinishConnectMainThread(uid, auth_token, auth_service); | 515 FinishConnect(uid, auth_token, auth_service); |
| 515 } else { | 516 } else { |
| 516 // Otherwise, create the policy watcher, and thunk the connect. | 517 // Otherwise, create the policy watcher, and thunk the connect. |
| 517 pending_connect_ = | 518 pending_connect_ = |
| 518 base::Bind(&HostNPScriptObject::FinishConnectMainThread, | 519 base::Bind(&HostNPScriptObject::FinishConnect, |
| 519 base::Unretained(this), uid, auth_token, auth_service); | 520 base::Unretained(this), uid, auth_token, auth_service); |
| 520 } | 521 } |
| 521 } | 522 } |
| 522 | 523 |
| 523 void HostNPScriptObject::FinishConnectMainThread( | 524 void HostNPScriptObject::FinishConnect( |
| 524 const std::string& uid, | |
| 525 const std::string& auth_token, | |
| 526 const std::string& auth_service) { | |
| 527 if (!host_context_->capture_task_runner()->BelongsToCurrentThread()) { | |
| 528 host_context_->capture_task_runner()->PostTask(FROM_HERE, base::Bind( | |
| 529 &HostNPScriptObject::FinishConnectMainThread, base::Unretained(this), | |
| 530 uid, auth_token, auth_service)); | |
| 531 return; | |
| 532 } | |
| 533 | |
| 534 // DesktopEnvironment must be initialized on the capture thread. | |
| 535 // | |
| 536 // TODO(sergeyu): Fix DesktopEnvironment so that it can be created | |
| 537 // on either the UI or the network thread so that we can avoid | |
| 538 // jumping to the main thread here. | |
| 539 desktop_environment_ = DesktopEnvironment::Create(host_context_.get()); | |
| 540 | |
| 541 FinishConnectNetworkThread(uid, auth_token, auth_service); | |
| 542 } | |
| 543 | |
| 544 void HostNPScriptObject::FinishConnectNetworkThread( | |
| 545 const std::string& uid, | 525 const std::string& uid, |
| 546 const std::string& auth_token, | 526 const std::string& auth_token, |
| 547 const std::string& auth_service) { | 527 const std::string& auth_service) { |
| 548 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { | 528 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { |
| 549 host_context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( | 529 host_context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( |
| 550 &HostNPScriptObject::FinishConnectNetworkThread, base::Unretained(this), | 530 &HostNPScriptObject::FinishConnect, base::Unretained(this), |
| 551 uid, auth_token, auth_service)); | 531 uid, auth_token, auth_service)); |
| 552 return; | 532 return; |
| 553 } | 533 } |
| 554 | 534 |
| 555 if (state_ != kStarting) { | 535 if (state_ != kStarting) { |
| 556 // Host has been stopped while we were fetching policy. | 536 // Host has been stopped while we were fetching policy. |
| 557 return; | 537 return; |
| 558 } | 538 } |
| 559 | 539 |
| 560 // Check the host domain policy. | 540 // Check the host domain policy. |
| 561 if (!required_host_domain_.empty() && | 541 if (!required_host_domain_.empty() && |
| 562 !EndsWith(uid, std::string("@") + required_host_domain_, false)) { | 542 !EndsWith(uid, std::string("@") + required_host_domain_, false)) { |
| 563 SetState(kError); | 543 SetState(kError); |
| 564 return; | 544 return; |
| 565 } | 545 } |
| 566 | 546 |
| 567 // Verify that DesktopEnvironment has been created. | |
| 568 if (desktop_environment_.get() == NULL) { | |
| 569 SetState(kError); | |
| 570 return; | |
| 571 } | |
| 572 | |
| 573 // Generate a key pair for the Host to use. | 547 // Generate a key pair for the Host to use. |
| 574 // TODO(wez): Move this to the worker thread. | 548 // TODO(wez): Move this to the worker thread. |
| 575 host_key_pair_.Generate(); | 549 host_key_pair_.Generate(); |
| 576 | 550 |
| 577 // Create XMPP connection. | 551 // Create XMPP connection. |
| 578 scoped_ptr<SignalStrategy> signal_strategy( | 552 scoped_ptr<SignalStrategy> signal_strategy( |
| 579 new XmppSignalStrategy(host_context_->url_request_context_getter(), | 553 new XmppSignalStrategy(host_context_->url_request_context_getter(), |
| 580 uid, auth_token, auth_service)); | 554 uid, auth_token, auth_service)); |
| 581 | 555 |
| 582 // Request registration of the host for support. | 556 // Request registration of the host for support. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 596 nat_traversal_enabled_ ? | 570 nat_traversal_enabled_ ? |
| 597 NetworkSettings::NAT_TRAVERSAL_ENABLED : | 571 NetworkSettings::NAT_TRAVERSAL_ENABLED : |
| 598 NetworkSettings::NAT_TRAVERSAL_DISABLED); | 572 NetworkSettings::NAT_TRAVERSAL_DISABLED); |
| 599 if (!nat_traversal_enabled_) { | 573 if (!nat_traversal_enabled_) { |
| 600 network_settings.min_port = NetworkSettings::kDefaultMinPort; | 574 network_settings.min_port = NetworkSettings::kDefaultMinPort; |
| 601 network_settings.max_port = NetworkSettings::kDefaultMaxPort; | 575 network_settings.max_port = NetworkSettings::kDefaultMaxPort; |
| 602 } | 576 } |
| 603 | 577 |
| 604 // Create the Host. | 578 // Create the Host. |
| 605 host_ = new ChromotingHost( | 579 host_ = new ChromotingHost( |
| 606 host_context_.get(), signal_strategy_.get(), desktop_environment_.get(), | 580 host_context_.get(), signal_strategy_.get(), |
| 581 desktop_environment_factory_.get(), |
| 607 CreateHostSessionManager(network_settings, | 582 CreateHostSessionManager(network_settings, |
| 608 host_context_->url_request_context_getter())); | 583 host_context_->url_request_context_getter())); |
| 609 host_->AddStatusObserver(this); | 584 host_->AddStatusObserver(this); |
| 610 log_to_server_.reset( | 585 log_to_server_.reset( |
| 611 new LogToServer(host_, ServerLogEntry::IT2ME, signal_strategy_.get())); | 586 new LogToServer(host_, ServerLogEntry::IT2ME, signal_strategy_.get())); |
| 612 base::Closure disconnect_callback = base::Bind( | 587 base::Closure disconnect_callback = base::Bind( |
| 613 &ChromotingHost::Shutdown, base::Unretained(host_.get()), | 588 &ChromotingHost::Shutdown, base::Unretained(host_.get()), |
| 614 base::Closure()); | 589 base::Closure()); |
| 615 it2me_host_user_interface_->Start(host_.get(), disconnect_callback); | 590 it2me_host_user_interface_->Start(host_.get(), disconnect_callback); |
| 616 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName); | 591 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName); |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 FROM_HERE, base::Bind(&HostNPScriptObject::DisconnectInternal, | 863 FROM_HERE, base::Bind(&HostNPScriptObject::DisconnectInternal, |
| 889 base::Unretained(this))); | 864 base::Unretained(this))); |
| 890 return; | 865 return; |
| 891 } | 866 } |
| 892 | 867 |
| 893 switch (state_) { | 868 switch (state_) { |
| 894 case kDisconnected: | 869 case kDisconnected: |
| 895 return; | 870 return; |
| 896 | 871 |
| 897 case kStarting: | 872 case kStarting: |
| 898 desktop_environment_.reset(); | |
| 899 SetState(kDisconnecting); | 873 SetState(kDisconnecting); |
| 900 SetState(kDisconnected); | 874 SetState(kDisconnected); |
| 901 return; | 875 return; |
| 902 | 876 |
| 903 case kDisconnecting: | 877 case kDisconnecting: |
| 904 return; | 878 return; |
| 905 | 879 |
| 906 default: | 880 default: |
| 907 SetState(kDisconnecting); | 881 SetState(kDisconnecting); |
| 908 | 882 |
| 909 if (!host_) { | 883 if (!host_) { |
| 910 OnShutdownFinished(); | 884 OnShutdownFinished(); |
| 911 return; | 885 return; |
| 912 } | 886 } |
| 913 // ChromotingHost::Shutdown() may destroy SignalStrategy | 887 // ChromotingHost::Shutdown() may destroy SignalStrategy |
| 914 // synchronously, but SignalStrategy::Listener handlers are not | 888 // synchronously, but SignalStrategy::Listener handlers are not |
| 915 // allowed to destroy SignalStrategy, so post task to call | 889 // allowed to destroy SignalStrategy, so post task to call |
| 916 // Shutdown() later. | 890 // Shutdown() later. |
| 917 host_context_->network_task_runner()->PostTask( | 891 host_context_->network_task_runner()->PostTask( |
| 918 FROM_HERE, base::Bind( | 892 FROM_HERE, base::Bind( |
| 919 &ChromotingHost::Shutdown, host_, | 893 &ChromotingHost::Shutdown, host_, |
| 920 base::Bind(&HostNPScriptObject::OnShutdownFinished, | 894 base::Bind(&HostNPScriptObject::OnShutdownFinished, |
| 921 base::Unretained(this)))); | 895 base::Unretained(this)))); |
| 922 return; | 896 return; |
| 923 } | 897 } |
| 924 } | 898 } |
| 925 | 899 |
| 926 void HostNPScriptObject::OnShutdownFinished() { | 900 void HostNPScriptObject::OnShutdownFinished() { |
| 927 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 901 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
| 928 | |
| 929 desktop_environment_.reset(); | |
| 930 } | 902 } |
| 931 | 903 |
| 932 void HostNPScriptObject::OnPolicyUpdate( | 904 void HostNPScriptObject::OnPolicyUpdate( |
| 933 scoped_ptr<base::DictionaryValue> policies) { | 905 scoped_ptr<base::DictionaryValue> policies) { |
| 934 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { | 906 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { |
| 935 host_context_->network_task_runner()->PostTask( | 907 host_context_->network_task_runner()->PostTask( |
| 936 FROM_HERE, | 908 FROM_HERE, |
| 937 base::Bind(&HostNPScriptObject::OnPolicyUpdate, | 909 base::Bind(&HostNPScriptObject::OnPolicyUpdate, |
| 938 base::Unretained(this), base::Passed(&policies))); | 910 base::Unretained(this), base::Passed(&policies))); |
| 939 return; | 911 return; |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1311 return is_good; | 1283 return is_good; |
| 1312 } | 1284 } |
| 1313 | 1285 |
| 1314 void HostNPScriptObject::SetException(const std::string& exception_string) { | 1286 void HostNPScriptObject::SetException(const std::string& exception_string) { |
| 1315 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 1287 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
| 1316 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); | 1288 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); |
| 1317 LOG(INFO) << exception_string; | 1289 LOG(INFO) << exception_string; |
| 1318 } | 1290 } |
| 1319 | 1291 |
| 1320 } // namespace remoting | 1292 } // namespace remoting |
| OLD | NEW |