Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: remoting/host/plugin/host_script_object.cc

Issue 10920019: [Chromoting] Refactoring DesktopEnvironment and moving screen/audio recorders to ClientSession. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 &HostNPScriptObject::ReadPolicyAndConnect, base::Unretained(this), 497 &HostNPScriptObject::ReadPolicyAndConnect, base::Unretained(this),
497 uid, auth_token, auth_service)); 498 uid, auth_token, auth_service));
498 return; 499 return;
499 } 500 }
500 501
501 SetState(kStarting); 502 SetState(kStarting);
502 503
503 // Only proceed to FinishConnect() if at least one policy update has been 504 // Only proceed to FinishConnect() if at least one policy update has been
504 // received. 505 // received.
505 if (policy_received_) { 506 if (policy_received_) {
506 FinishConnectMainThread(uid, auth_token, auth_service); 507 FinishConnect(uid, auth_token, auth_service);
507 } else { 508 } else {
508 // Otherwise, create the policy watcher, and thunk the connect. 509 // Otherwise, create the policy watcher, and thunk the connect.
509 pending_connect_ = 510 pending_connect_ =
510 base::Bind(&HostNPScriptObject::FinishConnectMainThread, 511 base::Bind(&HostNPScriptObject::FinishConnect,
511 base::Unretained(this), uid, auth_token, auth_service); 512 base::Unretained(this), uid, auth_token, auth_service);
512 } 513 }
513 } 514 }
514 515
515 void HostNPScriptObject::FinishConnectMainThread( 516 void HostNPScriptObject::FinishConnect(
516 const std::string& uid,
517 const std::string& auth_token,
518 const std::string& auth_service) {
519 if (!host_context_->capture_task_runner()->BelongsToCurrentThread()) {
520 host_context_->capture_task_runner()->PostTask(FROM_HERE, base::Bind(
521 &HostNPScriptObject::FinishConnectMainThread, base::Unretained(this),
522 uid, auth_token, auth_service));
523 return;
524 }
525
526 // DesktopEnvironment must be initialized on the capture thread.
527 //
528 // TODO(sergeyu): Fix DesktopEnvironment so that it can be created
529 // on either the UI or the network thread so that we can avoid
530 // jumping to the main thread here.
531 desktop_environment_ = DesktopEnvironment::Create(host_context_.get());
532
533 FinishConnectNetworkThread(uid, auth_token, auth_service);
534 }
535
536 void HostNPScriptObject::FinishConnectNetworkThread(
537 const std::string& uid, 517 const std::string& uid,
538 const std::string& auth_token, 518 const std::string& auth_token,
539 const std::string& auth_service) { 519 const std::string& auth_service) {
540 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { 520 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) {
541 host_context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( 521 host_context_->network_task_runner()->PostTask(FROM_HERE, base::Bind(
542 &HostNPScriptObject::FinishConnectNetworkThread, base::Unretained(this), 522 &HostNPScriptObject::FinishConnect, base::Unretained(this),
543 uid, auth_token, auth_service)); 523 uid, auth_token, auth_service));
544 return; 524 return;
545 } 525 }
546 526
547 if (state_ != kStarting) { 527 if (state_ != kStarting) {
548 // Host has been stopped while we were fetching policy. 528 // Host has been stopped while we were fetching policy.
549 return; 529 return;
550 } 530 }
551 531
552 // Check the host domain policy. 532 // Check the host domain policy.
553 if (!required_host_domain_.empty() && 533 if (!required_host_domain_.empty() &&
554 !EndsWith(uid, std::string("@") + required_host_domain_, false)) { 534 !EndsWith(uid, std::string("@") + required_host_domain_, false)) {
555 SetState(kError); 535 SetState(kError);
556 return; 536 return;
557 } 537 }
558 538
559 // Verify that DesktopEnvironment has been created.
560 if (desktop_environment_.get() == NULL) {
561 SetState(kError);
562 return;
563 }
564
565 // Generate a key pair for the Host to use. 539 // Generate a key pair for the Host to use.
566 // TODO(wez): Move this to the worker thread. 540 // TODO(wez): Move this to the worker thread.
567 host_key_pair_.Generate(); 541 host_key_pair_.Generate();
568 542
569 // Create XMPP connection. 543 // Create XMPP connection.
570 scoped_ptr<SignalStrategy> signal_strategy( 544 scoped_ptr<SignalStrategy> signal_strategy(
571 new XmppSignalStrategy(host_context_->url_request_context_getter(), 545 new XmppSignalStrategy(host_context_->url_request_context_getter(),
572 uid, auth_token, auth_service)); 546 uid, auth_token, auth_service));
573 547
574 // Request registration of the host for support. 548 // Request registration of the host for support.
575 scoped_ptr<RegisterSupportHostRequest> register_request( 549 scoped_ptr<RegisterSupportHostRequest> register_request(
576 new RegisterSupportHostRequest( 550 new RegisterSupportHostRequest(
577 signal_strategy.get(), &host_key_pair_, 551 signal_strategy.get(), &host_key_pair_,
578 base::Bind(&HostNPScriptObject::OnReceivedSupportID, 552 base::Bind(&HostNPScriptObject::OnReceivedSupportID,
579 base::Unretained(this)))); 553 base::Unretained(this))));
580 554
581 // Beyond this point nothing can fail, so save the config and request. 555 // Beyond this point nothing can fail, so save the config and request.
582 signal_strategy_.reset(signal_strategy.release()); 556 signal_strategy_.reset(signal_strategy.release());
583 register_request_.reset(register_request.release()); 557 register_request_.reset(register_request.release());
584 558
585 // Create the Host. 559 // Create the Host.
586 LOG(INFO) << "NAT state: " << nat_traversal_enabled_; 560 LOG(INFO) << "NAT state: " << nat_traversal_enabled_;
587 host_ = new ChromotingHost( 561 host_ = new ChromotingHost(
588 host_context_.get(), signal_strategy_.get(), desktop_environment_.get(), 562 host_context_.get(), signal_strategy_.get(),
563 desktop_environment_factory_.get(),
589 CreateHostSessionManager( 564 CreateHostSessionManager(
590 NetworkSettings(nat_traversal_enabled_ ? 565 NetworkSettings(nat_traversal_enabled_ ?
591 NetworkSettings::NAT_TRAVERSAL_ENABLED : 566 NetworkSettings::NAT_TRAVERSAL_ENABLED :
592 NetworkSettings::NAT_TRAVERSAL_DISABLED), 567 NetworkSettings::NAT_TRAVERSAL_DISABLED),
593 host_context_->url_request_context_getter())); 568 host_context_->url_request_context_getter()));
594 host_->AddStatusObserver(this); 569 host_->AddStatusObserver(this);
595 log_to_server_.reset( 570 log_to_server_.reset(
596 new LogToServer(host_, ServerLogEntry::IT2ME, signal_strategy_.get())); 571 new LogToServer(host_, ServerLogEntry::IT2ME, signal_strategy_.get()));
597 base::Closure disconnect_callback = base::Bind( 572 base::Closure disconnect_callback = base::Bind(
598 &ChromotingHost::Shutdown, base::Unretained(host_.get()), 573 &ChromotingHost::Shutdown, base::Unretained(host_.get()),
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 FROM_HERE, base::Bind(&HostNPScriptObject::DisconnectInternal, 848 FROM_HERE, base::Bind(&HostNPScriptObject::DisconnectInternal,
874 base::Unretained(this))); 849 base::Unretained(this)));
875 return; 850 return;
876 } 851 }
877 852
878 switch (state_) { 853 switch (state_) {
879 case kDisconnected: 854 case kDisconnected:
880 return; 855 return;
881 856
882 case kStarting: 857 case kStarting:
883 desktop_environment_.reset();
884 SetState(kDisconnecting); 858 SetState(kDisconnecting);
885 SetState(kDisconnected); 859 SetState(kDisconnected);
886 return; 860 return;
887 861
888 case kDisconnecting: 862 case kDisconnecting:
889 return; 863 return;
890 864
891 default: 865 default:
892 SetState(kDisconnecting); 866 SetState(kDisconnecting);
893 867
894 if (!host_) { 868 if (!host_) {
895 OnShutdownFinished(); 869 OnShutdownFinished();
896 return; 870 return;
897 } 871 }
898 // ChromotingHost::Shutdown() may destroy SignalStrategy 872 // ChromotingHost::Shutdown() may destroy SignalStrategy
899 // synchronously, but SignalStrategy::Listener handlers are not 873 // synchronously, but SignalStrategy::Listener handlers are not
900 // allowed to destroy SignalStrategy, so post task to call 874 // allowed to destroy SignalStrategy, so post task to call
901 // Shutdown() later. 875 // Shutdown() later.
902 host_context_->network_task_runner()->PostTask( 876 host_context_->network_task_runner()->PostTask(
903 FROM_HERE, base::Bind( 877 FROM_HERE, base::Bind(
904 &ChromotingHost::Shutdown, host_, 878 &ChromotingHost::Shutdown, host_,
905 base::Bind(&HostNPScriptObject::OnShutdownFinished, 879 base::Bind(&HostNPScriptObject::OnShutdownFinished,
906 base::Unretained(this)))); 880 base::Unretained(this))));
907 return; 881 return;
908 } 882 }
909 } 883 }
910 884
911 void HostNPScriptObject::OnShutdownFinished() { 885 void HostNPScriptObject::OnShutdownFinished() {
912 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 886 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
913
914 desktop_environment_.reset();
915 } 887 }
916 888
917 void HostNPScriptObject::OnPolicyUpdate( 889 void HostNPScriptObject::OnPolicyUpdate(
918 scoped_ptr<base::DictionaryValue> policies) { 890 scoped_ptr<base::DictionaryValue> policies) {
919 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { 891 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) {
920 host_context_->network_task_runner()->PostTask( 892 host_context_->network_task_runner()->PostTask(
921 FROM_HERE, 893 FROM_HERE,
922 base::Bind(&HostNPScriptObject::OnPolicyUpdate, 894 base::Bind(&HostNPScriptObject::OnPolicyUpdate,
923 base::Unretained(this), base::Passed(&policies))); 895 base::Unretained(this), base::Passed(&policies)));
924 return; 896 return;
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 return is_good; 1268 return is_good;
1297 } 1269 }
1298 1270
1299 void HostNPScriptObject::SetException(const std::string& exception_string) { 1271 void HostNPScriptObject::SetException(const std::string& exception_string) {
1300 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 1272 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
1301 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); 1273 g_npnetscape_funcs->setexception(parent_, exception_string.c_str());
1302 LOG(INFO) << exception_string; 1274 LOG(INFO) << exception_string;
1303 } 1275 }
1304 1276
1305 } // namespace remoting 1277 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698