Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: remoting/host/remoting_me2me_host.cc

Issue 719983002: Reporting of policy errors via host-offline-reason: part 3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hor-nohoststatussender
Patch Set: Rebasing... Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 733
740 context_->network_task_runner()->PostTask( 734 context_->network_task_runner()->PostTask(
741 FROM_HERE, 735 FROM_HERE,
742 base::Bind(&HostProcess::StartOnNetworkThread, this)); 736 base::Bind(&HostProcess::StartOnNetworkThread, this));
743 } 737 }
744 738
745 void HostProcess::ShutdownOnUiThread() { 739 void HostProcess::ShutdownOnUiThread() {
746 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); 740 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
747 741
748 // Tear down resources that need to be torn down on the UI thread. 742 // Tear down resources that need to be torn down on the UI thread.
749 network_change_notifier_.reset();
750 daemon_channel_.reset(); 743 daemon_channel_.reset();
751 desktop_environment_factory_.reset(); 744 desktop_environment_factory_.reset();
752 745
753 // It is now safe for the HostProcess to be deleted. 746 // It is now safe for the HostProcess to be deleted.
754 self_ = NULL; 747 self_ = NULL;
755 748
756 #if defined(OS_LINUX) 749 #if defined(OS_LINUX)
757 // Cause the global AudioPipeReader to be freed, otherwise the audio 750 // Cause the global AudioPipeReader to be freed, otherwise the audio
758 // thread will remain in-use and prevent the process from exiting. 751 // thread will remain in-use and prevent the process from exiting.
759 // TODO(wez): DesktopEnvironmentFactory should own the pipe reader. 752 // TODO(wez): DesktopEnvironmentFactory should own the pipe reader.
760 // See crbug.com/161373 and crbug.com/104544. 753 // See crbug.com/161373 and crbug.com/104544.
761 AudioCapturerLinux::InitializePipeReader(NULL, base::FilePath()); 754 AudioCapturerLinux::InitializePipeReader(NULL, base::FilePath());
762 #endif 755 #endif
763 } 756 }
764 757
765 // Overridden from HeartbeatSender::Listener
766 void HostProcess::OnUnknownHostIdError() { 758 void HostProcess::OnUnknownHostIdError() {
767 LOG(ERROR) << "Host ID not found."; 759 LOG(ERROR) << "Host ID not found.";
768 ShutdownHost(kInvalidHostIdExitCode); 760 ShutdownHost(kInvalidHostIdExitCode);
769 } 761 }
770 762
771 void HostProcess::OnHeartbeatSuccessful() { 763 void HostProcess::OnHeartbeatSuccessful() {
772 HOST_LOG << "Host ready to receive connections."; 764 HOST_LOG << "Host ready to receive connections.";
773 #if defined(OS_POSIX) 765 #if defined(OS_POSIX)
774 if (signal_parent_) { 766 if (signal_parent_) {
775 kill(getppid(), SIGUSR1); 767 kill(getppid(), SIGUSR1);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 if (!config.GetString(kXmppLoginConfigPath, &xmpp_server_config_.username) || 834 if (!config.GetString(kXmppLoginConfigPath, &xmpp_server_config_.username) ||
843 !(config.GetString(kXmppAuthTokenConfigPath, 835 !(config.GetString(kXmppAuthTokenConfigPath,
844 &xmpp_server_config_.auth_token) || 836 &xmpp_server_config_.auth_token) ||
845 config.GetString(kOAuthRefreshTokenConfigPath, 837 config.GetString(kOAuthRefreshTokenConfigPath,
846 &oauth_refresh_token_))) { 838 &oauth_refresh_token_))) {
847 LOG(ERROR) << "XMPP credentials are not defined in the config."; 839 LOG(ERROR) << "XMPP credentials are not defined in the config.";
848 return false; 840 return false;
849 } 841 }
850 842
851 if (!oauth_refresh_token_.empty()) { 843 if (!oauth_refresh_token_.empty()) {
852 // SignalingConnector is responsible for getting OAuth token. 844 // SignalingConnector (inside MinimumHeartbeatSupporter) is responsible for
845 // getting OAuth token.
853 xmpp_server_config_.auth_token = ""; 846 xmpp_server_config_.auth_token = "";
854 xmpp_server_config_.auth_service = "oauth2"; 847 xmpp_server_config_.auth_service = "oauth2";
855 } else if (!config.GetString(kXmppAuthServiceConfigPath, 848 } else if (!config.GetString(kXmppAuthServiceConfigPath,
856 &xmpp_server_config_.auth_service)) { 849 &xmpp_server_config_.auth_service)) {
857 // For the me2me host, we default to ClientLogin token for chromiumsync 850 // 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 851 // because earlier versions of the host had no HTTP stack with which to
859 // request an OAuth2 access token. 852 // request an OAuth2 access token.
860 xmpp_server_config_.auth_service = kChromotingTokenDefaultServiceName; 853 xmpp_server_config_.auth_service = kChromotingTokenDefaultServiceName;
861 } 854 }
862 855
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 } else { 1215 } else {
1223 HOST_LOG << "Policy disables gnubby auth."; 1216 HOST_LOG << "Policy disables gnubby auth.";
1224 } 1217 }
1225 1218
1226 if (desktop_environment_factory_) 1219 if (desktop_environment_factory_)
1227 desktop_environment_factory_->SetEnableGnubbyAuth(enable_gnubby_auth_); 1220 desktop_environment_factory_->SetEnableGnubbyAuth(enable_gnubby_auth_);
1228 1221
1229 return true; 1222 return true;
1230 } 1223 }
1231 1224
1225 scoped_refptr<MinimumHeartbeatSupporter>
1226 HostProcess::CreateMinimumHeartbeatSupporter() {
1227 DCHECK(!host_id_.empty()); // assumming |ApplyConfig| has already been run
Lambros 2014/12/02 03:35:23 nit: Comments should be English sentences. nit: Tw
Ɓukasz Anforowicz 2014/12/02 20:08:01 Done.
1228 return MinimumHeartbeatSupporter::Create(
1229 base::Bind(&HostProcess::OnHeartbeatSuccessful,
1230 weak_factory_for_network_task_runner_.GetWeakPtr()),
1231 base::Bind(&HostProcess::OnUnknownHostIdError,
1232 weak_factory_for_network_task_runner_.GetWeakPtr()),
1233 base::Bind(&HostProcess::OnAuthFailed,
1234 weak_factory_for_network_task_runner_.GetWeakPtr()),
1235 *context_,
1236 xmpp_server_config_,
1237 talkgadget_prefix_,
1238 host_id_,
1239 key_pair_,
1240 directory_bot_jid_,
1241 oauth_refresh_token_,
1242 use_service_account_);
1243 }
1244
1232 void HostProcess::StartHost() { 1245 void HostProcess::StartHost() {
1233 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); 1246 DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
1234 DCHECK(!host_); 1247 DCHECK(!host_);
1235 DCHECK(!signal_strategy_.get()); 1248 DCHECK(!minimum_heartbeat_supporter_.get());
1249
1236 DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART || 1250 DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART ||
1237 state_ == HOST_STOPPED) << state_; 1251 state_ == HOST_STOPPED) << state_;
1238 state_ = HOST_STARTED; 1252 state_ = HOST_STARTED;
1239 1253
1240 signal_strategy_.reset( 1254 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 1255
1271 uint32 network_flags = 0; 1256 uint32 network_flags = 0;
1272 if (allow_nat_traversal_) { 1257 if (allow_nat_traversal_) {
1273 network_flags = NetworkSettings::NAT_TRAVERSAL_STUN | 1258 network_flags = NetworkSettings::NAT_TRAVERSAL_STUN |
1274 NetworkSettings::NAT_TRAVERSAL_OUTGOING; 1259 NetworkSettings::NAT_TRAVERSAL_OUTGOING;
1275 if (allow_relay_) 1260 if (allow_relay_)
1276 network_flags |= NetworkSettings::NAT_TRAVERSAL_RELAY; 1261 network_flags |= NetworkSettings::NAT_TRAVERSAL_RELAY;
1277 } 1262 }
1278 1263
1279 NetworkSettings network_settings(network_flags); 1264 NetworkSettings network_settings(network_flags);
1280 1265
1281 if (min_udp_port_ && max_udp_port_) { 1266 if (min_udp_port_ && max_udp_port_) {
1282 network_settings.min_port = min_udp_port_; 1267 network_settings.min_port = min_udp_port_;
1283 network_settings.max_port = max_udp_port_; 1268 network_settings.max_port = max_udp_port_;
1284 } else if (!allow_nat_traversal_) { 1269 } else if (!allow_nat_traversal_) {
1285 // For legacy reasons we have to restrict the port range to a set of default 1270 // 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 1271 // values when nat traversal is disabled, even if the port range was not
1287 // set in policy. 1272 // set in policy.
1288 network_settings.min_port = NetworkSettings::kDefaultMinPort; 1273 network_settings.min_port = NetworkSettings::kDefaultMinPort;
1289 network_settings.max_port = NetworkSettings::kDefaultMaxPort; 1274 network_settings.max_port = NetworkSettings::kDefaultMaxPort;
1290 } 1275 }
1291 1276
1292 host_.reset(new ChromotingHost( 1277 host_.reset(new ChromotingHost(
1293 signal_strategy_.get(), 1278 minimum_heartbeat_supporter_->GetSignalStrategy(),
1294 desktop_environment_factory_.get(), 1279 desktop_environment_factory_.get(),
1295 CreateHostSessionManager(signal_strategy_.get(), network_settings, 1280 CreateHostSessionManager(
1296 context_->url_request_context_getter()), 1281 minimum_heartbeat_supporter_->GetSignalStrategy(),
1282 network_settings,
1283 context_->url_request_context_getter()),
1297 context_->audio_task_runner(), 1284 context_->audio_task_runner(),
1298 context_->input_task_runner(), 1285 context_->input_task_runner(),
1299 context_->video_capture_task_runner(), 1286 context_->video_capture_task_runner(),
1300 context_->video_encode_task_runner(), 1287 context_->video_encode_task_runner(),
1301 context_->network_task_runner(), 1288 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(
1324 base::Bind(&HostProcess::OnHeartbeatSuccessful, base::Unretained(this)), 1311 new HostChangeNotificationListener(
1325 base::Bind(&HostProcess::OnUnknownHostIdError, base::Unretained(this)), 1312 this,
1326 host_id_, signal_strategy_.get(), key_pair_, directory_bot_jid_)); 1313 host_id_,
1327 1314 minimum_heartbeat_supporter_->GetSignalStrategy(),
1328 host_change_notification_listener_.reset(new HostChangeNotificationListener( 1315 directory_bot_jid_));
1329 this, host_id_, signal_strategy_.get(), directory_bot_jid_));
1330 1316
1331 host_status_logger_.reset( 1317 host_status_logger_.reset(
1332 new HostStatusLogger(host_->AsWeakPtr(), ServerLogEntry::ME2ME, 1318 new HostStatusLogger(
1333 signal_strategy_.get(), directory_bot_jid_)); 1319 host_->AsWeakPtr(),
1320 ServerLogEntry::ME2ME,
1321 minimum_heartbeat_supporter_->GetSignalStrategy(),
1322 directory_bot_jid_));
1334 1323
1335 // Set up reporting the host status notifications. 1324 // Set up reporting the host status notifications.
1336 #if defined(REMOTING_MULTI_PROCESS) 1325 #if defined(REMOTING_MULTI_PROCESS)
1337 host_event_logger_.reset( 1326 host_event_logger_.reset(
1338 new IpcHostEventLogger(host_->AsWeakPtr(), daemon_channel_.get())); 1327 new IpcHostEventLogger(host_->AsWeakPtr(), daemon_channel_.get()));
1339 #else // !defined(REMOTING_MULTI_PROCESS) 1328 #else // !defined(REMOTING_MULTI_PROCESS)
1340 host_event_logger_ = 1329 host_event_logger_ =
1341 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); 1330 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName);
1342 #endif // !defined(REMOTING_MULTI_PROCESS) 1331 #endif // !defined(REMOTING_MULTI_PROCESS)
1343 1332
(...skipping 16 matching lines...) Expand all
1360 } 1349 }
1361 1350
1362 void HostProcess::ShutdownHost(HostExitCodes exit_code) { 1351 void HostProcess::ShutdownHost(HostExitCodes exit_code) {
1363 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); 1352 DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
1364 1353
1365 *exit_code_out_ = exit_code; 1354 *exit_code_out_ = exit_code;
1366 1355
1367 switch (state_) { 1356 switch (state_) {
1368 case HOST_INITIALIZING: 1357 case HOST_INITIALIZING:
1369 state_ = HOST_STOPPING; 1358 state_ = HOST_STOPPING;
1359 {
1360 DCHECK(!minimum_heartbeat_supporter_.get());
1361 scoped_refptr<MinimumHeartbeatSupporter> tmpHeartbeatSupporter =
1362 CreateMinimumHeartbeatSupporter();
1363 tmpHeartbeatSupporter->SendHostOfflineReason(
1364 ExitCodeToString(exit_code),
1365 base::TimeDelta::FromSeconds(30) /* timeout */);
1366 }
1370 ShutdownOnNetworkThread(); 1367 ShutdownOnNetworkThread();
1371 break; 1368 break;
1372 1369
1373 case HOST_STARTED: 1370 case HOST_STARTED:
1374 state_ = HOST_STOPPING; 1371 state_ = HOST_STOPPING;
1375 heartbeat_sender_->SetHostOfflineReason( 1372 minimum_heartbeat_supporter_->SendHostOfflineReason(
1376 ExitCodeToString(exit_code), base::Bind(base::DoNothing)); 1373 ExitCodeToString(exit_code),
1377 ScheduleHostShutdown(); 1374 base::TimeDelta::FromSeconds(30) /* timeout */);
1375 ShutdownOnNetworkThread();
1378 break; 1376 break;
1379 1377
1380 case HOST_STOPPING_TO_RESTART: 1378 case HOST_STOPPING_TO_RESTART:
1381 state_ = HOST_STOPPING; 1379 state_ = HOST_STOPPING;
1382 break; 1380 break;
1383 1381
1384 case HOST_STOPPING: 1382 case HOST_STOPPING:
1385 case HOST_STOPPED: 1383 case HOST_STOPPED:
1386 // Host is already stopped or being stopped. No action is required. 1384 // Host is already stopped or being stopped. No action is required.
1387 break; 1385 break;
1388 } 1386 }
1389 } 1387 }
1390 1388
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() { 1389 void HostProcess::ShutdownOnNetworkThread() {
1402 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); 1390 DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
1403 1391
1392 // Need to invalidate WeakPtrs on the same thread where they are dereferenced.
1393 weak_factory_for_network_task_runner_.InvalidateWeakPtrs();
1394
1404 host_.reset(); 1395 host_.reset();
1405 host_event_logger_.reset(); 1396 host_event_logger_.reset();
1406 host_status_logger_.reset(); 1397 host_status_logger_.reset();
1407 heartbeat_sender_.reset(); 1398 minimum_heartbeat_supporter_ = nullptr;
1408 host_change_notification_listener_.reset(); 1399 host_change_notification_listener_.reset();
1409 signaling_connector_.reset();
1410 oauth_token_getter_.reset();
1411 signal_strategy_.reset();
1412 network_change_notifier_.reset();
1413 1400
1414 if (state_ == HOST_STOPPING_TO_RESTART) { 1401 if (state_ == HOST_STOPPING_TO_RESTART) {
1415 StartHost(); 1402 StartHost();
1416 } else if (state_ == HOST_STOPPING) { 1403 } else if (state_ == HOST_STOPPING) {
1417 state_ = HOST_STOPPED; 1404 state_ = HOST_STOPPED;
1418 1405
1419 if (policy_watcher_.get()) { 1406 if (policy_watcher_.get()) {
1420 policy_watcher_->StopWatching( 1407 policy_watcher_->StopWatching(
1421 base::Bind(&HostProcess::OnPolicyWatcherShutdown, this)); 1408 base::Bind(&HostProcess::OnPolicyWatcherShutdown, this));
1422 } else { 1409 } else {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 int exit_code = kSuccessExitCode; 1468 int exit_code = kSuccessExitCode;
1482 new HostProcess(context.Pass(), &exit_code); 1469 new HostProcess(context.Pass(), &exit_code);
1483 1470
1484 // Run the main (also UI) message loop until the host no longer needs it. 1471 // Run the main (also UI) message loop until the host no longer needs it.
1485 message_loop.Run(); 1472 message_loop.Run();
1486 1473
1487 return exit_code; 1474 return exit_code;
1488 } 1475 }
1489 1476
1490 } // namespace remoting 1477 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698