| 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 #include "remoting/host/plugin/daemon_controller.h" | 6 #include "remoting/host/plugin/daemon_controller.h" |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 HostNPScriptObject::HostNPScriptObject( | 60 HostNPScriptObject::HostNPScriptObject( |
| 61 NPP plugin, | 61 NPP plugin, |
| 62 NPObject* parent, | 62 NPObject* parent, |
| 63 PluginMessageLoopProxy::Delegate* plugin_thread_delegate) | 63 PluginMessageLoopProxy::Delegate* plugin_thread_delegate) |
| 64 : plugin_(plugin), | 64 : plugin_(plugin), |
| 65 parent_(parent), | 65 parent_(parent), |
| 66 state_(kDisconnected), | 66 state_(kDisconnected), |
| 67 np_thread_id_(base::PlatformThread::CurrentId()), | 67 np_thread_id_(base::PlatformThread::CurrentId()), |
| 68 plugin_message_loop_proxy_( | 68 plugin_message_loop_proxy_( |
| 69 new PluginMessageLoopProxy(plugin_thread_delegate)), | 69 new PluginMessageLoopProxy(plugin_thread_delegate)), |
| 70 host_context_(plugin_message_loop_proxy_), | |
| 71 failed_login_attempts_(0), | 70 failed_login_attempts_(0), |
| 72 daemon_controller_(DaemonController::Create()), | 71 daemon_controller_(DaemonController::Create()), |
| 73 disconnected_event_(true, false), | 72 disconnected_event_(true, false), |
| 74 am_currently_logging_(false), | 73 am_currently_logging_(false), |
| 75 nat_traversal_enabled_(false), | 74 nat_traversal_enabled_(false), |
| 76 policy_received_(false) { | 75 policy_received_(false) { |
| 77 } | 76 } |
| 78 | 77 |
| 79 HostNPScriptObject::~HostNPScriptObject() { | 78 HostNPScriptObject::~HostNPScriptObject() { |
| 80 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); | 79 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); |
| 81 | 80 |
| 82 // Shutdown It2MeHostUserInterface first so that it doesn't try to post | 81 // Shutdown It2MeHostUserInterface first so that it doesn't try to post |
| 83 // tasks on the UI thread while we are stopping the host. | 82 // tasks on the UI thread while we are stopping the host. |
| 84 if (it2me_host_user_interface_.get()) { | 83 if (it2me_host_user_interface_.get()) { |
| 85 it2me_host_user_interface_->Shutdown(); | 84 it2me_host_user_interface_->Shutdown(); |
| 86 } | 85 } |
| 87 | 86 |
| 88 HostLogHandler::UnregisterLoggingScriptObject(this); | 87 HostLogHandler::UnregisterLoggingScriptObject(this); |
| 89 | 88 |
| 90 plugin_message_loop_proxy_->Detach(); | 89 plugin_message_loop_proxy_->Detach(); |
| 91 | 90 |
| 92 // Stop listening for policy updates. | 91 // Stop listening for policy updates. |
| 93 if (nat_policy_.get()) { | 92 if (nat_policy_.get()) { |
| 94 base::WaitableEvent nat_policy_stopped_(true, false); | 93 base::WaitableEvent nat_policy_stopped_(true, false); |
| 95 nat_policy_->StopWatching(&nat_policy_stopped_); | 94 nat_policy_->StopWatching(&nat_policy_stopped_); |
| 96 nat_policy_stopped_.Wait(); | 95 nat_policy_stopped_.Wait(); |
| 97 nat_policy_.reset(); | 96 nat_policy_.reset(); |
| 98 } | 97 } |
| 99 | 98 |
| 100 // Disconnect synchronously. We cannot disconnect asynchronously | 99 if (host_context_.get()) { |
| 101 // here because |host_context_| needs to be stopped on the plugin | 100 // Disconnect synchronously. We cannot disconnect asynchronously |
| 102 // thread, but the plugin thread may not exist after the instance | 101 // here because |host_context_| needs to be stopped on the plugin |
| 103 // is destroyed. | 102 // thread, but the plugin thread may not exist after the instance |
| 104 disconnected_event_.Reset(); | 103 // is destroyed. |
| 105 DisconnectInternal(); | 104 disconnected_event_.Reset(); |
| 106 disconnected_event_.Wait(); | 105 DisconnectInternal(); |
| 106 disconnected_event_.Wait(); |
| 107 | 107 |
| 108 // Stop all threads. | 108 // Stops all threads. |
| 109 host_context_.Stop(); | 109 host_context_.reset(); |
| 110 } |
| 110 } | 111 } |
| 111 | 112 |
| 112 bool HostNPScriptObject::Init() { | 113 bool HostNPScriptObject::Init() { |
| 113 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); | 114 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); |
| 114 VLOG(2) << "Init"; | 115 VLOG(2) << "Init"; |
| 115 // TODO(wez): This starts a bunch of threads, which might fail. | 116 |
| 116 host_context_.Start(); | 117 host_context_.reset(new ChromotingHostContext(plugin_message_loop_proxy_)); |
| 118 if (!host_context_->Start()) { |
| 119 host_context_.reset(); |
| 120 return false; |
| 121 } |
| 122 |
| 117 nat_policy_.reset( | 123 nat_policy_.reset( |
| 118 policy_hack::NatPolicy::Create(host_context_.network_message_loop())); | 124 policy_hack::NatPolicy::Create(host_context_->network_message_loop())); |
| 119 nat_policy_->StartWatching( | 125 nat_policy_->StartWatching( |
| 120 base::Bind(&HostNPScriptObject::OnNatPolicyUpdate, | 126 base::Bind(&HostNPScriptObject::OnNatPolicyUpdate, |
| 121 base::Unretained(this))); | 127 base::Unretained(this))); |
| 122 return true; | 128 return true; |
| 123 } | 129 } |
| 124 | 130 |
| 125 bool HostNPScriptObject::HasMethod(const std::string& method_name) { | 131 bool HostNPScriptObject::HasMethod(const std::string& method_name) { |
| 126 VLOG(2) << "HasMethod " << method_name; | 132 VLOG(2) << "HasMethod " << method_name; |
| 127 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); | 133 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); |
| 128 return (method_name == kFuncNameConnect || | 134 return (method_name == kFuncNameConnect || |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 kFuncNameStartDaemon, | 333 kFuncNameStartDaemon, |
| 328 kFuncNameStopDaemon | 334 kFuncNameStopDaemon |
| 329 }; | 335 }; |
| 330 for (size_t i = 0; i < arraysize(entries); ++i) { | 336 for (size_t i = 0; i < arraysize(entries); ++i) { |
| 331 values->push_back(entries[i]); | 337 values->push_back(entries[i]); |
| 332 } | 338 } |
| 333 return true; | 339 return true; |
| 334 } | 340 } |
| 335 | 341 |
| 336 void HostNPScriptObject::OnAccessDenied(const std::string& jid) { | 342 void HostNPScriptObject::OnAccessDenied(const std::string& jid) { |
| 337 DCHECK(host_context_.network_message_loop()->BelongsToCurrentThread()); | 343 DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); |
| 338 | 344 |
| 339 ++failed_login_attempts_; | 345 ++failed_login_attempts_; |
| 340 if (failed_login_attempts_ == kMaxLoginAttempts) { | 346 if (failed_login_attempts_ == kMaxLoginAttempts) { |
| 341 DisconnectInternal(); | 347 DisconnectInternal(); |
| 342 } | 348 } |
| 343 } | 349 } |
| 344 | 350 |
| 345 void HostNPScriptObject::OnClientAuthenticated(const std::string& jid) { | 351 void HostNPScriptObject::OnClientAuthenticated(const std::string& jid) { |
| 346 DCHECK(host_context_.network_message_loop()->BelongsToCurrentThread()); | 352 DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); |
| 347 | 353 |
| 348 if (state_ == kDisconnecting) { | 354 if (state_ == kDisconnecting) { |
| 349 // Ignore the new connection if we are disconnecting. | 355 // Ignore the new connection if we are disconnecting. |
| 350 return; | 356 return; |
| 351 } | 357 } |
| 352 | 358 |
| 353 client_username_ = jid; | 359 client_username_ = jid; |
| 354 size_t pos = client_username_.find('/'); | 360 size_t pos = client_username_.find('/'); |
| 355 if (pos != std::string::npos) | 361 if (pos != std::string::npos) |
| 356 client_username_.replace(pos, std::string::npos, ""); | 362 client_username_.replace(pos, std::string::npos, ""); |
| 357 LOG(INFO) << "Client " << client_username_ << " connected."; | 363 LOG(INFO) << "Client " << client_username_ << " connected."; |
| 358 SetState(kConnected); | 364 SetState(kConnected); |
| 359 } | 365 } |
| 360 | 366 |
| 361 void HostNPScriptObject::OnClientDisconnected(const std::string& jid) { | 367 void HostNPScriptObject::OnClientDisconnected(const std::string& jid) { |
| 362 DCHECK(host_context_.network_message_loop()->BelongsToCurrentThread()); | 368 DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); |
| 363 client_username_.clear(); | 369 client_username_.clear(); |
| 364 DisconnectInternal(); | 370 DisconnectInternal(); |
| 365 } | 371 } |
| 366 | 372 |
| 367 void HostNPScriptObject::OnShutdown() { | 373 void HostNPScriptObject::OnShutdown() { |
| 368 DCHECK(host_context_.network_message_loop()->BelongsToCurrentThread()); | 374 DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); |
| 369 | 375 |
| 370 register_request_.reset(); | 376 register_request_.reset(); |
| 371 log_to_server_.reset(); | 377 log_to_server_.reset(); |
| 372 signal_strategy_.reset(); | 378 signal_strategy_.reset(); |
| 373 host_->RemoveStatusObserver(this); | 379 host_->RemoveStatusObserver(this); |
| 374 host_ = NULL; | 380 host_ = NULL; |
| 375 | 381 |
| 376 if (state_ != kDisconnected) { | 382 if (state_ != kDisconnected) { |
| 377 SetState(kDisconnected); | 383 SetState(kDisconnected); |
| 378 } | 384 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 } | 419 } |
| 414 | 420 |
| 415 ReadPolicyAndConnect(uid, auth_token, auth_service); | 421 ReadPolicyAndConnect(uid, auth_token, auth_service); |
| 416 | 422 |
| 417 return true; | 423 return true; |
| 418 } | 424 } |
| 419 | 425 |
| 420 void HostNPScriptObject::ReadPolicyAndConnect(const std::string& uid, | 426 void HostNPScriptObject::ReadPolicyAndConnect(const std::string& uid, |
| 421 const std::string& auth_token, | 427 const std::string& auth_token, |
| 422 const std::string& auth_service) { | 428 const std::string& auth_service) { |
| 423 if (!host_context_.network_message_loop()->BelongsToCurrentThread()) { | 429 if (!host_context_->network_message_loop()->BelongsToCurrentThread()) { |
| 424 host_context_.network_message_loop()->PostTask( | 430 host_context_->network_message_loop()->PostTask( |
| 425 FROM_HERE, base::Bind( | 431 FROM_HERE, base::Bind( |
| 426 &HostNPScriptObject::ReadPolicyAndConnect, base::Unretained(this), | 432 &HostNPScriptObject::ReadPolicyAndConnect, base::Unretained(this), |
| 427 uid, auth_token, auth_service)); | 433 uid, auth_token, auth_service)); |
| 428 return; | 434 return; |
| 429 } | 435 } |
| 430 | 436 |
| 431 SetState(kStarting); | 437 SetState(kStarting); |
| 432 | 438 |
| 433 // Only proceed to FinishConnect() if at least one policy update has been | 439 // Only proceed to FinishConnect() if at least one policy update has been |
| 434 // received. | 440 // received. |
| 435 if (policy_received_) { | 441 if (policy_received_) { |
| 436 FinishConnectMainThread(uid, auth_token, auth_service); | 442 FinishConnectMainThread(uid, auth_token, auth_service); |
| 437 } else { | 443 } else { |
| 438 // Otherwise, create the policy watcher, and thunk the connect. | 444 // Otherwise, create the policy watcher, and thunk the connect. |
| 439 pending_connect_ = | 445 pending_connect_ = |
| 440 base::Bind(&HostNPScriptObject::FinishConnectMainThread, | 446 base::Bind(&HostNPScriptObject::FinishConnectMainThread, |
| 441 base::Unretained(this), uid, auth_token, auth_service); | 447 base::Unretained(this), uid, auth_token, auth_service); |
| 442 } | 448 } |
| 443 } | 449 } |
| 444 | 450 |
| 445 void HostNPScriptObject::FinishConnectMainThread( | 451 void HostNPScriptObject::FinishConnectMainThread( |
| 446 const std::string& uid, | 452 const std::string& uid, |
| 447 const std::string& auth_token, | 453 const std::string& auth_token, |
| 448 const std::string& auth_service) { | 454 const std::string& auth_service) { |
| 449 if (host_context_.main_message_loop() != MessageLoop::current()) { | 455 if (host_context_->main_message_loop() != MessageLoop::current()) { |
| 450 host_context_.main_message_loop()->PostTask(FROM_HERE, base::Bind( | 456 host_context_->main_message_loop()->PostTask(FROM_HERE, base::Bind( |
| 451 &HostNPScriptObject::FinishConnectMainThread, base::Unretained(this), | 457 &HostNPScriptObject::FinishConnectMainThread, base::Unretained(this), |
| 452 uid, auth_token, auth_service)); | 458 uid, auth_token, auth_service)); |
| 453 return; | 459 return; |
| 454 } | 460 } |
| 455 | 461 |
| 456 // DesktopEnvironment must be initialized on the main thread. | 462 // DesktopEnvironment must be initialized on the main thread. |
| 457 // | 463 // |
| 458 // TODO(sergeyu): Fix DesktopEnvironment so that it can be created | 464 // TODO(sergeyu): Fix DesktopEnvironment so that it can be created |
| 459 // on either the UI or the network thread so that we can avoid | 465 // on either the UI or the network thread so that we can avoid |
| 460 // jumping to the main thread here. | 466 // jumping to the main thread here. |
| 461 desktop_environment_.reset(DesktopEnvironment::Create(&host_context_)); | 467 desktop_environment_.reset(DesktopEnvironment::Create(host_context_.get())); |
| 462 | 468 |
| 463 FinishConnectNetworkThread(uid, auth_token, auth_service); | 469 FinishConnectNetworkThread(uid, auth_token, auth_service); |
| 464 } | 470 } |
| 465 | 471 |
| 466 void HostNPScriptObject::FinishConnectNetworkThread( | 472 void HostNPScriptObject::FinishConnectNetworkThread( |
| 467 const std::string& uid, | 473 const std::string& uid, |
| 468 const std::string& auth_token, | 474 const std::string& auth_token, |
| 469 const std::string& auth_service) { | 475 const std::string& auth_service) { |
| 470 if (!host_context_.network_message_loop()->BelongsToCurrentThread()) { | 476 if (!host_context_->network_message_loop()->BelongsToCurrentThread()) { |
| 471 host_context_.network_message_loop()->PostTask(FROM_HERE, base::Bind( | 477 host_context_->network_message_loop()->PostTask(FROM_HERE, base::Bind( |
| 472 &HostNPScriptObject::FinishConnectNetworkThread, base::Unretained(this), | 478 &HostNPScriptObject::FinishConnectNetworkThread, base::Unretained(this), |
| 473 uid, auth_token, auth_service)); | 479 uid, auth_token, auth_service)); |
| 474 return; | 480 return; |
| 475 } | 481 } |
| 476 | 482 |
| 477 if (state_ != kStarting) { | 483 if (state_ != kStarting) { |
| 478 // Host has been stopped while we were fetching policy. | 484 // Host has been stopped while we were fetching policy. |
| 479 return; | 485 return; |
| 480 } | 486 } |
| 481 | 487 |
| 482 // Verify that DesktopEnvironment has been created. | 488 // Verify that DesktopEnvironment has been created. |
| 483 if (desktop_environment_.get() == NULL) { | 489 if (desktop_environment_.get() == NULL) { |
| 484 SetState(kError); | 490 SetState(kError); |
| 485 return; | 491 return; |
| 486 } | 492 } |
| 487 | 493 |
| 488 // Generate a key pair for the Host to use. | 494 // Generate a key pair for the Host to use. |
| 489 // TODO(wez): Move this to the worker thread. | 495 // TODO(wez): Move this to the worker thread. |
| 490 host_key_pair_.Generate(); | 496 host_key_pair_.Generate(); |
| 491 | 497 |
| 492 // Create XMPP connection. | 498 // Create XMPP connection. |
| 493 scoped_ptr<SignalStrategy> signal_strategy( | 499 scoped_ptr<SignalStrategy> signal_strategy( |
| 494 new XmppSignalStrategy(host_context_.jingle_thread(), uid, | 500 new XmppSignalStrategy(host_context_->jingle_thread(), uid, |
| 495 auth_token, auth_service)); | 501 auth_token, auth_service)); |
| 496 | 502 |
| 497 // Request registration of the host for support. | 503 // Request registration of the host for support. |
| 498 scoped_ptr<RegisterSupportHostRequest> register_request( | 504 scoped_ptr<RegisterSupportHostRequest> register_request( |
| 499 new RegisterSupportHostRequest( | 505 new RegisterSupportHostRequest( |
| 500 signal_strategy.get(), &host_key_pair_, | 506 signal_strategy.get(), &host_key_pair_, |
| 501 base::Bind(&HostNPScriptObject::OnReceivedSupportID, | 507 base::Bind(&HostNPScriptObject::OnReceivedSupportID, |
| 502 base::Unretained(this)))); | 508 base::Unretained(this)))); |
| 503 | 509 |
| 504 // Beyond this point nothing can fail, so save the config and request. | 510 // Beyond this point nothing can fail, so save the config and request. |
| 505 signal_strategy_.reset(signal_strategy.release()); | 511 signal_strategy_.reset(signal_strategy.release()); |
| 506 register_request_.reset(register_request.release()); | 512 register_request_.reset(register_request.release()); |
| 507 | 513 |
| 508 // Create the Host. | 514 // Create the Host. |
| 509 LOG(INFO) << "NAT state: " << nat_traversal_enabled_; | 515 LOG(INFO) << "NAT state: " << nat_traversal_enabled_; |
| 510 host_ = new ChromotingHost( | 516 host_ = new ChromotingHost( |
| 511 &host_context_, signal_strategy_.get(), desktop_environment_.get(), | 517 host_context_.get(), signal_strategy_.get(), desktop_environment_.get(), |
| 512 protocol::NetworkSettings(nat_traversal_enabled_)); | 518 protocol::NetworkSettings(nat_traversal_enabled_)); |
| 513 host_->AddStatusObserver(this); | 519 host_->AddStatusObserver(this); |
| 514 log_to_server_.reset( | 520 log_to_server_.reset( |
| 515 new LogToServer(host_, ServerLogEntry::IT2ME, signal_strategy_.get())); | 521 new LogToServer(host_, ServerLogEntry::IT2ME, signal_strategy_.get())); |
| 516 it2me_host_user_interface_.reset( | 522 it2me_host_user_interface_.reset( |
| 517 new It2MeHostUserInterface(host_.get(), &host_context_)); | 523 new It2MeHostUserInterface(host_.get(), host_context_.get())); |
| 518 it2me_host_user_interface_->Init(); | 524 it2me_host_user_interface_->Init(); |
| 519 | 525 |
| 520 { | 526 { |
| 521 base::AutoLock auto_lock(ui_strings_lock_); | 527 base::AutoLock auto_lock(ui_strings_lock_); |
| 522 host_->SetUiStrings(ui_strings_); | 528 host_->SetUiStrings(ui_strings_); |
| 523 } | 529 } |
| 524 | 530 |
| 525 signal_strategy_->Connect(); | 531 signal_strategy_->Connect(); |
| 526 host_->Start(); | 532 host_->Start(); |
| 527 | 533 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 if (arg_count != 0) { | 604 if (arg_count != 0) { |
| 599 SetException("startDaemon: bad number of arguments"); | 605 SetException("startDaemon: bad number of arguments"); |
| 600 return false; | 606 return false; |
| 601 } | 607 } |
| 602 bool stop_result = daemon_controller_->Stop(); | 608 bool stop_result = daemon_controller_->Stop(); |
| 603 BOOLEAN_TO_NPVARIANT(stop_result, *result); | 609 BOOLEAN_TO_NPVARIANT(stop_result, *result); |
| 604 return true; | 610 return true; |
| 605 } | 611 } |
| 606 | 612 |
| 607 void HostNPScriptObject::DisconnectInternal() { | 613 void HostNPScriptObject::DisconnectInternal() { |
| 608 if (!host_context_.network_message_loop()->BelongsToCurrentThread()) { | 614 if (!host_context_->network_message_loop()->BelongsToCurrentThread()) { |
| 609 host_context_.network_message_loop()->PostTask( | 615 host_context_->network_message_loop()->PostTask( |
| 610 FROM_HERE, base::Bind(&HostNPScriptObject::DisconnectInternal, | 616 FROM_HERE, base::Bind(&HostNPScriptObject::DisconnectInternal, |
| 611 base::Unretained(this))); | 617 base::Unretained(this))); |
| 612 return; | 618 return; |
| 613 } | 619 } |
| 614 | 620 |
| 615 switch (state_) { | 621 switch (state_) { |
| 616 case kDisconnected: | 622 case kDisconnected: |
| 617 disconnected_event_.Signal(); | 623 disconnected_event_.Signal(); |
| 618 return; | 624 return; |
| 619 | 625 |
| 620 case kStarting: | 626 case kStarting: |
| 621 SetState(kDisconnecting); | 627 SetState(kDisconnecting); |
| 622 SetState(kDisconnected); | 628 SetState(kDisconnected); |
| 623 disconnected_event_.Signal(); | 629 disconnected_event_.Signal(); |
| 624 return; | 630 return; |
| 625 | 631 |
| 626 case kDisconnecting: | 632 case kDisconnecting: |
| 627 return; | 633 return; |
| 628 | 634 |
| 629 default: | 635 default: |
| 630 DCHECK(host_); | 636 DCHECK(host_); |
| 631 SetState(kDisconnecting); | 637 SetState(kDisconnecting); |
| 632 | 638 |
| 633 // ChromotingHost::Shutdown() may destroy SignalStrategy | 639 // ChromotingHost::Shutdown() may destroy SignalStrategy |
| 634 // synchronously, bug SignalStrategy::Listener handlers are not | 640 // synchronously, bug SignalStrategy::Listener handlers are not |
| 635 // allowed to destroy SignalStrategy, so post task to call | 641 // allowed to destroy SignalStrategy, so post task to call |
| 636 // Shutdown() later. | 642 // Shutdown() later. |
| 637 host_context_.network_message_loop()->PostTask( | 643 host_context_->network_message_loop()->PostTask( |
| 638 FROM_HERE, base::Bind( | 644 FROM_HERE, base::Bind( |
| 639 &ChromotingHost::Shutdown, host_, | 645 &ChromotingHost::Shutdown, host_, |
| 640 base::Bind(&HostNPScriptObject::OnShutdownFinished, | 646 base::Bind(&HostNPScriptObject::OnShutdownFinished, |
| 641 base::Unretained(this)))); | 647 base::Unretained(this)))); |
| 642 } | 648 } |
| 643 } | 649 } |
| 644 | 650 |
| 645 void HostNPScriptObject::OnShutdownFinished() { | 651 void HostNPScriptObject::OnShutdownFinished() { |
| 646 DCHECK(host_context_.network_message_loop()->BelongsToCurrentThread()); | 652 DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); |
| 647 | 653 |
| 648 disconnected_event_.Signal(); | 654 disconnected_event_.Signal(); |
| 649 } | 655 } |
| 650 | 656 |
| 651 void HostNPScriptObject::OnNatPolicyUpdate(bool nat_traversal_enabled) { | 657 void HostNPScriptObject::OnNatPolicyUpdate(bool nat_traversal_enabled) { |
| 652 if (!host_context_.network_message_loop()->BelongsToCurrentThread()) { | 658 if (!host_context_->network_message_loop()->BelongsToCurrentThread()) { |
| 653 host_context_.network_message_loop()->PostTask( | 659 host_context_->network_message_loop()->PostTask( |
| 654 FROM_HERE, | 660 FROM_HERE, |
| 655 base::Bind(&HostNPScriptObject::OnNatPolicyUpdate, | 661 base::Bind(&HostNPScriptObject::OnNatPolicyUpdate, |
| 656 base::Unretained(this), nat_traversal_enabled)); | 662 base::Unretained(this), nat_traversal_enabled)); |
| 657 return; | 663 return; |
| 658 } | 664 } |
| 659 | 665 |
| 660 VLOG(2) << "OnNatPolicyUpdate: " << nat_traversal_enabled; | 666 VLOG(2) << "OnNatPolicyUpdate: " << nat_traversal_enabled; |
| 661 | 667 |
| 662 // When transitioning from enabled to disabled, force disconnect any | 668 // When transitioning from enabled to disabled, force disconnect any |
| 663 // existing session. | 669 // existing session. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 676 if (!pending_connect_.is_null()) { | 682 if (!pending_connect_.is_null()) { |
| 677 pending_connect_.Run(); | 683 pending_connect_.Run(); |
| 678 pending_connect_.Reset(); | 684 pending_connect_.Reset(); |
| 679 } | 685 } |
| 680 } | 686 } |
| 681 | 687 |
| 682 void HostNPScriptObject::OnReceivedSupportID( | 688 void HostNPScriptObject::OnReceivedSupportID( |
| 683 bool success, | 689 bool success, |
| 684 const std::string& support_id, | 690 const std::string& support_id, |
| 685 const base::TimeDelta& lifetime) { | 691 const base::TimeDelta& lifetime) { |
| 686 DCHECK(host_context_.network_message_loop()->BelongsToCurrentThread()); | 692 DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); |
| 687 | 693 |
| 688 if (!success) { | 694 if (!success) { |
| 689 SetState(kError); | 695 SetState(kError); |
| 690 DisconnectInternal(); | 696 DisconnectInternal(); |
| 691 return; | 697 return; |
| 692 } | 698 } |
| 693 | 699 |
| 694 std::string host_secret = GenerateSupportHostSecret(); | 700 std::string host_secret = GenerateSupportHostSecret(); |
| 695 std::string access_code = support_id + host_secret; | 701 std::string access_code = support_id + host_secret; |
| 696 scoped_ptr<protocol::AuthenticatorFactory> factory( | 702 scoped_ptr<protocol::AuthenticatorFactory> factory( |
| 697 new protocol::It2MeHostAuthenticatorFactory( | 703 new protocol::It2MeHostAuthenticatorFactory( |
| 698 host_key_pair_.GenerateCertificate(), *host_key_pair_.private_key(), | 704 host_key_pair_.GenerateCertificate(), *host_key_pair_.private_key(), |
| 699 access_code)); | 705 access_code)); |
| 700 host_->SetAuthenticatorFactory(factory.Pass()); | 706 host_->SetAuthenticatorFactory(factory.Pass()); |
| 701 | 707 |
| 702 { | 708 { |
| 703 base::AutoLock lock(access_code_lock_); | 709 base::AutoLock lock(access_code_lock_); |
| 704 access_code_ = access_code; | 710 access_code_ = access_code; |
| 705 access_code_lifetime_ = lifetime; | 711 access_code_lifetime_ = lifetime; |
| 706 } | 712 } |
| 707 | 713 |
| 708 SetState(kReceivedAccessCode); | 714 SetState(kReceivedAccessCode); |
| 709 } | 715 } |
| 710 | 716 |
| 711 void HostNPScriptObject::SetState(State state) { | 717 void HostNPScriptObject::SetState(State state) { |
| 712 DCHECK(host_context_.network_message_loop()->BelongsToCurrentThread()); | 718 DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); |
| 713 switch (state_) { | 719 switch (state_) { |
| 714 case kDisconnected: | 720 case kDisconnected: |
| 715 DCHECK(state == kStarting || | 721 DCHECK(state == kStarting || |
| 716 state == kError) << state; | 722 state == kError) << state; |
| 717 break; | 723 break; |
| 718 case kStarting: | 724 case kStarting: |
| 719 DCHECK(state == kRequestedAccessCode || | 725 DCHECK(state == kRequestedAccessCode || |
| 720 state == kDisconnecting || | 726 state == kDisconnecting || |
| 721 state == kError) << state; | 727 state == kError) << state; |
| 722 break; | 728 break; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 uint32_t argCount) { | 880 uint32_t argCount) { |
| 875 NPVariant np_result; | 881 NPVariant np_result; |
| 876 bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args, | 882 bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args, |
| 877 argCount, &np_result); | 883 argCount, &np_result); |
| 878 if (is_good) | 884 if (is_good) |
| 879 g_npnetscape_funcs->releasevariantvalue(&np_result); | 885 g_npnetscape_funcs->releasevariantvalue(&np_result); |
| 880 return is_good; | 886 return is_good; |
| 881 } | 887 } |
| 882 | 888 |
| 883 } // namespace remoting | 889 } // namespace remoting |
| OLD | NEW |