Chromium Code Reviews| 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 // This file implements a standalone host process for Me2Me. | 5 // This file implements a standalone host process for Me2Me. |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 #include "net/base/network_change_notifier.h" | 29 #include "net/base/network_change_notifier.h" |
| 30 #include "net/socket/ssl_server_socket.h" | 30 #include "net/socket/ssl_server_socket.h" |
| 31 #include "remoting/base/breakpad.h" | 31 #include "remoting/base/breakpad.h" |
| 32 #include "remoting/base/constants.h" | 32 #include "remoting/base/constants.h" |
| 33 #include "remoting/host/branding.h" | 33 #include "remoting/host/branding.h" |
| 34 #include "remoting/host/chromoting_host.h" | 34 #include "remoting/host/chromoting_host.h" |
| 35 #include "remoting/host/chromoting_host_context.h" | 35 #include "remoting/host/chromoting_host_context.h" |
| 36 #include "remoting/host/composite_host_config.h" | 36 #include "remoting/host/composite_host_config.h" |
| 37 #include "remoting/host/constants.h" | 37 #include "remoting/host/constants.h" |
| 38 #include "remoting/host/desktop_environment.h" | 38 #include "remoting/host/desktop_environment.h" |
| 39 #include "remoting/host/dns_blackhole_checker.h" | |
| 39 #include "remoting/host/event_executor.h" | 40 #include "remoting/host/event_executor.h" |
| 40 #include "remoting/host/heartbeat_sender.h" | 41 #include "remoting/host/heartbeat_sender.h" |
| 41 #include "remoting/host/host_config.h" | 42 #include "remoting/host/host_config.h" |
| 42 #include "remoting/host/host_event_logger.h" | 43 #include "remoting/host/host_event_logger.h" |
| 43 #include "remoting/host/host_user_interface.h" | 44 #include "remoting/host/host_user_interface.h" |
| 44 #include "remoting/host/log_to_server.h" | 45 #include "remoting/host/log_to_server.h" |
| 45 #include "remoting/host/network_settings.h" | 46 #include "remoting/host/network_settings.h" |
| 46 #include "remoting/host/policy_hack/policy_watcher.h" | 47 #include "remoting/host/policy_hack/policy_watcher.h" |
| 47 #include "remoting/host/session_manager_factory.h" | 48 #include "remoting/host/session_manager_factory.h" |
| 48 #include "remoting/host/signaling_connector.h" | 49 #include "remoting/host/signaling_connector.h" |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 } | 372 } |
| 372 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName, | 373 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName, |
| 373 &bool_value)) { | 374 &bool_value)) { |
| 374 OnNatPolicyUpdate(bool_value); | 375 OnNatPolicyUpdate(bool_value); |
| 375 } | 376 } |
| 376 if (policies->GetBoolean( | 377 if (policies->GetBoolean( |
| 377 policy_hack::PolicyWatcher::kHostRequireCurtainPolicyName, | 378 policy_hack::PolicyWatcher::kHostRequireCurtainPolicyName, |
| 378 &bool_value)) { | 379 &bool_value)) { |
| 379 OnCurtainPolicyUpdate(bool_value); | 380 OnCurtainPolicyUpdate(bool_value); |
| 380 } | 381 } |
| 382 if (policies->GetString( | |
| 383 policy_hack::PolicyWatcher::kHostTalkGadgetPrefixPolicyName, | |
| 384 &string_value)) { | |
| 385 OnHostTalkGadgetPrefixPolicyUpdate(string_value); | |
| 386 } | |
| 381 } | 387 } |
| 382 | 388 |
| 383 void OnHostDomainPolicyUpdate(const std::string& host_domain) { | 389 void OnHostDomainPolicyUpdate(const std::string& host_domain) { |
| 384 if (!context_->network_task_runner()->BelongsToCurrentThread()) { | 390 if (!context_->network_task_runner()->BelongsToCurrentThread()) { |
| 385 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( | 391 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( |
| 386 &HostProcess::OnHostDomainPolicyUpdate, base::Unretained(this), | 392 &HostProcess::OnHostDomainPolicyUpdate, base::Unretained(this), |
| 387 host_domain)); | 393 host_domain)); |
| 388 return; | 394 return; |
| 389 } | 395 } |
| 390 | 396 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 438 | 444 |
| 439 host_->AddStatusObserver(&curtain_); | 445 host_->AddStatusObserver(&curtain_); |
| 440 curtain_.SetEnabled(true); | 446 curtain_.SetEnabled(true); |
| 441 } else { | 447 } else { |
| 442 curtain_.SetEnabled(false); | 448 curtain_.SetEnabled(false); |
| 443 host_->RemoveStatusObserver(&curtain_); | 449 host_->RemoveStatusObserver(&curtain_); |
| 444 } | 450 } |
| 445 #endif | 451 #endif |
| 446 } | 452 } |
| 447 | 453 |
| 454 void OnHostTalkGadgetPrefixPolicyUpdate( | |
| 455 const std::string& talkgadget_prefix) { | |
| 456 if (!context_->network_task_runner()->BelongsToCurrentThread()) { | |
| 457 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( | |
| 458 &HostProcess::OnHostTalkGadgetPrefixPolicyUpdate, | |
| 459 base::Unretained(this), talkgadget_prefix)); | |
| 460 return; | |
| 461 } | |
| 462 | |
| 463 if (talkgadget_prefix != talkgadget_prefix_) { | |
| 464 LOG(INFO) << "Restarting host due to updated talkgadget policy:"; | |
| 465 talkgadget_prefix_ = talkgadget_prefix; | |
| 466 RestartHost(); | |
| 467 } | |
| 468 } | |
| 469 | |
| 448 void StartHost() { | 470 void StartHost() { |
| 449 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 471 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 450 DCHECK(!host_); | 472 DCHECK(!host_); |
| 473 DCHECK(!signal_strategy_.get()); | |
| 474 DCHECK(!dns_blackhole_checker_.get()); | |
| 451 | 475 |
| 452 if (shutting_down_) | 476 if (shutting_down_) |
| 453 return; | 477 return; |
| 454 | 478 |
| 455 if (!signal_strategy_.get()) { | 479 signal_strategy_.reset( |
| 456 signal_strategy_.reset( | 480 new XmppSignalStrategy(context_->url_request_context_getter(), |
| 457 new XmppSignalStrategy(context_->url_request_context_getter(), | 481 xmpp_login_, xmpp_auth_token_, |
| 458 xmpp_login_, xmpp_auth_token_, | 482 xmpp_auth_service_)); |
| 459 xmpp_auth_service_)); | |
| 460 | 483 |
| 461 signaling_connector_.reset(new SignalingConnector( | 484 dns_blackhole_checker_.reset( |
| 462 signal_strategy_.get(), | 485 new DnsBlackholeChecker(context_.get(), talkgadget_prefix_)); |
| 463 base::Bind(&HostProcess::OnAuthFailed, base::Unretained(this)))); | |
| 464 | 486 |
| 465 if (!oauth_refresh_token_.empty()) { | 487 signaling_connector_.reset(new SignalingConnector( |
| 466 OAuthClientInfo client_info = { | 488 signal_strategy_.get(), context_.get(), dns_blackhole_checker_.get(), |
| 467 kUnofficialOAuth2ClientId, | 489 base::Bind(&HostProcess::OnAuthFailed, base::Unretained(this)))); |
| 468 kUnofficialOAuth2ClientSecret | 490 |
| 491 if (!oauth_refresh_token_.empty()) { | |
| 492 OAuthClientInfo client_info = { | |
| 493 kUnofficialOAuth2ClientId, | |
| 494 kUnofficialOAuth2ClientSecret | |
| 495 }; | |
| 496 | |
| 497 #ifdef OFFICIAL_BUILD | |
| 498 if (oauth_use_official_client_id_) { | |
| 499 OAuthClientInfo official_client_info = { | |
| 500 kOfficialOAuth2ClientId, | |
| 501 kOfficialOAuth2ClientSecret | |
| 469 }; | 502 }; |
| 470 | 503 |
| 471 #ifdef OFFICIAL_BUILD | 504 client_info = official_client_info; |
| 472 if (oauth_use_official_client_id_) { | 505 } |
| 473 OAuthClientInfo official_client_info = { | |
| 474 kOfficialOAuth2ClientId, | |
| 475 kOfficialOAuth2ClientSecret | |
| 476 }; | |
| 477 | |
| 478 client_info = official_client_info; | |
| 479 } | |
| 480 #endif // OFFICIAL_BUILD | 506 #endif // OFFICIAL_BUILD |
| 481 | 507 |
| 482 scoped_ptr<SignalingConnector::OAuthCredentials> oauth_credentials( | 508 scoped_ptr<SignalingConnector::OAuthCredentials> oauth_credentials( |
| 483 new SignalingConnector::OAuthCredentials( | 509 new SignalingConnector::OAuthCredentials( |
| 484 xmpp_login_, oauth_refresh_token_, client_info)); | 510 xmpp_login_, oauth_refresh_token_, client_info)); |
| 485 signaling_connector_->EnableOAuth( | 511 signaling_connector_->EnableOAuth(oauth_credentials.Pass()); |
| 486 oauth_credentials.Pass(), | |
| 487 context_->url_request_context_getter()); | |
| 488 } | |
| 489 } | 512 } |
| 490 | 513 |
| 491 if (!desktop_environment_.get()) { | 514 if (!desktop_environment_.get()) { |
| 492 desktop_environment_ = | 515 desktop_environment_ = |
| 493 DesktopEnvironment::CreateForService(context_.get()); | 516 DesktopEnvironment::CreateForService(context_.get()); |
| 494 } | 517 } |
| 495 | 518 |
| 496 NetworkSettings network_settings( | 519 NetworkSettings network_settings( |
| 497 allow_nat_traversal_ ? | 520 allow_nat_traversal_ ? |
| 498 NetworkSettings::NAT_TRAVERSAL_ENABLED : | 521 NetworkSettings::NAT_TRAVERSAL_ENABLED : |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 554 } | 577 } |
| 555 | 578 |
| 556 void RestartOnHostShutdown() { | 579 void RestartOnHostShutdown() { |
| 557 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 580 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 558 | 581 |
| 559 if (shutting_down_) | 582 if (shutting_down_) |
| 560 return; | 583 return; |
| 561 | 584 |
| 562 restarting_ = false; | 585 restarting_ = false; |
| 563 host_ = NULL; | 586 host_ = NULL; |
| 564 log_to_server_.reset(); | 587 ResetHost(); |
| 565 host_event_logger_.reset(); | |
| 566 heartbeat_sender_.reset(); | |
| 567 | 588 |
| 568 StartHost(); | 589 StartHost(); |
| 569 } | 590 } |
| 570 | 591 |
| 571 void Shutdown(int exit_code) { | 592 void Shutdown(int exit_code) { |
| 572 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 593 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 573 | 594 |
| 574 if (shutting_down_) | 595 if (shutting_down_) |
| 575 return; | 596 return; |
| 576 | 597 |
| 577 shutting_down_ = true; | 598 shutting_down_ = true; |
| 578 exit_code_ = exit_code; | 599 exit_code_ = exit_code; |
| 579 if (host_) { | 600 if (host_) { |
| 580 host_->Shutdown(base::Bind( | 601 host_->Shutdown(base::Bind( |
| 581 &HostProcess::OnShutdownFinished, base::Unretained(this))); | 602 &HostProcess::OnShutdownFinished, base::Unretained(this))); |
| 582 } else { | 603 } else { |
| 583 OnShutdownFinished(); | 604 OnShutdownFinished(); |
| 584 } | 605 } |
| 585 } | 606 } |
| 586 | 607 |
| 587 void OnShutdownFinished() { | 608 void OnShutdownFinished() { |
| 588 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 609 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 589 | 610 |
| 590 // Destroy networking objects while we are on the network thread. | 611 // Destroy networking objects while we are on the network thread. |
| 591 host_ = NULL; | 612 host_ = NULL; |
| 613 ResetHost(); | |
| 614 | |
| 615 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); | |
| 616 } | |
| 617 | |
| 618 void ResetHost() { | |
| 619 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | |
| 620 | |
| 592 host_event_logger_.reset(); | 621 host_event_logger_.reset(); |
| 593 log_to_server_.reset(); | 622 log_to_server_.reset(); |
| 594 heartbeat_sender_.reset(); | 623 heartbeat_sender_.reset(); |
| 595 signaling_connector_.reset(); | 624 signaling_connector_.reset(); |
| 625 dns_blackhole_checker_.reset(); | |
| 596 signal_strategy_.reset(); | 626 signal_strategy_.reset(); |
| 597 | |
| 598 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); | |
| 599 } | 627 } |
| 600 | 628 |
| 601 MessageLoop message_loop_; | 629 MessageLoop message_loop_; |
| 602 scoped_ptr<ChromotingHostContext> context_; | 630 scoped_ptr<ChromotingHostContext> context_; |
| 603 scoped_ptr<IPC::ChannelProxy> daemon_channel_; | 631 scoped_ptr<IPC::ChannelProxy> daemon_channel_; |
| 604 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 632 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 605 | 633 |
| 606 FilePath host_config_path_; | 634 FilePath host_config_path_; |
| 607 CompositeHostConfig config_; | 635 CompositeHostConfig config_; |
| 608 | 636 |
| 609 std::string host_id_; | 637 std::string host_id_; |
| 610 HostKeyPair key_pair_; | 638 HostKeyPair key_pair_; |
| 611 protocol::SharedSecretHash host_secret_hash_; | 639 protocol::SharedSecretHash host_secret_hash_; |
| 612 std::string xmpp_login_; | 640 std::string xmpp_login_; |
| 613 std::string xmpp_auth_token_; | 641 std::string xmpp_auth_token_; |
| 614 std::string xmpp_auth_service_; | 642 std::string xmpp_auth_service_; |
| 615 | 643 |
| 616 std::string oauth_refresh_token_; | 644 std::string oauth_refresh_token_; |
| 617 bool oauth_use_official_client_id_; | 645 bool oauth_use_official_client_id_; |
| 618 | 646 |
| 619 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; | 647 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; |
| 620 bool allow_nat_traversal_; | 648 bool allow_nat_traversal_; |
| 649 std::string talkgadget_prefix_; | |
| 621 scoped_ptr<base::files::FilePathWatcher> config_watcher_; | 650 scoped_ptr<base::files::FilePathWatcher> config_watcher_; |
|
Sergey Ulanov
2012/08/30 18:05:01
Please add an empty line above this one to separat
garykac
2012/08/31 18:28:23
Done.
| |
| 622 scoped_ptr<base::DelayTimer<HostProcess> > config_updated_timer_; | 651 scoped_ptr<base::DelayTimer<HostProcess> > config_updated_timer_; |
| 623 | 652 |
| 624 bool restarting_; | 653 bool restarting_; |
| 625 bool shutting_down_; | 654 bool shutting_down_; |
| 626 | 655 |
| 627 scoped_ptr<XmppSignalStrategy> signal_strategy_; | 656 scoped_ptr<XmppSignalStrategy> signal_strategy_; |
| 657 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker_; | |
|
Sergey Ulanov
2012/08/30 18:05:01
We don't really use this thing here. Just pass own
garykac
2012/08/31 18:28:23
Done.
| |
| 628 scoped_ptr<SignalingConnector> signaling_connector_; | 658 scoped_ptr<SignalingConnector> signaling_connector_; |
| 629 scoped_ptr<DesktopEnvironment> desktop_environment_; | 659 scoped_ptr<DesktopEnvironment> desktop_environment_; |
| 630 scoped_ptr<HeartbeatSender> heartbeat_sender_; | 660 scoped_ptr<HeartbeatSender> heartbeat_sender_; |
| 631 scoped_ptr<LogToServer> log_to_server_; | 661 scoped_ptr<LogToServer> log_to_server_; |
| 632 scoped_ptr<HostEventLogger> host_event_logger_; | 662 scoped_ptr<HostEventLogger> host_event_logger_; |
| 633 | 663 |
| 634 #if defined(OS_MACOSX) || defined(OS_WIN) | 664 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 635 scoped_ptr<HostUserInterface> host_user_interface_; | 665 scoped_ptr<HostUserInterface> host_user_interface_; |
| 636 #endif | 666 #endif |
| 637 | 667 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 731 user32.GetFunctionPointer("SetProcessDPIAware")); | 761 user32.GetFunctionPointer("SetProcessDPIAware")); |
| 732 set_process_dpi_aware(); | 762 set_process_dpi_aware(); |
| 733 } | 763 } |
| 734 | 764 |
| 735 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | 765 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
| 736 // the command line from GetCommandLineW(), so we can safely pass NULL here. | 766 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
| 737 return main(0, NULL); | 767 return main(0, NULL); |
| 738 } | 768 } |
| 739 | 769 |
| 740 #endif // defined(OS_WIN) | 770 #endif // defined(OS_WIN) |
| OLD | NEW |