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

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

Issue 11412305: Use AutoThread in ChromotingHostContext & NPAPI plugin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 8 years 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"
19 #include "remoting/base/auth_token_util.h" 18 #include "remoting/base/auth_token_util.h"
19 #include "remoting/base/auto_thread.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_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/host_status_observer.h" 27 #include "remoting/host/host_status_observer.h"
28 #include "remoting/host/it2me_host_user_interface.h" 28 #include "remoting/host/it2me_host_user_interface.h"
29 #include "remoting/host/network_settings.h" 29 #include "remoting/host/network_settings.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 virtual void OnAccessDenied(const std::string& jid) OVERRIDE; 107 virtual void OnAccessDenied(const std::string& jid) OVERRIDE;
108 virtual void OnClientAuthenticated(const std::string& jid) OVERRIDE; 108 virtual void OnClientAuthenticated(const std::string& jid) OVERRIDE;
109 virtual void OnClientDisconnected(const std::string& jid) OVERRIDE; 109 virtual void OnClientDisconnected(const std::string& jid) OVERRIDE;
110 virtual void OnShutdown() OVERRIDE; 110 virtual void OnShutdown() OVERRIDE;
111 111
112 private: 112 private:
113 friend class base::RefCountedThreadSafe<It2MeImpl>; 113 friend class base::RefCountedThreadSafe<It2MeImpl>;
114 114
115 virtual ~It2MeImpl(); 115 virtual ~It2MeImpl();
116 116
117 // Used to delete and join the ChromotingHostContext on the UI thread.
118 static void DeleteHostContext(scoped_ptr<ChromotingHostContext> context) {}
119
120 // Updates state of the host. Can be called only on the network thread. 117 // Updates state of the host. Can be called only on the network thread.
121 void SetState(State state); 118 void SetState(State state);
122 119
123 // Returns true if the host is connected. 120 // Returns true if the host is connected.
124 bool IsConnected() const; 121 bool IsConnected() const;
125 122
126 // Called by Connect() to check for policies and start connection process. 123 // Called by Connect() to check for policies and start connection process.
127 void ReadPolicyAndConnect(const std::string& uid, 124 void ReadPolicyAndConnect(const std::string& uid,
128 const std::string& auth_token, 125 const std::string& auth_token,
129 const std::string& auth_service); 126 const std::string& auth_service);
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 } 549 }
553 550
554 required_host_domain_ = host_domain; 551 required_host_domain_ = host_domain;
555 } 552 }
556 553
557 HostNPScriptObject::It2MeImpl::~It2MeImpl() { 554 HostNPScriptObject::It2MeImpl::~It2MeImpl() {
558 // Check that resources that need to be torn down on the UI thread are gone. 555 // Check that resources that need to be torn down on the UI thread are gone.
559 DCHECK(!it2me_host_user_interface_.get()); 556 DCHECK(!it2me_host_user_interface_.get());
560 DCHECK(!desktop_environment_factory_.get()); 557 DCHECK(!desktop_environment_factory_.get());
561 DCHECK(!policy_watcher_.get()); 558 DCHECK(!policy_watcher_.get());
562
563 // We might be getting deleted on one of the threads the |host_context| owns,
564 // so we need to post it back to the plugin thread to safely join & delete the
565 // threads it contains. This will go away when we move to AutoThread.
566 plugin_task_runner_->PostTask(FROM_HERE,
567 base::Bind(&It2MeImpl::DeleteHostContext, base::Passed(&host_context_)));
568 } 559 }
569 560
570 void HostNPScriptObject::It2MeImpl::SetState(State state) { 561 void HostNPScriptObject::It2MeImpl::SetState(State state) {
571 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 562 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
572 563
573 switch (state_) { 564 switch (state_) {
574 case kDisconnected: 565 case kDisconnected:
575 DCHECK(state == kStarting || 566 DCHECK(state == kStarting ||
576 state == kError) << state; 567 state == kError) << state;
577 break; 568 break;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 HostNPScriptObject::HostNPScriptObject( 650 HostNPScriptObject::HostNPScriptObject(
660 NPP plugin, 651 NPP plugin,
661 NPObject* parent, 652 NPObject* parent,
662 scoped_refptr<AutoThreadTaskRunner> plugin_task_runner) 653 scoped_refptr<AutoThreadTaskRunner> plugin_task_runner)
663 : plugin_(plugin), 654 : plugin_(plugin),
664 parent_(parent), 655 parent_(parent),
665 plugin_task_runner_(plugin_task_runner), 656 plugin_task_runner_(plugin_task_runner),
666 am_currently_logging_(false), 657 am_currently_logging_(false),
667 state_(kDisconnected), 658 state_(kDisconnected),
668 daemon_controller_(DaemonController::Create()), 659 daemon_controller_(DaemonController::Create()),
669 worker_thread_("RemotingHostPlugin"),
670 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 660 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
671 weak_ptr_(weak_factory_.GetWeakPtr()) { 661 weak_ptr_(weak_factory_.GetWeakPtr()) {
672 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 662 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
673 663
674 worker_thread_.Start(); 664 // Create worker thread for encryption key generation.
665 worker_thread_ = AutoThread::Create("ChromotingWorkerThread",
666 plugin_task_runner_);
675 } 667 }
676 668
677 HostNPScriptObject::~HostNPScriptObject() { 669 HostNPScriptObject::~HostNPScriptObject() {
678 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 670 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
679 671
680 HostLogHandler::UnregisterLoggingScriptObject(this); 672 HostLogHandler::UnregisterLoggingScriptObject(this);
681 673
682 // Stop the It2Me host if the caller forgot to. 674 // Stop the It2Me host if the caller forgot to.
683 if (it2me_impl_.get()) { 675 if (it2me_impl_.get()) {
684 it2me_impl_->Disconnect(); 676 it2me_impl_->Disconnect();
685 it2me_impl_ = NULL; 677 it2me_impl_ = NULL;
686 } 678 }
687
688 // Stop the worker thread.
689 worker_thread_.Stop();
690 } 679 }
691 680
692 bool HostNPScriptObject::HasMethod(const std::string& method_name) { 681 bool HostNPScriptObject::HasMethod(const std::string& method_name) {
693 VLOG(2) << "HasMethod " << method_name; 682 VLOG(2) << "HasMethod " << method_name;
694 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 683 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
695 return (method_name == kFuncNameConnect || 684 return (method_name == kFuncNameConnect ||
696 method_name == kFuncNameDisconnect || 685 method_name == kFuncNameDisconnect ||
697 method_name == kFuncNameLocalize || 686 method_name == kFuncNameLocalize ||
698 method_name == kFuncNameGetHostName || 687 method_name == kFuncNameGetHostName ||
699 method_name == kFuncNameGetPinHash || 688 method_name == kFuncNameGetPinHash ||
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 std::string auth_token; 937 std::string auth_token;
949 std::string auth_service; 938 std::string auth_service;
950 ParseAuthTokenWithService(auth_service_with_token, &auth_token, 939 ParseAuthTokenWithService(auth_service_with_token, &auth_token,
951 &auth_service); 940 &auth_service);
952 if (auth_token.empty()) { 941 if (auth_token.empty()) {
953 SetException("connect: auth_service_with_token argument has empty token"); 942 SetException("connect: auth_service_with_token argument has empty token");
954 return false; 943 return false;
955 } 944 }
956 945
957 // Create threads for the Chromoting host & desktop environment to use. 946 // Create threads for the Chromoting host & desktop environment to use.
958 scoped_ptr<ChromotingHostContext> host_context( 947 scoped_ptr<ChromotingHostContext> host_context =
959 new ChromotingHostContext(plugin_task_runner_)); 948 ChromotingHostContext::Create(plugin_task_runner_);
960 if (!host_context->Start()) { 949 if (!host_context) {
961 SetException("connect: failed to start threads"); 950 SetException("connect: failed to start threads");
962 return false; 951 return false;
963 } 952 }
964 953
965 // Create the It2Me host implementation and start connecting. 954 // Create the It2Me host implementation and start connecting.
966 it2me_impl_ = new It2MeImpl( 955 it2me_impl_ = new It2MeImpl(
967 host_context.Pass(), plugin_task_runner_, weak_ptr_, ui_strings_); 956 host_context.Pass(), plugin_task_runner_, weak_ptr_, ui_strings_);
968 it2me_impl_->Connect(uid, auth_token, auth_service); 957 it2me_impl_->Connect(uid, auth_token, auth_service);
969 958
970 return true; 959 return true;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 1042
1054 ScopedRefNPObject callback_obj(ObjectFromNPVariant(args[0])); 1043 ScopedRefNPObject callback_obj(ObjectFromNPVariant(args[0]));
1055 if (!callback_obj.get()) { 1044 if (!callback_obj.get()) {
1056 SetException("generateKeyPair: invalid callback parameter"); 1045 SetException("generateKeyPair: invalid callback parameter");
1057 return false; 1046 return false;
1058 } 1047 }
1059 1048
1060 // TODO(wez): HostNPScriptObject needn't be touched on worker 1049 // TODO(wez): HostNPScriptObject needn't be touched on worker
1061 // thread, so make DoGenerateKeyPair static and pass it a callback 1050 // thread, so make DoGenerateKeyPair static and pass it a callback
1062 // to run (crbug.com/156257). 1051 // to run (crbug.com/156257).
1063 worker_thread_.message_loop_proxy()->PostTask( 1052 worker_thread_->PostTask(
1064 FROM_HERE, base::Bind(&HostNPScriptObject::DoGenerateKeyPair, 1053 FROM_HERE, base::Bind(&HostNPScriptObject::DoGenerateKeyPair,
1065 base::Unretained(this), callback_obj)); 1054 base::Unretained(this), callback_obj));
1066 return true; 1055 return true;
1067 } 1056 }
1068 1057
1069 bool HostNPScriptObject::UpdateDaemonConfig(const NPVariant* args, 1058 bool HostNPScriptObject::UpdateDaemonConfig(const NPVariant* args,
1070 uint32_t arg_count, 1059 uint32_t arg_count,
1071 NPVariant* result) { 1060 NPVariant* result) {
1072 if (arg_count != 2) { 1061 if (arg_count != 2) {
1073 SetException("updateDaemonConfig: bad number of arguments"); 1062 SetException("updateDaemonConfig: bad number of arguments");
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 } 1482 }
1494 1483
1495 void HostNPScriptObject::SetException(const std::string& exception_string) { 1484 void HostNPScriptObject::SetException(const std::string& exception_string) {
1496 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 1485 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
1497 1486
1498 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); 1487 g_npnetscape_funcs->setexception(parent_, exception_string.c_str());
1499 LOG(INFO) << exception_string; 1488 LOG(INFO) << exception_string;
1500 } 1489 }
1501 1490
1502 } // namespace remoting 1491 } // 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