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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 #if defined(OS_MACOSX) | 108 #if defined(OS_MACOSX) |
| 109 #include "base/mac/scoped_cftyperef.h" | 109 #include "base/mac/scoped_cftyperef.h" |
| 110 #endif // defined(OS_MACOSX) | 110 #endif // defined(OS_MACOSX) |
| 111 | 111 |
| 112 #if defined(OS_LINUX) | 112 #if defined(OS_LINUX) |
| 113 #include <gtk/gtk.h> | 113 #include <gtk/gtk.h> |
| 114 #include <X11/Xlib.h> | 114 #include <X11/Xlib.h> |
| 115 #undef Status // Xlib.h #defines this, which breaks protobuf headers. | 115 #undef Status // Xlib.h #defines this, which breaks protobuf headers. |
| 116 #include <base/linux_util.h> | 116 #include <base/linux_util.h> |
| 117 #include "remoting/host/audio_capturer_linux.h" | 117 #include "remoting/host/audio_capturer_linux.h" |
| 118 #include "remoting/host/linux/certificate_watcher.h" | |
| 118 #endif // defined(OS_LINUX) | 119 #endif // defined(OS_LINUX) |
| 119 | 120 |
| 120 #if defined(OS_WIN) | 121 #if defined(OS_WIN) |
| 121 #include <commctrl.h> | 122 #include <commctrl.h> |
| 122 #include "base/win/registry.h" | 123 #include "base/win/registry.h" |
| 123 #include "base/win/scoped_handle.h" | 124 #include "base/win/scoped_handle.h" |
| 124 #include "remoting/host/pairing_registry_delegate_win.h" | 125 #include "remoting/host/pairing_registry_delegate_win.h" |
| 125 #include "remoting/host/win/session_desktop_environment.h" | 126 #include "remoting/host/win/session_desktop_environment.h" |
| 126 #endif // defined(OS_WIN) | 127 #endif // defined(OS_WIN) |
| 127 | 128 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 void StartHostIfReady(); | 360 void StartHostIfReady(); |
| 360 void StartHost(); | 361 void StartHost(); |
| 361 | 362 |
| 362 // Error handler for HeartbeatSender. | 363 // Error handler for HeartbeatSender. |
| 363 void OnHeartbeatSuccessful(); | 364 void OnHeartbeatSuccessful(); |
| 364 void OnUnknownHostIdError(); | 365 void OnUnknownHostIdError(); |
| 365 | 366 |
| 366 // Error handler for SignalingConnector. | 367 // Error handler for SignalingConnector. |
| 367 void OnAuthFailed(); | 368 void OnAuthFailed(); |
| 368 | 369 |
| 370 void OnHostRestartRequested(); | |
| 371 | |
| 369 void RestartHost(const std::string& host_offline_reason); | 372 void RestartHost(const std::string& host_offline_reason); |
| 370 void ShutdownHost(HostExitCodes exit_code); | 373 void ShutdownHost(HostExitCodes exit_code); |
| 371 | 374 |
| 372 // Helper methods doing the work needed by RestartHost and ShutdownHost. | 375 // Helper methods doing the work needed by RestartHost and ShutdownHost. |
| 373 void GoOffline(const std::string& host_offline_reason); | 376 void GoOffline(const std::string& host_offline_reason); |
| 374 void OnHostOfflineReasonAck(bool success); | 377 void OnHostOfflineReasonAck(bool success); |
| 375 | 378 |
| 376 #if defined(OS_WIN) | 379 #if defined(OS_WIN) |
| 377 // Initializes the pairing registry on Windows. This should be invoked on the | 380 // Initializes the pairing registry on Windows. This should be invoked on the |
| 378 // network thread. | 381 // network thread. |
| 379 void InitializePairingRegistry( | 382 void InitializePairingRegistry( |
| 380 IPC::PlatformFileForTransit privileged_key, | 383 IPC::PlatformFileForTransit privileged_key, |
| 381 IPC::PlatformFileForTransit unprivileged_key); | 384 IPC::PlatformFileForTransit unprivileged_key); |
| 382 #endif // defined(OS_WIN) | 385 #endif // defined(OS_WIN) |
| 383 | 386 |
| 384 // Crashes the process in response to a daemon's request. The daemon passes | 387 // Crashes the process in response to a daemon's request. The daemon passes |
| 385 // the location of the code that detected the fatal error resulted in this | 388 // the location of the code that detected the fatal error resulted in this |
| 386 // request. | 389 // request. |
| 387 void OnCrash(const std::string& function_name, | 390 void OnCrash(const std::string& function_name, |
| 388 const std::string& file_name, | 391 const std::string& file_name, |
| 389 const int& line_number); | 392 const int& line_number); |
| 390 | 393 |
| 391 scoped_ptr<ChromotingHostContext> context_; | 394 scoped_ptr<ChromotingHostContext> context_; |
| 392 | 395 |
| 396 #if defined(OS_LINUX) | |
| 397 // Watch for certificate changes and kill the host when changes occur | |
| 398 scoped_ptr<CertificateWatcher> cert_watcher_; | |
| 399 #endif | |
| 400 | |
| 393 // XMPP server/remoting bot configuration (initialized from the command line). | 401 // XMPP server/remoting bot configuration (initialized from the command line). |
| 394 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; | 402 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; |
| 395 std::string directory_bot_jid_; | 403 std::string directory_bot_jid_; |
| 396 | 404 |
| 397 // Created on the UI thread but used from the network thread. | 405 // Created on the UI thread but used from the network thread. |
| 398 base::FilePath host_config_path_; | 406 base::FilePath host_config_path_; |
| 399 std::string host_config_; | 407 std::string host_config_; |
| 400 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; | 408 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; |
| 401 | 409 |
| 402 // Accessed on the network thread. | 410 // Accessed on the network thread. |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 800 use_service_account_, host_owner_, local_certificate, key_pair_, | 808 use_service_account_, host_owner_, local_certificate, key_pair_, |
| 801 client_domain_, pin_hash_, pairing_registry); | 809 client_domain_, pin_hash_, pairing_registry); |
| 802 | 810 |
| 803 host_->set_pairing_registry(pairing_registry); | 811 host_->set_pairing_registry(pairing_registry); |
| 804 } else { | 812 } else { |
| 805 // ThirdPartyAuthConfig::Parse() leaves the config in a valid state, so | 813 // ThirdPartyAuthConfig::Parse() leaves the config in a valid state, so |
| 806 // these URLs are both valid. | 814 // these URLs are both valid. |
| 807 DCHECK(third_party_auth_config_.token_url.is_valid()); | 815 DCHECK(third_party_auth_config_.token_url.is_valid()); |
| 808 DCHECK(third_party_auth_config_.token_validation_url.is_valid()); | 816 DCHECK(third_party_auth_config_.token_validation_url.is_valid()); |
| 809 | 817 |
| 818 #if defined(OS_LINUX) | |
| 819 cert_watcher_.reset(new CertificateWatcher( | |
|
Sergey Ulanov
2016/03/31 22:36:16
CreateAuthenticatorFactory() is called every time
Yuwei
2016/03/31 23:08:33
Currently the watcher get constructed just before
Sergey Ulanov
2016/04/01 17:49:23
This code also resets it every time the host is re
Yuwei
2016/04/01 18:28:04
Okay. I guess I had mixed up the concept of HostPr
Yuwei
2016/04/01 23:41:03
Done.
| |
| 820 host_->AsWeakPtr(), | |
| 821 base::Bind(&HostProcess::OnHostRestartRequested, this))); | |
| 822 context_->file_task_runner()->PostTask( | |
|
Sergey Ulanov
2016/03/31 22:36:16
I don't think you need to use file_task_runner() h
Yuwei
2016/03/31 23:08:33
I tried this but it complained something like it's
Sergey Ulanov
2016/04/01 17:49:23
Network thread is an IO thread (see https://code.g
Yuwei
2016/04/01 18:28:04
Interesting... I tried
context_->network_task
Yuwei
2016/04/01 18:44:34
Line 114: network_task_runner->PostTask(FROM_HERE,
Sergey Ulanov
2016/04/01 20:11:00
I see. This error message is somewhat wrong. Netwo
Yuwei
2016/04/01 20:53:22
That sounds like a problem... I think I can start
| |
| 823 FROM_HERE, base::Bind(&CertificateWatcher::Start, | |
| 824 base::Unretained(cert_watcher_.get()))); | |
| 825 #endif | |
| 826 | |
| 810 scoped_refptr<protocol::TokenValidatorFactory> token_validator_factory = | 827 scoped_refptr<protocol::TokenValidatorFactory> token_validator_factory = |
| 811 new TokenValidatorFactoryImpl(third_party_auth_config_, key_pair_, | 828 new TokenValidatorFactoryImpl(third_party_auth_config_, key_pair_, |
| 812 context_->url_request_context_getter()); | 829 context_->url_request_context_getter()); |
| 813 factory = protocol::Me2MeHostAuthenticatorFactory::CreateWithThirdPartyAuth( | 830 factory = protocol::Me2MeHostAuthenticatorFactory::CreateWithThirdPartyAuth( |
| 814 use_service_account_, host_owner_, local_certificate, key_pair_, | 831 use_service_account_, host_owner_, local_certificate, key_pair_, |
| 815 client_domain_, token_validator_factory); | 832 client_domain_, token_validator_factory); |
| 816 } | 833 } |
| 817 | 834 |
| 818 #if defined(OS_POSIX) | 835 #if defined(OS_POSIX) |
| 819 // On Linux and Mac, perform a PAM authorization step after authentication. | 836 // On Linux and Mac, perform a PAM authorization step after authentication. |
| (...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1698 char message[1024]; | 1715 char message[1024]; |
| 1699 base::snprintf(message, sizeof(message), | 1716 base::snprintf(message, sizeof(message), |
| 1700 "Requested by %s at %s, line %d.", | 1717 "Requested by %s at %s, line %d.", |
| 1701 function_name.c_str(), file_name.c_str(), line_number); | 1718 function_name.c_str(), file_name.c_str(), line_number); |
| 1702 base::debug::Alias(message); | 1719 base::debug::Alias(message); |
| 1703 | 1720 |
| 1704 // The daemon requested us to crash the process. | 1721 // The daemon requested us to crash the process. |
| 1705 CHECK(false) << message; | 1722 CHECK(false) << message; |
| 1706 } | 1723 } |
| 1707 | 1724 |
| 1725 void HostProcess::OnHostRestartRequested() { | |
| 1726 // restarts(shutdowns) the server when the certificate is updated | |
| 1727 if (!context_->network_task_runner()->BelongsToCurrentThread()) { | |
| 1728 context_->network_task_runner()->PostTask(FROM_HERE, | |
| 1729 base::Bind(&HostProcess::OnHostRestartRequested, this)); | |
| 1730 return; | |
| 1731 } | |
| 1732 ShutdownHost(kSuccessExitCode); | |
| 1733 } | |
| 1734 | |
| 1708 int HostProcessMain() { | 1735 int HostProcessMain() { |
| 1709 HOST_LOG << "Starting host process: version " << STRINGIZE(VERSION); | 1736 HOST_LOG << "Starting host process: version " << STRINGIZE(VERSION); |
| 1710 | 1737 |
| 1711 #if defined(OS_LINUX) | 1738 #if defined(OS_LINUX) |
| 1712 // Required in order for us to run multiple X11 threads. | 1739 // Required in order for us to run multiple X11 threads. |
| 1713 XInitThreads(); | 1740 XInitThreads(); |
| 1714 | 1741 |
| 1715 // Required for any calls into GTK functions, such as the Disconnect and | 1742 // Required for any calls into GTK functions, such as the Disconnect and |
| 1716 // Continue windows, though these should not be used for the Me2Me case | 1743 // Continue windows, though these should not be used for the Me2Me case |
| 1717 // (crbug.com/104377). | 1744 // (crbug.com/104377). |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 1746 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); | 1773 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); |
| 1747 new HostProcess(std::move(context), &exit_code, &shutdown_watchdog); | 1774 new HostProcess(std::move(context), &exit_code, &shutdown_watchdog); |
| 1748 | 1775 |
| 1749 // Run the main (also UI) message loop until the host no longer needs it. | 1776 // Run the main (also UI) message loop until the host no longer needs it. |
| 1750 message_loop.Run(); | 1777 message_loop.Run(); |
| 1751 | 1778 |
| 1752 return exit_code; | 1779 return exit_code; |
| 1753 } | 1780 } |
| 1754 | 1781 |
| 1755 } // namespace remoting | 1782 } // namespace remoting |
| OLD | NEW |