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