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

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

Issue 10572005: Use SingleThreadTaskRunner instead of MessageLoopProxy in remoting/host. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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/policy_hack/nat_policy.h » ('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"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 HostNPScriptObject::HostNPScriptObject( 79 HostNPScriptObject::HostNPScriptObject(
80 NPP plugin, 80 NPP plugin,
81 NPObject* parent, 81 NPObject* parent,
82 PluginMessageLoopProxy::Delegate* plugin_thread_delegate) 82 PluginMessageLoopProxy::Delegate* plugin_thread_delegate)
83 : plugin_(plugin), 83 : plugin_(plugin),
84 parent_(parent), 84 parent_(parent),
85 am_currently_logging_(false), 85 am_currently_logging_(false),
86 state_(kDisconnected), 86 state_(kDisconnected),
87 np_thread_id_(base::PlatformThread::CurrentId()), 87 np_thread_id_(base::PlatformThread::CurrentId()),
88 plugin_message_loop_proxy_( 88 plugin_task_runner_(
89 new PluginMessageLoopProxy(plugin_thread_delegate)), 89 new PluginMessageLoopProxy(plugin_thread_delegate)),
90 failed_login_attempts_(0), 90 failed_login_attempts_(0),
91 disconnected_event_(true, false), 91 disconnected_event_(true, false),
92 nat_traversal_enabled_(false), 92 nat_traversal_enabled_(false),
93 policy_received_(false), 93 policy_received_(false),
94 daemon_controller_(DaemonController::Create()), 94 daemon_controller_(DaemonController::Create()),
95 worker_thread_("RemotingHostPlugin") { 95 worker_thread_("RemotingHostPlugin") {
96 worker_thread_.Start(); 96 worker_thread_.Start();
97 } 97 }
98 98
99 HostNPScriptObject::~HostNPScriptObject() { 99 HostNPScriptObject::~HostNPScriptObject() {
100 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); 100 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
101 101
102 HostLogHandler::UnregisterLoggingScriptObject(this); 102 HostLogHandler::UnregisterLoggingScriptObject(this);
103 103
104 plugin_message_loop_proxy_->Detach(); 104 plugin_task_runner_->Detach();
105 105
106 // Stop listening for policy updates. 106 // Stop listening for policy updates.
107 if (nat_policy_.get()) { 107 if (nat_policy_.get()) {
108 base::WaitableEvent nat_policy_stopped_(true, false); 108 base::WaitableEvent nat_policy_stopped_(true, false);
109 nat_policy_->StopWatching(&nat_policy_stopped_); 109 nat_policy_->StopWatching(&nat_policy_stopped_);
110 nat_policy_stopped_.Wait(); 110 nat_policy_stopped_.Wait();
111 nat_policy_.reset(); 111 nat_policy_.reset();
112 } 112 }
113 113
114 if (host_context_.get()) { 114 if (host_context_.get()) {
(...skipping 13 matching lines...) Expand all
128 it2me_host_user_interface_.reset(); 128 it2me_host_user_interface_.reset();
129 129
130 // Stops all threads. 130 // Stops all threads.
131 host_context_.reset(); 131 host_context_.reset();
132 } 132 }
133 133
134 worker_thread_.Stop(); 134 worker_thread_.Stop();
135 } 135 }
136 136
137 bool HostNPScriptObject::Init() { 137 bool HostNPScriptObject::Init() {
138 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); 138 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
139 VLOG(2) << "Init"; 139 VLOG(2) << "Init";
140 140
141 host_context_.reset(new ChromotingHostContext(plugin_message_loop_proxy_)); 141 host_context_.reset(new ChromotingHostContext(plugin_task_runner_));
142 if (!host_context_->Start()) { 142 if (!host_context_->Start()) {
143 host_context_.reset(); 143 host_context_.reset();
144 return false; 144 return false;
145 } 145 }
146 146
147 nat_policy_.reset( 147 nat_policy_.reset(
148 policy_hack::NatPolicy::Create(host_context_->network_message_loop())); 148 policy_hack::NatPolicy::Create(host_context_->network_task_runner()));
149 nat_policy_->StartWatching( 149 nat_policy_->StartWatching(
150 base::Bind(&HostNPScriptObject::OnNatPolicyUpdate, 150 base::Bind(&HostNPScriptObject::OnNatPolicyUpdate,
151 base::Unretained(this))); 151 base::Unretained(this)));
152 return true; 152 return true;
153 } 153 }
154 154
155 bool HostNPScriptObject::HasMethod(const std::string& method_name) { 155 bool HostNPScriptObject::HasMethod(const std::string& method_name) {
156 VLOG(2) << "HasMethod " << method_name; 156 VLOG(2) << "HasMethod " << method_name;
157 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); 157 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
158 return (method_name == kFuncNameConnect || 158 return (method_name == kFuncNameConnect ||
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 kFuncNameStartDaemon, 381 kFuncNameStartDaemon,
382 kFuncNameStopDaemon 382 kFuncNameStopDaemon
383 }; 383 };
384 for (size_t i = 0; i < arraysize(entries); ++i) { 384 for (size_t i = 0; i < arraysize(entries); ++i) {
385 values->push_back(entries[i]); 385 values->push_back(entries[i]);
386 } 386 }
387 return true; 387 return true;
388 } 388 }
389 389
390 void HostNPScriptObject::OnAccessDenied(const std::string& jid) { 390 void HostNPScriptObject::OnAccessDenied(const std::string& jid) {
391 DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); 391 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
392 392
393 ++failed_login_attempts_; 393 ++failed_login_attempts_;
394 if (failed_login_attempts_ == kMaxLoginAttempts) { 394 if (failed_login_attempts_ == kMaxLoginAttempts) {
395 DisconnectInternal(); 395 DisconnectInternal();
396 } 396 }
397 } 397 }
398 398
399 void HostNPScriptObject::OnClientAuthenticated(const std::string& jid) { 399 void HostNPScriptObject::OnClientAuthenticated(const std::string& jid) {
400 DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); 400 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
401 401
402 if (state_ == kDisconnecting) { 402 if (state_ == kDisconnecting) {
403 // Ignore the new connection if we are disconnecting. 403 // Ignore the new connection if we are disconnecting.
404 return; 404 return;
405 } 405 }
406 406
407 client_username_ = jid; 407 client_username_ = jid;
408 size_t pos = client_username_.find('/'); 408 size_t pos = client_username_.find('/');
409 if (pos != std::string::npos) 409 if (pos != std::string::npos)
410 client_username_.replace(pos, std::string::npos, ""); 410 client_username_.replace(pos, std::string::npos, "");
411 LOG(INFO) << "Client " << client_username_ << " connected."; 411 LOG(INFO) << "Client " << client_username_ << " connected.";
412 SetState(kConnected); 412 SetState(kConnected);
413 } 413 }
414 414
415 void HostNPScriptObject::OnClientDisconnected(const std::string& jid) { 415 void HostNPScriptObject::OnClientDisconnected(const std::string& jid) {
416 DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); 416 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
417 client_username_.clear(); 417 client_username_.clear();
418 DisconnectInternal(); 418 DisconnectInternal();
419 } 419 }
420 420
421 void HostNPScriptObject::OnShutdown() { 421 void HostNPScriptObject::OnShutdown() {
422 DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); 422 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
423 423
424 register_request_.reset(); 424 register_request_.reset();
425 log_to_server_.reset(); 425 log_to_server_.reset();
426 signal_strategy_.reset(); 426 signal_strategy_.reset();
427 host_->RemoveStatusObserver(this); 427 host_->RemoveStatusObserver(this);
428 host_ = NULL; 428 host_ = NULL;
429 429
430 if (state_ != kDisconnected) { 430 if (state_ != kDisconnected) {
431 SetState(kDisconnected); 431 SetState(kDisconnected);
432 } 432 }
433 } 433 }
434 434
435 // string uid, string auth_token 435 // string uid, string auth_token
436 bool HostNPScriptObject::Connect(const NPVariant* args, 436 bool HostNPScriptObject::Connect(const NPVariant* args,
437 uint32_t arg_count, 437 uint32_t arg_count,
438 NPVariant* result) { 438 NPVariant* result) {
439 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); 439 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
440 440
441 LOG(INFO) << "Connecting..."; 441 LOG(INFO) << "Connecting...";
442 442
443 if (arg_count != 2) { 443 if (arg_count != 2) {
444 SetException("connect: bad number of arguments"); 444 SetException("connect: bad number of arguments");
445 return false; 445 return false;
446 } 446 }
447 447
448 if (state_ != kDisconnected) { 448 if (state_ != kDisconnected) {
449 SetException("connect: can be called only when disconnected"); 449 SetException("connect: can be called only when disconnected");
(...skipping 21 matching lines...) Expand all
471 new It2MeHostUserInterface(host_context_.get())); 471 new It2MeHostUserInterface(host_context_.get()));
472 472
473 ReadPolicyAndConnect(uid, auth_token, auth_service); 473 ReadPolicyAndConnect(uid, auth_token, auth_service);
474 474
475 return true; 475 return true;
476 } 476 }
477 477
478 void HostNPScriptObject::ReadPolicyAndConnect(const std::string& uid, 478 void HostNPScriptObject::ReadPolicyAndConnect(const std::string& uid,
479 const std::string& auth_token, 479 const std::string& auth_token,
480 const std::string& auth_service) { 480 const std::string& auth_service) {
481 if (!host_context_->network_message_loop()->BelongsToCurrentThread()) { 481 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) {
482 host_context_->network_message_loop()->PostTask( 482 host_context_->network_task_runner()->PostTask(
483 FROM_HERE, base::Bind( 483 FROM_HERE, base::Bind(
484 &HostNPScriptObject::ReadPolicyAndConnect, base::Unretained(this), 484 &HostNPScriptObject::ReadPolicyAndConnect, base::Unretained(this),
485 uid, auth_token, auth_service)); 485 uid, auth_token, auth_service));
486 return; 486 return;
487 } 487 }
488 488
489 SetState(kStarting); 489 SetState(kStarting);
490 490
491 // Only proceed to FinishConnect() if at least one policy update has been 491 // Only proceed to FinishConnect() if at least one policy update has been
492 // received. 492 // received.
493 if (policy_received_) { 493 if (policy_received_) {
494 FinishConnectMainThread(uid, auth_token, auth_service); 494 FinishConnectMainThread(uid, auth_token, auth_service);
495 } else { 495 } else {
496 // Otherwise, create the policy watcher, and thunk the connect. 496 // Otherwise, create the policy watcher, and thunk the connect.
497 pending_connect_ = 497 pending_connect_ =
498 base::Bind(&HostNPScriptObject::FinishConnectMainThread, 498 base::Bind(&HostNPScriptObject::FinishConnectMainThread,
499 base::Unretained(this), uid, auth_token, auth_service); 499 base::Unretained(this), uid, auth_token, auth_service);
500 } 500 }
501 } 501 }
502 502
503 void HostNPScriptObject::FinishConnectMainThread( 503 void HostNPScriptObject::FinishConnectMainThread(
504 const std::string& uid, 504 const std::string& uid,
505 const std::string& auth_token, 505 const std::string& auth_token,
506 const std::string& auth_service) { 506 const std::string& auth_service) {
507 if (host_context_->main_message_loop() != MessageLoop::current()) { 507 if (!host_context_->capture_task_runner()->BelongsToCurrentThread()) {
508 host_context_->main_message_loop()->PostTask(FROM_HERE, base::Bind( 508 host_context_->capture_task_runner()->PostTask(FROM_HERE, base::Bind(
509 &HostNPScriptObject::FinishConnectMainThread, base::Unretained(this), 509 &HostNPScriptObject::FinishConnectMainThread, base::Unretained(this),
510 uid, auth_token, auth_service)); 510 uid, auth_token, auth_service));
511 return; 511 return;
512 } 512 }
513 513
514 // DesktopEnvironment must be initialized on the main thread. 514 // DesktopEnvironment must be initialized on the capture thread.
515 // 515 //
516 // TODO(sergeyu): Fix DesktopEnvironment so that it can be created 516 // TODO(sergeyu): Fix DesktopEnvironment so that it can be created
517 // on either the UI or the network thread so that we can avoid 517 // on either the UI or the network thread so that we can avoid
518 // jumping to the main thread here. 518 // jumping to the main thread here.
519 desktop_environment_ = DesktopEnvironment::Create(host_context_.get()); 519 desktop_environment_ = DesktopEnvironment::Create(host_context_.get());
520 520
521 FinishConnectNetworkThread(uid, auth_token, auth_service); 521 FinishConnectNetworkThread(uid, auth_token, auth_service);
522 } 522 }
523 523
524 void HostNPScriptObject::FinishConnectNetworkThread( 524 void HostNPScriptObject::FinishConnectNetworkThread(
525 const std::string& uid, 525 const std::string& uid,
526 const std::string& auth_token, 526 const std::string& auth_token,
527 const std::string& auth_service) { 527 const std::string& auth_service) {
528 if (!host_context_->network_message_loop()->BelongsToCurrentThread()) { 528 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) {
529 host_context_->network_message_loop()->PostTask(FROM_HERE, base::Bind( 529 host_context_->network_task_runner()->PostTask(FROM_HERE, base::Bind(
530 &HostNPScriptObject::FinishConnectNetworkThread, base::Unretained(this), 530 &HostNPScriptObject::FinishConnectNetworkThread, base::Unretained(this),
531 uid, auth_token, auth_service)); 531 uid, auth_token, auth_service));
532 return; 532 return;
533 } 533 }
534 534
535 if (state_ != kStarting) { 535 if (state_ != kStarting) {
536 // Host has been stopped while we were fetching policy. 536 // Host has been stopped while we were fetching policy.
537 return; 537 return;
538 } 538 }
539 539
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 signal_strategy_->Connect(); 588 signal_strategy_->Connect();
589 host_->Start(); 589 host_->Start();
590 590
591 SetState(kRequestedAccessCode); 591 SetState(kRequestedAccessCode);
592 return; 592 return;
593 } 593 }
594 594
595 bool HostNPScriptObject::Disconnect(const NPVariant* args, 595 bool HostNPScriptObject::Disconnect(const NPVariant* args,
596 uint32_t arg_count, 596 uint32_t arg_count,
597 NPVariant* result) { 597 NPVariant* result) {
598 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); 598 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
599 if (arg_count != 0) { 599 if (arg_count != 0) {
600 SetException("disconnect: bad number of arguments"); 600 SetException("disconnect: bad number of arguments");
601 return false; 601 return false;
602 } 602 }
603 603
604 DisconnectInternal(); 604 DisconnectInternal();
605 605
606 return true; 606 return true;
607 } 607 }
608 608
609 bool HostNPScriptObject::Localize(const NPVariant* args, 609 bool HostNPScriptObject::Localize(const NPVariant* args,
610 uint32_t arg_count, 610 uint32_t arg_count,
611 NPVariant* result) { 611 NPVariant* result) {
612 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); 612 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
613 if (arg_count != 1) { 613 if (arg_count != 1) {
614 SetException("localize: bad number of arguments"); 614 SetException("localize: bad number of arguments");
615 return false; 615 return false;
616 } 616 }
617 617
618 if (NPVARIANT_IS_OBJECT(args[0])) { 618 if (NPVARIANT_IS_OBJECT(args[0])) {
619 ScopedRefNPObject localize_func(NPVARIANT_TO_OBJECT(args[0])); 619 ScopedRefNPObject localize_func(NPVARIANT_TO_OBJECT(args[0]));
620 LocalizeStrings(localize_func.get()); 620 LocalizeStrings(localize_func.get());
621 return true; 621 return true;
622 } else { 622 } else {
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 return false; 841 return false;
842 } 842 }
843 843
844 daemon_controller_->Stop( 844 daemon_controller_->Stop(
845 base::Bind(&HostNPScriptObject::InvokeAsyncResultCallback, 845 base::Bind(&HostNPScriptObject::InvokeAsyncResultCallback,
846 base::Unretained(this), callback_obj)); 846 base::Unretained(this), callback_obj));
847 return true; 847 return true;
848 } 848 }
849 849
850 void HostNPScriptObject::DisconnectInternal() { 850 void HostNPScriptObject::DisconnectInternal() {
851 if (!host_context_->network_message_loop()->BelongsToCurrentThread()) { 851 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) {
852 host_context_->network_message_loop()->PostTask( 852 host_context_->network_task_runner()->PostTask(
853 FROM_HERE, base::Bind(&HostNPScriptObject::DisconnectInternal, 853 FROM_HERE, base::Bind(&HostNPScriptObject::DisconnectInternal,
854 base::Unretained(this))); 854 base::Unretained(this)));
855 return; 855 return;
856 } 856 }
857 857
858 switch (state_) { 858 switch (state_) {
859 case kDisconnected: 859 case kDisconnected:
860 disconnected_event_.Signal(); 860 disconnected_event_.Signal();
861 return; 861 return;
862 862
863 case kStarting: 863 case kStarting:
864 SetState(kDisconnecting); 864 SetState(kDisconnecting);
865 SetState(kDisconnected); 865 SetState(kDisconnected);
866 disconnected_event_.Signal(); 866 disconnected_event_.Signal();
867 return; 867 return;
868 868
869 case kDisconnecting: 869 case kDisconnecting:
870 return; 870 return;
871 871
872 default: 872 default:
873 DCHECK(host_); 873 DCHECK(host_);
874 SetState(kDisconnecting); 874 SetState(kDisconnecting);
875 875
876 // ChromotingHost::Shutdown() may destroy SignalStrategy 876 // ChromotingHost::Shutdown() may destroy SignalStrategy
877 // synchronously, bug SignalStrategy::Listener handlers are not 877 // synchronously, bug SignalStrategy::Listener handlers are not
878 // allowed to destroy SignalStrategy, so post task to call 878 // allowed to destroy SignalStrategy, so post task to call
879 // Shutdown() later. 879 // Shutdown() later.
880 host_context_->network_message_loop()->PostTask( 880 host_context_->network_task_runner()->PostTask(
881 FROM_HERE, base::Bind( 881 FROM_HERE, base::Bind(
882 &ChromotingHost::Shutdown, host_, 882 &ChromotingHost::Shutdown, host_,
883 base::Bind(&HostNPScriptObject::OnShutdownFinished, 883 base::Bind(&HostNPScriptObject::OnShutdownFinished,
884 base::Unretained(this)))); 884 base::Unretained(this))));
885 } 885 }
886 } 886 }
887 887
888 void HostNPScriptObject::OnShutdownFinished() { 888 void HostNPScriptObject::OnShutdownFinished() {
889 DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); 889 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
890 890
891 disconnected_event_.Signal(); 891 disconnected_event_.Signal();
892 } 892 }
893 893
894 void HostNPScriptObject::OnNatPolicyUpdate(bool nat_traversal_enabled) { 894 void HostNPScriptObject::OnNatPolicyUpdate(bool nat_traversal_enabled) {
895 if (!host_context_->network_message_loop()->BelongsToCurrentThread()) { 895 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) {
896 host_context_->network_message_loop()->PostTask( 896 host_context_->network_task_runner()->PostTask(
897 FROM_HERE, 897 FROM_HERE,
898 base::Bind(&HostNPScriptObject::OnNatPolicyUpdate, 898 base::Bind(&HostNPScriptObject::OnNatPolicyUpdate,
899 base::Unretained(this), nat_traversal_enabled)); 899 base::Unretained(this), nat_traversal_enabled));
900 return; 900 return;
901 } 901 }
902 902
903 VLOG(2) << "OnNatPolicyUpdate: " << nat_traversal_enabled; 903 VLOG(2) << "OnNatPolicyUpdate: " << nat_traversal_enabled;
904 904
905 // When transitioning from enabled to disabled, force disconnect any 905 // When transitioning from enabled to disabled, force disconnect any
906 // existing session. 906 // existing session.
(...skipping 12 matching lines...) Expand all
919 if (!pending_connect_.is_null()) { 919 if (!pending_connect_.is_null()) {
920 pending_connect_.Run(); 920 pending_connect_.Run();
921 pending_connect_.Reset(); 921 pending_connect_.Reset();
922 } 922 }
923 } 923 }
924 924
925 void HostNPScriptObject::OnReceivedSupportID( 925 void HostNPScriptObject::OnReceivedSupportID(
926 bool success, 926 bool success,
927 const std::string& support_id, 927 const std::string& support_id,
928 const base::TimeDelta& lifetime) { 928 const base::TimeDelta& lifetime) {
929 DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); 929 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
930 930
931 if (!success) { 931 if (!success) {
932 SetState(kError); 932 SetState(kError);
933 DisconnectInternal(); 933 DisconnectInternal();
934 return; 934 return;
935 } 935 }
936 936
937 std::string host_secret = GenerateSupportHostSecret(); 937 std::string host_secret = GenerateSupportHostSecret();
938 std::string access_code = support_id + host_secret; 938 std::string access_code = support_id + host_secret;
939 scoped_ptr<protocol::AuthenticatorFactory> factory( 939 scoped_ptr<protocol::AuthenticatorFactory> factory(
940 new protocol::It2MeHostAuthenticatorFactory( 940 new protocol::It2MeHostAuthenticatorFactory(
941 host_key_pair_.GenerateCertificate(), *host_key_pair_.private_key(), 941 host_key_pair_.GenerateCertificate(), *host_key_pair_.private_key(),
942 access_code)); 942 access_code));
943 host_->SetAuthenticatorFactory(factory.Pass()); 943 host_->SetAuthenticatorFactory(factory.Pass());
944 944
945 { 945 {
946 base::AutoLock lock(access_code_lock_); 946 base::AutoLock lock(access_code_lock_);
947 access_code_ = access_code; 947 access_code_ = access_code;
948 access_code_lifetime_ = lifetime; 948 access_code_lifetime_ = lifetime;
949 } 949 }
950 950
951 SetState(kReceivedAccessCode); 951 SetState(kReceivedAccessCode);
952 } 952 }
953 953
954 void HostNPScriptObject::SetState(State state) { 954 void HostNPScriptObject::SetState(State state) {
955 DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); 955 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
956 switch (state_) { 956 switch (state_) {
957 case kDisconnected: 957 case kDisconnected:
958 DCHECK(state == kStarting || 958 DCHECK(state == kStarting ||
959 state == kError) << state; 959 state == kError) << state;
960 break; 960 break;
961 case kStarting: 961 case kStarting:
962 DCHECK(state == kRequestedAccessCode || 962 DCHECK(state == kRequestedAccessCode ||
963 state == kDisconnecting || 963 state == kDisconnecting ||
964 state == kError) << state; 964 state == kError) << state;
965 break; 965 break;
(...skipping 17 matching lines...) Expand all
983 break; 983 break;
984 case kError: 984 case kError:
985 DCHECK(state == kDisconnecting) << state; 985 DCHECK(state == kDisconnecting) << state;
986 break; 986 break;
987 }; 987 };
988 state_ = state; 988 state_ = state;
989 NotifyStateChanged(state); 989 NotifyStateChanged(state);
990 } 990 }
991 991
992 void HostNPScriptObject::NotifyStateChanged(State state) { 992 void HostNPScriptObject::NotifyStateChanged(State state) {
993 if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { 993 if (!plugin_task_runner_->BelongsToCurrentThread()) {
994 plugin_message_loop_proxy_->PostTask( 994 plugin_task_runner_->PostTask(
995 FROM_HERE, base::Bind(&HostNPScriptObject::NotifyStateChanged, 995 FROM_HERE, base::Bind(&HostNPScriptObject::NotifyStateChanged,
996 base::Unretained(this), state)); 996 base::Unretained(this), state));
997 return; 997 return;
998 } 998 }
999 if (on_state_changed_func_.get()) { 999 if (on_state_changed_func_.get()) {
1000 VLOG(2) << "Calling state changed " << state; 1000 VLOG(2) << "Calling state changed " << state;
1001 NPVariant state_var; 1001 NPVariant state_var;
1002 INT32_TO_NPVARIANT(state, state_var); 1002 INT32_TO_NPVARIANT(state, state_var);
1003 bool is_good = InvokeAndIgnoreResult(on_state_changed_func_.get(), 1003 bool is_good = InvokeAndIgnoreResult(on_state_changed_func_.get(),
1004 &state_var, 1); 1004 &state_var, 1);
1005 LOG_IF(ERROR, !is_good) << "OnStateChanged failed"; 1005 LOG_IF(ERROR, !is_good) << "OnStateChanged failed";
1006 } 1006 }
1007 } 1007 }
1008 void HostNPScriptObject::PostLogDebugInfo(const std::string& message) { 1008 void HostNPScriptObject::PostLogDebugInfo(const std::string& message) {
1009 if (plugin_message_loop_proxy_->BelongsToCurrentThread()) { 1009 if (plugin_task_runner_->BelongsToCurrentThread()) {
1010 // Make sure we're not currently processing a log message. 1010 // Make sure we're not currently processing a log message.
1011 // We only need to check this if we're on the plugin thread. 1011 // We only need to check this if we're on the plugin thread.
1012 if (am_currently_logging_) 1012 if (am_currently_logging_)
1013 return; 1013 return;
1014 } 1014 }
1015 1015
1016 // Always post (even if we're already on the correct thread) so that debug 1016 // Always post (even if we're already on the correct thread) so that debug
1017 // log messages are shown in the correct order. 1017 // log messages are shown in the correct order.
1018 plugin_message_loop_proxy_->PostTask( 1018 plugin_task_runner_->PostTask(
1019 FROM_HERE, base::Bind(&HostNPScriptObject::LogDebugInfo, 1019 FROM_HERE, base::Bind(&HostNPScriptObject::LogDebugInfo,
1020 base::Unretained(this), message)); 1020 base::Unretained(this), message));
1021 } 1021 }
1022 1022
1023 void HostNPScriptObject::SetWindow(NPWindow* np_window) { 1023 void HostNPScriptObject::SetWindow(NPWindow* np_window) {
1024 daemon_controller_->SetWindow(np_window->window); 1024 daemon_controller_->SetWindow(np_window->window);
1025 } 1025 }
1026 1026
1027 void HostNPScriptObject::LocalizeStrings(NPObject* localize_func) { 1027 void HostNPScriptObject::LocalizeStrings(NPObject* localize_func) {
1028 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); 1028 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
1029 1029
1030 UiStrings ui_strings; 1030 UiStrings ui_strings;
1031 string16 direction; 1031 string16 direction;
1032 LocalizeString(localize_func, "@@bidi_dir", &direction); 1032 LocalizeString(localize_func, "@@bidi_dir", &direction);
1033 ui_strings.direction = UTF16ToUTF8(direction) == "rtl" ? 1033 ui_strings.direction = UTF16ToUTF8(direction) == "rtl" ?
1034 remoting::UiStrings::RTL : remoting::UiStrings::LTR; 1034 remoting::UiStrings::RTL : remoting::UiStrings::LTR;
1035 LocalizeString(localize_func, /*i18n-content*/"PRODUCT_NAME", 1035 LocalizeString(localize_func, /*i18n-content*/"PRODUCT_NAME",
1036 &ui_strings.product_name); 1036 &ui_strings.product_name);
1037 LocalizeString(localize_func, /*i18n-content*/"DISCONNECT_OTHER_BUTTON", 1037 LocalizeString(localize_func, /*i18n-content*/"DISCONNECT_OTHER_BUTTON",
1038 &ui_strings.disconnect_button_text); 1038 &ui_strings.disconnect_button_text);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 g_npnetscape_funcs->releasevariantvalue(&np_result); 1073 g_npnetscape_funcs->releasevariantvalue(&np_result);
1074 if (translation.empty()) { 1074 if (translation.empty()) {
1075 LOG(ERROR) << "Missing translation for " << tag; 1075 LOG(ERROR) << "Missing translation for " << tag;
1076 return false; 1076 return false;
1077 } 1077 }
1078 *result = UTF8ToUTF16(translation); 1078 *result = UTF8ToUTF16(translation);
1079 return true; 1079 return true;
1080 } 1080 }
1081 1081
1082 void HostNPScriptObject::UpdateWebappNatPolicy(bool nat_traversal_enabled) { 1082 void HostNPScriptObject::UpdateWebappNatPolicy(bool nat_traversal_enabled) {
1083 if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { 1083 if (!plugin_task_runner_->BelongsToCurrentThread()) {
1084 plugin_message_loop_proxy_->PostTask( 1084 plugin_task_runner_->PostTask(
1085 FROM_HERE, base::Bind(&HostNPScriptObject::UpdateWebappNatPolicy, 1085 FROM_HERE, base::Bind(&HostNPScriptObject::UpdateWebappNatPolicy,
1086 base::Unretained(this), nat_traversal_enabled)); 1086 base::Unretained(this), nat_traversal_enabled));
1087 return; 1087 return;
1088 } 1088 }
1089 if (on_nat_traversal_policy_changed_func_.get()) { 1089 if (on_nat_traversal_policy_changed_func_.get()) {
1090 NPVariant policy; 1090 NPVariant policy;
1091 BOOLEAN_TO_NPVARIANT(nat_traversal_enabled, policy); 1091 BOOLEAN_TO_NPVARIANT(nat_traversal_enabled, policy);
1092 InvokeAndIgnoreResult(on_nat_traversal_policy_changed_func_.get(), 1092 InvokeAndIgnoreResult(on_nat_traversal_policy_changed_func_.get(),
1093 &policy, 1); 1093 &policy, 1);
1094 } 1094 }
1095 } 1095 }
1096 1096
1097 void HostNPScriptObject::DoGenerateKeyPair(const ScopedRefNPObject& callback) { 1097 void HostNPScriptObject::DoGenerateKeyPair(const ScopedRefNPObject& callback) {
1098 HostKeyPair key_pair; 1098 HostKeyPair key_pair;
1099 key_pair.Generate(); 1099 key_pair.Generate();
1100 InvokeGenerateKeyPairCallback(callback, key_pair.GetAsString(), 1100 InvokeGenerateKeyPairCallback(callback, key_pair.GetAsString(),
1101 key_pair.GetPublicKey()); 1101 key_pair.GetPublicKey());
1102 } 1102 }
1103 1103
1104 void HostNPScriptObject::InvokeGenerateKeyPairCallback( 1104 void HostNPScriptObject::InvokeGenerateKeyPairCallback(
1105 const ScopedRefNPObject& callback, 1105 const ScopedRefNPObject& callback,
1106 const std::string& private_key, 1106 const std::string& private_key,
1107 const std::string& public_key) { 1107 const std::string& public_key) {
1108 if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { 1108 if (!plugin_task_runner_->BelongsToCurrentThread()) {
1109 plugin_message_loop_proxy_->PostTask( 1109 plugin_task_runner_->PostTask(
1110 FROM_HERE, base::Bind( 1110 FROM_HERE, base::Bind(
1111 &HostNPScriptObject::InvokeGenerateKeyPairCallback, 1111 &HostNPScriptObject::InvokeGenerateKeyPairCallback,
1112 base::Unretained(this), callback, private_key, public_key)); 1112 base::Unretained(this), callback, private_key, public_key));
1113 return; 1113 return;
1114 } 1114 }
1115 1115
1116 NPVariant params[2]; 1116 NPVariant params[2];
1117 params[0] = NPVariantFromString(private_key); 1117 params[0] = NPVariantFromString(private_key);
1118 params[1] = NPVariantFromString(public_key); 1118 params[1] = NPVariantFromString(public_key);
1119 InvokeAndIgnoreResult(callback.get(), params, arraysize(params)); 1119 InvokeAndIgnoreResult(callback.get(), params, arraysize(params));
1120 g_npnetscape_funcs->releasevariantvalue(&(params[0])); 1120 g_npnetscape_funcs->releasevariantvalue(&(params[0]));
1121 g_npnetscape_funcs->releasevariantvalue(&(params[1])); 1121 g_npnetscape_funcs->releasevariantvalue(&(params[1]));
1122 } 1122 }
1123 1123
1124 void HostNPScriptObject::InvokeAsyncResultCallback( 1124 void HostNPScriptObject::InvokeAsyncResultCallback(
1125 const ScopedRefNPObject& callback, 1125 const ScopedRefNPObject& callback,
1126 DaemonController::AsyncResult result) { 1126 DaemonController::AsyncResult result) {
1127 if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { 1127 if (!plugin_task_runner_->BelongsToCurrentThread()) {
1128 plugin_message_loop_proxy_->PostTask( 1128 plugin_task_runner_->PostTask(
1129 FROM_HERE, base::Bind( 1129 FROM_HERE, base::Bind(
1130 &HostNPScriptObject::InvokeAsyncResultCallback, 1130 &HostNPScriptObject::InvokeAsyncResultCallback,
1131 base::Unretained(this), callback, result)); 1131 base::Unretained(this), callback, result));
1132 return; 1132 return;
1133 } 1133 }
1134 1134
1135 NPVariant result_var; 1135 NPVariant result_var;
1136 INT32_TO_NPVARIANT(static_cast<int32>(result), result_var); 1136 INT32_TO_NPVARIANT(static_cast<int32>(result), result_var);
1137 InvokeAndIgnoreResult(callback.get(), &result_var, 1); 1137 InvokeAndIgnoreResult(callback.get(), &result_var, 1);
1138 g_npnetscape_funcs->releasevariantvalue(&result_var); 1138 g_npnetscape_funcs->releasevariantvalue(&result_var);
1139 } 1139 }
1140 1140
1141 void HostNPScriptObject::InvokeGetDaemonConfigCallback( 1141 void HostNPScriptObject::InvokeGetDaemonConfigCallback(
1142 const ScopedRefNPObject& callback, 1142 const ScopedRefNPObject& callback,
1143 scoped_ptr<base::DictionaryValue> config) { 1143 scoped_ptr<base::DictionaryValue> config) {
1144 if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { 1144 if (!plugin_task_runner_->BelongsToCurrentThread()) {
1145 plugin_message_loop_proxy_->PostTask( 1145 plugin_task_runner_->PostTask(
1146 FROM_HERE, base::Bind( 1146 FROM_HERE, base::Bind(
1147 &HostNPScriptObject::InvokeGetDaemonConfigCallback, 1147 &HostNPScriptObject::InvokeGetDaemonConfigCallback,
1148 base::Unretained(this), callback, base::Passed(&config))); 1148 base::Unretained(this), callback, base::Passed(&config)));
1149 return; 1149 return;
1150 } 1150 }
1151 1151
1152 // There is no easy way to create a dictionary from an NPAPI plugin 1152 // There is no easy way to create a dictionary from an NPAPI plugin
1153 // so we have to serialize the dictionary to pass it to JavaScript. 1153 // so we have to serialize the dictionary to pass it to JavaScript.
1154 std::string config_str; 1154 std::string config_str;
1155 if (config.get()) 1155 if (config.get())
1156 base::JSONWriter::Write(config.get(), &config_str); 1156 base::JSONWriter::Write(config.get(), &config_str);
1157 1157
1158 NPVariant config_val = NPVariantFromString(config_str); 1158 NPVariant config_val = NPVariantFromString(config_str);
1159 InvokeAndIgnoreResult(callback.get(), &config_val, 1); 1159 InvokeAndIgnoreResult(callback.get(), &config_val, 1);
1160 g_npnetscape_funcs->releasevariantvalue(&config_val); 1160 g_npnetscape_funcs->releasevariantvalue(&config_val);
1161 } 1161 }
1162 1162
1163 void HostNPScriptObject::InvokeGetDaemonVersionCallback( 1163 void HostNPScriptObject::InvokeGetDaemonVersionCallback(
1164 const ScopedRefNPObject& callback, const std::string& version) { 1164 const ScopedRefNPObject& callback, const std::string& version) {
1165 if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { 1165 if (!plugin_task_runner_->BelongsToCurrentThread()) {
1166 plugin_message_loop_proxy_->PostTask( 1166 plugin_task_runner_->PostTask(
1167 FROM_HERE, base::Bind( 1167 FROM_HERE, base::Bind(
1168 &HostNPScriptObject::InvokeGetDaemonVersionCallback, 1168 &HostNPScriptObject::InvokeGetDaemonVersionCallback,
1169 base::Unretained(this), callback, version)); 1169 base::Unretained(this), callback, version));
1170 return; 1170 return;
1171 } 1171 }
1172 1172
1173 NPVariant version_val = NPVariantFromString(version); 1173 NPVariant version_val = NPVariantFromString(version);
1174 InvokeAndIgnoreResult(callback.get(), &version_val, 1); 1174 InvokeAndIgnoreResult(callback.get(), &version_val, 1);
1175 g_npnetscape_funcs->releasevariantvalue(&version_val); 1175 g_npnetscape_funcs->releasevariantvalue(&version_val);
1176 } 1176 }
1177 1177
1178 void HostNPScriptObject::InvokeGetUsageStatsConsentCallback( 1178 void HostNPScriptObject::InvokeGetUsageStatsConsentCallback(
1179 const ScopedRefNPObject& callback, 1179 const ScopedRefNPObject& callback,
1180 bool supported, 1180 bool supported,
1181 bool allowed, 1181 bool allowed,
1182 bool set_by_policy) { 1182 bool set_by_policy) {
1183 if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { 1183 if (!plugin_task_runner_->BelongsToCurrentThread()) {
1184 plugin_message_loop_proxy_->PostTask( 1184 plugin_task_runner_->PostTask(
1185 FROM_HERE, base::Bind( 1185 FROM_HERE, base::Bind(
1186 &HostNPScriptObject::InvokeGetUsageStatsConsentCallback, 1186 &HostNPScriptObject::InvokeGetUsageStatsConsentCallback,
1187 base::Unretained(this), callback, supported, allowed, 1187 base::Unretained(this), callback, supported, allowed,
1188 set_by_policy)); 1188 set_by_policy));
1189 return; 1189 return;
1190 } 1190 }
1191 1191
1192 NPVariant params[3]; 1192 NPVariant params[3];
1193 BOOLEAN_TO_NPVARIANT(supported, params[0]); 1193 BOOLEAN_TO_NPVARIANT(supported, params[0]);
1194 BOOLEAN_TO_NPVARIANT(allowed, params[1]); 1194 BOOLEAN_TO_NPVARIANT(allowed, params[1]);
1195 BOOLEAN_TO_NPVARIANT(set_by_policy, params[2]); 1195 BOOLEAN_TO_NPVARIANT(set_by_policy, params[2]);
1196 InvokeAndIgnoreResult(callback.get(), params, arraysize(params)); 1196 InvokeAndIgnoreResult(callback.get(), params, arraysize(params));
1197 g_npnetscape_funcs->releasevariantvalue(&(params[0])); 1197 g_npnetscape_funcs->releasevariantvalue(&(params[0]));
1198 g_npnetscape_funcs->releasevariantvalue(&(params[1])); 1198 g_npnetscape_funcs->releasevariantvalue(&(params[1]));
1199 g_npnetscape_funcs->releasevariantvalue(&(params[2])); 1199 g_npnetscape_funcs->releasevariantvalue(&(params[2]));
1200 } 1200 }
1201 1201
1202 void HostNPScriptObject::LogDebugInfo(const std::string& message) { 1202 void HostNPScriptObject::LogDebugInfo(const std::string& message) {
1203 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); 1203 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
1204 if (log_debug_info_func_.get()) { 1204 if (log_debug_info_func_.get()) {
1205 am_currently_logging_ = true; 1205 am_currently_logging_ = true;
1206 NPVariant log_message; 1206 NPVariant log_message;
1207 STRINGZ_TO_NPVARIANT(message.c_str(), log_message); 1207 STRINGZ_TO_NPVARIANT(message.c_str(), log_message);
1208 bool is_good = InvokeAndIgnoreResult(log_debug_info_func_.get(), 1208 bool is_good = InvokeAndIgnoreResult(log_debug_info_func_.get(),
1209 &log_message, 1); 1209 &log_message, 1);
1210 if (!is_good) { 1210 if (!is_good) {
1211 LOG(ERROR) << "ERROR - LogDebugInfo failed\n"; 1211 LOG(ERROR) << "ERROR - LogDebugInfo failed\n";
1212 } 1212 }
1213 am_currently_logging_ = false; 1213 am_currently_logging_ = false;
1214 } 1214 }
1215 } 1215 }
1216 1216
1217 bool HostNPScriptObject::InvokeAndIgnoreResult(NPObject* func, 1217 bool HostNPScriptObject::InvokeAndIgnoreResult(NPObject* func,
1218 const NPVariant* args, 1218 const NPVariant* args,
1219 uint32_t arg_count) { 1219 uint32_t arg_count) {
1220 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); 1220 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
1221 NPVariant np_result; 1221 NPVariant np_result;
1222 bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args, 1222 bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args,
1223 arg_count, &np_result); 1223 arg_count, &np_result);
1224 if (is_good) 1224 if (is_good)
1225 g_npnetscape_funcs->releasevariantvalue(&np_result); 1225 g_npnetscape_funcs->releasevariantvalue(&np_result);
1226 return is_good; 1226 return is_good;
1227 } 1227 }
1228 1228
1229 void HostNPScriptObject::SetException(const std::string& exception_string) { 1229 void HostNPScriptObject::SetException(const std::string& exception_string) {
1230 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); 1230 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
1231 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); 1231 g_npnetscape_funcs->setexception(parent_, exception_string.c_str());
1232 LOG(INFO) << exception_string; 1232 LOG(INFO) << exception_string;
1233 } 1233 }
1234 1234
1235 } // namespace remoting 1235 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/plugin/host_script_object.h ('k') | remoting/host/policy_hack/nat_policy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698