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

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

Issue 11316247: Use AutoThread in ChromotingHostContext & NPAPI plugin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix ChromotingHostContext.StartAndStop test to run message loop. 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 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 HostNPScriptObject::HostNPScriptObject( 659 HostNPScriptObject::HostNPScriptObject(
660 NPP plugin, 660 NPP plugin,
661 NPObject* parent, 661 NPObject* parent,
662 scoped_refptr<AutoThreadTaskRunner> plugin_task_runner) 662 scoped_refptr<AutoThreadTaskRunner> plugin_task_runner)
663 : plugin_(plugin), 663 : plugin_(plugin),
664 parent_(parent), 664 parent_(parent),
665 plugin_task_runner_(plugin_task_runner), 665 plugin_task_runner_(plugin_task_runner),
666 am_currently_logging_(false), 666 am_currently_logging_(false),
667 state_(kDisconnected), 667 state_(kDisconnected),
668 daemon_controller_(DaemonController::Create()), 668 daemon_controller_(DaemonController::Create()),
669 worker_thread_("RemotingHostPlugin"),
670 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 669 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
671 weak_ptr_(weak_factory_.GetWeakPtr()) { 670 weak_ptr_(weak_factory_.GetWeakPtr()) {
672 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 671 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
673 672
674 worker_thread_.Start(); 673 // Create worker thread for encryption key generation.
674 worker_thread_ = AutoThread::Create("ChromotingWorkerThread",
675 plugin_task_runner_);
675 } 676 }
676 677
677 HostNPScriptObject::~HostNPScriptObject() { 678 HostNPScriptObject::~HostNPScriptObject() {
678 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 679 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
679 680
680 HostLogHandler::UnregisterLoggingScriptObject(this); 681 HostLogHandler::UnregisterLoggingScriptObject(this);
681 682
682 // Stop the It2Me host if the caller forgot to. 683 // Stop the It2Me host if the caller forgot to.
683 if (it2me_impl_.get()) { 684 if (it2me_impl_.get()) {
684 it2me_impl_->Disconnect(); 685 it2me_impl_->Disconnect();
685 it2me_impl_ = NULL; 686 it2me_impl_ = NULL;
686 } 687 }
687
688 // Stop the worker thread.
689 worker_thread_.Stop();
690 } 688 }
691 689
692 bool HostNPScriptObject::HasMethod(const std::string& method_name) { 690 bool HostNPScriptObject::HasMethod(const std::string& method_name) {
693 VLOG(2) << "HasMethod " << method_name; 691 VLOG(2) << "HasMethod " << method_name;
694 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 692 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
695 return (method_name == kFuncNameConnect || 693 return (method_name == kFuncNameConnect ||
696 method_name == kFuncNameDisconnect || 694 method_name == kFuncNameDisconnect ||
697 method_name == kFuncNameLocalize || 695 method_name == kFuncNameLocalize ||
698 method_name == kFuncNameGetHostName || 696 method_name == kFuncNameGetHostName ||
699 method_name == kFuncNameGetPinHash || 697 method_name == kFuncNameGetPinHash ||
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 std::string auth_token; 946 std::string auth_token;
949 std::string auth_service; 947 std::string auth_service;
950 ParseAuthTokenWithService(auth_service_with_token, &auth_token, 948 ParseAuthTokenWithService(auth_service_with_token, &auth_token,
951 &auth_service); 949 &auth_service);
952 if (auth_token.empty()) { 950 if (auth_token.empty()) {
953 SetException("connect: auth_service_with_token argument has empty token"); 951 SetException("connect: auth_service_with_token argument has empty token");
954 return false; 952 return false;
955 } 953 }
956 954
957 // Create threads for the Chromoting host & desktop environment to use. 955 // Create threads for the Chromoting host & desktop environment to use.
958 scoped_ptr<ChromotingHostContext> host_context( 956 scoped_ptr<ChromotingHostContext> host_context =
959 new ChromotingHostContext(plugin_task_runner_)); 957 ChromotingHostContext::Create(plugin_task_runner_);
960 if (!host_context->Start()) { 958 if (host_context) {
961 SetException("connect: failed to start threads"); 959 SetException("connect: failed to start threads");
962 return false; 960 return false;
963 } 961 }
964 962
965 // Create the It2Me host implementation and start connecting. 963 // Create the It2Me host implementation and start connecting.
966 it2me_impl_ = new It2MeImpl( 964 it2me_impl_ = new It2MeImpl(
967 host_context.Pass(), plugin_task_runner_, weak_ptr_, ui_strings_); 965 host_context.Pass(), plugin_task_runner_, weak_ptr_, ui_strings_);
968 it2me_impl_->Connect(uid, auth_token, auth_service); 966 it2me_impl_->Connect(uid, auth_token, auth_service);
969 967
970 return true; 968 return true;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 1051
1054 ScopedRefNPObject callback_obj(ObjectFromNPVariant(args[0])); 1052 ScopedRefNPObject callback_obj(ObjectFromNPVariant(args[0]));
1055 if (!callback_obj.get()) { 1053 if (!callback_obj.get()) {
1056 SetException("generateKeyPair: invalid callback parameter"); 1054 SetException("generateKeyPair: invalid callback parameter");
1057 return false; 1055 return false;
1058 } 1056 }
1059 1057
1060 // TODO(wez): HostNPScriptObject needn't be touched on worker 1058 // TODO(wez): HostNPScriptObject needn't be touched on worker
1061 // thread, so make DoGenerateKeyPair static and pass it a callback 1059 // thread, so make DoGenerateKeyPair static and pass it a callback
1062 // to run (crbug.com/156257). 1060 // to run (crbug.com/156257).
1063 worker_thread_.message_loop_proxy()->PostTask( 1061 worker_thread_->PostTask(
1064 FROM_HERE, base::Bind(&HostNPScriptObject::DoGenerateKeyPair, 1062 FROM_HERE, base::Bind(&HostNPScriptObject::DoGenerateKeyPair,
1065 base::Unretained(this), callback_obj)); 1063 base::Unretained(this), callback_obj));
1066 return true; 1064 return true;
1067 } 1065 }
1068 1066
1069 bool HostNPScriptObject::UpdateDaemonConfig(const NPVariant* args, 1067 bool HostNPScriptObject::UpdateDaemonConfig(const NPVariant* args,
1070 uint32_t arg_count, 1068 uint32_t arg_count,
1071 NPVariant* result) { 1069 NPVariant* result) {
1072 if (arg_count != 2) { 1070 if (arg_count != 2) {
1073 SetException("updateDaemonConfig: bad number of arguments"); 1071 SetException("updateDaemonConfig: bad number of arguments");
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 } 1491 }
1494 1492
1495 void HostNPScriptObject::SetException(const std::string& exception_string) { 1493 void HostNPScriptObject::SetException(const std::string& exception_string) {
1496 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 1494 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
1497 1495
1498 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); 1496 g_npnetscape_funcs->setexception(parent_, exception_string.c_str());
1499 LOG(INFO) << exception_string; 1497 LOG(INFO) << exception_string;
1500 } 1498 }
1501 1499
1502 } // namespace remoting 1500 } // 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