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" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 HostNPScriptObject::HostNPScriptObject( | 78 HostNPScriptObject::HostNPScriptObject( |
79 NPP plugin, | 79 NPP plugin, |
80 NPObject* parent, | 80 NPObject* parent, |
81 PluginMessageLoopProxy::Delegate* plugin_thread_delegate) | 81 PluginMessageLoopProxy::Delegate* plugin_thread_delegate) |
82 : plugin_(plugin), | 82 : plugin_(plugin), |
83 parent_(parent), | 83 parent_(parent), |
84 am_currently_logging_(false), | 84 am_currently_logging_(false), |
85 state_(kDisconnected), | 85 state_(kDisconnected), |
86 np_thread_id_(base::PlatformThread::CurrentId()), | 86 np_thread_id_(base::PlatformThread::CurrentId()), |
87 plugin_message_loop_proxy_( | 87 plugin_task_runner_( |
88 new PluginMessageLoopProxy(plugin_thread_delegate)), | 88 new PluginMessageLoopProxy(plugin_thread_delegate)), |
89 failed_login_attempts_(0), | 89 failed_login_attempts_(0), |
90 disconnected_event_(true, false), | 90 disconnected_event_(true, false), |
91 nat_traversal_enabled_(false), | 91 nat_traversal_enabled_(false), |
92 policy_received_(false), | 92 policy_received_(false), |
93 daemon_controller_(DaemonController::Create()), | 93 daemon_controller_(DaemonController::Create()), |
94 worker_thread_("RemotingHostPlugin") { | 94 worker_thread_("RemotingHostPlugin") { |
95 worker_thread_.Start(); | 95 worker_thread_.Start(); |
96 } | 96 } |
97 | 97 |
98 HostNPScriptObject::~HostNPScriptObject() { | 98 HostNPScriptObject::~HostNPScriptObject() { |
99 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); | 99 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); |
100 | 100 |
101 HostLogHandler::UnregisterLoggingScriptObject(this); | 101 HostLogHandler::UnregisterLoggingScriptObject(this); |
102 | 102 |
103 plugin_message_loop_proxy_->Detach(); | 103 plugin_task_runner_->Detach(); |
104 | 104 |
105 // Stop listening for policy updates. | 105 // Stop listening for policy updates. |
106 if (nat_policy_.get()) { | 106 if (nat_policy_.get()) { |
107 base::WaitableEvent nat_policy_stopped_(true, false); | 107 base::WaitableEvent nat_policy_stopped_(true, false); |
108 nat_policy_->StopWatching(&nat_policy_stopped_); | 108 nat_policy_->StopWatching(&nat_policy_stopped_); |
109 nat_policy_stopped_.Wait(); | 109 nat_policy_stopped_.Wait(); |
110 nat_policy_.reset(); | 110 nat_policy_.reset(); |
111 } | 111 } |
112 | 112 |
113 if (host_context_.get()) { | 113 if (host_context_.get()) { |
(...skipping 13 matching lines...) Expand all Loading... |
127 it2me_host_user_interface_.reset(); | 127 it2me_host_user_interface_.reset(); |
128 | 128 |
129 // Stops all threads. | 129 // Stops all threads. |
130 host_context_.reset(); | 130 host_context_.reset(); |
131 } | 131 } |
132 | 132 |
133 worker_thread_.Stop(); | 133 worker_thread_.Stop(); |
134 } | 134 } |
135 | 135 |
136 bool HostNPScriptObject::Init() { | 136 bool HostNPScriptObject::Init() { |
137 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); | 137 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
138 VLOG(2) << "Init"; | 138 VLOG(2) << "Init"; |
139 | 139 |
140 host_context_.reset(new ChromotingHostContext(plugin_message_loop_proxy_)); | 140 host_context_.reset(new ChromotingHostContext(plugin_task_runner_)); |
141 if (!host_context_->Start()) { | 141 if (!host_context_->Start()) { |
142 host_context_.reset(); | 142 host_context_.reset(); |
143 return false; | 143 return false; |
144 } | 144 } |
145 | 145 |
146 nat_policy_.reset( | 146 nat_policy_.reset( |
147 policy_hack::NatPolicy::Create(host_context_->network_message_loop())); | 147 policy_hack::NatPolicy::Create(host_context_->network_task_runner())); |
148 nat_policy_->StartWatching( | 148 nat_policy_->StartWatching( |
149 base::Bind(&HostNPScriptObject::OnNatPolicyUpdate, | 149 base::Bind(&HostNPScriptObject::OnNatPolicyUpdate, |
150 base::Unretained(this))); | 150 base::Unretained(this))); |
151 return true; | 151 return true; |
152 } | 152 } |
153 | 153 |
154 bool HostNPScriptObject::HasMethod(const std::string& method_name) { | 154 bool HostNPScriptObject::HasMethod(const std::string& method_name) { |
155 VLOG(2) << "HasMethod " << method_name; | 155 VLOG(2) << "HasMethod " << method_name; |
156 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); | 156 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); |
157 return (method_name == kFuncNameConnect || | 157 return (method_name == kFuncNameConnect || |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 kFuncNameStartDaemon, | 376 kFuncNameStartDaemon, |
377 kFuncNameStopDaemon | 377 kFuncNameStopDaemon |
378 }; | 378 }; |
379 for (size_t i = 0; i < arraysize(entries); ++i) { | 379 for (size_t i = 0; i < arraysize(entries); ++i) { |
380 values->push_back(entries[i]); | 380 values->push_back(entries[i]); |
381 } | 381 } |
382 return true; | 382 return true; |
383 } | 383 } |
384 | 384 |
385 void HostNPScriptObject::OnAccessDenied(const std::string& jid) { | 385 void HostNPScriptObject::OnAccessDenied(const std::string& jid) { |
386 DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); | 386 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
387 | 387 |
388 ++failed_login_attempts_; | 388 ++failed_login_attempts_; |
389 if (failed_login_attempts_ == kMaxLoginAttempts) { | 389 if (failed_login_attempts_ == kMaxLoginAttempts) { |
390 DisconnectInternal(); | 390 DisconnectInternal(); |
391 } | 391 } |
392 } | 392 } |
393 | 393 |
394 void HostNPScriptObject::OnClientAuthenticated(const std::string& jid) { | 394 void HostNPScriptObject::OnClientAuthenticated(const std::string& jid) { |
395 DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); | 395 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
396 | 396 |
397 if (state_ == kDisconnecting) { | 397 if (state_ == kDisconnecting) { |
398 // Ignore the new connection if we are disconnecting. | 398 // Ignore the new connection if we are disconnecting. |
399 return; | 399 return; |
400 } | 400 } |
401 | 401 |
402 client_username_ = jid; | 402 client_username_ = jid; |
403 size_t pos = client_username_.find('/'); | 403 size_t pos = client_username_.find('/'); |
404 if (pos != std::string::npos) | 404 if (pos != std::string::npos) |
405 client_username_.replace(pos, std::string::npos, ""); | 405 client_username_.replace(pos, std::string::npos, ""); |
406 LOG(INFO) << "Client " << client_username_ << " connected."; | 406 LOG(INFO) << "Client " << client_username_ << " connected."; |
407 SetState(kConnected); | 407 SetState(kConnected); |
408 } | 408 } |
409 | 409 |
410 void HostNPScriptObject::OnClientDisconnected(const std::string& jid) { | 410 void HostNPScriptObject::OnClientDisconnected(const std::string& jid) { |
411 DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); | 411 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
412 client_username_.clear(); | 412 client_username_.clear(); |
413 DisconnectInternal(); | 413 DisconnectInternal(); |
414 } | 414 } |
415 | 415 |
416 void HostNPScriptObject::OnShutdown() { | 416 void HostNPScriptObject::OnShutdown() { |
417 DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); | 417 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
418 | 418 |
419 register_request_.reset(); | 419 register_request_.reset(); |
420 log_to_server_.reset(); | 420 log_to_server_.reset(); |
421 signal_strategy_.reset(); | 421 signal_strategy_.reset(); |
422 host_->RemoveStatusObserver(this); | 422 host_->RemoveStatusObserver(this); |
423 host_ = NULL; | 423 host_ = NULL; |
424 | 424 |
425 if (state_ != kDisconnected) { | 425 if (state_ != kDisconnected) { |
426 SetState(kDisconnected); | 426 SetState(kDisconnected); |
427 } | 427 } |
428 } | 428 } |
429 | 429 |
430 // string uid, string auth_token | 430 // string uid, string auth_token |
431 bool HostNPScriptObject::Connect(const NPVariant* args, | 431 bool HostNPScriptObject::Connect(const NPVariant* args, |
432 uint32_t arg_count, | 432 uint32_t arg_count, |
433 NPVariant* result) { | 433 NPVariant* result) { |
434 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); | 434 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
435 | 435 |
436 LOG(INFO) << "Connecting..."; | 436 LOG(INFO) << "Connecting..."; |
437 | 437 |
438 if (arg_count != 2) { | 438 if (arg_count != 2) { |
439 SetException("connect: bad number of arguments"); | 439 SetException("connect: bad number of arguments"); |
440 return false; | 440 return false; |
441 } | 441 } |
442 | 442 |
443 if (state_ != kDisconnected) { | 443 if (state_ != kDisconnected) { |
444 SetException("connect: can be called only when disconnected"); | 444 SetException("connect: can be called only when disconnected"); |
(...skipping 21 matching lines...) Expand all Loading... |
466 new It2MeHostUserInterface(host_context_.get())); | 466 new It2MeHostUserInterface(host_context_.get())); |
467 | 467 |
468 ReadPolicyAndConnect(uid, auth_token, auth_service); | 468 ReadPolicyAndConnect(uid, auth_token, auth_service); |
469 | 469 |
470 return true; | 470 return true; |
471 } | 471 } |
472 | 472 |
473 void HostNPScriptObject::ReadPolicyAndConnect(const std::string& uid, | 473 void HostNPScriptObject::ReadPolicyAndConnect(const std::string& uid, |
474 const std::string& auth_token, | 474 const std::string& auth_token, |
475 const std::string& auth_service) { | 475 const std::string& auth_service) { |
476 if (!host_context_->network_message_loop()->BelongsToCurrentThread()) { | 476 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { |
477 host_context_->network_message_loop()->PostTask( | 477 host_context_->network_task_runner()->PostTask( |
478 FROM_HERE, base::Bind( | 478 FROM_HERE, base::Bind( |
479 &HostNPScriptObject::ReadPolicyAndConnect, base::Unretained(this), | 479 &HostNPScriptObject::ReadPolicyAndConnect, base::Unretained(this), |
480 uid, auth_token, auth_service)); | 480 uid, auth_token, auth_service)); |
481 return; | 481 return; |
482 } | 482 } |
483 | 483 |
484 SetState(kStarting); | 484 SetState(kStarting); |
485 | 485 |
486 // Only proceed to FinishConnect() if at least one policy update has been | 486 // Only proceed to FinishConnect() if at least one policy update has been |
487 // received. | 487 // received. |
488 if (policy_received_) { | 488 if (policy_received_) { |
489 FinishConnectMainThread(uid, auth_token, auth_service); | 489 FinishConnectMainThread(uid, auth_token, auth_service); |
490 } else { | 490 } else { |
491 // Otherwise, create the policy watcher, and thunk the connect. | 491 // Otherwise, create the policy watcher, and thunk the connect. |
492 pending_connect_ = | 492 pending_connect_ = |
493 base::Bind(&HostNPScriptObject::FinishConnectMainThread, | 493 base::Bind(&HostNPScriptObject::FinishConnectMainThread, |
494 base::Unretained(this), uid, auth_token, auth_service); | 494 base::Unretained(this), uid, auth_token, auth_service); |
495 } | 495 } |
496 } | 496 } |
497 | 497 |
498 void HostNPScriptObject::FinishConnectMainThread( | 498 void HostNPScriptObject::FinishConnectMainThread( |
499 const std::string& uid, | 499 const std::string& uid, |
500 const std::string& auth_token, | 500 const std::string& auth_token, |
501 const std::string& auth_service) { | 501 const std::string& auth_service) { |
502 if (host_context_->main_message_loop() != MessageLoop::current()) { | 502 if (!host_context_->capture_task_runner()->BelongsToCurrentThread()) { |
503 host_context_->main_message_loop()->PostTask(FROM_HERE, base::Bind( | 503 host_context_->capture_task_runner()->PostTask(FROM_HERE, base::Bind( |
504 &HostNPScriptObject::FinishConnectMainThread, base::Unretained(this), | 504 &HostNPScriptObject::FinishConnectMainThread, base::Unretained(this), |
505 uid, auth_token, auth_service)); | 505 uid, auth_token, auth_service)); |
506 return; | 506 return; |
507 } | 507 } |
508 | 508 |
509 // DesktopEnvironment must be initialized on the main thread. | 509 // DesktopEnvironment must be initialized on the capture thread. |
510 // | 510 // |
511 // TODO(sergeyu): Fix DesktopEnvironment so that it can be created | 511 // TODO(sergeyu): Fix DesktopEnvironment so that it can be created |
512 // on either the UI or the network thread so that we can avoid | 512 // on either the UI or the network thread so that we can avoid |
513 // jumping to the main thread here. | 513 // jumping to the main thread here. |
514 desktop_environment_ = DesktopEnvironment::Create(host_context_.get()); | 514 desktop_environment_ = DesktopEnvironment::Create(host_context_.get()); |
515 | 515 |
516 FinishConnectNetworkThread(uid, auth_token, auth_service); | 516 FinishConnectNetworkThread(uid, auth_token, auth_service); |
517 } | 517 } |
518 | 518 |
519 void HostNPScriptObject::FinishConnectNetworkThread( | 519 void HostNPScriptObject::FinishConnectNetworkThread( |
520 const std::string& uid, | 520 const std::string& uid, |
521 const std::string& auth_token, | 521 const std::string& auth_token, |
522 const std::string& auth_service) { | 522 const std::string& auth_service) { |
523 if (!host_context_->network_message_loop()->BelongsToCurrentThread()) { | 523 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { |
524 host_context_->network_message_loop()->PostTask(FROM_HERE, base::Bind( | 524 host_context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( |
525 &HostNPScriptObject::FinishConnectNetworkThread, base::Unretained(this), | 525 &HostNPScriptObject::FinishConnectNetworkThread, base::Unretained(this), |
526 uid, auth_token, auth_service)); | 526 uid, auth_token, auth_service)); |
527 return; | 527 return; |
528 } | 528 } |
529 | 529 |
530 if (state_ != kStarting) { | 530 if (state_ != kStarting) { |
531 // Host has been stopped while we were fetching policy. | 531 // Host has been stopped while we were fetching policy. |
532 return; | 532 return; |
533 } | 533 } |
534 | 534 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 signal_strategy_->Connect(); | 583 signal_strategy_->Connect(); |
584 host_->Start(); | 584 host_->Start(); |
585 | 585 |
586 SetState(kRequestedAccessCode); | 586 SetState(kRequestedAccessCode); |
587 return; | 587 return; |
588 } | 588 } |
589 | 589 |
590 bool HostNPScriptObject::Disconnect(const NPVariant* args, | 590 bool HostNPScriptObject::Disconnect(const NPVariant* args, |
591 uint32_t arg_count, | 591 uint32_t arg_count, |
592 NPVariant* result) { | 592 NPVariant* result) { |
593 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); | 593 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
594 if (arg_count != 0) { | 594 if (arg_count != 0) { |
595 SetException("disconnect: bad number of arguments"); | 595 SetException("disconnect: bad number of arguments"); |
596 return false; | 596 return false; |
597 } | 597 } |
598 | 598 |
599 DisconnectInternal(); | 599 DisconnectInternal(); |
600 | 600 |
601 return true; | 601 return true; |
602 } | 602 } |
603 | 603 |
604 bool HostNPScriptObject::Localize(const NPVariant* args, | 604 bool HostNPScriptObject::Localize(const NPVariant* args, |
605 uint32_t arg_count, | 605 uint32_t arg_count, |
606 NPVariant* result) { | 606 NPVariant* result) { |
607 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); | 607 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
608 if (arg_count != 1) { | 608 if (arg_count != 1) { |
609 SetException("localize: bad number of arguments"); | 609 SetException("localize: bad number of arguments"); |
610 return false; | 610 return false; |
611 } | 611 } |
612 | 612 |
613 if (NPVARIANT_IS_OBJECT(args[0])) { | 613 if (NPVARIANT_IS_OBJECT(args[0])) { |
614 ScopedRefNPObject localize_func(NPVARIANT_TO_OBJECT(args[0])); | 614 ScopedRefNPObject localize_func(NPVARIANT_TO_OBJECT(args[0])); |
615 LocalizeStrings(localize_func.get()); | 615 LocalizeStrings(localize_func.get()); |
616 return true; | 616 return true; |
617 } else { | 617 } else { |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 return false; | 808 return false; |
809 } | 809 } |
810 | 810 |
811 daemon_controller_->Stop( | 811 daemon_controller_->Stop( |
812 base::Bind(&HostNPScriptObject::InvokeAsyncResultCallback, | 812 base::Bind(&HostNPScriptObject::InvokeAsyncResultCallback, |
813 base::Unretained(this), callback_obj)); | 813 base::Unretained(this), callback_obj)); |
814 return true; | 814 return true; |
815 } | 815 } |
816 | 816 |
817 void HostNPScriptObject::DisconnectInternal() { | 817 void HostNPScriptObject::DisconnectInternal() { |
818 if (!host_context_->network_message_loop()->BelongsToCurrentThread()) { | 818 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { |
819 host_context_->network_message_loop()->PostTask( | 819 host_context_->network_task_runner()->PostTask( |
820 FROM_HERE, base::Bind(&HostNPScriptObject::DisconnectInternal, | 820 FROM_HERE, base::Bind(&HostNPScriptObject::DisconnectInternal, |
821 base::Unretained(this))); | 821 base::Unretained(this))); |
822 return; | 822 return; |
823 } | 823 } |
824 | 824 |
825 switch (state_) { | 825 switch (state_) { |
826 case kDisconnected: | 826 case kDisconnected: |
827 disconnected_event_.Signal(); | 827 disconnected_event_.Signal(); |
828 return; | 828 return; |
829 | 829 |
830 case kStarting: | 830 case kStarting: |
831 SetState(kDisconnecting); | 831 SetState(kDisconnecting); |
832 SetState(kDisconnected); | 832 SetState(kDisconnected); |
833 disconnected_event_.Signal(); | 833 disconnected_event_.Signal(); |
834 return; | 834 return; |
835 | 835 |
836 case kDisconnecting: | 836 case kDisconnecting: |
837 return; | 837 return; |
838 | 838 |
839 default: | 839 default: |
840 DCHECK(host_); | 840 DCHECK(host_); |
841 SetState(kDisconnecting); | 841 SetState(kDisconnecting); |
842 | 842 |
843 // ChromotingHost::Shutdown() may destroy SignalStrategy | 843 // ChromotingHost::Shutdown() may destroy SignalStrategy |
844 // synchronously, bug SignalStrategy::Listener handlers are not | 844 // synchronously, bug SignalStrategy::Listener handlers are not |
845 // allowed to destroy SignalStrategy, so post task to call | 845 // allowed to destroy SignalStrategy, so post task to call |
846 // Shutdown() later. | 846 // Shutdown() later. |
847 host_context_->network_message_loop()->PostTask( | 847 host_context_->network_task_runner()->PostTask( |
848 FROM_HERE, base::Bind( | 848 FROM_HERE, base::Bind( |
849 &ChromotingHost::Shutdown, host_, | 849 &ChromotingHost::Shutdown, host_, |
850 base::Bind(&HostNPScriptObject::OnShutdownFinished, | 850 base::Bind(&HostNPScriptObject::OnShutdownFinished, |
851 base::Unretained(this)))); | 851 base::Unretained(this)))); |
852 } | 852 } |
853 } | 853 } |
854 | 854 |
855 void HostNPScriptObject::OnShutdownFinished() { | 855 void HostNPScriptObject::OnShutdownFinished() { |
856 DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); | 856 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
857 | 857 |
858 disconnected_event_.Signal(); | 858 disconnected_event_.Signal(); |
859 } | 859 } |
860 | 860 |
861 void HostNPScriptObject::OnNatPolicyUpdate(bool nat_traversal_enabled) { | 861 void HostNPScriptObject::OnNatPolicyUpdate(bool nat_traversal_enabled) { |
862 if (!host_context_->network_message_loop()->BelongsToCurrentThread()) { | 862 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { |
863 host_context_->network_message_loop()->PostTask( | 863 host_context_->network_task_runner()->PostTask( |
864 FROM_HERE, | 864 FROM_HERE, |
865 base::Bind(&HostNPScriptObject::OnNatPolicyUpdate, | 865 base::Bind(&HostNPScriptObject::OnNatPolicyUpdate, |
866 base::Unretained(this), nat_traversal_enabled)); | 866 base::Unretained(this), nat_traversal_enabled)); |
867 return; | 867 return; |
868 } | 868 } |
869 | 869 |
870 VLOG(2) << "OnNatPolicyUpdate: " << nat_traversal_enabled; | 870 VLOG(2) << "OnNatPolicyUpdate: " << nat_traversal_enabled; |
871 | 871 |
872 // When transitioning from enabled to disabled, force disconnect any | 872 // When transitioning from enabled to disabled, force disconnect any |
873 // existing session. | 873 // existing session. |
(...skipping 12 matching lines...) Expand all Loading... |
886 if (!pending_connect_.is_null()) { | 886 if (!pending_connect_.is_null()) { |
887 pending_connect_.Run(); | 887 pending_connect_.Run(); |
888 pending_connect_.Reset(); | 888 pending_connect_.Reset(); |
889 } | 889 } |
890 } | 890 } |
891 | 891 |
892 void HostNPScriptObject::OnReceivedSupportID( | 892 void HostNPScriptObject::OnReceivedSupportID( |
893 bool success, | 893 bool success, |
894 const std::string& support_id, | 894 const std::string& support_id, |
895 const base::TimeDelta& lifetime) { | 895 const base::TimeDelta& lifetime) { |
896 DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); | 896 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
897 | 897 |
898 if (!success) { | 898 if (!success) { |
899 SetState(kError); | 899 SetState(kError); |
900 DisconnectInternal(); | 900 DisconnectInternal(); |
901 return; | 901 return; |
902 } | 902 } |
903 | 903 |
904 std::string host_secret = GenerateSupportHostSecret(); | 904 std::string host_secret = GenerateSupportHostSecret(); |
905 std::string access_code = support_id + host_secret; | 905 std::string access_code = support_id + host_secret; |
906 scoped_ptr<protocol::AuthenticatorFactory> factory( | 906 scoped_ptr<protocol::AuthenticatorFactory> factory( |
907 new protocol::It2MeHostAuthenticatorFactory( | 907 new protocol::It2MeHostAuthenticatorFactory( |
908 host_key_pair_.GenerateCertificate(), *host_key_pair_.private_key(), | 908 host_key_pair_.GenerateCertificate(), *host_key_pair_.private_key(), |
909 access_code)); | 909 access_code)); |
910 host_->SetAuthenticatorFactory(factory.Pass()); | 910 host_->SetAuthenticatorFactory(factory.Pass()); |
911 | 911 |
912 { | 912 { |
913 base::AutoLock lock(access_code_lock_); | 913 base::AutoLock lock(access_code_lock_); |
914 access_code_ = access_code; | 914 access_code_ = access_code; |
915 access_code_lifetime_ = lifetime; | 915 access_code_lifetime_ = lifetime; |
916 } | 916 } |
917 | 917 |
918 SetState(kReceivedAccessCode); | 918 SetState(kReceivedAccessCode); |
919 } | 919 } |
920 | 920 |
921 void HostNPScriptObject::SetState(State state) { | 921 void HostNPScriptObject::SetState(State state) { |
922 DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); | 922 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
923 switch (state_) { | 923 switch (state_) { |
924 case kDisconnected: | 924 case kDisconnected: |
925 DCHECK(state == kStarting || | 925 DCHECK(state == kStarting || |
926 state == kError) << state; | 926 state == kError) << state; |
927 break; | 927 break; |
928 case kStarting: | 928 case kStarting: |
929 DCHECK(state == kRequestedAccessCode || | 929 DCHECK(state == kRequestedAccessCode || |
930 state == kDisconnecting || | 930 state == kDisconnecting || |
931 state == kError) << state; | 931 state == kError) << state; |
932 break; | 932 break; |
(...skipping 17 matching lines...) Expand all Loading... |
950 break; | 950 break; |
951 case kError: | 951 case kError: |
952 DCHECK(state == kDisconnecting) << state; | 952 DCHECK(state == kDisconnecting) << state; |
953 break; | 953 break; |
954 }; | 954 }; |
955 state_ = state; | 955 state_ = state; |
956 NotifyStateChanged(state); | 956 NotifyStateChanged(state); |
957 } | 957 } |
958 | 958 |
959 void HostNPScriptObject::NotifyStateChanged(State state) { | 959 void HostNPScriptObject::NotifyStateChanged(State state) { |
960 if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { | 960 if (!plugin_task_runner_->BelongsToCurrentThread()) { |
961 plugin_message_loop_proxy_->PostTask( | 961 plugin_task_runner_->PostTask( |
962 FROM_HERE, base::Bind(&HostNPScriptObject::NotifyStateChanged, | 962 FROM_HERE, base::Bind(&HostNPScriptObject::NotifyStateChanged, |
963 base::Unretained(this), state)); | 963 base::Unretained(this), state)); |
964 return; | 964 return; |
965 } | 965 } |
966 if (on_state_changed_func_.get()) { | 966 if (on_state_changed_func_.get()) { |
967 VLOG(2) << "Calling state changed " << state; | 967 VLOG(2) << "Calling state changed " << state; |
968 NPVariant state_var; | 968 NPVariant state_var; |
969 INT32_TO_NPVARIANT(state, state_var); | 969 INT32_TO_NPVARIANT(state, state_var); |
970 bool is_good = InvokeAndIgnoreResult(on_state_changed_func_.get(), | 970 bool is_good = InvokeAndIgnoreResult(on_state_changed_func_.get(), |
971 &state_var, 1); | 971 &state_var, 1); |
972 LOG_IF(ERROR, !is_good) << "OnStateChanged failed"; | 972 LOG_IF(ERROR, !is_good) << "OnStateChanged failed"; |
973 } | 973 } |
974 } | 974 } |
975 void HostNPScriptObject::PostLogDebugInfo(const std::string& message) { | 975 void HostNPScriptObject::PostLogDebugInfo(const std::string& message) { |
976 if (plugin_message_loop_proxy_->BelongsToCurrentThread()) { | 976 if (plugin_task_runner_->BelongsToCurrentThread()) { |
977 // Make sure we're not currently processing a log message. | 977 // Make sure we're not currently processing a log message. |
978 // We only need to check this if we're on the plugin thread. | 978 // We only need to check this if we're on the plugin thread. |
979 if (am_currently_logging_) | 979 if (am_currently_logging_) |
980 return; | 980 return; |
981 } | 981 } |
982 | 982 |
983 // Always post (even if we're already on the correct thread) so that debug | 983 // Always post (even if we're already on the correct thread) so that debug |
984 // log messages are shown in the correct order. | 984 // log messages are shown in the correct order. |
985 plugin_message_loop_proxy_->PostTask( | 985 plugin_task_runner_->PostTask( |
986 FROM_HERE, base::Bind(&HostNPScriptObject::LogDebugInfo, | 986 FROM_HERE, base::Bind(&HostNPScriptObject::LogDebugInfo, |
987 base::Unretained(this), message)); | 987 base::Unretained(this), message)); |
988 } | 988 } |
989 | 989 |
990 void HostNPScriptObject::SetWindow(NPWindow* np_window) { | 990 void HostNPScriptObject::SetWindow(NPWindow* np_window) { |
991 daemon_controller_->SetWindow(np_window->window); | 991 daemon_controller_->SetWindow(np_window->window); |
992 } | 992 } |
993 | 993 |
994 void HostNPScriptObject::LocalizeStrings(NPObject* localize_func) { | 994 void HostNPScriptObject::LocalizeStrings(NPObject* localize_func) { |
995 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); | 995 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
996 | 996 |
997 UiStrings ui_strings; | 997 UiStrings ui_strings; |
998 string16 direction; | 998 string16 direction; |
999 LocalizeString(localize_func, "@@bidi_dir", &direction); | 999 LocalizeString(localize_func, "@@bidi_dir", &direction); |
1000 ui_strings.direction = UTF16ToUTF8(direction) == "rtl" ? | 1000 ui_strings.direction = UTF16ToUTF8(direction) == "rtl" ? |
1001 remoting::UiStrings::RTL : remoting::UiStrings::LTR; | 1001 remoting::UiStrings::RTL : remoting::UiStrings::LTR; |
1002 LocalizeString(localize_func, /*i18n-content*/"PRODUCT_NAME", | 1002 LocalizeString(localize_func, /*i18n-content*/"PRODUCT_NAME", |
1003 &ui_strings.product_name); | 1003 &ui_strings.product_name); |
1004 LocalizeString(localize_func, /*i18n-content*/"DISCONNECT_OTHER_BUTTON", | 1004 LocalizeString(localize_func, /*i18n-content*/"DISCONNECT_OTHER_BUTTON", |
1005 &ui_strings.disconnect_button_text); | 1005 &ui_strings.disconnect_button_text); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1040 g_npnetscape_funcs->releasevariantvalue(&np_result); | 1040 g_npnetscape_funcs->releasevariantvalue(&np_result); |
1041 if (translation.empty()) { | 1041 if (translation.empty()) { |
1042 LOG(ERROR) << "Missing translation for " << tag; | 1042 LOG(ERROR) << "Missing translation for " << tag; |
1043 return false; | 1043 return false; |
1044 } | 1044 } |
1045 *result = UTF8ToUTF16(translation); | 1045 *result = UTF8ToUTF16(translation); |
1046 return true; | 1046 return true; |
1047 } | 1047 } |
1048 | 1048 |
1049 void HostNPScriptObject::UpdateWebappNatPolicy(bool nat_traversal_enabled) { | 1049 void HostNPScriptObject::UpdateWebappNatPolicy(bool nat_traversal_enabled) { |
1050 if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { | 1050 if (!plugin_task_runner_->BelongsToCurrentThread()) { |
1051 plugin_message_loop_proxy_->PostTask( | 1051 plugin_task_runner_->PostTask( |
1052 FROM_HERE, base::Bind(&HostNPScriptObject::UpdateWebappNatPolicy, | 1052 FROM_HERE, base::Bind(&HostNPScriptObject::UpdateWebappNatPolicy, |
1053 base::Unretained(this), nat_traversal_enabled)); | 1053 base::Unretained(this), nat_traversal_enabled)); |
1054 return; | 1054 return; |
1055 } | 1055 } |
1056 if (on_nat_traversal_policy_changed_func_.get()) { | 1056 if (on_nat_traversal_policy_changed_func_.get()) { |
1057 NPVariant policy; | 1057 NPVariant policy; |
1058 BOOLEAN_TO_NPVARIANT(nat_traversal_enabled, policy); | 1058 BOOLEAN_TO_NPVARIANT(nat_traversal_enabled, policy); |
1059 InvokeAndIgnoreResult(on_nat_traversal_policy_changed_func_.get(), | 1059 InvokeAndIgnoreResult(on_nat_traversal_policy_changed_func_.get(), |
1060 &policy, 1); | 1060 &policy, 1); |
1061 } | 1061 } |
1062 } | 1062 } |
1063 | 1063 |
1064 void HostNPScriptObject::DoGenerateKeyPair(const ScopedRefNPObject& callback) { | 1064 void HostNPScriptObject::DoGenerateKeyPair(const ScopedRefNPObject& callback) { |
1065 HostKeyPair key_pair; | 1065 HostKeyPair key_pair; |
1066 key_pair.Generate(); | 1066 key_pair.Generate(); |
1067 InvokeGenerateKeyPairCallback(callback, key_pair.GetAsString(), | 1067 InvokeGenerateKeyPairCallback(callback, key_pair.GetAsString(), |
1068 key_pair.GetPublicKey()); | 1068 key_pair.GetPublicKey()); |
1069 } | 1069 } |
1070 | 1070 |
1071 void HostNPScriptObject::InvokeGenerateKeyPairCallback( | 1071 void HostNPScriptObject::InvokeGenerateKeyPairCallback( |
1072 const ScopedRefNPObject& callback, | 1072 const ScopedRefNPObject& callback, |
1073 const std::string& private_key, | 1073 const std::string& private_key, |
1074 const std::string& public_key) { | 1074 const std::string& public_key) { |
1075 if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { | 1075 if (!plugin_task_runner_->BelongsToCurrentThread()) { |
1076 plugin_message_loop_proxy_->PostTask( | 1076 plugin_task_runner_->PostTask( |
1077 FROM_HERE, base::Bind( | 1077 FROM_HERE, base::Bind( |
1078 &HostNPScriptObject::InvokeGenerateKeyPairCallback, | 1078 &HostNPScriptObject::InvokeGenerateKeyPairCallback, |
1079 base::Unretained(this), callback, private_key, public_key)); | 1079 base::Unretained(this), callback, private_key, public_key)); |
1080 return; | 1080 return; |
1081 } | 1081 } |
1082 | 1082 |
1083 NPVariant params[2]; | 1083 NPVariant params[2]; |
1084 params[0] = NPVariantFromString(private_key); | 1084 params[0] = NPVariantFromString(private_key); |
1085 params[1] = NPVariantFromString(public_key); | 1085 params[1] = NPVariantFromString(public_key); |
1086 InvokeAndIgnoreResult(callback.get(), params, arraysize(params)); | 1086 InvokeAndIgnoreResult(callback.get(), params, arraysize(params)); |
1087 g_npnetscape_funcs->releasevariantvalue(&(params[0])); | 1087 g_npnetscape_funcs->releasevariantvalue(&(params[0])); |
1088 g_npnetscape_funcs->releasevariantvalue(&(params[1])); | 1088 g_npnetscape_funcs->releasevariantvalue(&(params[1])); |
1089 } | 1089 } |
1090 | 1090 |
1091 void HostNPScriptObject::InvokeAsyncResultCallback( | 1091 void HostNPScriptObject::InvokeAsyncResultCallback( |
1092 const ScopedRefNPObject& callback, | 1092 const ScopedRefNPObject& callback, |
1093 DaemonController::AsyncResult result) { | 1093 DaemonController::AsyncResult result) { |
1094 if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { | 1094 if (!plugin_task_runner_->BelongsToCurrentThread()) { |
1095 plugin_message_loop_proxy_->PostTask( | 1095 plugin_task_runner_->PostTask( |
1096 FROM_HERE, base::Bind( | 1096 FROM_HERE, base::Bind( |
1097 &HostNPScriptObject::InvokeAsyncResultCallback, | 1097 &HostNPScriptObject::InvokeAsyncResultCallback, |
1098 base::Unretained(this), callback, result)); | 1098 base::Unretained(this), callback, result)); |
1099 return; | 1099 return; |
1100 } | 1100 } |
1101 | 1101 |
1102 NPVariant result_var; | 1102 NPVariant result_var; |
1103 INT32_TO_NPVARIANT(static_cast<int32>(result), result_var); | 1103 INT32_TO_NPVARIANT(static_cast<int32>(result), result_var); |
1104 InvokeAndIgnoreResult(callback.get(), &result_var, 1); | 1104 InvokeAndIgnoreResult(callback.get(), &result_var, 1); |
1105 g_npnetscape_funcs->releasevariantvalue(&result_var); | 1105 g_npnetscape_funcs->releasevariantvalue(&result_var); |
1106 } | 1106 } |
1107 | 1107 |
1108 void HostNPScriptObject::InvokeGetDaemonConfigCallback( | 1108 void HostNPScriptObject::InvokeGetDaemonConfigCallback( |
1109 const ScopedRefNPObject& callback, | 1109 const ScopedRefNPObject& callback, |
1110 scoped_ptr<base::DictionaryValue> config) { | 1110 scoped_ptr<base::DictionaryValue> config) { |
1111 if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { | 1111 if (!plugin_task_runner_->BelongsToCurrentThread()) { |
1112 plugin_message_loop_proxy_->PostTask( | 1112 plugin_task_runner_->PostTask( |
1113 FROM_HERE, base::Bind( | 1113 FROM_HERE, base::Bind( |
1114 &HostNPScriptObject::InvokeGetDaemonConfigCallback, | 1114 &HostNPScriptObject::InvokeGetDaemonConfigCallback, |
1115 base::Unretained(this), callback, base::Passed(&config))); | 1115 base::Unretained(this), callback, base::Passed(&config))); |
1116 return; | 1116 return; |
1117 } | 1117 } |
1118 | 1118 |
1119 // There is no easy way to create a dictionary from an NPAPI plugin | 1119 // There is no easy way to create a dictionary from an NPAPI plugin |
1120 // so we have to serialize the dictionary to pass it to JavaScript. | 1120 // so we have to serialize the dictionary to pass it to JavaScript. |
1121 std::string config_str; | 1121 std::string config_str; |
1122 if (config.get()) | 1122 if (config.get()) |
1123 base::JSONWriter::Write(config.get(), &config_str); | 1123 base::JSONWriter::Write(config.get(), &config_str); |
1124 | 1124 |
1125 NPVariant config_val = NPVariantFromString(config_str); | 1125 NPVariant config_val = NPVariantFromString(config_str); |
1126 InvokeAndIgnoreResult(callback.get(), &config_val, 1); | 1126 InvokeAndIgnoreResult(callback.get(), &config_val, 1); |
1127 g_npnetscape_funcs->releasevariantvalue(&config_val); | 1127 g_npnetscape_funcs->releasevariantvalue(&config_val); |
1128 } | 1128 } |
1129 | 1129 |
1130 void HostNPScriptObject::InvokeGetDaemonVersionCallback( | 1130 void HostNPScriptObject::InvokeGetDaemonVersionCallback( |
1131 const ScopedRefNPObject& callback, const std::string& version) { | 1131 const ScopedRefNPObject& callback, const std::string& version) { |
1132 if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { | 1132 if (!plugin_task_runner_->BelongsToCurrentThread()) { |
1133 plugin_message_loop_proxy_->PostTask( | 1133 plugin_task_runner_->PostTask( |
1134 FROM_HERE, base::Bind( | 1134 FROM_HERE, base::Bind( |
1135 &HostNPScriptObject::InvokeGetDaemonVersionCallback, | 1135 &HostNPScriptObject::InvokeGetDaemonVersionCallback, |
1136 base::Unretained(this), callback, version)); | 1136 base::Unretained(this), callback, version)); |
1137 return; | 1137 return; |
1138 } | 1138 } |
1139 | 1139 |
1140 NPVariant version_val = NPVariantFromString(version); | 1140 NPVariant version_val = NPVariantFromString(version); |
1141 InvokeAndIgnoreResult(callback.get(), &version_val, 1); | 1141 InvokeAndIgnoreResult(callback.get(), &version_val, 1); |
1142 g_npnetscape_funcs->releasevariantvalue(&version_val); | 1142 g_npnetscape_funcs->releasevariantvalue(&version_val); |
1143 } | 1143 } |
1144 | 1144 |
1145 void HostNPScriptObject::LogDebugInfo(const std::string& message) { | 1145 void HostNPScriptObject::LogDebugInfo(const std::string& message) { |
1146 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); | 1146 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
1147 if (log_debug_info_func_.get()) { | 1147 if (log_debug_info_func_.get()) { |
1148 am_currently_logging_ = true; | 1148 am_currently_logging_ = true; |
1149 NPVariant log_message; | 1149 NPVariant log_message; |
1150 STRINGZ_TO_NPVARIANT(message.c_str(), log_message); | 1150 STRINGZ_TO_NPVARIANT(message.c_str(), log_message); |
1151 bool is_good = InvokeAndIgnoreResult(log_debug_info_func_.get(), | 1151 bool is_good = InvokeAndIgnoreResult(log_debug_info_func_.get(), |
1152 &log_message, 1); | 1152 &log_message, 1); |
1153 if (!is_good) { | 1153 if (!is_good) { |
1154 LOG(ERROR) << "ERROR - LogDebugInfo failed\n"; | 1154 LOG(ERROR) << "ERROR - LogDebugInfo failed\n"; |
1155 } | 1155 } |
1156 am_currently_logging_ = false; | 1156 am_currently_logging_ = false; |
1157 } | 1157 } |
1158 } | 1158 } |
1159 | 1159 |
1160 bool HostNPScriptObject::InvokeAndIgnoreResult(NPObject* func, | 1160 bool HostNPScriptObject::InvokeAndIgnoreResult(NPObject* func, |
1161 const NPVariant* args, | 1161 const NPVariant* args, |
1162 uint32_t arg_count) { | 1162 uint32_t arg_count) { |
1163 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); | 1163 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
1164 NPVariant np_result; | 1164 NPVariant np_result; |
1165 bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args, | 1165 bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args, |
1166 arg_count, &np_result); | 1166 arg_count, &np_result); |
1167 if (is_good) | 1167 if (is_good) |
1168 g_npnetscape_funcs->releasevariantvalue(&np_result); | 1168 g_npnetscape_funcs->releasevariantvalue(&np_result); |
1169 return is_good; | 1169 return is_good; |
1170 } | 1170 } |
1171 | 1171 |
1172 void HostNPScriptObject::SetException(const std::string& exception_string) { | 1172 void HostNPScriptObject::SetException(const std::string& exception_string) { |
1173 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); | 1173 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
1174 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); | 1174 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); |
1175 LOG(INFO) << exception_string; | 1175 LOG(INFO) << exception_string; |
1176 } | 1176 } |
1177 | 1177 |
1178 } // namespace remoting | 1178 } // namespace remoting |
OLD | NEW |