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/synchronization/waitable_event.h" | 23 #include "base/synchronization/waitable_event.h" |
23 #include "base/threading/thread.h" | 24 #include "base/threading/thread.h" |
24 #include "build/build_config.h" | 25 #include "build/build_config.h" |
25 #include "crypto/nss_util.h" | 26 #include "crypto/nss_util.h" |
26 #include "ipc/ipc_channel.h" | 27 #include "ipc/ipc_channel.h" |
27 #include "ipc/ipc_channel_proxy.h" | 28 #include "ipc/ipc_channel_proxy.h" |
28 #include "ipc/ipc_listener.h" | 29 #include "ipc/ipc_listener.h" |
29 #include "media/base/media.h" | 30 #include "media/base/media.h" |
30 #include "net/base/network_change_notifier.h" | |
31 #include "net/socket/client_socket_factory.h" | 31 #include "net/socket/client_socket_factory.h" |
32 #include "net/socket/ssl_server_socket.h" | 32 #include "net/socket/ssl_server_socket.h" |
33 #include "net/url_request/url_fetcher.h" | 33 #include "net/url_request/url_fetcher.h" |
34 #include "remoting/base/auto_thread_task_runner.h" | 34 #include "remoting/base/auto_thread_task_runner.h" |
35 #include "remoting/base/breakpad.h" | 35 #include "remoting/base/breakpad.h" |
36 #include "remoting/base/constants.h" | 36 #include "remoting/base/constants.h" |
37 #include "remoting/base/logging.h" | 37 #include "remoting/base/logging.h" |
38 #include "remoting/base/rsa_key_pair.h" | 38 #include "remoting/base/rsa_key_pair.h" |
39 #include "remoting/base/service_urls.h" | 39 #include "remoting/base/service_urls.h" |
40 #include "remoting/base/util.h" | 40 #include "remoting/base/util.h" |
41 #include "remoting/host/branding.h" | 41 #include "remoting/host/branding.h" |
42 #include "remoting/host/chromoting_host.h" | 42 #include "remoting/host/chromoting_host.h" |
43 #include "remoting/host/chromoting_host_context.h" | 43 #include "remoting/host/chromoting_host_context.h" |
44 #include "remoting/host/chromoting_messages.h" | 44 #include "remoting/host/chromoting_messages.h" |
45 #include "remoting/host/config_file_watcher.h" | 45 #include "remoting/host/config_file_watcher.h" |
46 #include "remoting/host/config_watcher.h" | 46 #include "remoting/host/config_watcher.h" |
47 #include "remoting/host/desktop_environment.h" | 47 #include "remoting/host/desktop_environment.h" |
48 #include "remoting/host/desktop_session_connector.h" | 48 #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" | 49 #include "remoting/host/host_change_notification_listener.h" |
52 #include "remoting/host/host_config.h" | 50 #include "remoting/host/host_config.h" |
53 #include "remoting/host/host_event_logger.h" | 51 #include "remoting/host/host_event_logger.h" |
54 #include "remoting/host/host_exit_codes.h" | 52 #include "remoting/host/host_exit_codes.h" |
55 #include "remoting/host/host_main.h" | 53 #include "remoting/host/host_main.h" |
56 #include "remoting/host/host_status_logger.h" | 54 #include "remoting/host/host_status_logger.h" |
57 #include "remoting/host/ipc_constants.h" | 55 #include "remoting/host/ipc_constants.h" |
58 #include "remoting/host/ipc_desktop_environment.h" | 56 #include "remoting/host/ipc_desktop_environment.h" |
59 #include "remoting/host/ipc_host_event_logger.h" | 57 #include "remoting/host/ipc_host_event_logger.h" |
60 #include "remoting/host/json_host_config.h" | 58 #include "remoting/host/json_host_config.h" |
61 #include "remoting/host/logging.h" | 59 #include "remoting/host/logging.h" |
62 #include "remoting/host/me2me_desktop_environment.h" | 60 #include "remoting/host/me2me_desktop_environment.h" |
| 61 #include "remoting/host/minimum_heartbeat_supporter.h" |
63 #include "remoting/host/pairing_registry_delegate.h" | 62 #include "remoting/host/pairing_registry_delegate.h" |
64 #include "remoting/host/policy_hack/policy_watcher.h" | 63 #include "remoting/host/policy_hack/policy_watcher.h" |
65 #include "remoting/host/session_manager_factory.h" | 64 #include "remoting/host/session_manager_factory.h" |
66 #include "remoting/host/signaling_connector.h" | |
67 #include "remoting/host/single_window_desktop_environment.h" | 65 #include "remoting/host/single_window_desktop_environment.h" |
68 #include "remoting/host/token_validator_factory_impl.h" | 66 #include "remoting/host/token_validator_factory_impl.h" |
69 #include "remoting/host/usage_stats_consent.h" | 67 #include "remoting/host/usage_stats_consent.h" |
70 #include "remoting/host/username.h" | 68 #include "remoting/host/username.h" |
71 #include "remoting/host/video_frame_recorder_host_extension.h" | 69 #include "remoting/host/video_frame_recorder_host_extension.h" |
72 #include "remoting/protocol/me2me_host_authenticator_factory.h" | 70 #include "remoting/protocol/me2me_host_authenticator_factory.h" |
73 #include "remoting/protocol/network_settings.h" | 71 #include "remoting/protocol/network_settings.h" |
74 #include "remoting/protocol/pairing_registry.h" | 72 #include "remoting/protocol/pairing_registry.h" |
75 #include "remoting/protocol/token_validator.h" | 73 #include "remoting/protocol/token_validator.h" |
76 #include "remoting/signaling/xmpp_signal_strategy.h" | 74 #include "remoting/signaling/xmpp_signal_strategy.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 bool OnUsernamePolicyUpdate(base::DictionaryValue* policies); | 233 bool OnUsernamePolicyUpdate(base::DictionaryValue* policies); |
236 bool OnNatPolicyUpdate(base::DictionaryValue* policies); | 234 bool OnNatPolicyUpdate(base::DictionaryValue* policies); |
237 bool OnRelayPolicyUpdate(base::DictionaryValue* policies); | 235 bool OnRelayPolicyUpdate(base::DictionaryValue* policies); |
238 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies); | 236 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies); |
239 bool OnCurtainPolicyUpdate(base::DictionaryValue* policies); | 237 bool OnCurtainPolicyUpdate(base::DictionaryValue* policies); |
240 bool OnHostTalkGadgetPrefixPolicyUpdate(base::DictionaryValue* policies); | 238 bool OnHostTalkGadgetPrefixPolicyUpdate(base::DictionaryValue* policies); |
241 bool OnHostTokenUrlPolicyUpdate(base::DictionaryValue* policies); | 239 bool OnHostTokenUrlPolicyUpdate(base::DictionaryValue* policies); |
242 bool OnPairingPolicyUpdate(base::DictionaryValue* policies); | 240 bool OnPairingPolicyUpdate(base::DictionaryValue* policies); |
243 bool OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies); | 241 bool OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies); |
244 | 242 |
| 243 scoped_refptr<MinimumHeartbeatSupporter> CreateMinimumHeartbeatSupporter(); |
| 244 |
245 void StartHost(); | 245 void StartHost(); |
246 | 246 |
247 void OnHeartbeatSuccessful(); | 247 void OnHeartbeatSuccessful(); |
248 void OnUnknownHostIdError(); | 248 void OnUnknownHostIdError(); |
249 | 249 |
250 void OnAuthFailed(); | 250 void OnAuthFailed(); |
251 | 251 |
252 void RestartHost(); | 252 void RestartHost(); |
253 | 253 |
254 // 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|. |
255 void ShutdownHost(HostExitCodes exit_code); | 255 void ShutdownHost(HostExitCodes exit_code); |
256 | 256 |
257 void ScheduleHostShutdown(); | |
258 | |
259 void ShutdownOnNetworkThread(); | 257 void ShutdownOnNetworkThread(); |
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 base::WeakPtrFactory<HostProcess> weak_factory_for_network_task_runner_; |
343 }; | 336 }; |
344 | 337 |
345 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, | 338 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, |
346 int* exit_code_out) | 339 int* exit_code_out) |
347 : context_(context.Pass()), | 340 : context_(context.Pass()), |
348 state_(HOST_INITIALIZING), | 341 state_(HOST_INITIALIZING), |
349 use_service_account_(false), | 342 use_service_account_(false), |
350 enable_vp9_(false), | 343 enable_vp9_(false), |
351 frame_recorder_buffer_size_(0), | 344 frame_recorder_buffer_size_(0), |
352 host_username_match_required_(false), | 345 host_username_match_required_(false), |
353 allow_nat_traversal_(true), | 346 allow_nat_traversal_(true), |
354 allow_relay_(true), | 347 allow_relay_(true), |
355 min_udp_port_(0), | 348 min_udp_port_(0), |
356 max_udp_port_(0), | 349 max_udp_port_(0), |
357 allow_pairing_(true), | 350 allow_pairing_(true), |
358 curtain_required_(false), | 351 curtain_required_(false), |
359 enable_gnubby_auth_(false), | 352 enable_gnubby_auth_(false), |
360 enable_window_capture_(false), | 353 enable_window_capture_(false), |
361 window_id_(0), | 354 window_id_(0), |
362 #if defined(REMOTING_MULTI_PROCESS) | 355 #if defined(REMOTING_MULTI_PROCESS) |
363 desktop_session_connector_(NULL), | 356 desktop_session_connector_(NULL), |
364 #endif // defined(REMOTING_MULTI_PROCESS) | 357 #endif // defined(REMOTING_MULTI_PROCESS) |
365 self_(this), | 358 self_(this), |
366 exit_code_out_(exit_code_out), | 359 exit_code_out_(exit_code_out), |
367 signal_parent_(false) { | 360 signal_parent_(false), |
| 361 weak_factory_for_network_task_runner_(this) { |
368 StartOnUiThread(); | 362 StartOnUiThread(); |
369 } | 363 } |
370 | 364 |
371 HostProcess::~HostProcess() { | 365 HostProcess::~HostProcess() { |
372 // Verify that UI components have been torn down. | 366 // Verify that UI components have been torn down. |
373 DCHECK(!config_watcher_); | 367 DCHECK(!config_watcher_); |
374 DCHECK(!daemon_channel_); | 368 DCHECK(!daemon_channel_); |
375 DCHECK(!desktop_environment_factory_); | 369 DCHECK(!desktop_environment_factory_); |
376 | 370 |
377 // We might be getting deleted on one of the threads the |host_context| owns, | 371 // We might be getting deleted on one of the threads the |host_context| owns, |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 | 732 |
739 context_->network_task_runner()->PostTask( | 733 context_->network_task_runner()->PostTask( |
740 FROM_HERE, | 734 FROM_HERE, |
741 base::Bind(&HostProcess::StartOnNetworkThread, this)); | 735 base::Bind(&HostProcess::StartOnNetworkThread, this)); |
742 } | 736 } |
743 | 737 |
744 void HostProcess::ShutdownOnUiThread() { | 738 void HostProcess::ShutdownOnUiThread() { |
745 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 739 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
746 | 740 |
747 // Tear down resources that need to be torn down on the UI thread. | 741 // Tear down resources that need to be torn down on the UI thread. |
748 network_change_notifier_.reset(); | |
749 daemon_channel_.reset(); | 742 daemon_channel_.reset(); |
750 desktop_environment_factory_.reset(); | 743 desktop_environment_factory_.reset(); |
751 | 744 |
752 // It is now safe for the HostProcess to be deleted. | 745 // It is now safe for the HostProcess to be deleted. |
753 self_ = NULL; | 746 self_ = NULL; |
754 | 747 |
755 #if defined(OS_LINUX) | 748 #if defined(OS_LINUX) |
756 // Cause the global AudioPipeReader to be freed, otherwise the audio | 749 // Cause the global AudioPipeReader to be freed, otherwise the audio |
757 // thread will remain in-use and prevent the process from exiting. | 750 // thread will remain in-use and prevent the process from exiting. |
758 // TODO(wez): DesktopEnvironmentFactory should own the pipe reader. | 751 // TODO(wez): DesktopEnvironmentFactory should own the pipe reader. |
759 // See crbug.com/161373 and crbug.com/104544. | 752 // See crbug.com/161373 and crbug.com/104544. |
760 AudioCapturerLinux::InitializePipeReader(NULL, base::FilePath()); | 753 AudioCapturerLinux::InitializePipeReader(NULL, base::FilePath()); |
761 #endif | 754 #endif |
762 } | 755 } |
763 | 756 |
764 // Overridden from HeartbeatSender::Listener | |
765 void HostProcess::OnUnknownHostIdError() { | 757 void HostProcess::OnUnknownHostIdError() { |
766 LOG(ERROR) << "Host ID not found."; | 758 LOG(ERROR) << "Host ID not found."; |
767 ShutdownHost(kInvalidHostIdExitCode); | 759 ShutdownHost(kInvalidHostIdExitCode); |
768 } | 760 } |
769 | 761 |
770 void HostProcess::OnHeartbeatSuccessful() { | 762 void HostProcess::OnHeartbeatSuccessful() { |
771 HOST_LOG << "Host ready to receive connections."; | 763 HOST_LOG << "Host ready to receive connections."; |
772 #if defined(OS_POSIX) | 764 #if defined(OS_POSIX) |
773 if (signal_parent_) { | 765 if (signal_parent_) { |
774 kill(getppid(), SIGUSR1); | 766 kill(getppid(), SIGUSR1); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 if (!config->GetString(kXmppLoginConfigPath, &xmpp_server_config_.username) || | 833 if (!config->GetString(kXmppLoginConfigPath, &xmpp_server_config_.username) || |
842 !(config->GetString(kXmppAuthTokenConfigPath, | 834 !(config->GetString(kXmppAuthTokenConfigPath, |
843 &xmpp_server_config_.auth_token) || | 835 &xmpp_server_config_.auth_token) || |
844 config->GetString(kOAuthRefreshTokenConfigPath, | 836 config->GetString(kOAuthRefreshTokenConfigPath, |
845 &oauth_refresh_token_))) { | 837 &oauth_refresh_token_))) { |
846 LOG(ERROR) << "XMPP credentials are not defined in the config."; | 838 LOG(ERROR) << "XMPP credentials are not defined in the config."; |
847 return false; | 839 return false; |
848 } | 840 } |
849 | 841 |
850 if (!oauth_refresh_token_.empty()) { | 842 if (!oauth_refresh_token_.empty()) { |
851 // SignalingConnector is responsible for getting OAuth token. | 843 // SignalingConnector (inside MinimumHeartbeatSupporter) is responsible for |
| 844 // getting OAuth token. |
852 xmpp_server_config_.auth_token = ""; | 845 xmpp_server_config_.auth_token = ""; |
853 xmpp_server_config_.auth_service = "oauth2"; | 846 xmpp_server_config_.auth_service = "oauth2"; |
854 } else if (!config->GetString(kXmppAuthServiceConfigPath, | 847 } else if (!config->GetString(kXmppAuthServiceConfigPath, |
855 &xmpp_server_config_.auth_service)) { | 848 &xmpp_server_config_.auth_service)) { |
856 // For the me2me host, we default to ClientLogin token for chromiumsync | 849 // For the me2me host, we default to ClientLogin token for chromiumsync |
857 // because earlier versions of the host had no HTTP stack with which to | 850 // because earlier versions of the host had no HTTP stack with which to |
858 // request an OAuth2 access token. | 851 // request an OAuth2 access token. |
859 xmpp_server_config_.auth_service = kChromotingTokenDefaultServiceName; | 852 xmpp_server_config_.auth_service = kChromotingTokenDefaultServiceName; |
860 } | 853 } |
861 | 854 |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1221 } else { | 1214 } else { |
1222 HOST_LOG << "Policy disables gnubby auth."; | 1215 HOST_LOG << "Policy disables gnubby auth."; |
1223 } | 1216 } |
1224 | 1217 |
1225 if (desktop_environment_factory_) | 1218 if (desktop_environment_factory_) |
1226 desktop_environment_factory_->SetEnableGnubbyAuth(enable_gnubby_auth_); | 1219 desktop_environment_factory_->SetEnableGnubbyAuth(enable_gnubby_auth_); |
1227 | 1220 |
1228 return true; | 1221 return true; |
1229 } | 1222 } |
1230 | 1223 |
| 1224 scoped_refptr<MinimumHeartbeatSupporter> |
| 1225 HostProcess::CreateMinimumHeartbeatSupporter() { |
| 1226 DCHECK(!host_id_.empty()); // assumming |ApplyConfig| has already been run |
| 1227 return MinimumHeartbeatSupporter::Create( |
| 1228 base::Bind(&HostProcess::OnHeartbeatSuccessful, |
| 1229 weak_factory_for_network_task_runner_.GetWeakPtr()), |
| 1230 base::Bind(&HostProcess::OnUnknownHostIdError, |
| 1231 weak_factory_for_network_task_runner_.GetWeakPtr()), |
| 1232 base::Bind(&HostProcess::OnAuthFailed, |
| 1233 weak_factory_for_network_task_runner_.GetWeakPtr()), |
| 1234 *context_, |
| 1235 xmpp_server_config_, |
| 1236 talkgadget_prefix_, |
| 1237 host_id_, |
| 1238 key_pair_, |
| 1239 directory_bot_jid_, |
| 1240 oauth_refresh_token_, |
| 1241 use_service_account_); |
| 1242 } |
| 1243 |
1231 void HostProcess::StartHost() { | 1244 void HostProcess::StartHost() { |
1232 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1245 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
1233 DCHECK(!host_); | 1246 DCHECK(!host_); |
1234 DCHECK(!signal_strategy_.get()); | 1247 DCHECK(!minimum_heartbeat_supporter_.get()); |
| 1248 |
1235 DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART || | 1249 DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART || |
1236 state_ == HOST_STOPPED) << state_; | 1250 state_ == HOST_STOPPED) << state_; |
1237 state_ = HOST_STARTED; | 1251 state_ = HOST_STARTED; |
1238 | 1252 |
1239 signal_strategy_.reset( | 1253 minimum_heartbeat_supporter_ = CreateMinimumHeartbeatSupporter(); |
1240 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), | |
1241 context_->url_request_context_getter(), | |
1242 xmpp_server_config_)); | |
1243 | |
1244 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker( | |
1245 new DnsBlackholeChecker(context_->url_request_context_getter(), | |
1246 talkgadget_prefix_)); | |
1247 | |
1248 // Create a NetworkChangeNotifier for use by the signaling connector. | |
1249 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | |
1250 | |
1251 signaling_connector_.reset(new SignalingConnector( | |
1252 signal_strategy_.get(), | |
1253 dns_blackhole_checker.Pass(), | |
1254 base::Bind(&HostProcess::OnAuthFailed, this))); | |
1255 | |
1256 if (!oauth_refresh_token_.empty()) { | |
1257 scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials; | |
1258 oauth_credentials.reset( | |
1259 new OAuthTokenGetter::OAuthCredentials( | |
1260 xmpp_server_config_.username, oauth_refresh_token_, | |
1261 use_service_account_)); | |
1262 | |
1263 oauth_token_getter_.reset(new OAuthTokenGetter( | |
1264 oauth_credentials.Pass(), context_->url_request_context_getter(), | |
1265 false)); | |
1266 | |
1267 signaling_connector_->EnableOAuth(oauth_token_getter_.get()); | |
1268 } | |
1269 | 1254 |
1270 uint32 network_flags = 0; | 1255 uint32 network_flags = 0; |
1271 if (allow_nat_traversal_) { | 1256 if (allow_nat_traversal_) { |
1272 network_flags = NetworkSettings::NAT_TRAVERSAL_STUN | | 1257 network_flags = NetworkSettings::NAT_TRAVERSAL_STUN | |
1273 NetworkSettings::NAT_TRAVERSAL_OUTGOING; | 1258 NetworkSettings::NAT_TRAVERSAL_OUTGOING; |
1274 if (allow_relay_) | 1259 if (allow_relay_) |
1275 network_flags |= NetworkSettings::NAT_TRAVERSAL_RELAY; | 1260 network_flags |= NetworkSettings::NAT_TRAVERSAL_RELAY; |
1276 } | 1261 } |
1277 | 1262 |
1278 NetworkSettings network_settings(network_flags); | 1263 NetworkSettings network_settings(network_flags); |
1279 | 1264 |
1280 if (min_udp_port_ && max_udp_port_) { | 1265 if (min_udp_port_ && max_udp_port_) { |
1281 network_settings.min_port = min_udp_port_; | 1266 network_settings.min_port = min_udp_port_; |
1282 network_settings.max_port = max_udp_port_; | 1267 network_settings.max_port = max_udp_port_; |
1283 } else if (!allow_nat_traversal_) { | 1268 } else if (!allow_nat_traversal_) { |
1284 // For legacy reasons we have to restrict the port range to a set of default | 1269 // For legacy reasons we have to restrict the port range to a set of default |
1285 // values when nat traversal is disabled, even if the port range was not | 1270 // values when nat traversal is disabled, even if the port range was not |
1286 // set in policy. | 1271 // set in policy. |
1287 network_settings.min_port = NetworkSettings::kDefaultMinPort; | 1272 network_settings.min_port = NetworkSettings::kDefaultMinPort; |
1288 network_settings.max_port = NetworkSettings::kDefaultMaxPort; | 1273 network_settings.max_port = NetworkSettings::kDefaultMaxPort; |
1289 } | 1274 } |
1290 | 1275 |
1291 host_.reset(new ChromotingHost( | 1276 host_.reset(new ChromotingHost( |
1292 signal_strategy_.get(), | 1277 minimum_heartbeat_supporter_->GetSignalStrategy(), |
1293 desktop_environment_factory_.get(), | 1278 desktop_environment_factory_.get(), |
1294 CreateHostSessionManager(signal_strategy_.get(), network_settings, | 1279 CreateHostSessionManager( |
1295 context_->url_request_context_getter()), | 1280 minimum_heartbeat_supporter_->GetSignalStrategy(), |
| 1281 network_settings, |
| 1282 context_->url_request_context_getter()), |
1296 context_->audio_task_runner(), | 1283 context_->audio_task_runner(), |
1297 context_->input_task_runner(), | 1284 context_->input_task_runner(), |
1298 context_->video_capture_task_runner(), | 1285 context_->video_capture_task_runner(), |
1299 context_->video_encode_task_runner(), | 1286 context_->video_encode_task_runner(), |
1300 context_->network_task_runner(), | 1287 context_->network_task_runner(), |
1301 context_->ui_task_runner())); | 1288 context_->ui_task_runner())); |
1302 | 1289 |
1303 if (enable_vp9_) { | 1290 if (enable_vp9_) { |
1304 scoped_ptr<protocol::CandidateSessionConfig> config = | 1291 scoped_ptr<protocol::CandidateSessionConfig> config = |
1305 host_->protocol_config()->Clone(); | 1292 host_->protocol_config()->Clone(); |
1306 config->EnableVideoCodec(protocol::ChannelConfig::CODEC_VP9); | 1293 config->EnableVideoCodec(protocol::ChannelConfig::CODEC_VP9); |
1307 host_->set_protocol_config(config.Pass()); | 1294 host_->set_protocol_config(config.Pass()); |
1308 } | 1295 } |
1309 | 1296 |
1310 if (frame_recorder_buffer_size_ > 0) { | 1297 if (frame_recorder_buffer_size_ > 0) { |
1311 scoped_ptr<VideoFrameRecorderHostExtension> frame_recorder_extension( | 1298 scoped_ptr<VideoFrameRecorderHostExtension> frame_recorder_extension( |
1312 new VideoFrameRecorderHostExtension()); | 1299 new VideoFrameRecorderHostExtension()); |
1313 frame_recorder_extension->SetMaxContentBytes(frame_recorder_buffer_size_); | 1300 frame_recorder_extension->SetMaxContentBytes(frame_recorder_buffer_size_); |
1314 host_->AddExtension(frame_recorder_extension.Pass()); | 1301 host_->AddExtension(frame_recorder_extension.Pass()); |
1315 } | 1302 } |
1316 | 1303 |
1317 // TODO(simonmorris): Get the maximum session duration from a policy. | 1304 // TODO(simonmorris): Get the maximum session duration from a policy. |
1318 #if defined(OS_LINUX) | 1305 #if defined(OS_LINUX) |
1319 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); | 1306 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); |
1320 #endif | 1307 #endif |
1321 | 1308 |
1322 heartbeat_sender_.reset(new HeartbeatSender( | 1309 host_change_notification_listener_.reset( |
1323 base::Bind(&HostProcess::OnHeartbeatSuccessful, base::Unretained(this)), | 1310 new HostChangeNotificationListener( |
1324 base::Bind(&HostProcess::OnUnknownHostIdError, base::Unretained(this)), | 1311 this, |
1325 host_id_, signal_strategy_.get(), key_pair_, directory_bot_jid_)); | 1312 host_id_, |
1326 | 1313 minimum_heartbeat_supporter_->GetSignalStrategy(), |
1327 host_change_notification_listener_.reset(new HostChangeNotificationListener( | 1314 directory_bot_jid_)); |
1328 this, host_id_, signal_strategy_.get(), directory_bot_jid_)); | |
1329 | 1315 |
1330 host_status_logger_.reset( | 1316 host_status_logger_.reset( |
1331 new HostStatusLogger(host_->AsWeakPtr(), ServerLogEntry::ME2ME, | 1317 new HostStatusLogger( |
1332 signal_strategy_.get(), directory_bot_jid_)); | 1318 host_->AsWeakPtr(), |
| 1319 ServerLogEntry::ME2ME, |
| 1320 minimum_heartbeat_supporter_->GetSignalStrategy(), |
| 1321 directory_bot_jid_)); |
1333 | 1322 |
1334 // Set up reporting the host status notifications. | 1323 // Set up reporting the host status notifications. |
1335 #if defined(REMOTING_MULTI_PROCESS) | 1324 #if defined(REMOTING_MULTI_PROCESS) |
1336 host_event_logger_.reset( | 1325 host_event_logger_.reset( |
1337 new IpcHostEventLogger(host_->AsWeakPtr(), daemon_channel_.get())); | 1326 new IpcHostEventLogger(host_->AsWeakPtr(), daemon_channel_.get())); |
1338 #else // !defined(REMOTING_MULTI_PROCESS) | 1327 #else // !defined(REMOTING_MULTI_PROCESS) |
1339 host_event_logger_ = | 1328 host_event_logger_ = |
1340 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); | 1329 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); |
1341 #endif // !defined(REMOTING_MULTI_PROCESS) | 1330 #endif // !defined(REMOTING_MULTI_PROCESS) |
1342 | 1331 |
(...skipping 16 matching lines...) Expand all Loading... |
1359 } | 1348 } |
1360 | 1349 |
1361 void HostProcess::ShutdownHost(HostExitCodes exit_code) { | 1350 void HostProcess::ShutdownHost(HostExitCodes exit_code) { |
1362 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1351 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
1363 | 1352 |
1364 *exit_code_out_ = exit_code; | 1353 *exit_code_out_ = exit_code; |
1365 | 1354 |
1366 switch (state_) { | 1355 switch (state_) { |
1367 case HOST_INITIALIZING: | 1356 case HOST_INITIALIZING: |
1368 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 } |
1369 ShutdownOnNetworkThread(); | 1366 ShutdownOnNetworkThread(); |
1370 break; | 1367 break; |
1371 | 1368 |
1372 case HOST_STARTED: | 1369 case HOST_STARTED: |
1373 state_ = HOST_STOPPING; | 1370 state_ = HOST_STOPPING; |
1374 heartbeat_sender_->SetHostOfflineReason( | 1371 minimum_heartbeat_supporter_->SendHostOfflineReason( |
1375 ExitCodeToString(exit_code), base::Bind(base::DoNothing)); | 1372 ExitCodeToString(exit_code), |
1376 ScheduleHostShutdown(); | 1373 base::TimeDelta::FromSeconds(30) /* timeout */); |
| 1374 ShutdownOnNetworkThread(); |
1377 break; | 1375 break; |
1378 | 1376 |
1379 case HOST_STOPPING_TO_RESTART: | 1377 case HOST_STOPPING_TO_RESTART: |
1380 state_ = HOST_STOPPING; | 1378 state_ = HOST_STOPPING; |
1381 break; | 1379 break; |
1382 | 1380 |
1383 case HOST_STOPPING: | 1381 case HOST_STOPPING: |
1384 case HOST_STOPPED: | 1382 case HOST_STOPPED: |
1385 // Host is already stopped or being stopped. No action is required. | 1383 // Host is already stopped or being stopped. No action is required. |
1386 break; | 1384 break; |
1387 } | 1385 } |
1388 } | 1386 } |
1389 | 1387 |
1390 // TODO(weitaosu): shut down the host once we get an ACK for the offline status | |
1391 // XMPP message. | |
1392 void HostProcess::ScheduleHostShutdown() { | |
1393 // Delay the shutdown by 2 second to allow SendOfflineStatus to complete. | |
1394 context_->network_task_runner()->PostDelayedTask( | |
1395 FROM_HERE, | |
1396 base::Bind(&HostProcess::ShutdownOnNetworkThread, base::Unretained(this)), | |
1397 base::TimeDelta::FromSeconds(2)); | |
1398 } | |
1399 | |
1400 void HostProcess::ShutdownOnNetworkThread() { | 1388 void HostProcess::ShutdownOnNetworkThread() { |
1401 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1389 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
1402 | 1390 |
| 1391 // Need to invalidate WeakPtrs on the same thread where they are dereferenced. |
| 1392 weak_factory_for_network_task_runner_.InvalidateWeakPtrs(); |
| 1393 |
1403 host_.reset(); | 1394 host_.reset(); |
1404 host_event_logger_.reset(); | 1395 host_event_logger_.reset(); |
1405 host_status_logger_.reset(); | 1396 host_status_logger_.reset(); |
1406 heartbeat_sender_.reset(); | 1397 minimum_heartbeat_supporter_ = nullptr; |
1407 host_change_notification_listener_.reset(); | 1398 host_change_notification_listener_.reset(); |
1408 signaling_connector_.reset(); | |
1409 oauth_token_getter_.reset(); | |
1410 signal_strategy_.reset(); | |
1411 network_change_notifier_.reset(); | |
1412 | 1399 |
1413 if (state_ == HOST_STOPPING_TO_RESTART) { | 1400 if (state_ == HOST_STOPPING_TO_RESTART) { |
1414 StartHost(); | 1401 StartHost(); |
1415 } else if (state_ == HOST_STOPPING) { | 1402 } else if (state_ == HOST_STOPPING) { |
1416 state_ = HOST_STOPPED; | 1403 state_ = HOST_STOPPED; |
1417 | 1404 |
1418 if (policy_watcher_.get()) { | 1405 if (policy_watcher_.get()) { |
1419 base::WaitableEvent done_event(true, false); | 1406 base::WaitableEvent done_event(true, false); |
1420 policy_watcher_->StopWatching(&done_event); | 1407 policy_watcher_->StopWatching(&done_event); |
1421 done_event.Wait(); | 1408 done_event.Wait(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1479 int exit_code = kSuccessExitCode; | 1466 int exit_code = kSuccessExitCode; |
1480 new HostProcess(context.Pass(), &exit_code); | 1467 new HostProcess(context.Pass(), &exit_code); |
1481 | 1468 |
1482 // 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. |
1483 message_loop.Run(); | 1470 message_loop.Run(); |
1484 | 1471 |
1485 return exit_code; | 1472 return exit_code; |
1486 } | 1473 } |
1487 | 1474 |
1488 } // namespace remoting | 1475 } // namespace remoting |
OLD | NEW |