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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 scoped_refptr<PairingRegistry> pairing_registry_; | 460 scoped_refptr<PairingRegistry> pairing_registry_; |
461 | 461 |
462 ShutdownWatchdog* shutdown_watchdog_; | 462 ShutdownWatchdog* shutdown_watchdog_; |
463 | 463 |
464 DISALLOW_COPY_AND_ASSIGN(HostProcess); | 464 DISALLOW_COPY_AND_ASSIGN(HostProcess); |
465 }; | 465 }; |
466 | 466 |
467 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, | 467 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, |
468 int* exit_code_out, | 468 int* exit_code_out, |
469 ShutdownWatchdog* shutdown_watchdog) | 469 ShutdownWatchdog* shutdown_watchdog) |
470 : context_(context.Pass()), | 470 : context_(std::move(context)), |
471 state_(HOST_STARTING), | 471 state_(HOST_STARTING), |
472 use_service_account_(false), | 472 use_service_account_(false), |
473 enable_vp9_(false), | 473 enable_vp9_(false), |
474 frame_recorder_buffer_size_(0), | 474 frame_recorder_buffer_size_(0), |
475 policy_state_(POLICY_INITIALIZING), | 475 policy_state_(POLICY_INITIALIZING), |
476 host_username_match_required_(false), | 476 host_username_match_required_(false), |
477 allow_nat_traversal_(true), | 477 allow_nat_traversal_(true), |
478 allow_relay_(true), | 478 allow_relay_(true), |
479 allow_pairing_(true), | 479 allow_pairing_(true), |
480 curtain_required_(false), | 480 curtain_required_(false), |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 if (allow_pairing_) { | 769 if (allow_pairing_) { |
770 // On Windows |pairing_registry_| is initialized in | 770 // On Windows |pairing_registry_| is initialized in |
771 // InitializePairingRegistry(). | 771 // InitializePairingRegistry(). |
772 #if !defined(OS_WIN) | 772 #if !defined(OS_WIN) |
773 if (!pairing_registry_) { | 773 if (!pairing_registry_) { |
774 scoped_ptr<PairingRegistry::Delegate> delegate = | 774 scoped_ptr<PairingRegistry::Delegate> delegate = |
775 CreatePairingRegistryDelegate(); | 775 CreatePairingRegistryDelegate(); |
776 | 776 |
777 if (delegate) | 777 if (delegate) |
778 pairing_registry_ = new PairingRegistry(context_->file_task_runner(), | 778 pairing_registry_ = new PairingRegistry(context_->file_task_runner(), |
779 delegate.Pass()); | 779 std::move(delegate)); |
780 } | 780 } |
781 #endif // defined(OS_WIN) | 781 #endif // defined(OS_WIN) |
782 | 782 |
783 pairing_registry = pairing_registry_; | 783 pairing_registry = pairing_registry_; |
784 } | 784 } |
785 | 785 |
786 factory = protocol::Me2MeHostAuthenticatorFactory::CreateWithSharedSecret( | 786 factory = protocol::Me2MeHostAuthenticatorFactory::CreateWithSharedSecret( |
787 use_service_account_, host_owner_, local_certificate, key_pair_, | 787 use_service_account_, host_owner_, local_certificate, key_pair_, |
788 host_secret_hash_, pairing_registry); | 788 host_secret_hash_, pairing_registry); |
789 | 789 |
790 host_->set_pairing_registry(pairing_registry); | 790 host_->set_pairing_registry(pairing_registry); |
791 } else { | 791 } else { |
792 DCHECK(third_party_auth_config_.token_url.is_valid()); | 792 DCHECK(third_party_auth_config_.token_url.is_valid()); |
793 DCHECK(third_party_auth_config_.token_validation_url.is_valid()); | 793 DCHECK(third_party_auth_config_.token_validation_url.is_valid()); |
794 | 794 |
795 scoped_ptr<protocol::TokenValidatorFactory> token_validator_factory( | 795 scoped_ptr<protocol::TokenValidatorFactory> token_validator_factory( |
796 new TokenValidatorFactoryImpl( | 796 new TokenValidatorFactoryImpl( |
797 third_party_auth_config_, | 797 third_party_auth_config_, |
798 key_pair_, context_->url_request_context_getter())); | 798 key_pair_, context_->url_request_context_getter())); |
799 factory = protocol::Me2MeHostAuthenticatorFactory::CreateWithThirdPartyAuth( | 799 factory = protocol::Me2MeHostAuthenticatorFactory::CreateWithThirdPartyAuth( |
800 use_service_account_, host_owner_, local_certificate, key_pair_, | 800 use_service_account_, host_owner_, local_certificate, key_pair_, |
801 token_validator_factory.Pass()); | 801 std::move(token_validator_factory)); |
802 } | 802 } |
803 | 803 |
804 #if defined(OS_POSIX) | 804 #if defined(OS_POSIX) |
805 // On Linux and Mac, perform a PAM authorization step after authentication. | 805 // On Linux and Mac, perform a PAM authorization step after authentication. |
806 factory.reset(new PamAuthorizationFactory(factory.Pass())); | 806 factory.reset(new PamAuthorizationFactory(std::move(factory))); |
807 #endif | 807 #endif |
808 host_->SetAuthenticatorFactory(factory.Pass()); | 808 host_->SetAuthenticatorFactory(std::move(factory)); |
809 } | 809 } |
810 | 810 |
811 // IPC::Listener implementation. | 811 // IPC::Listener implementation. |
812 bool HostProcess::OnMessageReceived(const IPC::Message& message) { | 812 bool HostProcess::OnMessageReceived(const IPC::Message& message) { |
813 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 813 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
814 | 814 |
815 #if defined(REMOTING_MULTI_PROCESS) | 815 #if defined(REMOTING_MULTI_PROCESS) |
816 bool handled = true; | 816 bool handled = true; |
817 IPC_BEGIN_MESSAGE_MAP(HostProcess, message) | 817 IPC_BEGIN_MESSAGE_MAP(HostProcess, message) |
818 IPC_MESSAGE_HANDLER(ChromotingDaemonMsg_Crash, OnCrash) | 818 IPC_MESSAGE_HANDLER(ChromotingDaemonMsg_Crash, OnCrash) |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 HKEY privileged_hkey = reinterpret_cast<HKEY>( | 986 HKEY privileged_hkey = reinterpret_cast<HKEY>( |
987 IPC::PlatformFileForTransitToPlatformFile(privileged_key)); | 987 IPC::PlatformFileForTransitToPlatformFile(privileged_key)); |
988 HKEY unprivileged_hkey = reinterpret_cast<HKEY>( | 988 HKEY unprivileged_hkey = reinterpret_cast<HKEY>( |
989 IPC::PlatformFileForTransitToPlatformFile(unprivileged_key)); | 989 IPC::PlatformFileForTransitToPlatformFile(unprivileged_key)); |
990 | 990 |
991 scoped_ptr<PairingRegistryDelegateWin> delegate( | 991 scoped_ptr<PairingRegistryDelegateWin> delegate( |
992 new PairingRegistryDelegateWin()); | 992 new PairingRegistryDelegateWin()); |
993 delegate->SetRootKeys(privileged_hkey, unprivileged_hkey); | 993 delegate->SetRootKeys(privileged_hkey, unprivileged_hkey); |
994 | 994 |
995 pairing_registry_ = new PairingRegistry(context_->file_task_runner(), | 995 pairing_registry_ = new PairingRegistry(context_->file_task_runner(), |
996 delegate.Pass()); | 996 std::move(delegate)); |
997 | 997 |
998 // (Re)Create the authenticator factory now that |pairing_registry_| has been | 998 // (Re)Create the authenticator factory now that |pairing_registry_| has been |
999 // initialized. | 999 // initialized. |
1000 CreateAuthenticatorFactory(); | 1000 CreateAuthenticatorFactory(); |
1001 } | 1001 } |
1002 #endif // !defined(OS_WIN) | 1002 #endif // !defined(OS_WIN) |
1003 | 1003 |
1004 // Applies the host config, returning true if successful. | 1004 // Applies the host config, returning true if successful. |
1005 bool HostProcess::ApplyConfig(const base::DictionaryValue& config) { | 1005 bool HostProcess::ApplyConfig(const base::DictionaryValue& config) { |
1006 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1006 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1414 context_->url_request_context_getter(), xmpp_server_config_); | 1414 context_->url_request_context_getter(), xmpp_server_config_); |
1415 signal_strategy_.reset(xmpp_signal_strategy); | 1415 signal_strategy_.reset(xmpp_signal_strategy); |
1416 | 1416 |
1417 // Create SignalingConnector. | 1417 // Create SignalingConnector. |
1418 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker(new DnsBlackholeChecker( | 1418 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker(new DnsBlackholeChecker( |
1419 context_->url_request_context_getter(), talkgadget_prefix_)); | 1419 context_->url_request_context_getter(), talkgadget_prefix_)); |
1420 scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials( | 1420 scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials( |
1421 new OAuthTokenGetter::OAuthCredentials(xmpp_server_config_.username, | 1421 new OAuthTokenGetter::OAuthCredentials(xmpp_server_config_.username, |
1422 oauth_refresh_token_, | 1422 oauth_refresh_token_, |
1423 use_service_account_)); | 1423 use_service_account_)); |
1424 oauth_token_getter_.reset(new OAuthTokenGetterImpl( | 1424 oauth_token_getter_.reset( |
1425 oauth_credentials.Pass(), context_->url_request_context_getter(), false)); | 1425 new OAuthTokenGetterImpl(std::move(oauth_credentials), |
| 1426 context_->url_request_context_getter(), false)); |
1426 signaling_connector_.reset(new SignalingConnector( | 1427 signaling_connector_.reset(new SignalingConnector( |
1427 xmpp_signal_strategy, dns_blackhole_checker.Pass(), | 1428 xmpp_signal_strategy, std::move(dns_blackhole_checker), |
1428 oauth_token_getter_.get(), | 1429 oauth_token_getter_.get(), |
1429 base::Bind(&HostProcess::OnAuthFailed, base::Unretained(this)))); | 1430 base::Bind(&HostProcess::OnAuthFailed, base::Unretained(this)))); |
1430 | 1431 |
1431 #if defined(USE_GCD) | 1432 #if defined(USE_GCD) |
1432 // Create objects to manage GCD state. | 1433 // Create objects to manage GCD state. |
1433 ServiceUrls* service_urls = ServiceUrls::GetInstance(); | 1434 ServiceUrls* service_urls = ServiceUrls::GetInstance(); |
1434 scoped_ptr<GcdRestClient> gcd_rest_client(new GcdRestClient( | 1435 scoped_ptr<GcdRestClient> gcd_rest_client(new GcdRestClient( |
1435 service_urls->gcd_base_url(), host_id_, | 1436 service_urls->gcd_base_url(), host_id_, |
1436 context_->url_request_context_getter(), oauth_token_getter_.get())); | 1437 context_->url_request_context_getter(), oauth_token_getter_.get())); |
1437 gcd_state_updater_.reset( | 1438 gcd_state_updater_.reset(new GcdStateUpdater( |
1438 new GcdStateUpdater(base::Bind(&HostProcess::OnHeartbeatSuccessful, | 1439 base::Bind(&HostProcess::OnHeartbeatSuccessful, base::Unretained(this)), |
1439 base::Unretained(this)), | 1440 base::Bind(&HostProcess::OnUnknownHostIdError, base::Unretained(this)), |
1440 base::Bind(&HostProcess::OnUnknownHostIdError, | 1441 signal_strategy_.get(), std::move(gcd_rest_client))); |
1441 base::Unretained(this)), | |
1442 signal_strategy_.get(), gcd_rest_client.Pass())); | |
1443 PushNotificationSubscriber::Subscription sub; | 1442 PushNotificationSubscriber::Subscription sub; |
1444 sub.channel = "cloud_devices"; | 1443 sub.channel = "cloud_devices"; |
1445 PushNotificationSubscriber::SubscriptionList subs; | 1444 PushNotificationSubscriber::SubscriptionList subs; |
1446 subs.push_back(sub); | 1445 subs.push_back(sub); |
1447 gcd_subscriber_.reset( | 1446 gcd_subscriber_.reset( |
1448 new PushNotificationSubscriber(signal_strategy_.get(), subs)); | 1447 new PushNotificationSubscriber(signal_strategy_.get(), subs)); |
1449 #endif // defined(USE_GCD) | 1448 #endif // defined(USE_GCD) |
1450 | 1449 |
1451 // Create HeartbeatSender. | 1450 // Create HeartbeatSender. |
1452 heartbeat_sender_.reset(new HeartbeatSender( | 1451 heartbeat_sender_.reset(new HeartbeatSender( |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1517 #else // !defined(NDEBUG) | 1516 #else // !defined(NDEBUG) |
1518 LOG(ERROR) << "WebRTC is enabled only in debug builds."; | 1517 LOG(ERROR) << "WebRTC is enabled only in debug builds."; |
1519 ShutdownHost(kUsageExitCode); | 1518 ShutdownHost(kUsageExitCode); |
1520 return; | 1519 return; |
1521 #endif // defined(NDEBUG) | 1520 #endif // defined(NDEBUG) |
1522 } else { | 1521 } else { |
1523 transport_factory.reset( | 1522 transport_factory.reset( |
1524 new protocol::IceTransportFactory(transport_context)); | 1523 new protocol::IceTransportFactory(transport_context)); |
1525 } | 1524 } |
1526 scoped_ptr<protocol::SessionManager> session_manager( | 1525 scoped_ptr<protocol::SessionManager> session_manager( |
1527 new protocol::JingleSessionManager(transport_factory.Pass(), | 1526 new protocol::JingleSessionManager(std::move(transport_factory), |
1528 signal_strategy_.get())); | 1527 signal_strategy_.get())); |
1529 | 1528 |
1530 scoped_ptr<protocol::CandidateSessionConfig> protocol_config = | 1529 scoped_ptr<protocol::CandidateSessionConfig> protocol_config = |
1531 protocol::CandidateSessionConfig::CreateDefault(); | 1530 protocol::CandidateSessionConfig::CreateDefault(); |
1532 if (!desktop_environment_factory_->SupportsAudioCapture()) | 1531 if (!desktop_environment_factory_->SupportsAudioCapture()) |
1533 protocol_config->DisableAudioChannel(); | 1532 protocol_config->DisableAudioChannel(); |
1534 if (enable_vp9_) | 1533 if (enable_vp9_) |
1535 protocol_config->set_vp9_experiment_enabled(true); | 1534 protocol_config->set_vp9_experiment_enabled(true); |
1536 #if !defined(NDEBUG) | 1535 #if !defined(NDEBUG) |
1537 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kEnableWebrtc)) { | 1536 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kEnableWebrtc)) { |
1538 protocol_config->set_webrtc_supported(true); | 1537 protocol_config->set_webrtc_supported(true); |
1539 } | 1538 } |
1540 #endif // !defined(NDEBUG) | 1539 #endif // !defined(NDEBUG) |
1541 session_manager->set_protocol_config(protocol_config.Pass()); | 1540 session_manager->set_protocol_config(std::move(protocol_config)); |
1542 | 1541 |
1543 host_.reset(new ChromotingHost( | 1542 host_.reset(new ChromotingHost( |
1544 desktop_environment_factory_.get(), | 1543 desktop_environment_factory_.get(), std::move(session_manager), |
1545 session_manager.Pass(), context_->audio_task_runner(), | 1544 context_->audio_task_runner(), context_->input_task_runner(), |
1546 context_->input_task_runner(), context_->video_capture_task_runner(), | 1545 context_->video_capture_task_runner(), |
1547 context_->video_encode_task_runner(), context_->network_task_runner(), | 1546 context_->video_encode_task_runner(), context_->network_task_runner(), |
1548 context_->ui_task_runner())); | 1547 context_->ui_task_runner())); |
1549 | 1548 |
1550 if (frame_recorder_buffer_size_ > 0) { | 1549 if (frame_recorder_buffer_size_ > 0) { |
1551 scoped_ptr<VideoFrameRecorderHostExtension> frame_recorder_extension( | 1550 scoped_ptr<VideoFrameRecorderHostExtension> frame_recorder_extension( |
1552 new VideoFrameRecorderHostExtension()); | 1551 new VideoFrameRecorderHostExtension()); |
1553 frame_recorder_extension->SetMaxContentBytes(frame_recorder_buffer_size_); | 1552 frame_recorder_extension->SetMaxContentBytes(frame_recorder_buffer_size_); |
1554 host_->AddExtension(frame_recorder_extension.Pass()); | 1553 host_->AddExtension(std::move(frame_recorder_extension)); |
1555 } | 1554 } |
1556 | 1555 |
1557 // TODO(simonmorris): Get the maximum session duration from a policy. | 1556 // TODO(simonmorris): Get the maximum session duration from a policy. |
1558 #if defined(OS_LINUX) | 1557 #if defined(OS_LINUX) |
1559 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); | 1558 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); |
1560 #endif | 1559 #endif |
1561 | 1560 |
1562 host_change_notification_listener_.reset(new HostChangeNotificationListener( | 1561 host_change_notification_listener_.reset(new HostChangeNotificationListener( |
1563 this, host_id_, signal_strategy_.get(), directory_bot_jid_)); | 1562 this, host_id_, signal_strategy_.get(), directory_bot_jid_)); |
1564 | 1563 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1739 // NetworkChangeNotifier must be initialized after MessageLoop. | 1738 // NetworkChangeNotifier must be initialized after MessageLoop. |
1740 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier( | 1739 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier( |
1741 net::NetworkChangeNotifier::Create()); | 1740 net::NetworkChangeNotifier::Create()); |
1742 | 1741 |
1743 // Create & start the HostProcess using these threads. | 1742 // Create & start the HostProcess using these threads. |
1744 // TODO(wez): The HostProcess holds a reference to itself until Shutdown(). | 1743 // TODO(wez): The HostProcess holds a reference to itself until Shutdown(). |
1745 // Remove this hack as part of the multi-process refactoring. | 1744 // Remove this hack as part of the multi-process refactoring. |
1746 int exit_code = kSuccessExitCode; | 1745 int exit_code = kSuccessExitCode; |
1747 ShutdownWatchdog shutdown_watchdog( | 1746 ShutdownWatchdog shutdown_watchdog( |
1748 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); | 1747 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); |
1749 new HostProcess(context.Pass(), &exit_code, &shutdown_watchdog); | 1748 new HostProcess(std::move(context), &exit_code, &shutdown_watchdog); |
1750 | 1749 |
1751 // Run the main (also UI) message loop until the host no longer needs it. | 1750 // Run the main (also UI) message loop until the host no longer needs it. |
1752 message_loop.Run(); | 1751 message_loop.Run(); |
1753 | 1752 |
1754 return exit_code; | 1753 return exit_code; |
1755 } | 1754 } |
1756 | 1755 |
1757 } // namespace remoting | 1756 } // namespace remoting |
OLD | NEW |