Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // This file implements a standalone host process for Me2Me. | 5 // This file implements a standalone host process for Me2Me. |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 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/memory/weak_ptr.h" | |
| 17 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
| 18 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| 19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/threading/thread.h" | 23 #include "base/threading/thread.h" |
| 23 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 24 #include "crypto/nss_util.h" | 25 #include "crypto/nss_util.h" |
| 25 #include "ipc/ipc_channel.h" | 26 #include "ipc/ipc_channel.h" |
| 26 #include "ipc/ipc_channel_proxy.h" | 27 #include "ipc/ipc_channel_proxy.h" |
| 27 #include "ipc/ipc_listener.h" | 28 #include "ipc/ipc_listener.h" |
| 28 #include "media/base/media.h" | 29 #include "media/base/media.h" |
| 29 #include "net/base/network_change_notifier.h" | |
| 30 #include "net/socket/client_socket_factory.h" | 30 #include "net/socket/client_socket_factory.h" |
| 31 #include "net/socket/ssl_server_socket.h" | 31 #include "net/socket/ssl_server_socket.h" |
| 32 #include "net/url_request/url_fetcher.h" | 32 #include "net/url_request/url_fetcher.h" |
| 33 #include "remoting/base/auto_thread_task_runner.h" | 33 #include "remoting/base/auto_thread_task_runner.h" |
| 34 #include "remoting/base/breakpad.h" | 34 #include "remoting/base/breakpad.h" |
| 35 #include "remoting/base/constants.h" | 35 #include "remoting/base/constants.h" |
| 36 #include "remoting/base/logging.h" | 36 #include "remoting/base/logging.h" |
| 37 #include "remoting/base/rsa_key_pair.h" | 37 #include "remoting/base/rsa_key_pair.h" |
| 38 #include "remoting/base/service_urls.h" | 38 #include "remoting/base/service_urls.h" |
| 39 #include "remoting/base/util.h" | 39 #include "remoting/base/util.h" |
| 40 #include "remoting/host/branding.h" | 40 #include "remoting/host/branding.h" |
| 41 #include "remoting/host/chromoting_host.h" | 41 #include "remoting/host/chromoting_host.h" |
| 42 #include "remoting/host/chromoting_host_context.h" | 42 #include "remoting/host/chromoting_host_context.h" |
| 43 #include "remoting/host/chromoting_messages.h" | 43 #include "remoting/host/chromoting_messages.h" |
| 44 #include "remoting/host/config_file_watcher.h" | 44 #include "remoting/host/config_file_watcher.h" |
| 45 #include "remoting/host/config_watcher.h" | 45 #include "remoting/host/config_watcher.h" |
| 46 #include "remoting/host/desktop_environment.h" | 46 #include "remoting/host/desktop_environment.h" |
| 47 #include "remoting/host/desktop_session_connector.h" | 47 #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" | 48 #include "remoting/host/host_change_notification_listener.h" |
| 51 #include "remoting/host/host_config.h" | 49 #include "remoting/host/host_config.h" |
| 52 #include "remoting/host/host_event_logger.h" | 50 #include "remoting/host/host_event_logger.h" |
| 53 #include "remoting/host/host_exit_codes.h" | 51 #include "remoting/host/host_exit_codes.h" |
| 54 #include "remoting/host/host_main.h" | 52 #include "remoting/host/host_main.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" |
| 59 #include "remoting/host/minimum_heartbeat_supporter.h" | |
| 61 #include "remoting/host/pairing_registry_delegate.h" | 60 #include "remoting/host/pairing_registry_delegate.h" |
| 62 #include "remoting/host/policy_hack/policy_watcher.h" | 61 #include "remoting/host/policy_hack/policy_watcher.h" |
| 63 #include "remoting/host/session_manager_factory.h" | 62 #include "remoting/host/session_manager_factory.h" |
| 64 #include "remoting/host/signaling_connector.h" | |
| 65 #include "remoting/host/single_window_desktop_environment.h" | 63 #include "remoting/host/single_window_desktop_environment.h" |
| 66 #include "remoting/host/token_validator_factory_impl.h" | 64 #include "remoting/host/token_validator_factory_impl.h" |
| 67 #include "remoting/host/usage_stats_consent.h" | 65 #include "remoting/host/usage_stats_consent.h" |
| 68 #include "remoting/host/username.h" | 66 #include "remoting/host/username.h" |
| 69 #include "remoting/host/video_frame_recorder_host_extension.h" | 67 #include "remoting/host/video_frame_recorder_host_extension.h" |
| 70 #include "remoting/protocol/me2me_host_authenticator_factory.h" | 68 #include "remoting/protocol/me2me_host_authenticator_factory.h" |
| 71 #include "remoting/protocol/network_settings.h" | 69 #include "remoting/protocol/network_settings.h" |
| 72 #include "remoting/protocol/pairing_registry.h" | 70 #include "remoting/protocol/pairing_registry.h" |
| 73 #include "remoting/protocol/token_validator.h" | 71 #include "remoting/protocol/token_validator.h" |
| 74 #include "remoting/signaling/xmpp_signal_strategy.h" | 72 #include "remoting/signaling/xmpp_signal_strategy.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 bool OnUsernamePolicyUpdate(base::DictionaryValue* policies); | 231 bool OnUsernamePolicyUpdate(base::DictionaryValue* policies); |
| 234 bool OnNatPolicyUpdate(base::DictionaryValue* policies); | 232 bool OnNatPolicyUpdate(base::DictionaryValue* policies); |
| 235 bool OnRelayPolicyUpdate(base::DictionaryValue* policies); | 233 bool OnRelayPolicyUpdate(base::DictionaryValue* policies); |
| 236 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies); | 234 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies); |
| 237 bool OnCurtainPolicyUpdate(base::DictionaryValue* policies); | 235 bool OnCurtainPolicyUpdate(base::DictionaryValue* policies); |
| 238 bool OnHostTalkGadgetPrefixPolicyUpdate(base::DictionaryValue* policies); | 236 bool OnHostTalkGadgetPrefixPolicyUpdate(base::DictionaryValue* policies); |
| 239 bool OnHostTokenUrlPolicyUpdate(base::DictionaryValue* policies); | 237 bool OnHostTokenUrlPolicyUpdate(base::DictionaryValue* policies); |
| 240 bool OnPairingPolicyUpdate(base::DictionaryValue* policies); | 238 bool OnPairingPolicyUpdate(base::DictionaryValue* policies); |
| 241 bool OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies); | 239 bool OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies); |
| 242 | 240 |
| 241 scoped_refptr<MinimumHeartbeatSupporter> CreateMinimumHeartbeatSupporter(); | |
| 242 | |
| 243 void StartHost(); | 243 void StartHost(); |
| 244 | 244 |
| 245 void OnHeartbeatSuccessful(); | 245 void OnHeartbeatSuccessful(); |
| 246 void OnUnknownHostIdError(); | 246 void OnUnknownHostIdError(); |
| 247 | 247 |
| 248 void OnAuthFailed(); | 248 void OnAuthFailed(); |
| 249 | 249 |
| 250 void RestartHost(); | 250 void RestartHost(); |
| 251 | 251 |
| 252 // Stops the host and shuts down the process with the specified |exit_code|. | 252 // Stops the host and shuts down the process with the specified |exit_code|. |
| 253 void ShutdownHost(HostExitCodes exit_code); | 253 void ShutdownHost(HostExitCodes exit_code); |
| 254 | 254 |
| 255 void ScheduleHostShutdown(); | |
| 256 | |
| 257 void ShutdownOnNetworkThread(); | 255 void ShutdownOnNetworkThread(); |
| 258 | 256 |
| 259 void OnPolicyWatcherShutdown(); | 257 void OnPolicyWatcherShutdown(); |
| 260 | 258 |
| 261 // 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 |
| 262 // 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 |
| 263 // request. | 261 // request. |
| 264 void OnCrash(const std::string& function_name, | 262 void OnCrash(const std::string& function_name, |
| 265 const std::string& file_name, | 263 const std::string& file_name, |
| 266 const int& line_number); | 264 const int& line_number); |
| 267 | 265 |
| 268 scoped_ptr<ChromotingHostContext> context_; | 266 scoped_ptr<ChromotingHostContext> context_; |
| 269 | 267 |
| 270 // Created on the UI thread but used from the network thread. | |
| 271 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | |
| 272 | |
| 273 // Accessed on the UI thread. | 268 // Accessed on the UI thread. |
| 274 scoped_ptr<IPC::ChannelProxy> daemon_channel_; | 269 scoped_ptr<IPC::ChannelProxy> daemon_channel_; |
| 275 | 270 |
| 276 // XMPP server/remoting bot configuration (initialized from the command line). | 271 // XMPP server/remoting bot configuration (initialized from the command line). |
| 277 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; | 272 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; |
| 278 std::string directory_bot_jid_; | 273 std::string directory_bot_jid_; |
| 279 | 274 |
| 280 // Created on the UI thread but used from the network thread. | 275 // Created on the UI thread but used from the network thread. |
| 281 base::FilePath host_config_path_; | 276 base::FilePath host_config_path_; |
| 282 std::string host_config_; | 277 std::string host_config_; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 312 ThirdPartyAuthConfig third_party_auth_config_; | 307 ThirdPartyAuthConfig third_party_auth_config_; |
| 313 bool enable_gnubby_auth_; | 308 bool enable_gnubby_auth_; |
| 314 | 309 |
| 315 // Boolean to change flow, where ncessary, if we're | 310 // Boolean to change flow, where ncessary, if we're |
| 316 // capturing a window instead of the entire desktop. | 311 // capturing a window instead of the entire desktop. |
| 317 bool enable_window_capture_; | 312 bool enable_window_capture_; |
| 318 | 313 |
| 319 // Used to specify which window to stream, if enabled. | 314 // Used to specify which window to stream, if enabled. |
| 320 webrtc::WindowId window_id_; | 315 webrtc::WindowId window_id_; |
| 321 | 316 |
| 322 scoped_ptr<OAuthTokenGetter> oauth_token_getter_; | 317 scoped_refptr<MinimumHeartbeatSupporter> minimum_heartbeat_supporter_; |
| 323 scoped_ptr<XmppSignalStrategy> signal_strategy_; | |
| 324 scoped_ptr<SignalingConnector> signaling_connector_; | |
| 325 scoped_ptr<HeartbeatSender> heartbeat_sender_; | |
| 326 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; | 318 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; |
| 327 scoped_ptr<HostStatusLogger> host_status_logger_; | 319 scoped_ptr<HostStatusLogger> host_status_logger_; |
| 328 scoped_ptr<HostEventLogger> host_event_logger_; | 320 scoped_ptr<HostEventLogger> host_event_logger_; |
| 329 | 321 |
| 330 scoped_ptr<ChromotingHost> host_; | 322 scoped_ptr<ChromotingHost> host_; |
| 331 | 323 |
| 332 // Used to keep this HostProcess alive until it is shutdown. | 324 // Used to keep this HostProcess alive until it is shutdown. |
| 333 scoped_refptr<HostProcess> self_; | 325 scoped_refptr<HostProcess> self_; |
| 334 | 326 |
| 335 #if defined(REMOTING_MULTI_PROCESS) | 327 #if defined(REMOTING_MULTI_PROCESS) |
| 336 DesktopSessionConnector* desktop_session_connector_; | 328 DesktopSessionConnector* desktop_session_connector_; |
| 337 #endif // defined(REMOTING_MULTI_PROCESS) | 329 #endif // defined(REMOTING_MULTI_PROCESS) |
| 338 | 330 |
| 339 int* exit_code_out_; | 331 int* exit_code_out_; |
| 340 bool signal_parent_; | 332 bool signal_parent_; |
| 341 | 333 |
| 342 scoped_ptr<PairingRegistry::Delegate> pairing_registry_delegate_; | 334 scoped_ptr<PairingRegistry::Delegate> pairing_registry_delegate_; |
| 335 | |
| 336 // Factory of weak pointers to |this| that will to be referenced from the | |
| 337 // network thread (weak pointers are constrained to a single thread). | |
| 338 base::WeakPtrFactory<HostProcess> weak_factory_for_network_task_runner_; | |
|
Wez
2014/12/09 00:51:58
This should just be |weak_factory_| and the commen
Łukasz Anforowicz
2014/12/09 18:47:07
Maybe. This is what I started with, but I wasn't
| |
| 343 }; | 339 }; |
|
Wez
2014/12/09 00:51:58
While you're here this should have DISALLOW_COPY_A
Łukasz Anforowicz
2014/12/09 18:47:07
Ok.
| |
| 344 | 340 |
| 345 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, | 341 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, |
| 346 int* exit_code_out) | 342 int* exit_code_out) |
| 347 : context_(context.Pass()), | 343 : context_(context.Pass()), |
| 348 state_(HOST_INITIALIZING), | 344 state_(HOST_INITIALIZING), |
| 349 use_service_account_(false), | 345 use_service_account_(false), |
| 350 enable_vp9_(false), | 346 enable_vp9_(false), |
| 351 frame_recorder_buffer_size_(0), | 347 frame_recorder_buffer_size_(0), |
| 352 host_username_match_required_(false), | 348 host_username_match_required_(false), |
| 353 allow_nat_traversal_(true), | 349 allow_nat_traversal_(true), |
| 354 allow_relay_(true), | 350 allow_relay_(true), |
| 355 min_udp_port_(0), | 351 min_udp_port_(0), |
| 356 max_udp_port_(0), | 352 max_udp_port_(0), |
| 357 allow_pairing_(true), | 353 allow_pairing_(true), |
| 358 curtain_required_(false), | 354 curtain_required_(false), |
| 359 enable_gnubby_auth_(false), | 355 enable_gnubby_auth_(false), |
| 360 enable_window_capture_(false), | 356 enable_window_capture_(false), |
| 361 window_id_(0), | 357 window_id_(0), |
| 362 #if defined(REMOTING_MULTI_PROCESS) | 358 #if defined(REMOTING_MULTI_PROCESS) |
| 363 desktop_session_connector_(NULL), | 359 desktop_session_connector_(NULL), |
| 364 #endif // defined(REMOTING_MULTI_PROCESS) | 360 #endif // defined(REMOTING_MULTI_PROCESS) |
| 365 self_(this), | 361 self_(this), |
| 366 exit_code_out_(exit_code_out), | 362 exit_code_out_(exit_code_out), |
| 367 signal_parent_(false) { | 363 signal_parent_(false), |
| 364 weak_factory_for_network_task_runner_(this) { | |
| 368 StartOnUiThread(); | 365 StartOnUiThread(); |
| 369 } | 366 } |
| 370 | 367 |
| 371 HostProcess::~HostProcess() { | 368 HostProcess::~HostProcess() { |
| 372 // Verify that UI components have been torn down. | 369 // Verify that UI components have been torn down. |
| 373 DCHECK(!config_watcher_); | 370 DCHECK(!config_watcher_); |
| 374 DCHECK(!daemon_channel_); | 371 DCHECK(!daemon_channel_); |
| 375 DCHECK(!desktop_environment_factory_); | 372 DCHECK(!desktop_environment_factory_); |
| 376 | 373 |
| 377 // We might be getting deleted on one of the threads the |host_context| owns, | 374 // We might be getting deleted on one of the threads the |host_context| owns, |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 739 | 736 |
| 740 context_->network_task_runner()->PostTask( | 737 context_->network_task_runner()->PostTask( |
| 741 FROM_HERE, | 738 FROM_HERE, |
| 742 base::Bind(&HostProcess::StartOnNetworkThread, this)); | 739 base::Bind(&HostProcess::StartOnNetworkThread, this)); |
| 743 } | 740 } |
| 744 | 741 |
| 745 void HostProcess::ShutdownOnUiThread() { | 742 void HostProcess::ShutdownOnUiThread() { |
| 746 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 743 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 747 | 744 |
| 748 // Tear down resources that need to be torn down on the UI thread. | 745 // Tear down resources that need to be torn down on the UI thread. |
| 749 network_change_notifier_.reset(); | |
| 750 daemon_channel_.reset(); | 746 daemon_channel_.reset(); |
| 751 desktop_environment_factory_.reset(); | 747 desktop_environment_factory_.reset(); |
| 752 | 748 |
| 753 // It is now safe for the HostProcess to be deleted. | 749 // It is now safe for the HostProcess to be deleted. |
| 754 self_ = NULL; | 750 self_ = NULL; |
| 755 | 751 |
| 756 #if defined(OS_LINUX) | 752 #if defined(OS_LINUX) |
| 757 // Cause the global AudioPipeReader to be freed, otherwise the audio | 753 // Cause the global AudioPipeReader to be freed, otherwise the audio |
| 758 // thread will remain in-use and prevent the process from exiting. | 754 // thread will remain in-use and prevent the process from exiting. |
| 759 // TODO(wez): DesktopEnvironmentFactory should own the pipe reader. | 755 // TODO(wez): DesktopEnvironmentFactory should own the pipe reader. |
| 760 // See crbug.com/161373 and crbug.com/104544. | 756 // See crbug.com/161373 and crbug.com/104544. |
| 761 AudioCapturerLinux::InitializePipeReader(NULL, base::FilePath()); | 757 AudioCapturerLinux::InitializePipeReader(NULL, base::FilePath()); |
| 762 #endif | 758 #endif |
| 763 } | 759 } |
| 764 | 760 |
| 765 // Overridden from HeartbeatSender::Listener | |
| 766 void HostProcess::OnUnknownHostIdError() { | 761 void HostProcess::OnUnknownHostIdError() { |
| 767 LOG(ERROR) << "Host ID not found."; | 762 LOG(ERROR) << "Host ID not found."; |
| 768 ShutdownHost(kInvalidHostIdExitCode); | 763 ShutdownHost(kInvalidHostIdExitCode); |
| 769 } | 764 } |
| 770 | 765 |
| 771 void HostProcess::OnHeartbeatSuccessful() { | 766 void HostProcess::OnHeartbeatSuccessful() { |
| 772 HOST_LOG << "Host ready to receive connections."; | 767 HOST_LOG << "Host ready to receive connections."; |
| 773 #if defined(OS_POSIX) | 768 #if defined(OS_POSIX) |
| 774 if (signal_parent_) { | 769 if (signal_parent_) { |
| 775 kill(getppid(), SIGUSR1); | 770 kill(getppid(), SIGUSR1); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 842 if (!config.GetString(kXmppLoginConfigPath, &xmpp_server_config_.username) || | 837 if (!config.GetString(kXmppLoginConfigPath, &xmpp_server_config_.username) || |
| 843 !(config.GetString(kXmppAuthTokenConfigPath, | 838 !(config.GetString(kXmppAuthTokenConfigPath, |
| 844 &xmpp_server_config_.auth_token) || | 839 &xmpp_server_config_.auth_token) || |
| 845 config.GetString(kOAuthRefreshTokenConfigPath, | 840 config.GetString(kOAuthRefreshTokenConfigPath, |
| 846 &oauth_refresh_token_))) { | 841 &oauth_refresh_token_))) { |
| 847 LOG(ERROR) << "XMPP credentials are not defined in the config."; | 842 LOG(ERROR) << "XMPP credentials are not defined in the config."; |
| 848 return false; | 843 return false; |
| 849 } | 844 } |
| 850 | 845 |
| 851 if (!oauth_refresh_token_.empty()) { | 846 if (!oauth_refresh_token_.empty()) { |
| 852 // SignalingConnector is responsible for getting OAuth token. | 847 // SignalingConnector (inside MinimumHeartbeatSupporter) is responsible for |
| 848 // getting OAuth token. | |
| 853 xmpp_server_config_.auth_token = ""; | 849 xmpp_server_config_.auth_token = ""; |
| 854 xmpp_server_config_.auth_service = "oauth2"; | 850 xmpp_server_config_.auth_service = "oauth2"; |
| 855 } else if (!config.GetString(kXmppAuthServiceConfigPath, | 851 } else if (!config.GetString(kXmppAuthServiceConfigPath, |
| 856 &xmpp_server_config_.auth_service)) { | 852 &xmpp_server_config_.auth_service)) { |
| 857 // For the me2me host, we default to ClientLogin token for chromiumsync | 853 // For the me2me host, we default to ClientLogin token for chromiumsync |
| 858 // 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 |
| 859 // request an OAuth2 access token. | 855 // request an OAuth2 access token. |
| 860 xmpp_server_config_.auth_service = kChromotingTokenDefaultServiceName; | 856 xmpp_server_config_.auth_service = kChromotingTokenDefaultServiceName; |
| 861 } | 857 } |
| 862 | 858 |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1222 } else { | 1218 } else { |
| 1223 HOST_LOG << "Policy disables gnubby auth."; | 1219 HOST_LOG << "Policy disables gnubby auth."; |
| 1224 } | 1220 } |
| 1225 | 1221 |
| 1226 if (desktop_environment_factory_) | 1222 if (desktop_environment_factory_) |
| 1227 desktop_environment_factory_->SetEnableGnubbyAuth(enable_gnubby_auth_); | 1223 desktop_environment_factory_->SetEnableGnubbyAuth(enable_gnubby_auth_); |
| 1228 | 1224 |
| 1229 return true; | 1225 return true; |
| 1230 } | 1226 } |
| 1231 | 1227 |
| 1228 scoped_refptr<MinimumHeartbeatSupporter> | |
| 1229 HostProcess::CreateMinimumHeartbeatSupporter() { | |
| 1230 DCHECK(!host_id_.empty()); // Assumming |ApplyConfig| has already been run. | |
| 1231 return MinimumHeartbeatSupporter::Create( | |
| 1232 base::Bind(&HostProcess::OnHeartbeatSuccessful, | |
| 1233 weak_factory_for_network_task_runner_.GetWeakPtr()), | |
| 1234 base::Bind(&HostProcess::OnUnknownHostIdError, | |
| 1235 weak_factory_for_network_task_runner_.GetWeakPtr()), | |
| 1236 base::Bind(&HostProcess::OnAuthFailed, | |
| 1237 weak_factory_for_network_task_runner_.GetWeakPtr()), | |
|
Wez
2014/12/09 00:51:58
Why are we passing three Callbacks here rather tha
Łukasz Anforowicz
2014/12/09 18:47:07
We rely on WeakPtrs translating the callbacks into
| |
| 1238 *context_, xmpp_server_config_, talkgadget_prefix_, host_id_, key_pair_, | |
| 1239 directory_bot_jid_, oauth_refresh_token_, use_service_account_); | |
| 1240 } | |
| 1241 | |
| 1232 void HostProcess::StartHost() { | 1242 void HostProcess::StartHost() { |
| 1233 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1243 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 1234 DCHECK(!host_); | 1244 DCHECK(!host_); |
| 1235 DCHECK(!signal_strategy_.get()); | 1245 DCHECK(!minimum_heartbeat_supporter_.get()); |
|
Wez
2014/12/09 00:51:58
nit: Remove the .get()
Łukasz Anforowicz
2014/12/09 18:47:07
Done.
| |
| 1246 | |
| 1236 DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART || | 1247 DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART || |
| 1237 state_ == HOST_STOPPED) << state_; | 1248 state_ == HOST_STOPPED) << state_; |
| 1238 state_ = HOST_STARTED; | 1249 state_ = HOST_STARTED; |
| 1239 | 1250 |
| 1240 signal_strategy_.reset( | 1251 minimum_heartbeat_supporter_ = CreateMinimumHeartbeatSupporter(); |
| 1241 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), | |
| 1242 context_->url_request_context_getter(), | |
| 1243 xmpp_server_config_)); | |
| 1244 | |
| 1245 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker( | |
| 1246 new DnsBlackholeChecker(context_->url_request_context_getter(), | |
| 1247 talkgadget_prefix_)); | |
| 1248 | |
| 1249 // Create a NetworkChangeNotifier for use by the signaling connector. | |
| 1250 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | |
| 1251 | |
| 1252 signaling_connector_.reset(new SignalingConnector( | |
| 1253 signal_strategy_.get(), | |
| 1254 dns_blackhole_checker.Pass(), | |
| 1255 base::Bind(&HostProcess::OnAuthFailed, this))); | |
| 1256 | |
| 1257 if (!oauth_refresh_token_.empty()) { | |
| 1258 scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials; | |
| 1259 oauth_credentials.reset( | |
| 1260 new OAuthTokenGetter::OAuthCredentials( | |
| 1261 xmpp_server_config_.username, oauth_refresh_token_, | |
| 1262 use_service_account_)); | |
| 1263 | |
| 1264 oauth_token_getter_.reset(new OAuthTokenGetter( | |
| 1265 oauth_credentials.Pass(), context_->url_request_context_getter(), | |
| 1266 false)); | |
| 1267 | |
| 1268 signaling_connector_->EnableOAuth(oauth_token_getter_.get()); | |
| 1269 } | |
| 1270 | 1252 |
| 1271 uint32 network_flags = 0; | 1253 uint32 network_flags = 0; |
| 1272 if (allow_nat_traversal_) { | 1254 if (allow_nat_traversal_) { |
| 1273 network_flags = NetworkSettings::NAT_TRAVERSAL_STUN | | 1255 network_flags = NetworkSettings::NAT_TRAVERSAL_STUN | |
| 1274 NetworkSettings::NAT_TRAVERSAL_OUTGOING; | 1256 NetworkSettings::NAT_TRAVERSAL_OUTGOING; |
| 1275 if (allow_relay_) | 1257 if (allow_relay_) |
| 1276 network_flags |= NetworkSettings::NAT_TRAVERSAL_RELAY; | 1258 network_flags |= NetworkSettings::NAT_TRAVERSAL_RELAY; |
| 1277 } | 1259 } |
| 1278 | 1260 |
| 1279 NetworkSettings network_settings(network_flags); | 1261 NetworkSettings network_settings(network_flags); |
| 1280 | 1262 |
| 1281 if (min_udp_port_ && max_udp_port_) { | 1263 if (min_udp_port_ && max_udp_port_) { |
| 1282 network_settings.min_port = min_udp_port_; | 1264 network_settings.min_port = min_udp_port_; |
| 1283 network_settings.max_port = max_udp_port_; | 1265 network_settings.max_port = max_udp_port_; |
| 1284 } else if (!allow_nat_traversal_) { | 1266 } else if (!allow_nat_traversal_) { |
| 1285 // For legacy reasons we have to restrict the port range to a set of default | 1267 // For legacy reasons we have to restrict the port range to a set of default |
| 1286 // values when nat traversal is disabled, even if the port range was not | 1268 // values when nat traversal is disabled, even if the port range was not |
| 1287 // set in policy. | 1269 // set in policy. |
| 1288 network_settings.min_port = NetworkSettings::kDefaultMinPort; | 1270 network_settings.min_port = NetworkSettings::kDefaultMinPort; |
| 1289 network_settings.max_port = NetworkSettings::kDefaultMaxPort; | 1271 network_settings.max_port = NetworkSettings::kDefaultMaxPort; |
| 1290 } | 1272 } |
| 1291 | 1273 |
| 1292 host_.reset(new ChromotingHost( | 1274 host_.reset(new ChromotingHost( |
| 1293 signal_strategy_.get(), | 1275 minimum_heartbeat_supporter_->signal_strategy(), |
| 1294 desktop_environment_factory_.get(), | 1276 desktop_environment_factory_.get(), |
| 1295 CreateHostSessionManager(signal_strategy_.get(), network_settings, | 1277 CreateHostSessionManager(minimum_heartbeat_supporter_->signal_strategy(), |
| 1278 network_settings, | |
| 1296 context_->url_request_context_getter()), | 1279 context_->url_request_context_getter()), |
| 1297 context_->audio_task_runner(), | 1280 context_->audio_task_runner(), context_->input_task_runner(), |
| 1298 context_->input_task_runner(), | |
| 1299 context_->video_capture_task_runner(), | 1281 context_->video_capture_task_runner(), |
| 1300 context_->video_encode_task_runner(), | 1282 context_->video_encode_task_runner(), context_->network_task_runner(), |
| 1301 context_->network_task_runner(), | |
| 1302 context_->ui_task_runner())); | 1283 context_->ui_task_runner())); |
| 1303 | 1284 |
| 1304 if (enable_vp9_) { | 1285 if (enable_vp9_) { |
| 1305 scoped_ptr<protocol::CandidateSessionConfig> config = | 1286 scoped_ptr<protocol::CandidateSessionConfig> config = |
| 1306 host_->protocol_config()->Clone(); | 1287 host_->protocol_config()->Clone(); |
| 1307 config->EnableVideoCodec(protocol::ChannelConfig::CODEC_VP9); | 1288 config->EnableVideoCodec(protocol::ChannelConfig::CODEC_VP9); |
| 1308 host_->set_protocol_config(config.Pass()); | 1289 host_->set_protocol_config(config.Pass()); |
| 1309 } | 1290 } |
| 1310 | 1291 |
| 1311 if (frame_recorder_buffer_size_ > 0) { | 1292 if (frame_recorder_buffer_size_ > 0) { |
| 1312 scoped_ptr<VideoFrameRecorderHostExtension> frame_recorder_extension( | 1293 scoped_ptr<VideoFrameRecorderHostExtension> frame_recorder_extension( |
| 1313 new VideoFrameRecorderHostExtension()); | 1294 new VideoFrameRecorderHostExtension()); |
| 1314 frame_recorder_extension->SetMaxContentBytes(frame_recorder_buffer_size_); | 1295 frame_recorder_extension->SetMaxContentBytes(frame_recorder_buffer_size_); |
| 1315 host_->AddExtension(frame_recorder_extension.Pass()); | 1296 host_->AddExtension(frame_recorder_extension.Pass()); |
| 1316 } | 1297 } |
| 1317 | 1298 |
| 1318 // TODO(simonmorris): Get the maximum session duration from a policy. | 1299 // TODO(simonmorris): Get the maximum session duration from a policy. |
| 1319 #if defined(OS_LINUX) | 1300 #if defined(OS_LINUX) |
| 1320 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); | 1301 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); |
| 1321 #endif | 1302 #endif |
| 1322 | 1303 |
| 1323 heartbeat_sender_.reset(new HeartbeatSender( | 1304 host_change_notification_listener_.reset(new HostChangeNotificationListener( |
| 1324 base::Bind(&HostProcess::OnHeartbeatSuccessful, base::Unretained(this)), | 1305 this, host_id_, minimum_heartbeat_supporter_->signal_strategy(), |
| 1325 base::Bind(&HostProcess::OnUnknownHostIdError, base::Unretained(this)), | 1306 directory_bot_jid_)); |
| 1326 host_id_, signal_strategy_.get(), key_pair_, directory_bot_jid_)); | |
| 1327 | 1307 |
| 1328 host_change_notification_listener_.reset(new HostChangeNotificationListener( | 1308 host_status_logger_.reset(new HostStatusLogger( |
| 1329 this, host_id_, signal_strategy_.get(), directory_bot_jid_)); | 1309 host_->AsWeakPtr(), ServerLogEntry::ME2ME, |
| 1330 | 1310 minimum_heartbeat_supporter_->signal_strategy(), directory_bot_jid_)); |
| 1331 host_status_logger_.reset( | |
| 1332 new HostStatusLogger(host_->AsWeakPtr(), ServerLogEntry::ME2ME, | |
| 1333 signal_strategy_.get(), directory_bot_jid_)); | |
| 1334 | 1311 |
| 1335 // Set up reporting the host status notifications. | 1312 // Set up reporting the host status notifications. |
| 1336 #if defined(REMOTING_MULTI_PROCESS) | 1313 #if defined(REMOTING_MULTI_PROCESS) |
| 1337 host_event_logger_.reset( | 1314 host_event_logger_.reset( |
| 1338 new IpcHostEventLogger(host_->AsWeakPtr(), daemon_channel_.get())); | 1315 new IpcHostEventLogger(host_->AsWeakPtr(), daemon_channel_.get())); |
| 1339 #else // !defined(REMOTING_MULTI_PROCESS) | 1316 #else // !defined(REMOTING_MULTI_PROCESS) |
| 1340 host_event_logger_ = | 1317 host_event_logger_ = |
| 1341 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); | 1318 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); |
| 1342 #endif // !defined(REMOTING_MULTI_PROCESS) | 1319 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 1343 | 1320 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1360 } | 1337 } |
| 1361 | 1338 |
| 1362 void HostProcess::ShutdownHost(HostExitCodes exit_code) { | 1339 void HostProcess::ShutdownHost(HostExitCodes exit_code) { |
| 1363 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1340 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 1364 | 1341 |
| 1365 *exit_code_out_ = exit_code; | 1342 *exit_code_out_ = exit_code; |
| 1366 | 1343 |
| 1367 switch (state_) { | 1344 switch (state_) { |
| 1368 case HOST_INITIALIZING: | 1345 case HOST_INITIALIZING: |
| 1369 state_ = HOST_STOPPING; | 1346 state_ = HOST_STOPPING; |
| 1347 { | |
| 1348 DCHECK(!minimum_heartbeat_supporter_.get()); | |
| 1349 scoped_refptr<MinimumHeartbeatSupporter> tmpHeartbeatSupporter = | |
| 1350 CreateMinimumHeartbeatSupporter(); | |
| 1351 tmpHeartbeatSupporter->SendHostOfflineReason( | |
| 1352 ExitCodeToString(exit_code), | |
| 1353 base::TimeDelta::FromSeconds(10) /* timeout */); | |
| 1354 } | |
| 1370 ShutdownOnNetworkThread(); | 1355 ShutdownOnNetworkThread(); |
| 1371 break; | 1356 break; |
| 1372 | 1357 |
| 1373 case HOST_STARTED: | 1358 case HOST_STARTED: |
| 1374 state_ = HOST_STOPPING; | 1359 state_ = HOST_STOPPING; |
| 1375 heartbeat_sender_->SetHostOfflineReason( | 1360 minimum_heartbeat_supporter_->SendHostOfflineReason( |
| 1376 ExitCodeToString(exit_code), base::Bind(base::DoNothing)); | 1361 ExitCodeToString(exit_code), |
| 1377 ScheduleHostShutdown(); | 1362 base::TimeDelta::FromSeconds(10) /* timeout */); |
| 1363 ShutdownOnNetworkThread(); | |
| 1378 break; | 1364 break; |
| 1379 | 1365 |
| 1380 case HOST_STOPPING_TO_RESTART: | 1366 case HOST_STOPPING_TO_RESTART: |
| 1381 state_ = HOST_STOPPING; | 1367 state_ = HOST_STOPPING; |
| 1382 break; | 1368 break; |
| 1383 | 1369 |
| 1384 case HOST_STOPPING: | 1370 case HOST_STOPPING: |
| 1385 case HOST_STOPPED: | 1371 case HOST_STOPPED: |
| 1386 // Host is already stopped or being stopped. No action is required. | 1372 // Host is already stopped or being stopped. No action is required. |
| 1387 break; | 1373 break; |
| 1388 } | 1374 } |
| 1389 } | 1375 } |
| 1390 | 1376 |
| 1391 // TODO(weitaosu): shut down the host once we get an ACK for the offline status | |
| 1392 // XMPP message. | |
| 1393 void HostProcess::ScheduleHostShutdown() { | |
| 1394 // Delay the shutdown by 2 second to allow SendOfflineStatus to complete. | |
| 1395 context_->network_task_runner()->PostDelayedTask( | |
| 1396 FROM_HERE, | |
| 1397 base::Bind(&HostProcess::ShutdownOnNetworkThread, base::Unretained(this)), | |
| 1398 base::TimeDelta::FromSeconds(2)); | |
| 1399 } | |
| 1400 | |
| 1401 void HostProcess::ShutdownOnNetworkThread() { | 1377 void HostProcess::ShutdownOnNetworkThread() { |
| 1402 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1378 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 1403 | 1379 |
| 1380 // Need to invalidate WeakPtrs on the same thread where they are dereferenced. | |
|
Wez
2014/12/09 00:51:58
nit: This is always a requirement for invalidating
| |
| 1381 weak_factory_for_network_task_runner_.InvalidateWeakPtrs(); | |
| 1382 | |
| 1404 host_.reset(); | 1383 host_.reset(); |
| 1405 host_event_logger_.reset(); | 1384 host_event_logger_.reset(); |
| 1406 host_status_logger_.reset(); | 1385 host_status_logger_.reset(); |
| 1407 heartbeat_sender_.reset(); | 1386 minimum_heartbeat_supporter_ = nullptr; |
|
Wez
2014/12/09 00:51:58
Why are you NULLing this here?
| |
| 1408 host_change_notification_listener_.reset(); | 1387 host_change_notification_listener_.reset(); |
| 1409 signaling_connector_.reset(); | |
| 1410 oauth_token_getter_.reset(); | |
| 1411 signal_strategy_.reset(); | |
| 1412 network_change_notifier_.reset(); | |
| 1413 | 1388 |
| 1414 if (state_ == HOST_STOPPING_TO_RESTART) { | 1389 if (state_ == HOST_STOPPING_TO_RESTART) { |
| 1415 StartHost(); | 1390 StartHost(); |
| 1416 } else if (state_ == HOST_STOPPING) { | 1391 } else if (state_ == HOST_STOPPING) { |
| 1417 state_ = HOST_STOPPED; | 1392 state_ = HOST_STOPPED; |
| 1418 | 1393 |
| 1419 if (policy_watcher_.get()) { | 1394 if (policy_watcher_.get()) { |
| 1420 policy_watcher_->StopWatching( | 1395 policy_watcher_->StopWatching( |
| 1421 base::Bind(&HostProcess::OnPolicyWatcherShutdown, this)); | 1396 base::Bind(&HostProcess::OnPolicyWatcherShutdown, this)); |
| 1422 } else { | 1397 } else { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1481 int exit_code = kSuccessExitCode; | 1456 int exit_code = kSuccessExitCode; |
| 1482 new HostProcess(context.Pass(), &exit_code); | 1457 new HostProcess(context.Pass(), &exit_code); |
| 1483 | 1458 |
| 1484 // Run the main (also UI) message loop until the host no longer needs it. | 1459 // Run the main (also UI) message loop until the host no longer needs it. |
| 1485 message_loop.Run(); | 1460 message_loop.Run(); |
| 1486 | 1461 |
| 1487 return exit_code; | 1462 return exit_code; |
| 1488 } | 1463 } |
| 1489 | 1464 |
| 1490 } // namespace remoting | 1465 } // namespace remoting |
| OLD | NEW |