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 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 } | 371 } |
| 372 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName, | 372 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName, |
| 373 &bool_value)) { | 373 &bool_value)) { |
| 374 OnNatPolicyUpdate(bool_value); | 374 OnNatPolicyUpdate(bool_value); |
| 375 } | 375 } |
| 376 if (policies->GetBoolean( | 376 if (policies->GetBoolean( |
| 377 policy_hack::PolicyWatcher::kHostRequireCurtainPolicyName, | 377 policy_hack::PolicyWatcher::kHostRequireCurtainPolicyName, |
| 378 &bool_value)) { | 378 &bool_value)) { |
| 379 OnCurtainPolicyUpdate(bool_value); | 379 OnCurtainPolicyUpdate(bool_value); |
| 380 } | 380 } |
| 381 if (policies->GetString( | |
| 382 policy_hack::PolicyWatcher::kHostTalkGadgetPrefixPolicyName, | |
| 383 &string_value)) { | |
| 384 OnHostTalkGadgetPrefixPolicyUpdate(string_value); | |
| 385 } | |
| 381 } | 386 } |
| 382 | 387 |
| 383 void OnHostDomainPolicyUpdate(const std::string& host_domain) { | 388 void OnHostDomainPolicyUpdate(const std::string& host_domain) { |
| 384 if (!context_->network_task_runner()->BelongsToCurrentThread()) { | 389 if (!context_->network_task_runner()->BelongsToCurrentThread()) { |
| 385 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( | 390 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( |
| 386 &HostProcess::OnHostDomainPolicyUpdate, base::Unretained(this), | 391 &HostProcess::OnHostDomainPolicyUpdate, base::Unretained(this), |
| 387 host_domain)); | 392 host_domain)); |
| 388 return; | 393 return; |
| 389 } | 394 } |
| 390 | 395 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 438 | 443 |
| 439 host_->AddStatusObserver(&curtain_); | 444 host_->AddStatusObserver(&curtain_); |
| 440 curtain_.SetEnabled(true); | 445 curtain_.SetEnabled(true); |
| 441 } else { | 446 } else { |
| 442 curtain_.SetEnabled(false); | 447 curtain_.SetEnabled(false); |
| 443 host_->RemoveStatusObserver(&curtain_); | 448 host_->RemoveStatusObserver(&curtain_); |
| 444 } | 449 } |
| 445 #endif | 450 #endif |
| 446 } | 451 } |
| 447 | 452 |
| 453 void OnHostTalkGadgetPrefixPolicyUpdate( | |
| 454 const std::string& talkgadget_prefix) { | |
| 455 if (!context_->network_task_runner()->BelongsToCurrentThread()) { | |
| 456 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( | |
| 457 &HostProcess::OnHostTalkGadgetPrefixPolicyUpdate, | |
| 458 base::Unretained(this), talkgadget_prefix)); | |
| 459 return; | |
| 460 } | |
| 461 | |
| 462 if (talkgadget_prefix != talkgadget_prefix_) { | |
| 463 LOG(INFO) << "Restarting host due to updated talkgadget policy:"; | |
| 464 talkgadget_prefix_ = talkgadget_prefix; | |
| 465 RestartHost(); | |
| 466 } | |
| 467 } | |
| 468 | |
| 448 void StartHost() { | 469 void StartHost() { |
| 449 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 470 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 450 DCHECK(!host_); | 471 DCHECK(!host_); |
| 451 | 472 |
| 452 if (shutting_down_) | 473 if (shutting_down_) |
| 453 return; | 474 return; |
| 454 | 475 |
| 455 if (!signal_strategy_.get()) { | 476 if (!signal_strategy_.get()) { |
|
Sergey Ulanov
2012/08/24 19:43:33
replace this with DCHECK(!signal_strategy_.get())?
garykac
2012/08/27 22:34:57
Done.
| |
| 456 signal_strategy_.reset( | 477 signal_strategy_.reset( |
| 457 new XmppSignalStrategy(context_->url_request_context_getter(), | 478 new XmppSignalStrategy(context_->url_request_context_getter(), |
| 458 xmpp_login_, xmpp_auth_token_, | 479 xmpp_login_, xmpp_auth_token_, |
| 459 xmpp_auth_service_)); | 480 xmpp_auth_service_)); |
| 460 | 481 |
| 461 signaling_connector_.reset(new SignalingConnector( | 482 signaling_connector_.reset(new SignalingConnector( |
| 462 signal_strategy_.get(), | 483 signal_strategy_.get(), context_.get(), talkgadget_prefix_, |
|
Sergey Ulanov
2012/08/24 19:43:33
I think you need to update simple_host as it uses
garykac
2012/08/27 22:34:57
Done.
| |
| 463 base::Bind(&HostProcess::OnAuthFailed, base::Unretained(this)))); | 484 base::Bind(&HostProcess::OnAuthFailed, base::Unretained(this)))); |
| 464 | 485 |
| 465 if (!oauth_refresh_token_.empty()) { | 486 if (!oauth_refresh_token_.empty()) { |
| 466 OAuthClientInfo client_info = { | 487 OAuthClientInfo client_info = { |
| 467 kUnofficialOAuth2ClientId, | 488 kUnofficialOAuth2ClientId, |
| 468 kUnofficialOAuth2ClientSecret | 489 kUnofficialOAuth2ClientSecret |
| 469 }; | 490 }; |
| 470 | 491 |
| 471 #ifdef OFFICIAL_BUILD | 492 #ifdef OFFICIAL_BUILD |
| 472 if (oauth_use_official_client_id_) { | 493 if (oauth_use_official_client_id_) { |
| 473 OAuthClientInfo official_client_info = { | 494 OAuthClientInfo official_client_info = { |
| 474 kOfficialOAuth2ClientId, | 495 kOfficialOAuth2ClientId, |
| 475 kOfficialOAuth2ClientSecret | 496 kOfficialOAuth2ClientSecret |
| 476 }; | 497 }; |
| 477 | 498 |
| 478 client_info = official_client_info; | 499 client_info = official_client_info; |
| 479 } | 500 } |
| 480 #endif // OFFICIAL_BUILD | 501 #endif // OFFICIAL_BUILD |
| 481 | 502 |
| 482 scoped_ptr<SignalingConnector::OAuthCredentials> oauth_credentials( | 503 scoped_ptr<SignalingConnector::OAuthCredentials> oauth_credentials( |
| 483 new SignalingConnector::OAuthCredentials( | 504 new SignalingConnector::OAuthCredentials( |
| 484 xmpp_login_, oauth_refresh_token_, client_info)); | 505 xmpp_login_, oauth_refresh_token_, client_info)); |
| 485 signaling_connector_->EnableOAuth( | 506 signaling_connector_->EnableOAuth(oauth_credentials.Pass()); |
| 486 oauth_credentials.Pass(), | |
| 487 context_->url_request_context_getter()); | |
| 488 } | 507 } |
| 489 } | 508 } |
| 490 | 509 |
| 491 if (!desktop_environment_.get()) { | 510 if (!desktop_environment_.get()) { |
| 492 desktop_environment_ = | 511 desktop_environment_ = |
| 493 DesktopEnvironment::CreateForService(context_.get()); | 512 DesktopEnvironment::CreateForService(context_.get()); |
| 494 } | 513 } |
| 495 | 514 |
| 496 NetworkSettings network_settings( | 515 NetworkSettings network_settings( |
| 497 allow_nat_traversal_ ? | 516 allow_nat_traversal_ ? |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 554 } | 573 } |
| 555 | 574 |
| 556 void RestartOnHostShutdown() { | 575 void RestartOnHostShutdown() { |
| 557 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 576 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 558 | 577 |
| 559 if (shutting_down_) | 578 if (shutting_down_) |
| 560 return; | 579 return; |
| 561 | 580 |
| 562 restarting_ = false; | 581 restarting_ = false; |
| 563 host_ = NULL; | 582 host_ = NULL; |
| 564 log_to_server_.reset(); | 583 ResetHost(); |
| 565 host_event_logger_.reset(); | |
| 566 heartbeat_sender_.reset(); | |
| 567 | 584 |
| 568 StartHost(); | 585 StartHost(); |
| 569 } | 586 } |
| 570 | 587 |
| 571 void Shutdown(int exit_code) { | 588 void Shutdown(int exit_code) { |
| 572 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 589 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 573 | 590 |
| 574 if (shutting_down_) | 591 if (shutting_down_) |
| 575 return; | 592 return; |
| 576 | 593 |
| 577 shutting_down_ = true; | 594 shutting_down_ = true; |
| 578 exit_code_ = exit_code; | 595 exit_code_ = exit_code; |
| 579 if (host_) { | 596 if (host_) { |
| 580 host_->Shutdown(base::Bind( | 597 host_->Shutdown(base::Bind( |
| 581 &HostProcess::OnShutdownFinished, base::Unretained(this))); | 598 &HostProcess::OnShutdownFinished, base::Unretained(this))); |
| 582 } else { | 599 } else { |
| 583 OnShutdownFinished(); | 600 OnShutdownFinished(); |
| 584 } | 601 } |
| 585 } | 602 } |
| 586 | 603 |
| 587 void OnShutdownFinished() { | 604 void OnShutdownFinished() { |
| 588 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 605 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 589 | 606 |
| 590 // Destroy networking objects while we are on the network thread. | 607 // Destroy networking objects while we are on the network thread. |
| 591 host_ = NULL; | 608 host_ = NULL; |
| 609 ResetHost(); | |
| 610 | |
| 611 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); | |
| 612 } | |
| 613 | |
| 614 void ResetHost() { | |
| 615 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | |
| 616 | |
| 592 host_event_logger_.reset(); | 617 host_event_logger_.reset(); |
| 593 log_to_server_.reset(); | 618 log_to_server_.reset(); |
| 594 heartbeat_sender_.reset(); | 619 heartbeat_sender_.reset(); |
| 595 signaling_connector_.reset(); | 620 signaling_connector_.reset(); |
| 596 signal_strategy_.reset(); | 621 signal_strategy_.reset(); |
| 597 | |
| 598 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); | |
| 599 } | 622 } |
| 600 | 623 |
| 601 MessageLoop message_loop_; | 624 MessageLoop message_loop_; |
| 602 scoped_ptr<ChromotingHostContext> context_; | 625 scoped_ptr<ChromotingHostContext> context_; |
| 603 scoped_ptr<IPC::ChannelProxy> daemon_channel_; | 626 scoped_ptr<IPC::ChannelProxy> daemon_channel_; |
| 604 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 627 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 605 | 628 |
| 606 FilePath host_config_path_; | 629 FilePath host_config_path_; |
| 607 CompositeHostConfig config_; | 630 CompositeHostConfig config_; |
| 608 | 631 |
| 609 std::string host_id_; | 632 std::string host_id_; |
| 610 HostKeyPair key_pair_; | 633 HostKeyPair key_pair_; |
| 611 protocol::SharedSecretHash host_secret_hash_; | 634 protocol::SharedSecretHash host_secret_hash_; |
| 612 std::string xmpp_login_; | 635 std::string xmpp_login_; |
| 613 std::string xmpp_auth_token_; | 636 std::string xmpp_auth_token_; |
| 614 std::string xmpp_auth_service_; | 637 std::string xmpp_auth_service_; |
| 615 | 638 |
| 616 std::string oauth_refresh_token_; | 639 std::string oauth_refresh_token_; |
| 617 bool oauth_use_official_client_id_; | 640 bool oauth_use_official_client_id_; |
| 618 | 641 |
| 619 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; | 642 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; |
| 620 bool allow_nat_traversal_; | 643 bool allow_nat_traversal_; |
| 644 std::string talkgadget_prefix_; | |
| 621 scoped_ptr<base::files::FilePathWatcher> config_watcher_; | 645 scoped_ptr<base::files::FilePathWatcher> config_watcher_; |
| 622 scoped_ptr<base::DelayTimer<HostProcess> > config_updated_timer_; | 646 scoped_ptr<base::DelayTimer<HostProcess> > config_updated_timer_; |
| 623 | 647 |
| 624 bool restarting_; | 648 bool restarting_; |
| 625 bool shutting_down_; | 649 bool shutting_down_; |
| 626 | 650 |
| 627 scoped_ptr<XmppSignalStrategy> signal_strategy_; | 651 scoped_ptr<XmppSignalStrategy> signal_strategy_; |
| 628 scoped_ptr<SignalingConnector> signaling_connector_; | 652 scoped_ptr<SignalingConnector> signaling_connector_; |
| 629 scoped_ptr<DesktopEnvironment> desktop_environment_; | 653 scoped_ptr<DesktopEnvironment> desktop_environment_; |
| 630 scoped_ptr<HeartbeatSender> heartbeat_sender_; | 654 scoped_ptr<HeartbeatSender> heartbeat_sender_; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 731 user32.GetFunctionPointer("SetProcessDPIAware")); | 755 user32.GetFunctionPointer("SetProcessDPIAware")); |
| 732 set_process_dpi_aware(); | 756 set_process_dpi_aware(); |
| 733 } | 757 } |
| 734 | 758 |
| 735 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | 759 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
| 736 // the command line from GetCommandLineW(), so we can safely pass NULL here. | 760 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
| 737 return main(0, NULL); | 761 return main(0, NULL); |
| 738 } | 762 } |
| 739 | 763 |
| 740 #endif // defined(OS_WIN) | 764 #endif // defined(OS_WIN) |
| OLD | NEW |