| 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/synchronization/waitable_event.h" | 22 #include "base/synchronization/waitable_event.h" |
| 23 #include "base/threading/thread.h" | 23 #include "base/threading/thread.h" |
| 24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 25 #include "crypto/nss_util.h" | 25 #include "crypto/nss_util.h" |
| 26 #include "ipc/ipc_channel.h" | 26 #include "ipc/ipc_channel.h" |
| 27 #include "ipc/ipc_channel_proxy.h" | 27 #include "ipc/ipc_channel_proxy.h" |
| 28 #include "ipc/ipc_listener.h" | 28 #include "ipc/ipc_listener.h" |
| 29 #include "media/base/media.h" | 29 #include "media/base/media.h" |
| 30 #include "net/base/network_change_notifier.h" | |
| 31 #include "net/socket/client_socket_factory.h" | 30 #include "net/socket/client_socket_factory.h" |
| 32 #include "net/socket/ssl_server_socket.h" | 31 #include "net/socket/ssl_server_socket.h" |
| 33 #include "net/url_request/url_fetcher.h" | 32 #include "net/url_request/url_fetcher.h" |
| 34 #include "remoting/base/auto_thread_task_runner.h" | 33 #include "remoting/base/auto_thread_task_runner.h" |
| 35 #include "remoting/base/breakpad.h" | 34 #include "remoting/base/breakpad.h" |
| 36 #include "remoting/base/constants.h" | 35 #include "remoting/base/constants.h" |
| 37 #include "remoting/base/logging.h" | 36 #include "remoting/base/logging.h" |
| 38 #include "remoting/base/rsa_key_pair.h" | 37 #include "remoting/base/rsa_key_pair.h" |
| 39 #include "remoting/base/service_urls.h" | 38 #include "remoting/base/service_urls.h" |
| 40 #include "remoting/base/util.h" | 39 #include "remoting/base/util.h" |
| 41 #include "remoting/host/branding.h" | 40 #include "remoting/host/branding.h" |
| 42 #include "remoting/host/chromoting_host.h" | 41 #include "remoting/host/chromoting_host.h" |
| 43 #include "remoting/host/chromoting_host_context.h" | 42 #include "remoting/host/chromoting_host_context.h" |
| 44 #include "remoting/host/chromoting_messages.h" | 43 #include "remoting/host/chromoting_messages.h" |
| 45 #include "remoting/host/config_file_watcher.h" | 44 #include "remoting/host/config_file_watcher.h" |
| 46 #include "remoting/host/config_watcher.h" | 45 #include "remoting/host/config_watcher.h" |
| 47 #include "remoting/host/desktop_environment.h" | 46 #include "remoting/host/desktop_environment.h" |
| 48 #include "remoting/host/desktop_session_connector.h" | 47 #include "remoting/host/desktop_session_connector.h" |
| 49 #include "remoting/host/dns_blackhole_checker.h" | |
| 50 #include "remoting/host/heartbeat_sender.h" | |
| 51 #include "remoting/host/host_change_notification_listener.h" | 48 #include "remoting/host/host_change_notification_listener.h" |
| 52 #include "remoting/host/host_config.h" | 49 #include "remoting/host/host_config.h" |
| 53 #include "remoting/host/host_event_logger.h" | 50 #include "remoting/host/host_event_logger.h" |
| 54 #include "remoting/host/host_exit_codes.h" | 51 #include "remoting/host/host_exit_codes.h" |
| 55 #include "remoting/host/host_main.h" | 52 #include "remoting/host/host_main.h" |
| 56 #include "remoting/host/host_status_logger.h" | 53 #include "remoting/host/host_status_logger.h" |
| 57 #include "remoting/host/ipc_constants.h" | 54 #include "remoting/host/ipc_constants.h" |
| 58 #include "remoting/host/ipc_desktop_environment.h" | 55 #include "remoting/host/ipc_desktop_environment.h" |
| 59 #include "remoting/host/ipc_host_event_logger.h" | 56 #include "remoting/host/ipc_host_event_logger.h" |
| 60 #include "remoting/host/json_host_config.h" | 57 #include "remoting/host/json_host_config.h" |
| 61 #include "remoting/host/logging.h" | 58 #include "remoting/host/logging.h" |
| 62 #include "remoting/host/me2me_desktop_environment.h" | 59 #include "remoting/host/me2me_desktop_environment.h" |
| 60 #include "remoting/host/minimum_heartbeat_supporter.h" |
| 63 #include "remoting/host/pairing_registry_delegate.h" | 61 #include "remoting/host/pairing_registry_delegate.h" |
| 64 #include "remoting/host/policy_hack/policy_watcher.h" | 62 #include "remoting/host/policy_hack/policy_watcher.h" |
| 65 #include "remoting/host/session_manager_factory.h" | 63 #include "remoting/host/session_manager_factory.h" |
| 66 #include "remoting/host/signaling_connector.h" | |
| 67 #include "remoting/host/single_window_desktop_environment.h" | 64 #include "remoting/host/single_window_desktop_environment.h" |
| 68 #include "remoting/host/token_validator_factory_impl.h" | 65 #include "remoting/host/token_validator_factory_impl.h" |
| 69 #include "remoting/host/usage_stats_consent.h" | 66 #include "remoting/host/usage_stats_consent.h" |
| 70 #include "remoting/host/username.h" | 67 #include "remoting/host/username.h" |
| 71 #include "remoting/host/video_frame_recorder_host_extension.h" | 68 #include "remoting/host/video_frame_recorder_host_extension.h" |
| 72 #include "remoting/protocol/me2me_host_authenticator_factory.h" | 69 #include "remoting/protocol/me2me_host_authenticator_factory.h" |
| 73 #include "remoting/protocol/network_settings.h" | 70 #include "remoting/protocol/network_settings.h" |
| 74 #include "remoting/protocol/pairing_registry.h" | 71 #include "remoting/protocol/pairing_registry.h" |
| 75 #include "remoting/protocol/token_validator.h" | 72 #include "remoting/protocol/token_validator.h" |
| 76 #include "remoting/signaling/xmpp_signal_strategy.h" | 73 #include "remoting/signaling/xmpp_signal_strategy.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 const char kStdinConfigPath[] = "-"; | 132 const char kStdinConfigPath[] = "-"; |
| 136 | 133 |
| 137 const char kWindowIdSwitchName[] = "window-id"; | 134 const char kWindowIdSwitchName[] = "window-id"; |
| 138 | 135 |
| 139 } // namespace | 136 } // namespace |
| 140 | 137 |
| 141 namespace remoting { | 138 namespace remoting { |
| 142 | 139 |
| 143 class HostProcess | 140 class HostProcess |
| 144 : public ConfigWatcher::Delegate, | 141 : public ConfigWatcher::Delegate, |
| 145 public HeartbeatSender::Listener, | 142 public MinimumHeartbeatSupporter::Listener, |
| 146 public HostChangeNotificationListener::Listener, | 143 public HostChangeNotificationListener::Listener, |
| 147 public IPC::Listener, | 144 public IPC::Listener, |
| 148 public base::RefCountedThreadSafe<HostProcess> { | 145 public base::RefCountedThreadSafe<HostProcess> { |
| 149 public: | 146 public: |
| 150 HostProcess(scoped_ptr<ChromotingHostContext> context, | 147 HostProcess(scoped_ptr<ChromotingHostContext> context, |
| 151 int* exit_code_out); | 148 int* exit_code_out); |
| 152 | 149 |
| 153 // ConfigWatcher::Delegate interface. | 150 // ConfigWatcher::Delegate interface. |
| 154 virtual void OnConfigUpdated(const std::string& serialized_config) override; | 151 virtual void OnConfigUpdated(const std::string& serialized_config) override; |
| 155 virtual void OnConfigWatcherError() override; | 152 virtual void OnConfigWatcherError() override; |
| 156 | 153 |
| 157 // IPC::Listener implementation. | 154 // IPC::Listener implementation. |
| 158 virtual bool OnMessageReceived(const IPC::Message& message) override; | 155 virtual bool OnMessageReceived(const IPC::Message& message) override; |
| 159 virtual void OnChannelError() override; | 156 virtual void OnChannelError() override; |
| 160 | 157 |
| 161 // HeartbeatSender::Listener overrides. | 158 // MinimumHeartbeatSupporter::Listener overrides. |
| 162 virtual void OnHeartbeatSuccessful() override; | 159 virtual void OnHeartbeatSuccessful() override; |
| 163 virtual void OnUnknownHostIdError() override; | 160 virtual void OnUnknownHostIdError() override; |
| 161 virtual void OnAuthFailed() override; |
| 164 | 162 |
| 165 // HostChangeNotificationListener::Listener overrides. | 163 // HostChangeNotificationListener::Listener overrides. |
| 166 virtual void OnHostDeleted() override; | 164 virtual void OnHostDeleted() override; |
| 167 | 165 |
| 168 // Initializes the pairing registry on Windows. | 166 // Initializes the pairing registry on Windows. |
| 169 void OnInitializePairingRegistry( | 167 void OnInitializePairingRegistry( |
| 170 IPC::PlatformFileForTransit privileged_key, | 168 IPC::PlatformFileForTransit privileged_key, |
| 171 IPC::PlatformFileForTransit unprivileged_key); | 169 IPC::PlatformFileForTransit unprivileged_key); |
| 172 | 170 |
| 173 private: | 171 private: |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 bool OnUsernamePolicyUpdate(base::DictionaryValue* policies); | 238 bool OnUsernamePolicyUpdate(base::DictionaryValue* policies); |
| 241 bool OnNatPolicyUpdate(base::DictionaryValue* policies); | 239 bool OnNatPolicyUpdate(base::DictionaryValue* policies); |
| 242 bool OnRelayPolicyUpdate(base::DictionaryValue* policies); | 240 bool OnRelayPolicyUpdate(base::DictionaryValue* policies); |
| 243 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies); | 241 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies); |
| 244 bool OnCurtainPolicyUpdate(base::DictionaryValue* policies); | 242 bool OnCurtainPolicyUpdate(base::DictionaryValue* policies); |
| 245 bool OnHostTalkGadgetPrefixPolicyUpdate(base::DictionaryValue* policies); | 243 bool OnHostTalkGadgetPrefixPolicyUpdate(base::DictionaryValue* policies); |
| 246 bool OnHostTokenUrlPolicyUpdate(base::DictionaryValue* policies); | 244 bool OnHostTokenUrlPolicyUpdate(base::DictionaryValue* policies); |
| 247 bool OnPairingPolicyUpdate(base::DictionaryValue* policies); | 245 bool OnPairingPolicyUpdate(base::DictionaryValue* policies); |
| 248 bool OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies); | 246 bool OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies); |
| 249 | 247 |
| 248 scoped_refptr<MinimumHeartbeatSupporter> CreateMinimumHeartbeatSupporter(); |
| 249 |
| 250 void StartHost(); | 250 void StartHost(); |
| 251 | 251 |
| 252 void OnAuthFailed(); | |
| 253 | |
| 254 void RestartHost(); | 252 void RestartHost(); |
| 255 | 253 |
| 256 // Stops the host and shuts down the process with the specified |exit_code|. | 254 // Stops the host and shuts down the process with the specified |exit_code|. |
| 257 void ShutdownHost(HostExitCodes exit_code); | 255 void ShutdownHost(HostExitCodes exit_code); |
| 258 | 256 |
| 259 void ScheduleHostShutdown(); | |
| 260 | |
| 261 void ShutdownOnNetworkThread(); | 257 void ShutdownOnNetworkThread(); |
| 262 | 258 |
| 263 // Crashes the process in response to a daemon's request. The daemon passes | 259 // Crashes the process in response to a daemon's request. The daemon passes |
| 264 // the location of the code that detected the fatal error resulted in this | 260 // the location of the code that detected the fatal error resulted in this |
| 265 // request. | 261 // request. |
| 266 void OnCrash(const std::string& function_name, | 262 void OnCrash(const std::string& function_name, |
| 267 const std::string& file_name, | 263 const std::string& file_name, |
| 268 const int& line_number); | 264 const int& line_number); |
| 269 | 265 |
| 270 scoped_ptr<ChromotingHostContext> context_; | 266 scoped_ptr<ChromotingHostContext> context_; |
| 271 | 267 |
| 272 // Created on the UI thread but used from the network thread. | |
| 273 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | |
| 274 | |
| 275 // Accessed on the UI thread. | 268 // Accessed on the UI thread. |
| 276 scoped_ptr<IPC::ChannelProxy> daemon_channel_; | 269 scoped_ptr<IPC::ChannelProxy> daemon_channel_; |
| 277 | 270 |
| 278 // XMPP server/remoting bot configuration (initialized from the command line). | 271 // XMPP server/remoting bot configuration (initialized from the command line). |
| 279 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; | 272 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; |
| 280 std::string directory_bot_jid_; | 273 std::string directory_bot_jid_; |
| 281 | 274 |
| 282 // Created on the UI thread but used from the network thread. | 275 // Created on the UI thread but used from the network thread. |
| 283 base::FilePath host_config_path_; | 276 base::FilePath host_config_path_; |
| 284 std::string host_config_; | 277 std::string host_config_; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 314 ThirdPartyAuthConfig third_party_auth_config_; | 307 ThirdPartyAuthConfig third_party_auth_config_; |
| 315 bool enable_gnubby_auth_; | 308 bool enable_gnubby_auth_; |
| 316 | 309 |
| 317 // Boolean to change flow, where ncessary, if we're | 310 // Boolean to change flow, where ncessary, if we're |
| 318 // capturing a window instead of the entire desktop. | 311 // capturing a window instead of the entire desktop. |
| 319 bool enable_window_capture_; | 312 bool enable_window_capture_; |
| 320 | 313 |
| 321 // Used to specify which window to stream, if enabled. | 314 // Used to specify which window to stream, if enabled. |
| 322 webrtc::WindowId window_id_; | 315 webrtc::WindowId window_id_; |
| 323 | 316 |
| 324 scoped_ptr<OAuthTokenGetter> oauth_token_getter_; | 317 scoped_refptr<MinimumHeartbeatSupporter> minimum_heartbeat_supporter_; |
| 325 scoped_ptr<XmppSignalStrategy> signal_strategy_; | |
| 326 scoped_ptr<SignalingConnector> signaling_connector_; | |
| 327 scoped_ptr<HeartbeatSender> heartbeat_sender_; | |
| 328 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; | 318 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; |
| 329 scoped_ptr<HostStatusLogger> host_status_logger_; | 319 scoped_ptr<HostStatusLogger> host_status_logger_; |
| 330 scoped_ptr<HostEventLogger> host_event_logger_; | 320 scoped_ptr<HostEventLogger> host_event_logger_; |
| 331 | 321 |
| 332 scoped_ptr<ChromotingHost> host_; | 322 scoped_ptr<ChromotingHost> host_; |
| 333 | 323 |
| 334 // Used to keep this HostProcess alive until it is shutdown. | 324 // Used to keep this HostProcess alive until it is shutdown. |
| 335 scoped_refptr<HostProcess> self_; | 325 scoped_refptr<HostProcess> self_; |
| 336 | 326 |
| 337 #if defined(REMOTING_MULTI_PROCESS) | 327 #if defined(REMOTING_MULTI_PROCESS) |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 | 734 |
| 745 context_->network_task_runner()->PostTask( | 735 context_->network_task_runner()->PostTask( |
| 746 FROM_HERE, | 736 FROM_HERE, |
| 747 base::Bind(&HostProcess::StartOnNetworkThread, this)); | 737 base::Bind(&HostProcess::StartOnNetworkThread, this)); |
| 748 } | 738 } |
| 749 | 739 |
| 750 void HostProcess::ShutdownOnUiThread() { | 740 void HostProcess::ShutdownOnUiThread() { |
| 751 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 741 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 752 | 742 |
| 753 // Tear down resources that need to be torn down on the UI thread. | 743 // Tear down resources that need to be torn down on the UI thread. |
| 754 network_change_notifier_.reset(); | |
| 755 daemon_channel_.reset(); | 744 daemon_channel_.reset(); |
| 756 desktop_environment_factory_.reset(); | 745 desktop_environment_factory_.reset(); |
| 757 | 746 |
| 758 // It is now safe for the HostProcess to be deleted. | 747 // It is now safe for the HostProcess to be deleted. |
| 759 self_ = NULL; | 748 self_ = NULL; |
| 760 | 749 |
| 761 #if defined(OS_LINUX) | 750 #if defined(OS_LINUX) |
| 762 // Cause the global AudioPipeReader to be freed, otherwise the audio | 751 // Cause the global AudioPipeReader to be freed, otherwise the audio |
| 763 // thread will remain in-use and prevent the process from exiting. | 752 // thread will remain in-use and prevent the process from exiting. |
| 764 // TODO(wez): DesktopEnvironmentFactory should own the pipe reader. | 753 // TODO(wez): DesktopEnvironmentFactory should own the pipe reader. |
| 765 // See crbug.com/161373 and crbug.com/104544. | 754 // See crbug.com/161373 and crbug.com/104544. |
| 766 AudioCapturerLinux::InitializePipeReader(NULL, base::FilePath()); | 755 AudioCapturerLinux::InitializePipeReader(NULL, base::FilePath()); |
| 767 #endif | 756 #endif |
| 768 } | 757 } |
| 769 | 758 |
| 770 // Overridden from HeartbeatSender::Listener | 759 // Overridden from MinimumHeartbeatSupporter::Listener |
| 771 void HostProcess::OnUnknownHostIdError() { | 760 void HostProcess::OnUnknownHostIdError() { |
| 772 LOG(ERROR) << "Host ID not found."; | 761 LOG(ERROR) << "Host ID not found."; |
| 773 ShutdownHost(kInvalidHostIdExitCode); | 762 ShutdownHost(kInvalidHostIdExitCode); |
| 774 } | 763 } |
| 775 | 764 |
| 765 // Overridden from MinimumHeartbeatSupporter::Listener |
| 776 void HostProcess::OnHeartbeatSuccessful() { | 766 void HostProcess::OnHeartbeatSuccessful() { |
| 777 HOST_LOG << "Host ready to receive connections."; | 767 HOST_LOG << "Host ready to receive connections."; |
| 778 #if defined(OS_POSIX) | 768 #if defined(OS_POSIX) |
| 779 if (signal_parent_) { | 769 if (signal_parent_) { |
| 780 kill(getppid(), SIGUSR1); | 770 kill(getppid(), SIGUSR1); |
| 781 signal_parent_ = false; | 771 signal_parent_ = false; |
| 782 } | 772 } |
| 783 #endif | 773 #endif |
| 784 } | 774 } |
| 785 | 775 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 if (!config->GetString(kXmppLoginConfigPath, &xmpp_server_config_.username) || | 837 if (!config->GetString(kXmppLoginConfigPath, &xmpp_server_config_.username) || |
| 848 !(config->GetString(kXmppAuthTokenConfigPath, | 838 !(config->GetString(kXmppAuthTokenConfigPath, |
| 849 &xmpp_server_config_.auth_token) || | 839 &xmpp_server_config_.auth_token) || |
| 850 config->GetString(kOAuthRefreshTokenConfigPath, | 840 config->GetString(kOAuthRefreshTokenConfigPath, |
| 851 &oauth_refresh_token_))) { | 841 &oauth_refresh_token_))) { |
| 852 LOG(ERROR) << "XMPP credentials are not defined in the config."; | 842 LOG(ERROR) << "XMPP credentials are not defined in the config."; |
| 853 return false; | 843 return false; |
| 854 } | 844 } |
| 855 | 845 |
| 856 if (!oauth_refresh_token_.empty()) { | 846 if (!oauth_refresh_token_.empty()) { |
| 857 // SignalingConnector is responsible for getting OAuth token. | 847 // SignalingConnector (inside MinimumHeartbeatSupporter) is responsible for |
| 848 // getting OAuth token. |
| 858 xmpp_server_config_.auth_token = ""; | 849 xmpp_server_config_.auth_token = ""; |
| 859 xmpp_server_config_.auth_service = "oauth2"; | 850 xmpp_server_config_.auth_service = "oauth2"; |
| 860 } else if (!config->GetString(kXmppAuthServiceConfigPath, | 851 } else if (!config->GetString(kXmppAuthServiceConfigPath, |
| 861 &xmpp_server_config_.auth_service)) { | 852 &xmpp_server_config_.auth_service)) { |
| 862 // For the me2me host, we default to ClientLogin token for chromiumsync | 853 // For the me2me host, we default to ClientLogin token for chromiumsync |
| 863 // because earlier versions of the host had no HTTP stack with which to | 854 // because earlier versions of the host had no HTTP stack with which to |
| 864 // request an OAuth2 access token. | 855 // request an OAuth2 access token. |
| 865 xmpp_server_config_.auth_service = kChromotingTokenDefaultServiceName; | 856 xmpp_server_config_.auth_service = kChromotingTokenDefaultServiceName; |
| 866 } | 857 } |
| 867 | 858 |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1227 } else { | 1218 } else { |
| 1228 HOST_LOG << "Policy disables gnubby auth."; | 1219 HOST_LOG << "Policy disables gnubby auth."; |
| 1229 } | 1220 } |
| 1230 | 1221 |
| 1231 if (desktop_environment_factory_) | 1222 if (desktop_environment_factory_) |
| 1232 desktop_environment_factory_->SetEnableGnubbyAuth(enable_gnubby_auth_); | 1223 desktop_environment_factory_->SetEnableGnubbyAuth(enable_gnubby_auth_); |
| 1233 | 1224 |
| 1234 return true; | 1225 return true; |
| 1235 } | 1226 } |
| 1236 | 1227 |
| 1228 scoped_refptr<MinimumHeartbeatSupporter> |
| 1229 HostProcess::CreateMinimumHeartbeatSupporter() { |
| 1230 DCHECK(!host_id_.empty()); // assumming |ApplyConfig| has already been run |
| 1231 return new MinimumHeartbeatSupporter( |
| 1232 context_.get(), |
| 1233 xmpp_server_config_, |
| 1234 talkgadget_prefix_, |
| 1235 host_id_, |
| 1236 key_pair_, |
| 1237 directory_bot_jid_, |
| 1238 oauth_refresh_token_, |
| 1239 use_service_account_); |
| 1240 } |
| 1241 |
| 1237 void HostProcess::StartHost() { | 1242 void HostProcess::StartHost() { |
| 1238 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1243 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 1239 DCHECK(!host_); | 1244 DCHECK(!host_); |
| 1240 DCHECK(!signal_strategy_.get()); | 1245 DCHECK(!minimum_heartbeat_supporter_.get()); |
| 1246 |
| 1241 DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART || | 1247 DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART || |
| 1242 state_ == HOST_STOPPED) << state_; | 1248 state_ == HOST_STOPPED) << state_; |
| 1243 state_ = HOST_STARTED; | 1249 state_ = HOST_STARTED; |
| 1244 | 1250 |
| 1245 signal_strategy_.reset( | 1251 minimum_heartbeat_supporter_ = CreateMinimumHeartbeatSupporter(); |
| 1246 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), | 1252 minimum_heartbeat_supporter_->SetListener(this); |
| 1247 context_->url_request_context_getter(), | |
| 1248 xmpp_server_config_)); | |
| 1249 | |
| 1250 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker( | |
| 1251 new DnsBlackholeChecker(context_->url_request_context_getter(), | |
| 1252 talkgadget_prefix_)); | |
| 1253 | |
| 1254 // Create a NetworkChangeNotifier for use by the signaling connector. | |
| 1255 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | |
| 1256 | |
| 1257 signaling_connector_.reset(new SignalingConnector( | |
| 1258 signal_strategy_.get(), | |
| 1259 dns_blackhole_checker.Pass(), | |
| 1260 base::Bind(&HostProcess::OnAuthFailed, this))); | |
| 1261 | |
| 1262 if (!oauth_refresh_token_.empty()) { | |
| 1263 scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials; | |
| 1264 oauth_credentials.reset( | |
| 1265 new OAuthTokenGetter::OAuthCredentials( | |
| 1266 xmpp_server_config_.username, oauth_refresh_token_, | |
| 1267 use_service_account_)); | |
| 1268 | |
| 1269 oauth_token_getter_.reset(new OAuthTokenGetter( | |
| 1270 oauth_credentials.Pass(), context_->url_request_context_getter(), | |
| 1271 false)); | |
| 1272 | |
| 1273 signaling_connector_->EnableOAuth(oauth_token_getter_.get()); | |
| 1274 } | |
| 1275 | 1253 |
| 1276 uint32 network_flags = 0; | 1254 uint32 network_flags = 0; |
| 1277 if (allow_nat_traversal_) { | 1255 if (allow_nat_traversal_) { |
| 1278 network_flags = NetworkSettings::NAT_TRAVERSAL_STUN | | 1256 network_flags = NetworkSettings::NAT_TRAVERSAL_STUN | |
| 1279 NetworkSettings::NAT_TRAVERSAL_OUTGOING; | 1257 NetworkSettings::NAT_TRAVERSAL_OUTGOING; |
| 1280 if (allow_relay_) | 1258 if (allow_relay_) |
| 1281 network_flags |= NetworkSettings::NAT_TRAVERSAL_RELAY; | 1259 network_flags |= NetworkSettings::NAT_TRAVERSAL_RELAY; |
| 1282 } | 1260 } |
| 1283 | 1261 |
| 1284 NetworkSettings network_settings(network_flags); | 1262 NetworkSettings network_settings(network_flags); |
| 1285 | 1263 |
| 1286 if (min_udp_port_ && max_udp_port_) { | 1264 if (min_udp_port_ && max_udp_port_) { |
| 1287 network_settings.min_port = min_udp_port_; | 1265 network_settings.min_port = min_udp_port_; |
| 1288 network_settings.max_port = max_udp_port_; | 1266 network_settings.max_port = max_udp_port_; |
| 1289 } else if (!allow_nat_traversal_) { | 1267 } else if (!allow_nat_traversal_) { |
| 1290 // For legacy reasons we have to restrict the port range to a set of default | 1268 // For legacy reasons we have to restrict the port range to a set of default |
| 1291 // values when nat traversal is disabled, even if the port range was not | 1269 // values when nat traversal is disabled, even if the port range was not |
| 1292 // set in policy. | 1270 // set in policy. |
| 1293 network_settings.min_port = NetworkSettings::kDefaultMinPort; | 1271 network_settings.min_port = NetworkSettings::kDefaultMinPort; |
| 1294 network_settings.max_port = NetworkSettings::kDefaultMaxPort; | 1272 network_settings.max_port = NetworkSettings::kDefaultMaxPort; |
| 1295 } | 1273 } |
| 1296 | 1274 |
| 1297 host_.reset(new ChromotingHost( | 1275 host_.reset(new ChromotingHost( |
| 1298 signal_strategy_.get(), | 1276 minimum_heartbeat_supporter_->GetSignalStrategy(), |
| 1299 desktop_environment_factory_.get(), | 1277 desktop_environment_factory_.get(), |
| 1300 CreateHostSessionManager(signal_strategy_.get(), network_settings, | 1278 CreateHostSessionManager( |
| 1301 context_->url_request_context_getter()), | 1279 minimum_heartbeat_supporter_->GetSignalStrategy(), |
| 1280 network_settings, |
| 1281 context_->url_request_context_getter()), |
| 1302 context_->audio_task_runner(), | 1282 context_->audio_task_runner(), |
| 1303 context_->input_task_runner(), | 1283 context_->input_task_runner(), |
| 1304 context_->video_capture_task_runner(), | 1284 context_->video_capture_task_runner(), |
| 1305 context_->video_encode_task_runner(), | 1285 context_->video_encode_task_runner(), |
| 1306 context_->network_task_runner(), | 1286 context_->network_task_runner(), |
| 1307 context_->ui_task_runner())); | 1287 context_->ui_task_runner())); |
| 1308 | 1288 |
| 1309 if (enable_vp9_) { | 1289 if (enable_vp9_) { |
| 1310 scoped_ptr<protocol::CandidateSessionConfig> config = | 1290 scoped_ptr<protocol::CandidateSessionConfig> config = |
| 1311 host_->protocol_config()->Clone(); | 1291 host_->protocol_config()->Clone(); |
| 1312 config->EnableVideoCodec(protocol::ChannelConfig::CODEC_VP9); | 1292 config->EnableVideoCodec(protocol::ChannelConfig::CODEC_VP9); |
| 1313 host_->set_protocol_config(config.Pass()); | 1293 host_->set_protocol_config(config.Pass()); |
| 1314 } | 1294 } |
| 1315 | 1295 |
| 1316 if (frame_recorder_buffer_size_ > 0) { | 1296 if (frame_recorder_buffer_size_ > 0) { |
| 1317 scoped_ptr<VideoFrameRecorderHostExtension> frame_recorder_extension( | 1297 scoped_ptr<VideoFrameRecorderHostExtension> frame_recorder_extension( |
| 1318 new VideoFrameRecorderHostExtension()); | 1298 new VideoFrameRecorderHostExtension()); |
| 1319 frame_recorder_extension->SetMaxContentBytes(frame_recorder_buffer_size_); | 1299 frame_recorder_extension->SetMaxContentBytes(frame_recorder_buffer_size_); |
| 1320 host_->AddExtension(frame_recorder_extension.Pass()); | 1300 host_->AddExtension(frame_recorder_extension.Pass()); |
| 1321 } | 1301 } |
| 1322 | 1302 |
| 1323 // TODO(simonmorris): Get the maximum session duration from a policy. | 1303 // TODO(simonmorris): Get the maximum session duration from a policy. |
| 1324 #if defined(OS_LINUX) | 1304 #if defined(OS_LINUX) |
| 1325 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); | 1305 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); |
| 1326 #endif | 1306 #endif |
| 1327 | 1307 |
| 1328 heartbeat_sender_.reset(new HeartbeatSender( | 1308 host_change_notification_listener_.reset( |
| 1329 this, host_id_, signal_strategy_.get(), key_pair_, | 1309 new HostChangeNotificationListener( |
| 1330 directory_bot_jid_)); | 1310 this, |
| 1331 | 1311 host_id_, |
| 1332 host_change_notification_listener_.reset(new HostChangeNotificationListener( | 1312 minimum_heartbeat_supporter_->GetSignalStrategy(), |
| 1333 this, host_id_, signal_strategy_.get(), directory_bot_jid_)); | 1313 directory_bot_jid_)); |
| 1334 | 1314 |
| 1335 host_status_logger_.reset( | 1315 host_status_logger_.reset( |
| 1336 new HostStatusLogger(host_->AsWeakPtr(), ServerLogEntry::ME2ME, | 1316 new HostStatusLogger( |
| 1337 signal_strategy_.get(), directory_bot_jid_)); | 1317 host_->AsWeakPtr(), |
| 1318 ServerLogEntry::ME2ME, |
| 1319 minimum_heartbeat_supporter_->GetSignalStrategy(), |
| 1320 directory_bot_jid_)); |
| 1338 | 1321 |
| 1339 // Set up reporting the host status notifications. | 1322 // Set up reporting the host status notifications. |
| 1340 #if defined(REMOTING_MULTI_PROCESS) | 1323 #if defined(REMOTING_MULTI_PROCESS) |
| 1341 host_event_logger_.reset( | 1324 host_event_logger_.reset( |
| 1342 new IpcHostEventLogger(host_->AsWeakPtr(), daemon_channel_.get())); | 1325 new IpcHostEventLogger(host_->AsWeakPtr(), daemon_channel_.get())); |
| 1343 #else // !defined(REMOTING_MULTI_PROCESS) | 1326 #else // !defined(REMOTING_MULTI_PROCESS) |
| 1344 host_event_logger_ = | 1327 host_event_logger_ = |
| 1345 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); | 1328 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); |
| 1346 #endif // !defined(REMOTING_MULTI_PROCESS) | 1329 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 1347 | 1330 |
| 1348 host_->SetEnableCurtaining(curtain_required_); | 1331 host_->SetEnableCurtaining(curtain_required_); |
| 1349 host_->Start(host_owner_email_); | 1332 host_->Start(host_owner_email_); |
| 1350 | 1333 |
| 1351 CreateAuthenticatorFactory(); | 1334 CreateAuthenticatorFactory(); |
| 1352 } | 1335 } |
| 1353 | 1336 |
| 1337 // Overridden from MinimumHeartbeatSupporter::Listener |
| 1354 void HostProcess::OnAuthFailed() { | 1338 void HostProcess::OnAuthFailed() { |
| 1355 ShutdownHost(kInvalidOauthCredentialsExitCode); | 1339 ShutdownHost(kInvalidOauthCredentialsExitCode); |
| 1356 } | 1340 } |
| 1357 | 1341 |
| 1358 void HostProcess::RestartHost() { | 1342 void HostProcess::RestartHost() { |
| 1359 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1343 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 1360 DCHECK_EQ(state_, HOST_STARTED); | 1344 DCHECK_EQ(state_, HOST_STARTED); |
| 1361 | 1345 |
| 1362 state_ = HOST_STOPPING_TO_RESTART; | 1346 state_ = HOST_STOPPING_TO_RESTART; |
| 1363 ShutdownOnNetworkThread(); | 1347 ShutdownOnNetworkThread(); |
| 1364 } | 1348 } |
| 1365 | 1349 |
| 1366 void HostProcess::ShutdownHost(HostExitCodes exit_code) { | 1350 void HostProcess::ShutdownHost(HostExitCodes exit_code) { |
| 1367 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1351 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 1368 | 1352 |
| 1369 *exit_code_out_ = exit_code; | 1353 *exit_code_out_ = exit_code; |
| 1370 | 1354 |
| 1371 switch (state_) { | 1355 switch (state_) { |
| 1372 case HOST_INITIALIZING: | 1356 case HOST_INITIALIZING: |
| 1373 state_ = HOST_STOPPING; | 1357 state_ = HOST_STOPPING; |
| 1358 { |
| 1359 DCHECK(!minimum_heartbeat_supporter_.get()); |
| 1360 scoped_refptr<MinimumHeartbeatSupporter> tmpHeartbeatSupporter = |
| 1361 CreateMinimumHeartbeatSupporter(); |
| 1362 tmpHeartbeatSupporter->SendHostOfflineReason( |
| 1363 ExitCodeToString(exit_code), |
| 1364 base::TimeDelta::FromSeconds(30) /* timeout */); |
| 1365 } |
| 1374 ShutdownOnNetworkThread(); | 1366 ShutdownOnNetworkThread(); |
| 1375 break; | 1367 break; |
| 1376 | 1368 |
| 1377 case HOST_STARTED: | 1369 case HOST_STARTED: |
| 1378 state_ = HOST_STOPPING; | 1370 state_ = HOST_STOPPING; |
| 1379 heartbeat_sender_->SetHostOfflineReason( | 1371 minimum_heartbeat_supporter_->SendHostOfflineReason( |
| 1380 ExitCodeToString(exit_code), base::Bind(base::DoNothing)); | 1372 ExitCodeToString(exit_code), |
| 1381 ScheduleHostShutdown(); | 1373 base::TimeDelta::FromSeconds(30) /* timeout */); |
| 1374 ShutdownOnNetworkThread(); |
| 1382 break; | 1375 break; |
| 1383 | 1376 |
| 1384 case HOST_STOPPING_TO_RESTART: | 1377 case HOST_STOPPING_TO_RESTART: |
| 1385 state_ = HOST_STOPPING; | 1378 state_ = HOST_STOPPING; |
| 1386 break; | 1379 break; |
| 1387 | 1380 |
| 1388 case HOST_STOPPING: | 1381 case HOST_STOPPING: |
| 1389 case HOST_STOPPED: | 1382 case HOST_STOPPED: |
| 1390 // Host is already stopped or being stopped. No action is required. | 1383 // Host is already stopped or being stopped. No action is required. |
| 1391 break; | 1384 break; |
| 1392 } | 1385 } |
| 1393 } | 1386 } |
| 1394 | 1387 |
| 1395 // TODO(weitaosu): shut down the host once we get an ACK for the offline status | |
| 1396 // XMPP message. | |
| 1397 void HostProcess::ScheduleHostShutdown() { | |
| 1398 // Delay the shutdown by 2 second to allow SendOfflineStatus to complete. | |
| 1399 context_->network_task_runner()->PostDelayedTask( | |
| 1400 FROM_HERE, | |
| 1401 base::Bind(&HostProcess::ShutdownOnNetworkThread, base::Unretained(this)), | |
| 1402 base::TimeDelta::FromSeconds(2)); | |
| 1403 } | |
| 1404 | |
| 1405 void HostProcess::ShutdownOnNetworkThread() { | 1388 void HostProcess::ShutdownOnNetworkThread() { |
| 1406 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1389 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 1407 | 1390 |
| 1408 host_.reset(); | 1391 host_.reset(); |
| 1409 host_event_logger_.reset(); | 1392 host_event_logger_.reset(); |
| 1410 host_status_logger_.reset(); | 1393 host_status_logger_.reset(); |
| 1411 heartbeat_sender_.reset(); | 1394 if (minimum_heartbeat_supporter_.get()) { |
| 1395 minimum_heartbeat_supporter_->SetListener(nullptr); |
| 1396 minimum_heartbeat_supporter_ = nullptr; |
| 1397 } |
| 1412 host_change_notification_listener_.reset(); | 1398 host_change_notification_listener_.reset(); |
| 1413 signaling_connector_.reset(); | |
| 1414 oauth_token_getter_.reset(); | |
| 1415 signal_strategy_.reset(); | |
| 1416 network_change_notifier_.reset(); | |
| 1417 | 1399 |
| 1418 if (state_ == HOST_STOPPING_TO_RESTART) { | 1400 if (state_ == HOST_STOPPING_TO_RESTART) { |
| 1419 StartHost(); | 1401 StartHost(); |
| 1420 } else if (state_ == HOST_STOPPING) { | 1402 } else if (state_ == HOST_STOPPING) { |
| 1421 state_ = HOST_STOPPED; | 1403 state_ = HOST_STOPPED; |
| 1422 | 1404 |
| 1423 if (policy_watcher_.get()) { | 1405 if (policy_watcher_.get()) { |
| 1424 base::WaitableEvent done_event(true, false); | 1406 base::WaitableEvent done_event(true, false); |
| 1425 policy_watcher_->StopWatching(&done_event); | 1407 policy_watcher_->StopWatching(&done_event); |
| 1426 done_event.Wait(); | 1408 done_event.Wait(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1484 int exit_code = kSuccessExitCode; | 1466 int exit_code = kSuccessExitCode; |
| 1485 new HostProcess(context.Pass(), &exit_code); | 1467 new HostProcess(context.Pass(), &exit_code); |
| 1486 | 1468 |
| 1487 // Run the main (also UI) message loop until the host no longer needs it. | 1469 // Run the main (also UI) message loop until the host no longer needs it. |
| 1488 message_loop.Run(); | 1470 message_loop.Run(); |
| 1489 | 1471 |
| 1490 return exit_code; | 1472 return exit_code; |
| 1491 } | 1473 } |
| 1492 | 1474 |
| 1493 } // namespace remoting | 1475 } // namespace remoting |
| OLD | NEW |