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

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

Issue 10911248: Revert 156297 - [Chromoting] Refactoring DesktopEnvironment and moving screen/audio recorders to Cl… (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
« no previous file with comments | « remoting/host/plugin/host_script_object.h ('k') | remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_factory.h" 22 #include "remoting/host/desktop_environment.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()),
97 failed_login_attempts_(0), 96 failed_login_attempts_(0),
98 disconnected_event_(true, false), 97 disconnected_event_(true, false),
99 nat_traversal_enabled_(false), 98 nat_traversal_enabled_(false),
100 policy_received_(false), 99 policy_received_(false),
101 daemon_controller_(DaemonController::Create()), 100 daemon_controller_(DaemonController::Create()),
102 worker_thread_("RemotingHostPlugin") { 101 worker_thread_("RemotingHostPlugin") {
103 worker_thread_.Start(); 102 worker_thread_.Start();
104 } 103 }
105 104
106 HostNPScriptObject::~HostNPScriptObject() { 105 HostNPScriptObject::~HostNPScriptObject() {
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 &HostNPScriptObject::ReadPolicyAndConnect, base::Unretained(this), 504 &HostNPScriptObject::ReadPolicyAndConnect, base::Unretained(this),
506 uid, auth_token, auth_service)); 505 uid, auth_token, auth_service));
507 return; 506 return;
508 } 507 }
509 508
510 SetState(kStarting); 509 SetState(kStarting);
511 510
512 // Only proceed to FinishConnect() if at least one policy update has been 511 // Only proceed to FinishConnect() if at least one policy update has been
513 // received. 512 // received.
514 if (policy_received_) { 513 if (policy_received_) {
515 FinishConnect(uid, auth_token, auth_service); 514 FinishConnectMainThread(uid, auth_token, auth_service);
516 } else { 515 } else {
517 // Otherwise, create the policy watcher, and thunk the connect. 516 // Otherwise, create the policy watcher, and thunk the connect.
518 pending_connect_ = 517 pending_connect_ =
519 base::Bind(&HostNPScriptObject::FinishConnect, 518 base::Bind(&HostNPScriptObject::FinishConnectMainThread,
520 base::Unretained(this), uid, auth_token, auth_service); 519 base::Unretained(this), uid, auth_token, auth_service);
521 } 520 }
522 } 521 }
523 522
524 void HostNPScriptObject::FinishConnect( 523 void HostNPScriptObject::FinishConnectMainThread(
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(
525 const std::string& uid, 545 const std::string& uid,
526 const std::string& auth_token, 546 const std::string& auth_token,
527 const std::string& auth_service) { 547 const std::string& auth_service) {
528 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { 548 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) {
529 host_context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( 549 host_context_->network_task_runner()->PostTask(FROM_HERE, base::Bind(
530 &HostNPScriptObject::FinishConnect, base::Unretained(this), 550 &HostNPScriptObject::FinishConnectNetworkThread, base::Unretained(this),
531 uid, auth_token, auth_service)); 551 uid, auth_token, auth_service));
532 return; 552 return;
533 } 553 }
534 554
535 if (state_ != kStarting) { 555 if (state_ != kStarting) {
536 // Host has been stopped while we were fetching policy. 556 // Host has been stopped while we were fetching policy.
537 return; 557 return;
538 } 558 }
539 559
540 // Check the host domain policy. 560 // Check the host domain policy.
541 if (!required_host_domain_.empty() && 561 if (!required_host_domain_.empty() &&
542 !EndsWith(uid, std::string("@") + required_host_domain_, false)) { 562 !EndsWith(uid, std::string("@") + required_host_domain_, false)) {
543 SetState(kError); 563 SetState(kError);
544 return; 564 return;
545 } 565 }
546 566
567 // Verify that DesktopEnvironment has been created.
568 if (desktop_environment_.get() == NULL) {
569 SetState(kError);
570 return;
571 }
572
547 // Generate a key pair for the Host to use. 573 // Generate a key pair for the Host to use.
548 // TODO(wez): Move this to the worker thread. 574 // TODO(wez): Move this to the worker thread.
549 host_key_pair_.Generate(); 575 host_key_pair_.Generate();
550 576
551 // Create XMPP connection. 577 // Create XMPP connection.
552 scoped_ptr<SignalStrategy> signal_strategy( 578 scoped_ptr<SignalStrategy> signal_strategy(
553 new XmppSignalStrategy(host_context_->url_request_context_getter(), 579 new XmppSignalStrategy(host_context_->url_request_context_getter(),
554 uid, auth_token, auth_service)); 580 uid, auth_token, auth_service));
555 581
556 // Request registration of the host for support. 582 // Request registration of the host for support.
(...skipping 13 matching lines...) Expand all
570 nat_traversal_enabled_ ? 596 nat_traversal_enabled_ ?
571 NetworkSettings::NAT_TRAVERSAL_ENABLED : 597 NetworkSettings::NAT_TRAVERSAL_ENABLED :
572 NetworkSettings::NAT_TRAVERSAL_DISABLED); 598 NetworkSettings::NAT_TRAVERSAL_DISABLED);
573 if (!nat_traversal_enabled_) { 599 if (!nat_traversal_enabled_) {
574 network_settings.min_port = NetworkSettings::kDefaultMinPort; 600 network_settings.min_port = NetworkSettings::kDefaultMinPort;
575 network_settings.max_port = NetworkSettings::kDefaultMaxPort; 601 network_settings.max_port = NetworkSettings::kDefaultMaxPort;
576 } 602 }
577 603
578 // Create the Host. 604 // Create the Host.
579 host_ = new ChromotingHost( 605 host_ = new ChromotingHost(
580 host_context_.get(), signal_strategy_.get(), 606 host_context_.get(), signal_strategy_.get(), desktop_environment_.get(),
581 desktop_environment_factory_.get(),
582 CreateHostSessionManager(network_settings, 607 CreateHostSessionManager(network_settings,
583 host_context_->url_request_context_getter())); 608 host_context_->url_request_context_getter()));
584 host_->AddStatusObserver(this); 609 host_->AddStatusObserver(this);
585 log_to_server_.reset( 610 log_to_server_.reset(
586 new LogToServer(host_, ServerLogEntry::IT2ME, signal_strategy_.get())); 611 new LogToServer(host_, ServerLogEntry::IT2ME, signal_strategy_.get()));
587 base::Closure disconnect_callback = base::Bind( 612 base::Closure disconnect_callback = base::Bind(
588 &ChromotingHost::Shutdown, base::Unretained(host_.get()), 613 &ChromotingHost::Shutdown, base::Unretained(host_.get()),
589 base::Closure()); 614 base::Closure());
590 it2me_host_user_interface_->Start(host_.get(), disconnect_callback); 615 it2me_host_user_interface_->Start(host_.get(), disconnect_callback);
591 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName); 616 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName);
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 FROM_HERE, base::Bind(&HostNPScriptObject::DisconnectInternal, 888 FROM_HERE, base::Bind(&HostNPScriptObject::DisconnectInternal,
864 base::Unretained(this))); 889 base::Unretained(this)));
865 return; 890 return;
866 } 891 }
867 892
868 switch (state_) { 893 switch (state_) {
869 case kDisconnected: 894 case kDisconnected:
870 return; 895 return;
871 896
872 case kStarting: 897 case kStarting:
898 desktop_environment_.reset();
873 SetState(kDisconnecting); 899 SetState(kDisconnecting);
874 SetState(kDisconnected); 900 SetState(kDisconnected);
875 return; 901 return;
876 902
877 case kDisconnecting: 903 case kDisconnecting:
878 return; 904 return;
879 905
880 default: 906 default:
881 SetState(kDisconnecting); 907 SetState(kDisconnecting);
882 908
883 if (!host_) { 909 if (!host_) {
884 OnShutdownFinished(); 910 OnShutdownFinished();
885 return; 911 return;
886 } 912 }
887 // ChromotingHost::Shutdown() may destroy SignalStrategy 913 // ChromotingHost::Shutdown() may destroy SignalStrategy
888 // synchronously, but SignalStrategy::Listener handlers are not 914 // synchronously, but SignalStrategy::Listener handlers are not
889 // allowed to destroy SignalStrategy, so post task to call 915 // allowed to destroy SignalStrategy, so post task to call
890 // Shutdown() later. 916 // Shutdown() later.
891 host_context_->network_task_runner()->PostTask( 917 host_context_->network_task_runner()->PostTask(
892 FROM_HERE, base::Bind( 918 FROM_HERE, base::Bind(
893 &ChromotingHost::Shutdown, host_, 919 &ChromotingHost::Shutdown, host_,
894 base::Bind(&HostNPScriptObject::OnShutdownFinished, 920 base::Bind(&HostNPScriptObject::OnShutdownFinished,
895 base::Unretained(this)))); 921 base::Unretained(this))));
896 return; 922 return;
897 } 923 }
898 } 924 }
899 925
900 void HostNPScriptObject::OnShutdownFinished() { 926 void HostNPScriptObject::OnShutdownFinished() {
901 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 927 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
928
929 desktop_environment_.reset();
902 } 930 }
903 931
904 void HostNPScriptObject::OnPolicyUpdate( 932 void HostNPScriptObject::OnPolicyUpdate(
905 scoped_ptr<base::DictionaryValue> policies) { 933 scoped_ptr<base::DictionaryValue> policies) {
906 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { 934 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) {
907 host_context_->network_task_runner()->PostTask( 935 host_context_->network_task_runner()->PostTask(
908 FROM_HERE, 936 FROM_HERE,
909 base::Bind(&HostNPScriptObject::OnPolicyUpdate, 937 base::Bind(&HostNPScriptObject::OnPolicyUpdate,
910 base::Unretained(this), base::Passed(&policies))); 938 base::Unretained(this), base::Passed(&policies)));
911 return; 939 return;
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 return is_good; 1311 return is_good;
1284 } 1312 }
1285 1313
1286 void HostNPScriptObject::SetException(const std::string& exception_string) { 1314 void HostNPScriptObject::SetException(const std::string& exception_string) {
1287 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 1315 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
1288 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); 1316 g_npnetscape_funcs->setexception(parent_, exception_string.c_str());
1289 LOG(INFO) << exception_string; 1317 LOG(INFO) << exception_string;
1290 } 1318 }
1291 1319
1292 } // namespace remoting 1320 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/plugin/host_script_object.h ('k') | remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698