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" |
53 #include "remoting/host/host_signaling_manager.h" | |
55 #include "remoting/host/host_status_logger.h" | 54 #include "remoting/host/host_status_logger.h" |
56 #include "remoting/host/ipc_constants.h" | 55 #include "remoting/host/ipc_constants.h" |
57 #include "remoting/host/ipc_desktop_environment.h" | 56 #include "remoting/host/ipc_desktop_environment.h" |
58 #include "remoting/host/ipc_host_event_logger.h" | 57 #include "remoting/host/ipc_host_event_logger.h" |
59 #include "remoting/host/logging.h" | 58 #include "remoting/host/logging.h" |
60 #include "remoting/host/me2me_desktop_environment.h" | 59 #include "remoting/host/me2me_desktop_environment.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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 | 125 |
128 // Command line switch used to enable and configure the frame-recorder. | 126 // Command line switch used to enable and configure the frame-recorder. |
129 const char kFrameRecorderBufferKbName[] = "frame-recorder-buffer-kb"; | 127 const char kFrameRecorderBufferKbName[] = "frame-recorder-buffer-kb"; |
130 | 128 |
131 // Value used for --host-config option to indicate that the path must be read | 129 // Value used for --host-config option to indicate that the path must be read |
132 // from stdin. | 130 // from stdin. |
133 const char kStdinConfigPath[] = "-"; | 131 const char kStdinConfigPath[] = "-"; |
134 | 132 |
135 const char kWindowIdSwitchName[] = "window-id"; | 133 const char kWindowIdSwitchName[] = "window-id"; |
136 | 134 |
135 // Maximum time to wait for reporting host-offline-reason to the service, | |
136 // before continuing normal process shutdown. | |
137 const int kHostOfflineReasonTimeoutSeconds = 10; | |
138 | |
137 } // namespace | 139 } // namespace |
138 | 140 |
139 namespace remoting { | 141 namespace remoting { |
140 | 142 |
141 class HostProcess | 143 class HostProcess |
142 : public ConfigWatcher::Delegate, | 144 : public ConfigWatcher::Delegate, |
143 public HostChangeNotificationListener::Listener, | 145 public HostChangeNotificationListener::Listener, |
144 public IPC::Listener, | 146 public IPC::Listener, |
145 public base::RefCountedThreadSafe<HostProcess> { | 147 public base::RefCountedThreadSafe<HostProcess> { |
146 public: | 148 public: |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 bool OnUsernamePolicyUpdate(base::DictionaryValue* policies); | 235 bool OnUsernamePolicyUpdate(base::DictionaryValue* policies); |
234 bool OnNatPolicyUpdate(base::DictionaryValue* policies); | 236 bool OnNatPolicyUpdate(base::DictionaryValue* policies); |
235 bool OnRelayPolicyUpdate(base::DictionaryValue* policies); | 237 bool OnRelayPolicyUpdate(base::DictionaryValue* policies); |
236 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies); | 238 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies); |
237 bool OnCurtainPolicyUpdate(base::DictionaryValue* policies); | 239 bool OnCurtainPolicyUpdate(base::DictionaryValue* policies); |
238 bool OnHostTalkGadgetPrefixPolicyUpdate(base::DictionaryValue* policies); | 240 bool OnHostTalkGadgetPrefixPolicyUpdate(base::DictionaryValue* policies); |
239 bool OnHostTokenUrlPolicyUpdate(base::DictionaryValue* policies); | 241 bool OnHostTokenUrlPolicyUpdate(base::DictionaryValue* policies); |
240 bool OnPairingPolicyUpdate(base::DictionaryValue* policies); | 242 bool OnPairingPolicyUpdate(base::DictionaryValue* policies); |
241 bool OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies); | 243 bool OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies); |
242 | 244 |
245 scoped_ptr<HostSignalingManager> CreateHostSignalingManager(); | |
246 | |
243 void StartHost(); | 247 void StartHost(); |
244 | 248 |
245 void OnHeartbeatSuccessful(); | 249 void OnHeartbeatSuccessful(); |
246 void OnUnknownHostIdError(); | 250 void OnUnknownHostIdError(); |
247 | 251 |
248 void OnAuthFailed(); | 252 void OnAuthFailed(); |
249 | 253 |
250 void RestartHost(); | 254 void RestartHost(); |
251 | 255 |
252 // Stops the host and shuts down the process with the specified |exit_code|. | 256 // Stops the host and shuts down the process with the specified |exit_code|. |
253 void ShutdownHost(HostExitCodes exit_code); | 257 void ShutdownHost(HostExitCodes exit_code); |
254 | 258 |
255 void ScheduleHostShutdown(); | |
256 | |
257 void ShutdownOnNetworkThread(); | 259 void ShutdownOnNetworkThread(); |
258 | 260 |
259 void OnPolicyWatcherShutdown(); | 261 void OnPolicyWatcherShutdown(); |
260 | 262 |
261 // Crashes the process in response to a daemon's request. The daemon passes | 263 // 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 | 264 // the location of the code that detected the fatal error resulted in this |
263 // request. | 265 // request. |
264 void OnCrash(const std::string& function_name, | 266 void OnCrash(const std::string& function_name, |
265 const std::string& file_name, | 267 const std::string& file_name, |
266 const int& line_number); | 268 const int& line_number); |
267 | 269 |
268 scoped_ptr<ChromotingHostContext> context_; | 270 scoped_ptr<ChromotingHostContext> context_; |
269 | 271 |
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. | 272 // Accessed on the UI thread. |
274 scoped_ptr<IPC::ChannelProxy> daemon_channel_; | 273 scoped_ptr<IPC::ChannelProxy> daemon_channel_; |
275 | 274 |
276 // XMPP server/remoting bot configuration (initialized from the command line). | 275 // XMPP server/remoting bot configuration (initialized from the command line). |
277 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; | 276 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; |
278 std::string directory_bot_jid_; | 277 std::string directory_bot_jid_; |
279 | 278 |
280 // Created on the UI thread but used from the network thread. | 279 // Created on the UI thread but used from the network thread. |
281 base::FilePath host_config_path_; | 280 base::FilePath host_config_path_; |
282 std::string host_config_; | 281 std::string host_config_; |
(...skipping 29 matching lines...) Expand all Loading... | |
312 ThirdPartyAuthConfig third_party_auth_config_; | 311 ThirdPartyAuthConfig third_party_auth_config_; |
313 bool enable_gnubby_auth_; | 312 bool enable_gnubby_auth_; |
314 | 313 |
315 // Boolean to change flow, where ncessary, if we're | 314 // Boolean to change flow, where ncessary, if we're |
316 // capturing a window instead of the entire desktop. | 315 // capturing a window instead of the entire desktop. |
317 bool enable_window_capture_; | 316 bool enable_window_capture_; |
318 | 317 |
319 // Used to specify which window to stream, if enabled. | 318 // Used to specify which window to stream, if enabled. |
320 webrtc::WindowId window_id_; | 319 webrtc::WindowId window_id_; |
321 | 320 |
322 scoped_ptr<OAuthTokenGetter> oauth_token_getter_; | 321 scoped_ptr<HostSignalingManager> host_signaling_manager_; |
Wez
2014/12/18 00:46:22
nit: Add a brief comment to explain this member's
Łukasz Anforowicz
2014/12/18 19:02:34
Good point. Done.
| |
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_; | 322 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; |
327 scoped_ptr<HostStatusLogger> host_status_logger_; | 323 scoped_ptr<HostStatusLogger> host_status_logger_; |
328 scoped_ptr<HostEventLogger> host_event_logger_; | 324 scoped_ptr<HostEventLogger> host_event_logger_; |
329 | 325 |
330 scoped_ptr<ChromotingHost> host_; | 326 scoped_ptr<ChromotingHost> host_; |
331 | 327 |
332 // Used to keep this HostProcess alive until it is shutdown. | 328 // Used to keep this HostProcess alive until it is shutdown. |
333 scoped_refptr<HostProcess> self_; | 329 scoped_refptr<HostProcess> self_; |
334 | 330 |
335 #if defined(REMOTING_MULTI_PROCESS) | 331 #if defined(REMOTING_MULTI_PROCESS) |
336 DesktopSessionConnector* desktop_session_connector_; | 332 DesktopSessionConnector* desktop_session_connector_; |
337 #endif // defined(REMOTING_MULTI_PROCESS) | 333 #endif // defined(REMOTING_MULTI_PROCESS) |
338 | 334 |
339 int* exit_code_out_; | 335 int* exit_code_out_; |
340 bool signal_parent_; | 336 bool signal_parent_; |
341 | 337 |
342 scoped_ptr<PairingRegistry::Delegate> pairing_registry_delegate_; | 338 scoped_ptr<PairingRegistry::Delegate> pairing_registry_delegate_; |
339 | |
340 // Factory of weak pointers to |this| that will to be referenced from the | |
341 // network thread (weak pointers are constrained to a single thread). | |
342 base::WeakPtrFactory<HostProcess> weak_factory_for_network_task_runner_; | |
343 | |
344 DISALLOW_COPY_AND_ASSIGN(HostProcess); | |
343 }; | 345 }; |
344 | 346 |
345 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, | 347 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, |
346 int* exit_code_out) | 348 int* exit_code_out) |
347 : context_(context.Pass()), | 349 : context_(context.Pass()), |
348 state_(HOST_INITIALIZING), | 350 state_(HOST_INITIALIZING), |
349 use_service_account_(false), | 351 use_service_account_(false), |
350 enable_vp9_(false), | 352 enable_vp9_(false), |
351 frame_recorder_buffer_size_(0), | 353 frame_recorder_buffer_size_(0), |
352 host_username_match_required_(false), | 354 host_username_match_required_(false), |
353 allow_nat_traversal_(true), | 355 allow_nat_traversal_(true), |
354 allow_relay_(true), | 356 allow_relay_(true), |
355 min_udp_port_(0), | 357 min_udp_port_(0), |
356 max_udp_port_(0), | 358 max_udp_port_(0), |
357 allow_pairing_(true), | 359 allow_pairing_(true), |
358 curtain_required_(false), | 360 curtain_required_(false), |
359 enable_gnubby_auth_(false), | 361 enable_gnubby_auth_(false), |
360 enable_window_capture_(false), | 362 enable_window_capture_(false), |
361 window_id_(0), | 363 window_id_(0), |
362 #if defined(REMOTING_MULTI_PROCESS) | 364 #if defined(REMOTING_MULTI_PROCESS) |
363 desktop_session_connector_(NULL), | 365 desktop_session_connector_(NULL), |
364 #endif // defined(REMOTING_MULTI_PROCESS) | 366 #endif // defined(REMOTING_MULTI_PROCESS) |
365 self_(this), | 367 self_(this), |
366 exit_code_out_(exit_code_out), | 368 exit_code_out_(exit_code_out), |
367 signal_parent_(false) { | 369 signal_parent_(false), |
370 weak_factory_for_network_task_runner_(this) { | |
368 StartOnUiThread(); | 371 StartOnUiThread(); |
369 } | 372 } |
370 | 373 |
371 HostProcess::~HostProcess() { | 374 HostProcess::~HostProcess() { |
372 // Verify that UI components have been torn down. | 375 // Verify that UI components have been torn down. |
373 DCHECK(!config_watcher_); | 376 DCHECK(!config_watcher_); |
374 DCHECK(!daemon_channel_); | 377 DCHECK(!daemon_channel_); |
375 DCHECK(!desktop_environment_factory_); | 378 DCHECK(!desktop_environment_factory_); |
376 | 379 |
377 // We might be getting deleted on one of the threads the |host_context| owns, | 380 // 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 | 742 |
740 context_->network_task_runner()->PostTask( | 743 context_->network_task_runner()->PostTask( |
741 FROM_HERE, | 744 FROM_HERE, |
742 base::Bind(&HostProcess::StartOnNetworkThread, this)); | 745 base::Bind(&HostProcess::StartOnNetworkThread, this)); |
743 } | 746 } |
744 | 747 |
745 void HostProcess::ShutdownOnUiThread() { | 748 void HostProcess::ShutdownOnUiThread() { |
746 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 749 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
747 | 750 |
748 // Tear down resources that need to be torn down on the UI thread. | 751 // Tear down resources that need to be torn down on the UI thread. |
749 network_change_notifier_.reset(); | |
750 daemon_channel_.reset(); | 752 daemon_channel_.reset(); |
751 desktop_environment_factory_.reset(); | 753 desktop_environment_factory_.reset(); |
752 | 754 |
753 // It is now safe for the HostProcess to be deleted. | 755 // It is now safe for the HostProcess to be deleted. |
754 self_ = NULL; | 756 self_ = NULL; |
755 | 757 |
756 #if defined(OS_LINUX) | 758 #if defined(OS_LINUX) |
757 // Cause the global AudioPipeReader to be freed, otherwise the audio | 759 // Cause the global AudioPipeReader to be freed, otherwise the audio |
758 // thread will remain in-use and prevent the process from exiting. | 760 // thread will remain in-use and prevent the process from exiting. |
759 // TODO(wez): DesktopEnvironmentFactory should own the pipe reader. | 761 // TODO(wez): DesktopEnvironmentFactory should own the pipe reader. |
760 // See crbug.com/161373 and crbug.com/104544. | 762 // See crbug.com/161373 and crbug.com/104544. |
761 AudioCapturerLinux::InitializePipeReader(NULL, base::FilePath()); | 763 AudioCapturerLinux::InitializePipeReader(NULL, base::FilePath()); |
762 #endif | 764 #endif |
763 } | 765 } |
764 | 766 |
765 // Overridden from HeartbeatSender::Listener | |
766 void HostProcess::OnUnknownHostIdError() { | 767 void HostProcess::OnUnknownHostIdError() { |
767 LOG(ERROR) << "Host ID not found."; | 768 LOG(ERROR) << "Host ID not found."; |
768 ShutdownHost(kInvalidHostIdExitCode); | 769 ShutdownHost(kInvalidHostIdExitCode); |
769 } | 770 } |
770 | 771 |
771 void HostProcess::OnHeartbeatSuccessful() { | 772 void HostProcess::OnHeartbeatSuccessful() { |
772 HOST_LOG << "Host ready to receive connections."; | 773 HOST_LOG << "Host ready to receive connections."; |
773 #if defined(OS_POSIX) | 774 #if defined(OS_POSIX) |
774 if (signal_parent_) { | 775 if (signal_parent_) { |
775 kill(getppid(), SIGUSR1); | 776 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) || | 843 if (!config.GetString(kXmppLoginConfigPath, &xmpp_server_config_.username) || |
843 !(config.GetString(kXmppAuthTokenConfigPath, | 844 !(config.GetString(kXmppAuthTokenConfigPath, |
844 &xmpp_server_config_.auth_token) || | 845 &xmpp_server_config_.auth_token) || |
845 config.GetString(kOAuthRefreshTokenConfigPath, | 846 config.GetString(kOAuthRefreshTokenConfigPath, |
846 &oauth_refresh_token_))) { | 847 &oauth_refresh_token_))) { |
847 LOG(ERROR) << "XMPP credentials are not defined in the config."; | 848 LOG(ERROR) << "XMPP credentials are not defined in the config."; |
848 return false; | 849 return false; |
849 } | 850 } |
850 | 851 |
851 if (!oauth_refresh_token_.empty()) { | 852 if (!oauth_refresh_token_.empty()) { |
852 // SignalingConnector is responsible for getting OAuth token. | 853 // SignalingConnector (inside HostSignalingManager) is responsible for |
854 // getting OAuth token. | |
853 xmpp_server_config_.auth_token = ""; | 855 xmpp_server_config_.auth_token = ""; |
854 xmpp_server_config_.auth_service = "oauth2"; | 856 xmpp_server_config_.auth_service = "oauth2"; |
855 } else if (!config.GetString(kXmppAuthServiceConfigPath, | 857 } else if (!config.GetString(kXmppAuthServiceConfigPath, |
856 &xmpp_server_config_.auth_service)) { | 858 &xmpp_server_config_.auth_service)) { |
857 // For the me2me host, we default to ClientLogin token for chromiumsync | 859 // 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 | 860 // because earlier versions of the host had no HTTP stack with which to |
859 // request an OAuth2 access token. | 861 // request an OAuth2 access token. |
860 xmpp_server_config_.auth_service = kChromotingTokenDefaultServiceName; | 862 xmpp_server_config_.auth_service = kChromotingTokenDefaultServiceName; |
861 } | 863 } |
862 | 864 |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1222 } else { | 1224 } else { |
1223 HOST_LOG << "Policy disables gnubby auth."; | 1225 HOST_LOG << "Policy disables gnubby auth."; |
1224 } | 1226 } |
1225 | 1227 |
1226 if (desktop_environment_factory_) | 1228 if (desktop_environment_factory_) |
1227 desktop_environment_factory_->SetEnableGnubbyAuth(enable_gnubby_auth_); | 1229 desktop_environment_factory_->SetEnableGnubbyAuth(enable_gnubby_auth_); |
1228 | 1230 |
1229 return true; | 1231 return true; |
1230 } | 1232 } |
1231 | 1233 |
1234 scoped_ptr<HostSignalingManager> HostProcess::CreateHostSignalingManager() { | |
1235 DCHECK(!host_id_.empty()); // Assumming |ApplyConfig| has already been run. | |
Lambros
2014/12/17 23:44:34
typo: Assuming
Maybe better: |ApplyConfig| should
Łukasz Anforowicz
2014/12/18 00:03:41
Done.
| |
1236 return HostSignalingManager::Create( | |
1237 base::Bind(&HostProcess::OnHeartbeatSuccessful, | |
1238 weak_factory_for_network_task_runner_.GetWeakPtr()), | |
1239 base::Bind(&HostProcess::OnUnknownHostIdError, | |
1240 weak_factory_for_network_task_runner_.GetWeakPtr()), | |
1241 base::Bind(&HostProcess::OnAuthFailed, | |
1242 weak_factory_for_network_task_runner_.GetWeakPtr()), | |
Wez
2014/12/18 00:46:22
When you replace this with a HostSignalingManager:
Łukasz Anforowicz
2014/12/18 19:02:34
Yes. I had that in patchset #1. I think I prefer
| |
1243 *context_, xmpp_server_config_, talkgadget_prefix_, host_id_, key_pair_, | |
1244 directory_bot_jid_, oauth_refresh_token_, use_service_account_); | |
1245 } | |
1246 | |
1232 void HostProcess::StartHost() { | 1247 void HostProcess::StartHost() { |
1233 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1248 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
1234 DCHECK(!host_); | 1249 DCHECK(!host_); |
1235 DCHECK(!signal_strategy_.get()); | 1250 DCHECK(!host_signaling_manager_); |
1251 | |
1236 DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART || | 1252 DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART || |
1237 state_ == HOST_STOPPED) << state_; | 1253 state_ == HOST_STOPPED) |
1254 << "state_ = " << state_; | |
Lambros
2014/12/17 23:44:34
nit: Will fit on previous line.
Łukasz Anforowicz
2014/12/18 00:03:41
It was on a previous line until I did "git cl form
| |
1238 state_ = HOST_STARTED; | 1255 state_ = HOST_STARTED; |
1239 | 1256 |
1240 signal_strategy_.reset( | 1257 host_signaling_manager_ = CreateHostSignalingManager(); |
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 | 1258 |
1271 uint32 network_flags = 0; | 1259 uint32 network_flags = 0; |
1272 if (allow_nat_traversal_) { | 1260 if (allow_nat_traversal_) { |
1273 network_flags = NetworkSettings::NAT_TRAVERSAL_STUN | | 1261 network_flags = NetworkSettings::NAT_TRAVERSAL_STUN | |
1274 NetworkSettings::NAT_TRAVERSAL_OUTGOING; | 1262 NetworkSettings::NAT_TRAVERSAL_OUTGOING; |
1275 if (allow_relay_) | 1263 if (allow_relay_) |
1276 network_flags |= NetworkSettings::NAT_TRAVERSAL_RELAY; | 1264 network_flags |= NetworkSettings::NAT_TRAVERSAL_RELAY; |
1277 } | 1265 } |
1278 | 1266 |
1279 NetworkSettings network_settings(network_flags); | 1267 NetworkSettings network_settings(network_flags); |
1280 | 1268 |
1281 if (min_udp_port_ && max_udp_port_) { | 1269 if (min_udp_port_ && max_udp_port_) { |
1282 network_settings.min_port = min_udp_port_; | 1270 network_settings.min_port = min_udp_port_; |
1283 network_settings.max_port = max_udp_port_; | 1271 network_settings.max_port = max_udp_port_; |
1284 } else if (!allow_nat_traversal_) { | 1272 } else if (!allow_nat_traversal_) { |
1285 // For legacy reasons we have to restrict the port range to a set of default | 1273 // 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 | 1274 // values when nat traversal is disabled, even if the port range was not |
1287 // set in policy. | 1275 // set in policy. |
1288 network_settings.min_port = NetworkSettings::kDefaultMinPort; | 1276 network_settings.min_port = NetworkSettings::kDefaultMinPort; |
1289 network_settings.max_port = NetworkSettings::kDefaultMaxPort; | 1277 network_settings.max_port = NetworkSettings::kDefaultMaxPort; |
1290 } | 1278 } |
1291 | 1279 |
1292 host_.reset(new ChromotingHost( | 1280 host_.reset(new ChromotingHost( |
1293 signal_strategy_.get(), | 1281 host_signaling_manager_->signal_strategy(), |
1294 desktop_environment_factory_.get(), | 1282 desktop_environment_factory_.get(), |
1295 CreateHostSessionManager(signal_strategy_.get(), network_settings, | 1283 CreateHostSessionManager(host_signaling_manager_->signal_strategy(), |
1284 network_settings, | |
1296 context_->url_request_context_getter()), | 1285 context_->url_request_context_getter()), |
1297 context_->audio_task_runner(), | 1286 context_->audio_task_runner(), context_->input_task_runner(), |
1298 context_->input_task_runner(), | |
1299 context_->video_capture_task_runner(), | 1287 context_->video_capture_task_runner(), |
1300 context_->video_encode_task_runner(), | 1288 context_->video_encode_task_runner(), context_->network_task_runner(), |
1301 context_->network_task_runner(), | |
1302 context_->ui_task_runner())); | 1289 context_->ui_task_runner())); |
1303 | 1290 |
1304 if (enable_vp9_) { | 1291 if (enable_vp9_) { |
1305 scoped_ptr<protocol::CandidateSessionConfig> config = | 1292 scoped_ptr<protocol::CandidateSessionConfig> config = |
1306 host_->protocol_config()->Clone(); | 1293 host_->protocol_config()->Clone(); |
1307 config->EnableVideoCodec(protocol::ChannelConfig::CODEC_VP9); | 1294 config->EnableVideoCodec(protocol::ChannelConfig::CODEC_VP9); |
1308 host_->set_protocol_config(config.Pass()); | 1295 host_->set_protocol_config(config.Pass()); |
1309 } | 1296 } |
1310 | 1297 |
1311 if (frame_recorder_buffer_size_ > 0) { | 1298 if (frame_recorder_buffer_size_ > 0) { |
1312 scoped_ptr<VideoFrameRecorderHostExtension> frame_recorder_extension( | 1299 scoped_ptr<VideoFrameRecorderHostExtension> frame_recorder_extension( |
1313 new VideoFrameRecorderHostExtension()); | 1300 new VideoFrameRecorderHostExtension()); |
1314 frame_recorder_extension->SetMaxContentBytes(frame_recorder_buffer_size_); | 1301 frame_recorder_extension->SetMaxContentBytes(frame_recorder_buffer_size_); |
1315 host_->AddExtension(frame_recorder_extension.Pass()); | 1302 host_->AddExtension(frame_recorder_extension.Pass()); |
1316 } | 1303 } |
1317 | 1304 |
1318 // TODO(simonmorris): Get the maximum session duration from a policy. | 1305 // TODO(simonmorris): Get the maximum session duration from a policy. |
1319 #if defined(OS_LINUX) | 1306 #if defined(OS_LINUX) |
1320 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); | 1307 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); |
1321 #endif | 1308 #endif |
1322 | 1309 |
1323 heartbeat_sender_.reset(new HeartbeatSender( | 1310 host_change_notification_listener_.reset(new HostChangeNotificationListener( |
1324 base::Bind(&HostProcess::OnHeartbeatSuccessful, base::Unretained(this)), | 1311 this, host_id_, host_signaling_manager_->signal_strategy(), |
1325 base::Bind(&HostProcess::OnUnknownHostIdError, base::Unretained(this)), | 1312 directory_bot_jid_)); |
1326 host_id_, signal_strategy_.get(), key_pair_, directory_bot_jid_)); | |
1327 | 1313 |
1328 host_change_notification_listener_.reset(new HostChangeNotificationListener( | 1314 host_status_logger_.reset(new HostStatusLogger( |
1329 this, host_id_, signal_strategy_.get(), directory_bot_jid_)); | 1315 host_->AsWeakPtr(), ServerLogEntry::ME2ME, |
1330 | 1316 host_signaling_manager_->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 | 1317 |
1335 // Set up reporting the host status notifications. | 1318 // Set up reporting the host status notifications. |
1336 #if defined(REMOTING_MULTI_PROCESS) | 1319 #if defined(REMOTING_MULTI_PROCESS) |
1337 host_event_logger_.reset( | 1320 host_event_logger_.reset( |
1338 new IpcHostEventLogger(host_->AsWeakPtr(), daemon_channel_.get())); | 1321 new IpcHostEventLogger(host_->AsWeakPtr(), daemon_channel_.get())); |
1339 #else // !defined(REMOTING_MULTI_PROCESS) | 1322 #else // !defined(REMOTING_MULTI_PROCESS) |
1340 host_event_logger_ = | 1323 host_event_logger_ = |
1341 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); | 1324 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); |
1342 #endif // !defined(REMOTING_MULTI_PROCESS) | 1325 #endif // !defined(REMOTING_MULTI_PROCESS) |
1343 | 1326 |
(...skipping 16 matching lines...) Expand all Loading... | |
1360 } | 1343 } |
1361 | 1344 |
1362 void HostProcess::ShutdownHost(HostExitCodes exit_code) { | 1345 void HostProcess::ShutdownHost(HostExitCodes exit_code) { |
1363 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1346 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
1364 | 1347 |
1365 *exit_code_out_ = exit_code; | 1348 *exit_code_out_ = exit_code; |
1366 | 1349 |
1367 switch (state_) { | 1350 switch (state_) { |
1368 case HOST_INITIALIZING: | 1351 case HOST_INITIALIZING: |
1369 state_ = HOST_STOPPING; | 1352 state_ = HOST_STOPPING; |
1353 { | |
1354 DCHECK(!host_signaling_manager_); | |
1355 scoped_ptr<HostSignalingManager> tmp_signaling_manager = | |
1356 CreateHostSignalingManager(); | |
1357 tmp_signaling_manager.release()->SendHostOfflineReasonAndDelete( | |
1358 ExitCodeToString(exit_code), | |
1359 base::TimeDelta::FromSeconds(kHostOfflineReasonTimeoutSeconds)); | |
1360 } | |
1370 ShutdownOnNetworkThread(); | 1361 ShutdownOnNetworkThread(); |
Wez
2014/12/18 00:46:22
This and the HOST_STARTED case are now almost iden
Łukasz Anforowicz
2014/12/18 19:02:34
Ok.
| |
1371 break; | 1362 break; |
1372 | 1363 |
1373 case HOST_STARTED: | 1364 case HOST_STARTED: |
1374 state_ = HOST_STOPPING; | 1365 state_ = HOST_STOPPING; |
1375 heartbeat_sender_->SetHostOfflineReason( | 1366 host_signaling_manager_.release()->SendHostOfflineReasonAndDelete( |
1376 ExitCodeToString(exit_code), base::Bind(base::DoNothing)); | 1367 ExitCodeToString(exit_code), |
1377 ScheduleHostShutdown(); | 1368 base::TimeDelta::FromSeconds(kHostOfflineReasonTimeoutSeconds)); |
1369 ShutdownOnNetworkThread(); | |
1378 break; | 1370 break; |
1379 | 1371 |
1380 case HOST_STOPPING_TO_RESTART: | 1372 case HOST_STOPPING_TO_RESTART: |
1381 state_ = HOST_STOPPING; | 1373 state_ = HOST_STOPPING; |
1382 break; | 1374 break; |
1383 | 1375 |
1384 case HOST_STOPPING: | 1376 case HOST_STOPPING: |
1385 case HOST_STOPPED: | 1377 case HOST_STOPPED: |
1386 // Host is already stopped or being stopped. No action is required. | 1378 // Host is already stopped or being stopped. No action is required. |
1387 break; | 1379 break; |
1388 } | 1380 } |
1389 } | 1381 } |
1390 | 1382 |
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() { | 1383 void HostProcess::ShutdownOnNetworkThread() { |
1402 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1384 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
1403 | 1385 |
1386 // Need to invalidate WeakPtrs on the same thread where they are dereferenced. | |
1387 weak_factory_for_network_task_runner_.InvalidateWeakPtrs(); | |
1388 | |
1404 host_.reset(); | 1389 host_.reset(); |
1405 host_event_logger_.reset(); | 1390 host_event_logger_.reset(); |
1406 host_status_logger_.reset(); | 1391 host_status_logger_.reset(); |
1407 heartbeat_sender_.reset(); | 1392 host_signaling_manager_.reset(); |
1408 host_change_notification_listener_.reset(); | 1393 host_change_notification_listener_.reset(); |
1409 signaling_connector_.reset(); | |
1410 oauth_token_getter_.reset(); | |
1411 signal_strategy_.reset(); | |
1412 network_change_notifier_.reset(); | |
1413 | 1394 |
1414 if (state_ == HOST_STOPPING_TO_RESTART) { | 1395 if (state_ == HOST_STOPPING_TO_RESTART) { |
1415 StartHost(); | 1396 StartHost(); |
1416 } else if (state_ == HOST_STOPPING) { | 1397 } else if (state_ == HOST_STOPPING) { |
1417 state_ = HOST_STOPPED; | 1398 state_ = HOST_STOPPED; |
1418 | 1399 |
1419 if (policy_watcher_.get()) { | 1400 if (policy_watcher_.get()) { |
1420 policy_watcher_->StopWatching( | 1401 policy_watcher_->StopWatching( |
1421 base::Bind(&HostProcess::OnPolicyWatcherShutdown, this)); | 1402 base::Bind(&HostProcess::OnPolicyWatcherShutdown, this)); |
1422 } else { | 1403 } else { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1481 int exit_code = kSuccessExitCode; | 1462 int exit_code = kSuccessExitCode; |
1482 new HostProcess(context.Pass(), &exit_code); | 1463 new HostProcess(context.Pass(), &exit_code); |
1483 | 1464 |
1484 // Run the main (also UI) message loop until the host no longer needs it. | 1465 // Run the main (also UI) message loop until the host no longer needs it. |
1485 message_loop.Run(); | 1466 message_loop.Run(); |
1486 | 1467 |
1487 return exit_code; | 1468 return exit_code; |
1488 } | 1469 } |
1489 | 1470 |
1490 } // namespace remoting | 1471 } // namespace remoting |
OLD | NEW |