Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| 11 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | |
| 13 #include "remoting/base/auth_token_util.h" | 14 #include "remoting/base/auth_token_util.h" |
| 14 #include "remoting/host/chromoting_host.h" | 15 #include "remoting/host/chromoting_host.h" |
| 15 #include "remoting/host/chromoting_host_context.h" | 16 #include "remoting/host/chromoting_host_context.h" |
| 16 #include "remoting/host/desktop_environment.h" | 17 #include "remoting/host/desktop_environment.h" |
| 17 #include "remoting/host/host_config.h" | 18 #include "remoting/host/host_config.h" |
| 18 #include "remoting/host/host_key_pair.h" | 19 #include "remoting/host/host_key_pair.h" |
| 19 #include "remoting/host/host_secret.h" | 20 #include "remoting/host/host_secret.h" |
| 20 #include "remoting/host/in_memory_host_config.h" | 21 #include "remoting/host/in_memory_host_config.h" |
| 21 #include "remoting/host/it2me_host_user_interface.h" | 22 #include "remoting/host/it2me_host_user_interface.h" |
| 22 #include "remoting/host/plugin/host_log_handler.h" | 23 #include "remoting/host/plugin/host_log_handler.h" |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 kAttrNameConnected, | 331 kAttrNameConnected, |
| 331 kAttrNameDisconnecting, | 332 kAttrNameDisconnecting, |
| 332 kAttrNameError | 333 kAttrNameError |
| 333 }; | 334 }; |
| 334 for (size_t i = 0; i < arraysize(entries); ++i) { | 335 for (size_t i = 0; i < arraysize(entries); ++i) { |
| 335 values->push_back(entries[i]); | 336 values->push_back(entries[i]); |
| 336 } | 337 } |
| 337 return true; | 338 return true; |
| 338 } | 339 } |
| 339 | 340 |
| 340 void HostNPScriptObject::OnSignallingConnected( | |
| 341 SignalStrategy* signal_strategy) { | |
| 342 } | |
| 343 | |
| 344 void HostNPScriptObject::OnSignallingDisconnected() { | |
| 345 } | |
| 346 | |
| 347 void HostNPScriptObject::OnAccessDenied() { | 341 void HostNPScriptObject::OnAccessDenied() { |
| 348 DCHECK(host_context_.network_message_loop()->BelongsToCurrentThread()); | 342 DCHECK(host_context_.network_message_loop()->BelongsToCurrentThread()); |
| 349 | 343 |
| 350 ++failed_login_attempts_; | 344 ++failed_login_attempts_; |
| 351 if (failed_login_attempts_ == kMaxLoginAttempts) | 345 if (failed_login_attempts_ == kMaxLoginAttempts) |
| 352 DisconnectInternal(); | 346 DisconnectInternal(); |
| 353 } | 347 } |
| 354 | 348 |
| 355 void HostNPScriptObject::OnClientAuthenticated(const std::string& jid) { | 349 void HostNPScriptObject::OnClientAuthenticated(const std::string& jid) { |
| 356 if (MessageLoop::current() != host_context_.main_message_loop()) { | 350 if (MessageLoop::current() != host_context_.main_message_loop()) { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 const std::string& uid, | 462 const std::string& uid, |
| 469 const std::string& auth_token, | 463 const std::string& auth_token, |
| 470 const std::string& auth_service) { | 464 const std::string& auth_service) { |
| 471 DCHECK_EQ(MessageLoop::current(), host_context_.main_message_loop()); | 465 DCHECK_EQ(MessageLoop::current(), host_context_.main_message_loop()); |
| 472 | 466 |
| 473 if (state_ != kStarting) { | 467 if (state_ != kStarting) { |
| 474 // Host has been stopped while we were fetching policy. | 468 // Host has been stopped while we were fetching policy. |
| 475 return; | 469 return; |
| 476 } | 470 } |
| 477 | 471 |
| 478 // Store the supplied user ID and token to the Host configuration. | |
| 479 scoped_refptr<MutableHostConfig> host_config = new InMemoryHostConfig(); | 472 scoped_refptr<MutableHostConfig> host_config = new InMemoryHostConfig(); |
| 480 host_config->SetString(kXmppLoginConfigPath, uid); | |
| 481 host_config->SetString(kXmppAuthTokenConfigPath, auth_token); | |
| 482 host_config->SetString(kXmppAuthServiceConfigPath, auth_service); | |
| 483 | 473 |
| 484 // Generate a key pair for the Host to use. | 474 // Generate a key pair for the Host to use. |
| 485 // TODO(wez): Move this to the worker thread. | 475 // TODO(wez): Move this to the worker thread. |
| 486 HostKeyPair host_key_pair; | 476 HostKeyPair host_key_pair; |
| 487 host_key_pair.Generate(); | 477 host_key_pair.Generate(); |
| 488 host_key_pair.Save(host_config); | 478 host_key_pair.Save(host_config); |
| 489 | 479 |
| 480 // Create and start XMPP connection. | |
| 481 scoped_ptr<SignalStrategy> signal_strategy( | |
| 482 new XmppSignalStrategy(host_context_.jingle_thread(), uid, | |
| 483 auth_token, auth_service)); | |
| 484 | |
| 490 // Request registration of the host for support. | 485 // Request registration of the host for support. |
| 491 scoped_ptr<RegisterSupportHostRequest> register_request( | 486 scoped_ptr<RegisterSupportHostRequest> register_request( |
| 492 new RegisterSupportHostRequest()); | 487 new RegisterSupportHostRequest()); |
| 493 if (!register_request->Init( | 488 if (!register_request->Init( |
| 489 signal_strategy.get(), | |
| 494 host_config.get(), | 490 host_config.get(), |
| 495 base::Bind(&HostNPScriptObject::OnReceivedSupportID, | 491 base::Bind(&HostNPScriptObject::OnReceivedSupportID, |
| 496 base::Unretained(this)))) { | 492 base::Unretained(this)))) { |
| 497 SetState(kError); | 493 SetState(kError); |
| 498 return; | 494 return; |
| 499 } | 495 } |
| 500 | 496 |
| 501 // Create DesktopEnvironment. | 497 // Create DesktopEnvironment. |
| 502 desktop_environment_.reset(DesktopEnvironment::Create(&host_context_)); | 498 desktop_environment_.reset(DesktopEnvironment::Create(&host_context_)); |
| 503 if (desktop_environment_.get() == NULL) { | 499 if (desktop_environment_.get() == NULL) { |
| 504 SetState(kError); | 500 SetState(kError); |
| 505 return; | 501 return; |
| 506 } | 502 } |
| 507 | 503 |
| 508 // Beyond this point nothing can fail, so save the config and request. | 504 // Beyond this point nothing can fail,xs so save the config and request. |
|
Wez
2012/01/03 16:25:04
typo: xs
Sergey Ulanov
2012/01/03 21:51:02
Done.
| |
| 509 host_config_ = host_config; | 505 host_config_ = host_config; |
| 506 signal_strategy_.reset(signal_strategy.release()); | |
| 510 register_request_.reset(register_request.release()); | 507 register_request_.reset(register_request.release()); |
| 511 | 508 |
| 512 // Create the Host. | 509 // Create the Host. |
| 513 LOG(INFO) << "NAT state: " << nat_traversal_enabled_; | 510 LOG(INFO) << "NAT state: " << nat_traversal_enabled_; |
| 514 host_ = ChromotingHost::Create( | 511 host_ = new ChromotingHost( |
| 515 &host_context_, host_config_, desktop_environment_.get(), | 512 &host_context_, host_config_, signal_strategy_.get(), |
| 516 nat_traversal_enabled_); | 513 desktop_environment_.get(), nat_traversal_enabled_); |
| 517 host_->AddStatusObserver(this); | 514 host_->AddStatusObserver(this); |
| 518 host_->AddStatusObserver(register_request_.get()); | |
| 519 if (enable_log_to_server_) { | 515 if (enable_log_to_server_) { |
| 520 log_to_server_.reset(new LogToServer(host_context_.network_message_loop())); | 516 log_to_server_.reset(new LogToServer(signal_strategy_.get())); |
| 521 host_->AddStatusObserver(log_to_server_.get()); | 517 host_->AddStatusObserver(log_to_server_.get()); |
| 522 } | 518 } |
| 523 host_->set_it2me(true); | 519 host_->set_it2me(true); |
| 524 it2me_host_user_interface_.reset(new It2MeHostUserInterface(host_.get(), | 520 it2me_host_user_interface_.reset(new It2MeHostUserInterface(host_.get(), |
| 525 &host_context_)); | 521 &host_context_)); |
| 526 it2me_host_user_interface_->Init(); | 522 it2me_host_user_interface_->Init(); |
| 527 host_->AddStatusObserver(it2me_host_user_interface_.get()); | 523 host_->AddStatusObserver(it2me_host_user_interface_.get()); |
| 528 | 524 |
| 529 { | 525 { |
| 530 base::AutoLock auto_lock(ui_strings_lock_); | 526 base::AutoLock auto_lock(ui_strings_lock_); |
| 531 host_->SetUiStrings(ui_strings_); | 527 host_->SetUiStrings(ui_strings_); |
| 532 } | 528 } |
| 533 | 529 |
| 530 // Post a task to start XMPP connection. | |
| 531 host_context_.network_message_loop()->PostTask( | |
| 532 FROM_HERE, base::Bind(&SignalStrategy::Connect, | |
| 533 base::Unretained(signal_strategy_.get()))); | |
| 534 | |
| 534 // Start the Host. | 535 // Start the Host. |
| 535 host_->Start(); | 536 host_->Start(); |
| 536 | 537 |
| 537 SetState(kRequestedAccessCode); | 538 SetState(kRequestedAccessCode); |
| 538 return; | 539 return; |
| 539 } | 540 } |
| 540 | 541 |
| 541 bool HostNPScriptObject::Disconnect(const NPVariant* args, | 542 bool HostNPScriptObject::Disconnect(const NPVariant* args, |
| 542 uint32_t arg_count, | 543 uint32_t arg_count, |
| 543 NPVariant* result) { | 544 NPVariant* result) { |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 842 uint32_t argCount) { | 843 uint32_t argCount) { |
| 843 NPVariant np_result; | 844 NPVariant np_result; |
| 844 bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args, | 845 bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args, |
| 845 argCount, &np_result); | 846 argCount, &np_result); |
| 846 if (is_good) | 847 if (is_good) |
| 847 g_npnetscape_funcs->releasevariantvalue(&np_result); | 848 g_npnetscape_funcs->releasevariantvalue(&np_result); |
| 848 return is_good; | 849 return is_good; |
| 849 } | 850 } |
| 850 | 851 |
| 851 } // namespace remoting | 852 } // namespace remoting |
| OLD | NEW |