| 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" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/debug/alias.h" | 13 #include "base/debug/alias.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
| 23 #include "build/build_config.h" | 23 #include "build/build_config.h" |
| 24 #include "crypto/nss_util.h" | 24 #include "crypto/nss_util.h" |
| 25 #include "ipc/ipc_channel.h" | 25 #include "ipc/ipc_channel.h" |
| 26 #include "ipc/ipc_channel_proxy.h" | 26 #include "ipc/ipc_channel_proxy.h" |
| 27 #include "ipc/ipc_listener.h" | 27 #include "ipc/ipc_listener.h" |
| 28 #include "media/base/media.h" | 28 #include "media/base/media.h" |
| 29 #include "net/base/network_change_notifier.h" | |
| 30 #include "net/socket/client_socket_factory.h" | 29 #include "net/socket/client_socket_factory.h" |
| 31 #include "net/socket/ssl_server_socket.h" | 30 #include "net/socket/ssl_server_socket.h" |
| 32 #include "net/url_request/url_fetcher.h" | 31 #include "net/url_request/url_fetcher.h" |
| 33 #include "remoting/base/auto_thread_task_runner.h" | 32 #include "remoting/base/auto_thread_task_runner.h" |
| 34 #include "remoting/base/breakpad.h" | 33 #include "remoting/base/breakpad.h" |
| 35 #include "remoting/base/constants.h" | 34 #include "remoting/base/constants.h" |
| 36 #include "remoting/base/logging.h" | 35 #include "remoting/base/logging.h" |
| 37 #include "remoting/base/rsa_key_pair.h" | 36 #include "remoting/base/rsa_key_pair.h" |
| 38 #include "remoting/base/service_urls.h" | 37 #include "remoting/base/service_urls.h" |
| 39 #include "remoting/base/util.h" | 38 #include "remoting/base/util.h" |
| 40 #include "remoting/host/branding.h" | 39 #include "remoting/host/branding.h" |
| 41 #include "remoting/host/chromoting_host.h" | 40 #include "remoting/host/chromoting_host.h" |
| 42 #include "remoting/host/chromoting_host_context.h" | 41 #include "remoting/host/chromoting_host_context.h" |
| 43 #include "remoting/host/chromoting_messages.h" | 42 #include "remoting/host/chromoting_messages.h" |
| 44 #include "remoting/host/config_file_watcher.h" | 43 #include "remoting/host/config_file_watcher.h" |
| 45 #include "remoting/host/config_watcher.h" | 44 #include "remoting/host/config_watcher.h" |
| 46 #include "remoting/host/desktop_environment.h" | 45 #include "remoting/host/desktop_environment.h" |
| 47 #include "remoting/host/desktop_session_connector.h" | 46 #include "remoting/host/desktop_session_connector.h" |
| 48 #include "remoting/host/dns_blackhole_checker.h" | |
| 49 #include "remoting/host/heartbeat_sender.h" | |
| 50 #include "remoting/host/host_change_notification_listener.h" | 47 #include "remoting/host/host_change_notification_listener.h" |
| 51 #include "remoting/host/host_config.h" | 48 #include "remoting/host/host_config.h" |
| 52 #include "remoting/host/host_event_logger.h" | 49 #include "remoting/host/host_event_logger.h" |
| 53 #include "remoting/host/host_exit_codes.h" | 50 #include "remoting/host/host_exit_codes.h" |
| 54 #include "remoting/host/host_main.h" | 51 #include "remoting/host/host_main.h" |
| 52 #include "remoting/host/host_signaling_manager.h" |
| 55 #include "remoting/host/host_status_logger.h" | 53 #include "remoting/host/host_status_logger.h" |
| 56 #include "remoting/host/ipc_constants.h" | 54 #include "remoting/host/ipc_constants.h" |
| 57 #include "remoting/host/ipc_desktop_environment.h" | 55 #include "remoting/host/ipc_desktop_environment.h" |
| 58 #include "remoting/host/ipc_host_event_logger.h" | 56 #include "remoting/host/ipc_host_event_logger.h" |
| 59 #include "remoting/host/logging.h" | 57 #include "remoting/host/logging.h" |
| 60 #include "remoting/host/me2me_desktop_environment.h" | 58 #include "remoting/host/me2me_desktop_environment.h" |
| 61 #include "remoting/host/pairing_registry_delegate.h" | 59 #include "remoting/host/pairing_registry_delegate.h" |
| 62 #include "remoting/host/policy_hack/policy_watcher.h" | 60 #include "remoting/host/policy_hack/policy_watcher.h" |
| 63 #include "remoting/host/session_manager_factory.h" | 61 #include "remoting/host/session_manager_factory.h" |
| 64 #include "remoting/host/shutdown_watchdog.h" | 62 #include "remoting/host/shutdown_watchdog.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 // Value used for --host-config option to indicate that the path must be read | 134 // Value used for --host-config option to indicate that the path must be read |
| 137 // from stdin. | 135 // from stdin. |
| 138 const char kStdinConfigPath[] = "-"; | 136 const char kStdinConfigPath[] = "-"; |
| 139 | 137 |
| 140 const char kWindowIdSwitchName[] = "window-id"; | 138 const char kWindowIdSwitchName[] = "window-id"; |
| 141 | 139 |
| 142 // Maximum time to wait for clean shutdown to occur, before forcing termination | 140 // Maximum time to wait for clean shutdown to occur, before forcing termination |
| 143 // of the process. | 141 // of the process. |
| 144 const int kShutdownTimeoutSeconds = 15; | 142 const int kShutdownTimeoutSeconds = 15; |
| 145 | 143 |
| 144 // Maximum time to wait for reporting host-offline-reason to the service, |
| 145 // before continuing normal process shutdown. |
| 146 const int kHostOfflineReasonTimeoutSeconds = 10; |
| 147 |
| 146 } // namespace | 148 } // namespace |
| 147 | 149 |
| 148 namespace remoting { | 150 namespace remoting { |
| 149 | 151 |
| 150 class HostProcess | 152 class HostProcess : public ConfigWatcher::Delegate, |
| 151 : public ConfigWatcher::Delegate, | 153 public HostSignalingManager::Listener, |
| 152 public HostChangeNotificationListener::Listener, | 154 public HostChangeNotificationListener::Listener, |
| 153 public IPC::Listener, | 155 public IPC::Listener, |
| 154 public base::RefCountedThreadSafe<HostProcess> { | 156 public base::RefCountedThreadSafe<HostProcess> { |
| 155 public: | 157 public: |
| 156 // |shutdown_watchdog| is armed when shutdown is started, and should be kept | 158 // |shutdown_watchdog| is armed when shutdown is started, and should be kept |
| 157 // alive as long as possible until the process exits (since destroying the | 159 // alive as long as possible until the process exits (since destroying the |
| 158 // watchdog disarms it). | 160 // watchdog disarms it). |
| 159 HostProcess(scoped_ptr<ChromotingHostContext> context, | 161 HostProcess(scoped_ptr<ChromotingHostContext> context, |
| 160 int* exit_code_out, | 162 int* exit_code_out, |
| 161 ShutdownWatchdog* shutdown_watchdog); | 163 ShutdownWatchdog* shutdown_watchdog); |
| 162 | 164 |
| 163 // ConfigWatcher::Delegate interface. | 165 // ConfigWatcher::Delegate interface. |
| 164 void OnConfigUpdated(const std::string& serialized_config) override; | 166 void OnConfigUpdated(const std::string& serialized_config) override; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 bool OnUsernamePolicyUpdate(base::DictionaryValue* policies); | 249 bool OnUsernamePolicyUpdate(base::DictionaryValue* policies); |
| 248 bool OnNatPolicyUpdate(base::DictionaryValue* policies); | 250 bool OnNatPolicyUpdate(base::DictionaryValue* policies); |
| 249 bool OnRelayPolicyUpdate(base::DictionaryValue* policies); | 251 bool OnRelayPolicyUpdate(base::DictionaryValue* policies); |
| 250 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies); | 252 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies); |
| 251 bool OnCurtainPolicyUpdate(base::DictionaryValue* policies); | 253 bool OnCurtainPolicyUpdate(base::DictionaryValue* policies); |
| 252 bool OnHostTalkGadgetPrefixPolicyUpdate(base::DictionaryValue* policies); | 254 bool OnHostTalkGadgetPrefixPolicyUpdate(base::DictionaryValue* policies); |
| 253 bool OnHostTokenUrlPolicyUpdate(base::DictionaryValue* policies); | 255 bool OnHostTokenUrlPolicyUpdate(base::DictionaryValue* policies); |
| 254 bool OnPairingPolicyUpdate(base::DictionaryValue* policies); | 256 bool OnPairingPolicyUpdate(base::DictionaryValue* policies); |
| 255 bool OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies); | 257 bool OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies); |
| 256 | 258 |
| 259 scoped_ptr<HostSignalingManager> CreateHostSignalingManager(); |
| 260 |
| 257 void StartHost(); | 261 void StartHost(); |
| 258 | 262 |
| 259 void OnHeartbeatSuccessful(); | 263 // Overrides for HostSignalingManager::Listener interface. |
| 260 void OnUnknownHostIdError(); | 264 void OnHeartbeatSuccessful() override; |
| 261 | 265 void OnUnknownHostIdError() override; |
| 262 void OnAuthFailed(); | 266 void OnAuthFailed() override; |
| 263 | 267 |
| 264 void RestartHost(); | 268 void RestartHost(); |
| 265 | 269 |
| 266 // Stops the host and shuts down the process with the specified |exit_code|. | 270 // Stops the host and shuts down the process with the specified |exit_code|. |
| 267 void ShutdownHost(HostExitCodes exit_code); | 271 void ShutdownHost(HostExitCodes exit_code); |
| 268 | 272 |
| 269 void ScheduleHostShutdown(); | 273 // Private helper used by ShutdownHost method to initiate sending of |
| 274 // host-offline-reason before continuing shutdown. |
| 275 void SendOfflineReasonAndShutdownOnNetworkThread(HostExitCodes exit_code); |
| 270 | 276 |
| 271 void ShutdownOnNetworkThread(); | 277 void ShutdownOnNetworkThread(); |
| 272 | 278 |
| 273 void OnPolicyWatcherShutdown(); | 279 void OnPolicyWatcherShutdown(); |
| 274 | 280 |
| 275 #if defined(OS_WIN) | 281 #if defined(OS_WIN) |
| 276 // Initializes the pairing registry on Windows. This should be invoked on the | 282 // Initializes the pairing registry on Windows. This should be invoked on the |
| 277 // network thread. | 283 // network thread. |
| 278 void InitializePairingRegistry( | 284 void InitializePairingRegistry( |
| 279 IPC::PlatformFileForTransit privileged_key, | 285 IPC::PlatformFileForTransit privileged_key, |
| 280 IPC::PlatformFileForTransit unprivileged_key); | 286 IPC::PlatformFileForTransit unprivileged_key); |
| 281 #endif // defined(OS_WIN) | 287 #endif // defined(OS_WIN) |
| 282 | 288 |
| 283 // Crashes the process in response to a daemon's request. The daemon passes | 289 // Crashes the process in response to a daemon's request. The daemon passes |
| 284 // the location of the code that detected the fatal error resulted in this | 290 // the location of the code that detected the fatal error resulted in this |
| 285 // request. | 291 // request. |
| 286 void OnCrash(const std::string& function_name, | 292 void OnCrash(const std::string& function_name, |
| 287 const std::string& file_name, | 293 const std::string& file_name, |
| 288 const int& line_number); | 294 const int& line_number); |
| 289 | 295 |
| 290 scoped_ptr<ChromotingHostContext> context_; | 296 scoped_ptr<ChromotingHostContext> context_; |
| 291 | 297 |
| 292 // Created on the UI thread but used from the network thread. | |
| 293 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | |
| 294 | |
| 295 // Accessed on the UI thread. | 298 // Accessed on the UI thread. |
| 296 scoped_ptr<IPC::ChannelProxy> daemon_channel_; | 299 scoped_ptr<IPC::ChannelProxy> daemon_channel_; |
| 297 | 300 |
| 298 // XMPP server/remoting bot configuration (initialized from the command line). | 301 // XMPP server/remoting bot configuration (initialized from the command line). |
| 299 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; | 302 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; |
| 300 std::string directory_bot_jid_; | 303 std::string directory_bot_jid_; |
| 301 | 304 |
| 302 // Created on the UI thread but used from the network thread. | 305 // Created on the UI thread but used from the network thread. |
| 303 base::FilePath host_config_path_; | 306 base::FilePath host_config_path_; |
| 304 std::string host_config_; | 307 std::string host_config_; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 334 ThirdPartyAuthConfig third_party_auth_config_; | 337 ThirdPartyAuthConfig third_party_auth_config_; |
| 335 bool enable_gnubby_auth_; | 338 bool enable_gnubby_auth_; |
| 336 | 339 |
| 337 // Boolean to change flow, where ncessary, if we're | 340 // Boolean to change flow, where ncessary, if we're |
| 338 // capturing a window instead of the entire desktop. | 341 // capturing a window instead of the entire desktop. |
| 339 bool enable_window_capture_; | 342 bool enable_window_capture_; |
| 340 | 343 |
| 341 // Used to specify which window to stream, if enabled. | 344 // Used to specify which window to stream, if enabled. |
| 342 webrtc::WindowId window_id_; | 345 webrtc::WindowId window_id_; |
| 343 | 346 |
| 344 scoped_ptr<OAuthTokenGetter> oauth_token_getter_; | 347 // Used to send heartbeats while running, and the reason for going offline |
| 345 scoped_ptr<XmppSignalStrategy> signal_strategy_; | 348 // when shutting down. |
| 346 scoped_ptr<SignalingConnector> signaling_connector_; | 349 scoped_ptr<HostSignalingManager> host_signaling_manager_; |
| 347 scoped_ptr<HeartbeatSender> heartbeat_sender_; | 350 |
| 348 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; | 351 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; |
| 349 scoped_ptr<HostStatusLogger> host_status_logger_; | 352 scoped_ptr<HostStatusLogger> host_status_logger_; |
| 350 scoped_ptr<HostEventLogger> host_event_logger_; | 353 scoped_ptr<HostEventLogger> host_event_logger_; |
| 351 | 354 |
| 352 scoped_ptr<ChromotingHost> host_; | 355 scoped_ptr<ChromotingHost> host_; |
| 353 | 356 |
| 354 // Used to keep this HostProcess alive until it is shutdown. | 357 // Used to keep this HostProcess alive until it is shutdown. |
| 355 scoped_refptr<HostProcess> self_; | 358 scoped_refptr<HostProcess> self_; |
| 356 | 359 |
| 357 #if defined(REMOTING_MULTI_PROCESS) | 360 #if defined(REMOTING_MULTI_PROCESS) |
| 358 DesktopSessionConnector* desktop_session_connector_; | 361 DesktopSessionConnector* desktop_session_connector_; |
| 359 #endif // defined(REMOTING_MULTI_PROCESS) | 362 #endif // defined(REMOTING_MULTI_PROCESS) |
| 360 | 363 |
| 361 int* exit_code_out_; | 364 int* exit_code_out_; |
| 362 bool signal_parent_; | 365 bool signal_parent_; |
| 363 | 366 |
| 364 scoped_refptr<PairingRegistry> pairing_registry_; | 367 scoped_refptr<PairingRegistry> pairing_registry_; |
| 365 | 368 |
| 366 ShutdownWatchdog* shutdown_watchdog_; | 369 ShutdownWatchdog* shutdown_watchdog_; |
| 370 |
| 371 DISALLOW_COPY_AND_ASSIGN(HostProcess); |
| 367 }; | 372 }; |
| 368 | 373 |
| 369 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, | 374 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, |
| 370 int* exit_code_out, | 375 int* exit_code_out, |
| 371 ShutdownWatchdog* shutdown_watchdog) | 376 ShutdownWatchdog* shutdown_watchdog) |
| 372 : context_(context.Pass()), | 377 : context_(context.Pass()), |
| 373 state_(HOST_INITIALIZING), | 378 state_(HOST_INITIALIZING), |
| 374 use_service_account_(false), | 379 use_service_account_(false), |
| 375 enable_vp9_(false), | 380 enable_vp9_(false), |
| 376 frame_recorder_buffer_size_(0), | 381 frame_recorder_buffer_size_(0), |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 | 775 |
| 771 context_->network_task_runner()->PostTask( | 776 context_->network_task_runner()->PostTask( |
| 772 FROM_HERE, | 777 FROM_HERE, |
| 773 base::Bind(&HostProcess::StartOnNetworkThread, this)); | 778 base::Bind(&HostProcess::StartOnNetworkThread, this)); |
| 774 } | 779 } |
| 775 | 780 |
| 776 void HostProcess::ShutdownOnUiThread() { | 781 void HostProcess::ShutdownOnUiThread() { |
| 777 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 782 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 778 | 783 |
| 779 // Tear down resources that need to be torn down on the UI thread. | 784 // Tear down resources that need to be torn down on the UI thread. |
| 780 network_change_notifier_.reset(); | |
| 781 daemon_channel_.reset(); | 785 daemon_channel_.reset(); |
| 782 desktop_environment_factory_.reset(); | 786 desktop_environment_factory_.reset(); |
| 783 | 787 |
| 784 // It is now safe for the HostProcess to be deleted. | 788 // It is now safe for the HostProcess to be deleted. |
| 785 self_ = nullptr; | 789 self_ = nullptr; |
| 786 | 790 |
| 787 #if defined(OS_LINUX) | 791 #if defined(OS_LINUX) |
| 788 // Cause the global AudioPipeReader to be freed, otherwise the audio | 792 // Cause the global AudioPipeReader to be freed, otherwise the audio |
| 789 // thread will remain in-use and prevent the process from exiting. | 793 // thread will remain in-use and prevent the process from exiting. |
| 790 // TODO(wez): DesktopEnvironmentFactory should own the pipe reader. | 794 // TODO(wez): DesktopEnvironmentFactory should own the pipe reader. |
| 791 // See crbug.com/161373 and crbug.com/104544. | 795 // See crbug.com/161373 and crbug.com/104544. |
| 792 AudioCapturerLinux::InitializePipeReader(nullptr, base::FilePath()); | 796 AudioCapturerLinux::InitializePipeReader(nullptr, base::FilePath()); |
| 793 #endif | 797 #endif |
| 794 } | 798 } |
| 795 | 799 |
| 796 // Overridden from HeartbeatSender::Listener | |
| 797 void HostProcess::OnUnknownHostIdError() { | 800 void HostProcess::OnUnknownHostIdError() { |
| 798 LOG(ERROR) << "Host ID not found."; | 801 LOG(ERROR) << "Host ID not found."; |
| 799 ShutdownHost(kInvalidHostIdExitCode); | 802 ShutdownHost(kInvalidHostIdExitCode); |
| 800 } | 803 } |
| 801 | 804 |
| 802 void HostProcess::OnHeartbeatSuccessful() { | 805 void HostProcess::OnHeartbeatSuccessful() { |
| 803 HOST_LOG << "Host ready to receive connections."; | 806 HOST_LOG << "Host ready to receive connections."; |
| 804 #if defined(OS_POSIX) | 807 #if defined(OS_POSIX) |
| 805 if (signal_parent_) { | 808 if (signal_parent_) { |
| 806 kill(getppid(), SIGUSR1); | 809 kill(getppid(), SIGUSR1); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 if (!config.GetString(kXmppLoginConfigPath, &xmpp_server_config_.username) || | 895 if (!config.GetString(kXmppLoginConfigPath, &xmpp_server_config_.username) || |
| 893 !(config.GetString(kXmppAuthTokenConfigPath, | 896 !(config.GetString(kXmppAuthTokenConfigPath, |
| 894 &xmpp_server_config_.auth_token) || | 897 &xmpp_server_config_.auth_token) || |
| 895 config.GetString(kOAuthRefreshTokenConfigPath, | 898 config.GetString(kOAuthRefreshTokenConfigPath, |
| 896 &oauth_refresh_token_))) { | 899 &oauth_refresh_token_))) { |
| 897 LOG(ERROR) << "XMPP credentials are not defined in the config."; | 900 LOG(ERROR) << "XMPP credentials are not defined in the config."; |
| 898 return false; | 901 return false; |
| 899 } | 902 } |
| 900 | 903 |
| 901 if (!oauth_refresh_token_.empty()) { | 904 if (!oauth_refresh_token_.empty()) { |
| 902 // SignalingConnector is responsible for getting OAuth token. | 905 // SignalingConnector (inside HostSignalingManager) is responsible for |
| 906 // getting OAuth token. |
| 903 xmpp_server_config_.auth_token = ""; | 907 xmpp_server_config_.auth_token = ""; |
| 904 xmpp_server_config_.auth_service = "oauth2"; | 908 xmpp_server_config_.auth_service = "oauth2"; |
| 905 } else if (!config.GetString(kXmppAuthServiceConfigPath, | 909 } else if (!config.GetString(kXmppAuthServiceConfigPath, |
| 906 &xmpp_server_config_.auth_service)) { | 910 &xmpp_server_config_.auth_service)) { |
| 907 // For the me2me host, we default to ClientLogin token for chromiumsync | 911 // For the me2me host, we default to ClientLogin token for chromiumsync |
| 908 // because earlier versions of the host had no HTTP stack with which to | 912 // because earlier versions of the host had no HTTP stack with which to |
| 909 // request an OAuth2 access token. | 913 // request an OAuth2 access token. |
| 910 xmpp_server_config_.auth_service = kChromotingTokenDefaultServiceName; | 914 xmpp_server_config_.auth_service = kChromotingTokenDefaultServiceName; |
| 911 } | 915 } |
| 912 | 916 |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1272 } else { | 1276 } else { |
| 1273 HOST_LOG << "Policy disables gnubby auth."; | 1277 HOST_LOG << "Policy disables gnubby auth."; |
| 1274 } | 1278 } |
| 1275 | 1279 |
| 1276 if (desktop_environment_factory_) | 1280 if (desktop_environment_factory_) |
| 1277 desktop_environment_factory_->SetEnableGnubbyAuth(enable_gnubby_auth_); | 1281 desktop_environment_factory_->SetEnableGnubbyAuth(enable_gnubby_auth_); |
| 1278 | 1282 |
| 1279 return true; | 1283 return true; |
| 1280 } | 1284 } |
| 1281 | 1285 |
| 1286 scoped_ptr<HostSignalingManager> HostProcess::CreateHostSignalingManager() { |
| 1287 DCHECK(!host_id_.empty()); // |ApplyConfig| should already have been run. |
| 1288 |
| 1289 scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials( |
| 1290 new OAuthTokenGetter::OAuthCredentials(xmpp_server_config_.username, |
| 1291 oauth_refresh_token_, |
| 1292 use_service_account_)); |
| 1293 |
| 1294 return HostSignalingManager::Create(this, context_->network_task_runner(), |
| 1295 context_->url_request_context_getter(), |
| 1296 xmpp_server_config_, talkgadget_prefix_, |
| 1297 host_id_, key_pair_, directory_bot_jid_, |
| 1298 oauth_credentials.Pass()); |
| 1299 } |
| 1300 |
| 1282 void HostProcess::StartHost() { | 1301 void HostProcess::StartHost() { |
| 1283 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1302 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 1284 DCHECK(!host_); | 1303 DCHECK(!host_); |
| 1285 DCHECK(!signal_strategy_.get()); | 1304 DCHECK(!host_signaling_manager_); |
| 1305 |
| 1286 DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART || | 1306 DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART || |
| 1287 state_ == HOST_STOPPED) << state_; | 1307 state_ == HOST_STOPPED) |
| 1308 << "state_ = " << state_; |
| 1288 state_ = HOST_STARTED; | 1309 state_ = HOST_STARTED; |
| 1289 | 1310 |
| 1290 signal_strategy_.reset( | 1311 host_signaling_manager_ = CreateHostSignalingManager(); |
| 1291 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), | |
| 1292 context_->url_request_context_getter(), | |
| 1293 xmpp_server_config_)); | |
| 1294 | |
| 1295 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker( | |
| 1296 new DnsBlackholeChecker(context_->url_request_context_getter(), | |
| 1297 talkgadget_prefix_)); | |
| 1298 | |
| 1299 // Create a NetworkChangeNotifier for use by the signaling connector. | |
| 1300 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | |
| 1301 | |
| 1302 signaling_connector_.reset(new SignalingConnector( | |
| 1303 signal_strategy_.get(), | |
| 1304 dns_blackhole_checker.Pass(), | |
| 1305 base::Bind(&HostProcess::OnAuthFailed, this))); | |
| 1306 | |
| 1307 if (!oauth_refresh_token_.empty()) { | |
| 1308 scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials; | |
| 1309 oauth_credentials.reset( | |
| 1310 new OAuthTokenGetter::OAuthCredentials( | |
| 1311 xmpp_server_config_.username, oauth_refresh_token_, | |
| 1312 use_service_account_)); | |
| 1313 | |
| 1314 oauth_token_getter_.reset(new OAuthTokenGetter( | |
| 1315 oauth_credentials.Pass(), context_->url_request_context_getter(), | |
| 1316 false)); | |
| 1317 | |
| 1318 signaling_connector_->EnableOAuth(oauth_token_getter_.get()); | |
| 1319 } | |
| 1320 | 1312 |
| 1321 uint32 network_flags = 0; | 1313 uint32 network_flags = 0; |
| 1322 if (allow_nat_traversal_) { | 1314 if (allow_nat_traversal_) { |
| 1323 network_flags = NetworkSettings::NAT_TRAVERSAL_STUN | | 1315 network_flags = NetworkSettings::NAT_TRAVERSAL_STUN | |
| 1324 NetworkSettings::NAT_TRAVERSAL_OUTGOING; | 1316 NetworkSettings::NAT_TRAVERSAL_OUTGOING; |
| 1325 if (allow_relay_) | 1317 if (allow_relay_) |
| 1326 network_flags |= NetworkSettings::NAT_TRAVERSAL_RELAY; | 1318 network_flags |= NetworkSettings::NAT_TRAVERSAL_RELAY; |
| 1327 } | 1319 } |
| 1328 | 1320 |
| 1329 NetworkSettings network_settings(network_flags); | 1321 NetworkSettings network_settings(network_flags); |
| 1330 | 1322 |
| 1331 if (min_udp_port_ && max_udp_port_) { | 1323 if (min_udp_port_ && max_udp_port_) { |
| 1332 network_settings.min_port = min_udp_port_; | 1324 network_settings.min_port = min_udp_port_; |
| 1333 network_settings.max_port = max_udp_port_; | 1325 network_settings.max_port = max_udp_port_; |
| 1334 } else if (!allow_nat_traversal_) { | 1326 } else if (!allow_nat_traversal_) { |
| 1335 // For legacy reasons we have to restrict the port range to a set of default | 1327 // For legacy reasons we have to restrict the port range to a set of default |
| 1336 // values when nat traversal is disabled, even if the port range was not | 1328 // values when nat traversal is disabled, even if the port range was not |
| 1337 // set in policy. | 1329 // set in policy. |
| 1338 network_settings.min_port = NetworkSettings::kDefaultMinPort; | 1330 network_settings.min_port = NetworkSettings::kDefaultMinPort; |
| 1339 network_settings.max_port = NetworkSettings::kDefaultMaxPort; | 1331 network_settings.max_port = NetworkSettings::kDefaultMaxPort; |
| 1340 } | 1332 } |
| 1341 | 1333 |
| 1342 host_.reset(new ChromotingHost( | 1334 host_.reset(new ChromotingHost( |
| 1343 signal_strategy_.get(), | 1335 host_signaling_manager_->signal_strategy(), |
| 1344 desktop_environment_factory_.get(), | 1336 desktop_environment_factory_.get(), |
| 1345 CreateHostSessionManager(signal_strategy_.get(), network_settings, | 1337 CreateHostSessionManager(host_signaling_manager_->signal_strategy(), |
| 1338 network_settings, |
| 1346 context_->url_request_context_getter()), | 1339 context_->url_request_context_getter()), |
| 1347 context_->audio_task_runner(), | 1340 context_->audio_task_runner(), context_->input_task_runner(), |
| 1348 context_->input_task_runner(), | |
| 1349 context_->video_capture_task_runner(), | 1341 context_->video_capture_task_runner(), |
| 1350 context_->video_encode_task_runner(), | 1342 context_->video_encode_task_runner(), context_->network_task_runner(), |
| 1351 context_->network_task_runner(), | |
| 1352 context_->ui_task_runner())); | 1343 context_->ui_task_runner())); |
| 1353 | 1344 |
| 1354 if (enable_vp9_) { | 1345 if (enable_vp9_) { |
| 1355 scoped_ptr<protocol::CandidateSessionConfig> config = | 1346 scoped_ptr<protocol::CandidateSessionConfig> config = |
| 1356 host_->protocol_config()->Clone(); | 1347 host_->protocol_config()->Clone(); |
| 1357 config->EnableVideoCodec(protocol::ChannelConfig::CODEC_VP9); | 1348 config->EnableVideoCodec(protocol::ChannelConfig::CODEC_VP9); |
| 1358 host_->set_protocol_config(config.Pass()); | 1349 host_->set_protocol_config(config.Pass()); |
| 1359 } | 1350 } |
| 1360 | 1351 |
| 1361 if (frame_recorder_buffer_size_ > 0) { | 1352 if (frame_recorder_buffer_size_ > 0) { |
| 1362 scoped_ptr<VideoFrameRecorderHostExtension> frame_recorder_extension( | 1353 scoped_ptr<VideoFrameRecorderHostExtension> frame_recorder_extension( |
| 1363 new VideoFrameRecorderHostExtension()); | 1354 new VideoFrameRecorderHostExtension()); |
| 1364 frame_recorder_extension->SetMaxContentBytes(frame_recorder_buffer_size_); | 1355 frame_recorder_extension->SetMaxContentBytes(frame_recorder_buffer_size_); |
| 1365 host_->AddExtension(frame_recorder_extension.Pass()); | 1356 host_->AddExtension(frame_recorder_extension.Pass()); |
| 1366 } | 1357 } |
| 1367 | 1358 |
| 1368 // TODO(simonmorris): Get the maximum session duration from a policy. | 1359 // TODO(simonmorris): Get the maximum session duration from a policy. |
| 1369 #if defined(OS_LINUX) | 1360 #if defined(OS_LINUX) |
| 1370 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); | 1361 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); |
| 1371 #endif | 1362 #endif |
| 1372 | 1363 |
| 1373 heartbeat_sender_.reset(new HeartbeatSender( | 1364 host_change_notification_listener_.reset(new HostChangeNotificationListener( |
| 1374 base::Bind(&HostProcess::OnHeartbeatSuccessful, base::Unretained(this)), | 1365 this, host_id_, host_signaling_manager_->signal_strategy(), |
| 1375 base::Bind(&HostProcess::OnUnknownHostIdError, base::Unretained(this)), | 1366 directory_bot_jid_)); |
| 1376 host_id_, signal_strategy_.get(), key_pair_, directory_bot_jid_)); | |
| 1377 | 1367 |
| 1378 host_change_notification_listener_.reset(new HostChangeNotificationListener( | 1368 host_status_logger_.reset(new HostStatusLogger( |
| 1379 this, host_id_, signal_strategy_.get(), directory_bot_jid_)); | 1369 host_->AsWeakPtr(), ServerLogEntry::ME2ME, |
| 1380 | 1370 host_signaling_manager_->signal_strategy(), directory_bot_jid_)); |
| 1381 host_status_logger_.reset( | |
| 1382 new HostStatusLogger(host_->AsWeakPtr(), ServerLogEntry::ME2ME, | |
| 1383 signal_strategy_.get(), directory_bot_jid_)); | |
| 1384 | 1371 |
| 1385 // Set up reporting the host status notifications. | 1372 // Set up reporting the host status notifications. |
| 1386 #if defined(REMOTING_MULTI_PROCESS) | 1373 #if defined(REMOTING_MULTI_PROCESS) |
| 1387 host_event_logger_.reset( | 1374 host_event_logger_.reset( |
| 1388 new IpcHostEventLogger(host_->AsWeakPtr(), daemon_channel_.get())); | 1375 new IpcHostEventLogger(host_->AsWeakPtr(), daemon_channel_.get())); |
| 1389 #else // !defined(REMOTING_MULTI_PROCESS) | 1376 #else // !defined(REMOTING_MULTI_PROCESS) |
| 1390 host_event_logger_ = | 1377 host_event_logger_ = |
| 1391 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); | 1378 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); |
| 1392 #endif // !defined(REMOTING_MULTI_PROCESS) | 1379 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 1393 | 1380 |
| 1394 host_->SetEnableCurtaining(curtain_required_); | 1381 host_->SetEnableCurtaining(curtain_required_); |
| 1395 host_->Start(host_owner_email_); | 1382 host_->Start(host_owner_email_); |
| 1396 | 1383 |
| 1397 CreateAuthenticatorFactory(); | 1384 CreateAuthenticatorFactory(); |
| 1398 } | 1385 } |
| 1399 | 1386 |
| 1400 void HostProcess::OnAuthFailed() { | 1387 void HostProcess::OnAuthFailed() { |
| 1401 ShutdownHost(kInvalidOauthCredentialsExitCode); | 1388 ShutdownHost(kInvalidOauthCredentialsExitCode); |
| 1402 } | 1389 } |
| 1403 | 1390 |
| 1404 void HostProcess::RestartHost() { | 1391 void HostProcess::RestartHost() { |
| 1405 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1392 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 1406 DCHECK_EQ(state_, HOST_STARTED); | 1393 DCHECK_EQ(state_, HOST_STARTED); |
| 1407 | 1394 |
| 1408 state_ = HOST_STOPPING_TO_RESTART; | 1395 state_ = HOST_STOPPING_TO_RESTART; |
| 1409 ShutdownOnNetworkThread(); | 1396 ShutdownOnNetworkThread(); |
| 1410 } | 1397 } |
| 1411 | 1398 |
| 1399 void HostProcess::SendOfflineReasonAndShutdownOnNetworkThread( |
| 1400 HostExitCodes exit_code) { |
| 1401 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 1402 DCHECK(host_signaling_manager_); |
| 1403 host_signaling_manager_.release()->SendHostOfflineReasonAndDelete( |
| 1404 ExitCodeToString(exit_code), |
| 1405 base::TimeDelta::FromSeconds(kHostOfflineReasonTimeoutSeconds)); |
| 1406 ShutdownOnNetworkThread(); |
| 1407 } |
| 1408 |
| 1412 void HostProcess::ShutdownHost(HostExitCodes exit_code) { | 1409 void HostProcess::ShutdownHost(HostExitCodes exit_code) { |
| 1413 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1410 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 1414 | 1411 |
| 1415 *exit_code_out_ = exit_code; | 1412 *exit_code_out_ = exit_code; |
| 1416 | 1413 |
| 1417 switch (state_) { | 1414 switch (state_) { |
| 1418 case HOST_INITIALIZING: | 1415 case HOST_INITIALIZING: |
| 1419 state_ = HOST_STOPPING; | 1416 state_ = HOST_STOPPING; |
| 1420 ShutdownOnNetworkThread(); | 1417 DCHECK(!host_signaling_manager_); |
| 1418 host_signaling_manager_ = CreateHostSignalingManager(); |
| 1419 SendOfflineReasonAndShutdownOnNetworkThread(exit_code); |
| 1421 break; | 1420 break; |
| 1422 | 1421 |
| 1423 case HOST_STARTED: | 1422 case HOST_STARTED: |
| 1424 state_ = HOST_STOPPING; | 1423 state_ = HOST_STOPPING; |
| 1425 heartbeat_sender_->SetHostOfflineReason( | 1424 SendOfflineReasonAndShutdownOnNetworkThread(exit_code); |
| 1426 ExitCodeToString(exit_code), base::Bind(base::DoNothing)); | |
| 1427 ScheduleHostShutdown(); | |
| 1428 break; | 1425 break; |
| 1429 | 1426 |
| 1430 case HOST_STOPPING_TO_RESTART: | 1427 case HOST_STOPPING_TO_RESTART: |
| 1431 state_ = HOST_STOPPING; | 1428 state_ = HOST_STOPPING; |
| 1432 break; | 1429 break; |
| 1433 | 1430 |
| 1434 case HOST_STOPPING: | 1431 case HOST_STOPPING: |
| 1435 case HOST_STOPPED: | 1432 case HOST_STOPPED: |
| 1436 // Host is already stopped or being stopped. No action is required. | 1433 // Host is already stopped or being stopped. No action is required. |
| 1437 break; | 1434 break; |
| 1438 } | 1435 } |
| 1439 } | 1436 } |
| 1440 | 1437 |
| 1441 // TODO(weitaosu): shut down the host once we get an ACK for the offline status | |
| 1442 // XMPP message. | |
| 1443 void HostProcess::ScheduleHostShutdown() { | |
| 1444 // Delay the shutdown by 2 second to allow SendOfflineStatus to complete. | |
| 1445 context_->network_task_runner()->PostDelayedTask( | |
| 1446 FROM_HERE, | |
| 1447 base::Bind(&HostProcess::ShutdownOnNetworkThread, base::Unretained(this)), | |
| 1448 base::TimeDelta::FromSeconds(2)); | |
| 1449 } | |
| 1450 | |
| 1451 void HostProcess::ShutdownOnNetworkThread() { | 1438 void HostProcess::ShutdownOnNetworkThread() { |
| 1452 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1439 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 1453 | 1440 |
| 1454 host_.reset(); | 1441 host_.reset(); |
| 1455 host_event_logger_.reset(); | 1442 host_event_logger_.reset(); |
| 1456 host_status_logger_.reset(); | 1443 host_status_logger_.reset(); |
| 1457 heartbeat_sender_.reset(); | 1444 host_signaling_manager_.reset(); |
| 1458 host_change_notification_listener_.reset(); | 1445 host_change_notification_listener_.reset(); |
| 1459 signaling_connector_.reset(); | |
| 1460 oauth_token_getter_.reset(); | |
| 1461 signal_strategy_.reset(); | |
| 1462 network_change_notifier_.reset(); | |
| 1463 | 1446 |
| 1464 if (state_ == HOST_STOPPING_TO_RESTART) { | 1447 if (state_ == HOST_STOPPING_TO_RESTART) { |
| 1465 StartHost(); | 1448 StartHost(); |
| 1466 } else if (state_ == HOST_STOPPING) { | 1449 } else if (state_ == HOST_STOPPING) { |
| 1467 state_ = HOST_STOPPED; | 1450 state_ = HOST_STOPPED; |
| 1468 | 1451 |
| 1469 shutdown_watchdog_->SetExitCode(*exit_code_out_); | 1452 shutdown_watchdog_->SetExitCode(*exit_code_out_); |
| 1470 shutdown_watchdog_->Arm(); | 1453 shutdown_watchdog_->Arm(); |
| 1471 | 1454 |
| 1472 if (policy_watcher_.get()) { | 1455 if (policy_watcher_.get()) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1536 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); | 1519 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); |
| 1537 new HostProcess(context.Pass(), &exit_code, &shutdown_watchdog); | 1520 new HostProcess(context.Pass(), &exit_code, &shutdown_watchdog); |
| 1538 | 1521 |
| 1539 // Run the main (also UI) message loop until the host no longer needs it. | 1522 // Run the main (also UI) message loop until the host no longer needs it. |
| 1540 message_loop.Run(); | 1523 message_loop.Run(); |
| 1541 | 1524 |
| 1542 return exit_code; | 1525 return exit_code; |
| 1543 } | 1526 } |
| 1544 | 1527 |
| 1545 } // namespace remoting | 1528 } // namespace remoting |
| OLD | NEW |