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

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

Issue 10916263: [Chromoting] Refactoring DesktopEnvironment and moving screen/audio recorders to ClientSession. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased 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.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 stopped_event_(true, false), 99 stopped_event_(true, false),
99 nat_traversal_enabled_(false), 100 nat_traversal_enabled_(false),
100 policy_received_(false), 101 policy_received_(false),
101 daemon_controller_(DaemonController::Create()), 102 daemon_controller_(DaemonController::Create()),
102 worker_thread_("RemotingHostPlugin") { 103 worker_thread_("RemotingHostPlugin") {
103 worker_thread_.Start(); 104 worker_thread_.Start();
104 } 105 }
105 106
(...skipping 30 matching lines...) Expand all
136 // UI needs to be shut down on the UI thread before we destroy the 137 // UI needs to be shut down on the UI thread before we destroy the
137 // host context (because it depends on the context object), but 138 // host context (because it depends on the context object), but
138 // only after the host has been shut down (becase the UI object is 139 // only after the host has been shut down (becase the UI object is
139 // registered as status observer for the host, and we can't 140 // registered as status observer for the host, and we can't
140 // unregister it from this thread). 141 // unregister it from this thread).
141 it2me_host_user_interface_.reset(); 142 it2me_host_user_interface_.reset();
142 143
143 // Release the context's TaskRunner references for the threads, so they can 144 // Release the context's TaskRunner references for the threads, so they can
144 // exit when no objects need them. 145 // exit when no objects need them.
145 host_context_->ReleaseTaskRunners(); 146 host_context_->ReleaseTaskRunners();
146 desktop_environment_.reset();
147 147
148 // |stopped_event_| is signalled when the last reference to the plugin 148 // |stopped_event_| is signalled when the last reference to the plugin
149 // thread is dropped. 149 // thread is dropped.
150 stopped_event_.Wait(); 150 stopped_event_.Wait();
151 151
152 // Stop all threads. 152 // Stop all threads.
153 host_context_.reset(); 153 host_context_.reset();
154 } 154 }
155 155
156 worker_thread_.Stop(); 156 worker_thread_.Stop();
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 &HostNPScriptObject::ReadPolicyAndConnect, base::Unretained(this), 510 &HostNPScriptObject::ReadPolicyAndConnect, base::Unretained(this),
511 uid, auth_token, auth_service)); 511 uid, auth_token, auth_service));
512 return; 512 return;
513 } 513 }
514 514
515 SetState(kStarting); 515 SetState(kStarting);
516 516
517 // Only proceed to FinishConnect() if at least one policy update has been 517 // Only proceed to FinishConnect() if at least one policy update has been
518 // received. 518 // received.
519 if (policy_received_) { 519 if (policy_received_) {
520 FinishConnectMainThread(uid, auth_token, auth_service); 520 FinishConnect(uid, auth_token, auth_service);
521 } else { 521 } else {
522 // Otherwise, create the policy watcher, and thunk the connect. 522 // Otherwise, create the policy watcher, and thunk the connect.
523 pending_connect_ = 523 pending_connect_ =
524 base::Bind(&HostNPScriptObject::FinishConnectMainThread, 524 base::Bind(&HostNPScriptObject::FinishConnect,
525 base::Unretained(this), uid, auth_token, auth_service); 525 base::Unretained(this), uid, auth_token, auth_service);
526 } 526 }
527 } 527 }
528 528
529 void HostNPScriptObject::FinishConnectMainThread( 529 void HostNPScriptObject::FinishConnect(
530 const std::string& uid,
531 const std::string& auth_token,
532 const std::string& auth_service) {
533 if (!host_context_->capture_task_runner()->BelongsToCurrentThread()) {
534 host_context_->capture_task_runner()->PostTask(FROM_HERE, base::Bind(
535 &HostNPScriptObject::FinishConnectMainThread, base::Unretained(this),
536 uid, auth_token, auth_service));
537 return;
538 }
539
540 // DesktopEnvironment must be initialized on the capture thread.
541 //
542 // TODO(sergeyu): Fix DesktopEnvironment so that it can be created
543 // on either the UI or the network thread so that we can avoid
544 // jumping to the main thread here.
545 desktop_environment_ = DesktopEnvironment::Create(host_context_.get());
546
547 FinishConnectNetworkThread(uid, auth_token, auth_service);
548 }
549
550 void HostNPScriptObject::FinishConnectNetworkThread(
551 const std::string& uid, 530 const std::string& uid,
552 const std::string& auth_token, 531 const std::string& auth_token,
553 const std::string& auth_service) { 532 const std::string& auth_service) {
554 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { 533 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) {
555 host_context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( 534 host_context_->network_task_runner()->PostTask(FROM_HERE, base::Bind(
556 &HostNPScriptObject::FinishConnectNetworkThread, base::Unretained(this), 535 &HostNPScriptObject::FinishConnect, base::Unretained(this),
557 uid, auth_token, auth_service)); 536 uid, auth_token, auth_service));
558 return; 537 return;
559 } 538 }
560 539
561 if (state_ != kStarting) { 540 if (state_ != kStarting) {
562 // Host has been stopped while we were fetching policy. 541 // Host has been stopped while we were fetching policy.
563 return; 542 return;
564 } 543 }
565 544
566 // Check the host domain policy. 545 // Check the host domain policy.
567 if (!required_host_domain_.empty() && 546 if (!required_host_domain_.empty() &&
568 !EndsWith(uid, std::string("@") + required_host_domain_, false)) { 547 !EndsWith(uid, std::string("@") + required_host_domain_, false)) {
569 SetState(kError); 548 SetState(kError);
570 return; 549 return;
571 } 550 }
572 551
573 // Verify that DesktopEnvironment has been created.
574 if (desktop_environment_.get() == NULL) {
575 SetState(kError);
576 return;
577 }
578
579 // Generate a key pair for the Host to use. 552 // Generate a key pair for the Host to use.
580 // TODO(wez): Move this to the worker thread. 553 // TODO(wez): Move this to the worker thread.
581 host_key_pair_.Generate(); 554 host_key_pair_.Generate();
582 555
583 // Create XMPP connection. 556 // Create XMPP connection.
584 scoped_ptr<SignalStrategy> signal_strategy( 557 scoped_ptr<SignalStrategy> signal_strategy(
585 new XmppSignalStrategy(host_context_->url_request_context_getter(), 558 new XmppSignalStrategy(host_context_->url_request_context_getter(),
586 uid, auth_token, auth_service)); 559 uid, auth_token, auth_service));
587 560
588 // Request registration of the host for support. 561 // Request registration of the host for support.
(...skipping 13 matching lines...) Expand all
602 nat_traversal_enabled_ ? 575 nat_traversal_enabled_ ?
603 NetworkSettings::NAT_TRAVERSAL_ENABLED : 576 NetworkSettings::NAT_TRAVERSAL_ENABLED :
604 NetworkSettings::NAT_TRAVERSAL_DISABLED); 577 NetworkSettings::NAT_TRAVERSAL_DISABLED);
605 if (!nat_traversal_enabled_) { 578 if (!nat_traversal_enabled_) {
606 network_settings.min_port = NetworkSettings::kDefaultMinPort; 579 network_settings.min_port = NetworkSettings::kDefaultMinPort;
607 network_settings.max_port = NetworkSettings::kDefaultMaxPort; 580 network_settings.max_port = NetworkSettings::kDefaultMaxPort;
608 } 581 }
609 582
610 // Create the Host. 583 // Create the Host.
611 host_ = new ChromotingHost( 584 host_ = new ChromotingHost(
612 host_context_.get(), signal_strategy_.get(), desktop_environment_.get(), 585 host_context_.get(), signal_strategy_.get(),
586 desktop_environment_factory_.get(),
613 CreateHostSessionManager(network_settings, 587 CreateHostSessionManager(network_settings,
614 host_context_->url_request_context_getter())); 588 host_context_->url_request_context_getter()));
615 host_->AddStatusObserver(this); 589 host_->AddStatusObserver(this);
616 log_to_server_.reset( 590 log_to_server_.reset(
617 new LogToServer(host_, ServerLogEntry::IT2ME, signal_strategy_.get())); 591 new LogToServer(host_, ServerLogEntry::IT2ME, signal_strategy_.get()));
618 base::Closure disconnect_callback = base::Bind( 592 base::Closure disconnect_callback = base::Bind(
619 &ChromotingHost::Shutdown, base::Unretained(host_.get()), 593 &ChromotingHost::Shutdown, base::Unretained(host_.get()),
620 base::Closure()); 594 base::Closure());
621 it2me_host_user_interface_->Start(host_.get(), disconnect_callback); 595 it2me_host_user_interface_->Start(host_.get(), disconnect_callback);
622 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName); 596 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName);
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 return is_good; 1292 return is_good;
1319 } 1293 }
1320 1294
1321 void HostNPScriptObject::SetException(const std::string& exception_string) { 1295 void HostNPScriptObject::SetException(const std::string& exception_string) {
1322 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 1296 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
1323 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); 1297 g_npnetscape_funcs->setexception(parent_, exception_string.c_str());
1324 LOG(INFO) << exception_string; 1298 LOG(INFO) << exception_string;
1325 } 1299 }
1326 1300
1327 } // namespace remoting 1301 } // 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