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

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 5 years, 11 months 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"
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/shutdown_watchdog.h" 63 #include "remoting/host/shutdown_watchdog.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // Value used for --host-config option to indicate that the path must be read 135 // Value used for --host-config option to indicate that the path must be read
137 // from stdin. 136 // from stdin.
138 const char kStdinConfigPath[] = "-"; 137 const char kStdinConfigPath[] = "-";
139 138
140 const char kWindowIdSwitchName[] = "window-id"; 139 const char kWindowIdSwitchName[] = "window-id";
141 140
142 // Maximum time to wait for clean shutdown to occur, before forcing termination 141 // Maximum time to wait for clean shutdown to occur, before forcing termination
143 // of the process. 142 // of the process.
144 const int kShutdownTimeoutSeconds = 15; 143 const int kShutdownTimeoutSeconds = 15;
145 144
145 // Maximum time to wait for reporting host-offline-reason to the service,
146 // before continuing normal process shutdown.
147 const int kHostOfflineReasonTimeoutSeconds = 10;
148
146 } // namespace 149 } // namespace
147 150
148 namespace remoting { 151 namespace remoting {
149 152
150 class HostProcess 153 class HostProcess
151 : public ConfigWatcher::Delegate, 154 : public ConfigWatcher::Delegate,
152 public HostChangeNotificationListener::Listener, 155 public HostChangeNotificationListener::Listener,
153 public IPC::Listener, 156 public IPC::Listener,
154 public base::RefCountedThreadSafe<HostProcess> { 157 public base::RefCountedThreadSafe<HostProcess> {
155 public: 158 public:
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 bool OnUsernamePolicyUpdate(base::DictionaryValue* policies); 250 bool OnUsernamePolicyUpdate(base::DictionaryValue* policies);
248 bool OnNatPolicyUpdate(base::DictionaryValue* policies); 251 bool OnNatPolicyUpdate(base::DictionaryValue* policies);
249 bool OnRelayPolicyUpdate(base::DictionaryValue* policies); 252 bool OnRelayPolicyUpdate(base::DictionaryValue* policies);
250 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies); 253 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies);
251 bool OnCurtainPolicyUpdate(base::DictionaryValue* policies); 254 bool OnCurtainPolicyUpdate(base::DictionaryValue* policies);
252 bool OnHostTalkGadgetPrefixPolicyUpdate(base::DictionaryValue* policies); 255 bool OnHostTalkGadgetPrefixPolicyUpdate(base::DictionaryValue* policies);
253 bool OnHostTokenUrlPolicyUpdate(base::DictionaryValue* policies); 256 bool OnHostTokenUrlPolicyUpdate(base::DictionaryValue* policies);
254 bool OnPairingPolicyUpdate(base::DictionaryValue* policies); 257 bool OnPairingPolicyUpdate(base::DictionaryValue* policies);
255 bool OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies); 258 bool OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies);
256 259
260 scoped_ptr<HostSignalingManager> CreateHostSignalingManager();
261
257 void StartHost(); 262 void StartHost();
258 263
259 void OnHeartbeatSuccessful(); 264 void OnHeartbeatSuccessful();
260 void OnUnknownHostIdError(); 265 void OnUnknownHostIdError();
261 266
262 void OnAuthFailed(); 267 void OnAuthFailed();
263 268
264 void RestartHost(); 269 void RestartHost();
265 270
266 // Stops the host and shuts down the process with the specified |exit_code|. 271 // Stops the host and shuts down the process with the specified |exit_code|.
267 void ShutdownHost(HostExitCodes exit_code); 272 void ShutdownHost(HostExitCodes exit_code);
268 273
269 void ScheduleHostShutdown(); 274 // Private helper used by ShutdownHost method to initiate sending of
275 // host-offline-reason before continuing shutdown.
276 void SendOfflineReasonAndShutdownOnNetworkThread(HostExitCodes exit_code);
270 277
271 void ShutdownOnNetworkThread(); 278 void ShutdownOnNetworkThread();
272 279
273 void OnPolicyWatcherShutdown(); 280 void OnPolicyWatcherShutdown();
274 281
275 #if defined(OS_WIN) 282 #if defined(OS_WIN)
276 // Initializes the pairing registry on Windows. This should be invoked on the 283 // Initializes the pairing registry on Windows. This should be invoked on the
277 // network thread. 284 // network thread.
278 void InitializePairingRegistry( 285 void InitializePairingRegistry(
279 IPC::PlatformFileForTransit privileged_key, 286 IPC::PlatformFileForTransit privileged_key,
280 IPC::PlatformFileForTransit unprivileged_key); 287 IPC::PlatformFileForTransit unprivileged_key);
281 #endif // defined(OS_WIN) 288 #endif // defined(OS_WIN)
282 289
283 // Crashes the process in response to a daemon's request. The daemon passes 290 // Crashes the process in response to a daemon's request. The daemon passes
284 // the location of the code that detected the fatal error resulted in this 291 // the location of the code that detected the fatal error resulted in this
285 // request. 292 // request.
286 void OnCrash(const std::string& function_name, 293 void OnCrash(const std::string& function_name,
287 const std::string& file_name, 294 const std::string& file_name,
288 const int& line_number); 295 const int& line_number);
289 296
290 scoped_ptr<ChromotingHostContext> context_; 297 scoped_ptr<ChromotingHostContext> context_;
291 298
292 // Created on the UI thread but used from the network thread.
293 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
294
295 // Accessed on the UI thread. 299 // Accessed on the UI thread.
296 scoped_ptr<IPC::ChannelProxy> daemon_channel_; 300 scoped_ptr<IPC::ChannelProxy> daemon_channel_;
297 301
298 // XMPP server/remoting bot configuration (initialized from the command line). 302 // XMPP server/remoting bot configuration (initialized from the command line).
299 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; 303 XmppSignalStrategy::XmppServerConfig xmpp_server_config_;
300 std::string directory_bot_jid_; 304 std::string directory_bot_jid_;
301 305
302 // Created on the UI thread but used from the network thread. 306 // Created on the UI thread but used from the network thread.
303 base::FilePath host_config_path_; 307 base::FilePath host_config_path_;
304 std::string host_config_; 308 std::string host_config_;
(...skipping 29 matching lines...) Expand all
334 ThirdPartyAuthConfig third_party_auth_config_; 338 ThirdPartyAuthConfig third_party_auth_config_;
335 bool enable_gnubby_auth_; 339 bool enable_gnubby_auth_;
336 340
337 // Boolean to change flow, where ncessary, if we're 341 // Boolean to change flow, where ncessary, if we're
338 // capturing a window instead of the entire desktop. 342 // capturing a window instead of the entire desktop.
339 bool enable_window_capture_; 343 bool enable_window_capture_;
340 344
341 // Used to specify which window to stream, if enabled. 345 // Used to specify which window to stream, if enabled.
342 webrtc::WindowId window_id_; 346 webrtc::WindowId window_id_;
343 347
344 scoped_ptr<OAuthTokenGetter> oauth_token_getter_; 348 // Used to send heartbeats while running, and the reason for going offline
345 scoped_ptr<XmppSignalStrategy> signal_strategy_; 349 // when shutting down.
346 scoped_ptr<SignalingConnector> signaling_connector_; 350 scoped_ptr<HostSignalingManager> host_signaling_manager_;
347 scoped_ptr<HeartbeatSender> heartbeat_sender_; 351
348 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; 352 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_;
349 scoped_ptr<HostStatusLogger> host_status_logger_; 353 scoped_ptr<HostStatusLogger> host_status_logger_;
350 scoped_ptr<HostEventLogger> host_event_logger_; 354 scoped_ptr<HostEventLogger> host_event_logger_;
351 355
352 scoped_ptr<ChromotingHost> host_; 356 scoped_ptr<ChromotingHost> host_;
353 357
354 // Used to keep this HostProcess alive until it is shutdown. 358 // Used to keep this HostProcess alive until it is shutdown.
355 scoped_refptr<HostProcess> self_; 359 scoped_refptr<HostProcess> self_;
356 360
357 #if defined(REMOTING_MULTI_PROCESS) 361 #if defined(REMOTING_MULTI_PROCESS)
358 DesktopSessionConnector* desktop_session_connector_; 362 DesktopSessionConnector* desktop_session_connector_;
359 #endif // defined(REMOTING_MULTI_PROCESS) 363 #endif // defined(REMOTING_MULTI_PROCESS)
360 364
361 int* exit_code_out_; 365 int* exit_code_out_;
362 bool signal_parent_; 366 bool signal_parent_;
363 367
364 scoped_refptr<PairingRegistry> pairing_registry_; 368 scoped_refptr<PairingRegistry> pairing_registry_;
365 369
366 ShutdownWatchdog* shutdown_watchdog_; 370 ShutdownWatchdog* shutdown_watchdog_;
371
372 // Factory of weak pointers to |this| that will to be referenced from the
Wez 2015/01/09 02:55:45 typo: that will to be
Ɓukasz Anforowicz 2015/01/09 19:00:14 Done.
373 // network thread (weak pointers are constrained to a single thread).
Wez 2015/01/09 02:55:46 Weak pointers are constrained to a single thread i
Ɓukasz Anforowicz 2015/01/09 19:00:14 Done.
374 base::WeakPtrFactory<HostProcess> weak_factory_for_network_task_runner_;
Wez 2015/01/09 02:55:46 Just weak_factory_, please - it's implicit that th
Ɓukasz Anforowicz 2015/01/09 19:00:14 I thought that the qualification is useful because
Wez 2015/01/10 01:43:32 The point is that _any_ WeakPtrFactory _must_ be i
Ɓukasz Anforowicz 2015/01/12 18:05:14 Oh, ok. I think I get your point: 1) there should
375
376 DISALLOW_COPY_AND_ASSIGN(HostProcess);
367 }; 377 };
368 378
369 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, 379 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context,
370 int* exit_code_out, 380 int* exit_code_out,
371 ShutdownWatchdog* shutdown_watchdog) 381 ShutdownWatchdog* shutdown_watchdog)
372 : context_(context.Pass()), 382 : context_(context.Pass()),
373 state_(HOST_INITIALIZING), 383 state_(HOST_INITIALIZING),
374 use_service_account_(false), 384 use_service_account_(false),
375 enable_vp9_(false), 385 enable_vp9_(false),
376 frame_recorder_buffer_size_(0), 386 frame_recorder_buffer_size_(0),
377 host_username_match_required_(false), 387 host_username_match_required_(false),
378 allow_nat_traversal_(true), 388 allow_nat_traversal_(true),
379 allow_relay_(true), 389 allow_relay_(true),
380 min_udp_port_(0), 390 min_udp_port_(0),
381 max_udp_port_(0), 391 max_udp_port_(0),
382 allow_pairing_(true), 392 allow_pairing_(true),
383 curtain_required_(false), 393 curtain_required_(false),
384 enable_gnubby_auth_(false), 394 enable_gnubby_auth_(false),
385 enable_window_capture_(false), 395 enable_window_capture_(false),
386 window_id_(0), 396 window_id_(0),
387 #if defined(REMOTING_MULTI_PROCESS) 397 #if defined(REMOTING_MULTI_PROCESS)
388 desktop_session_connector_(NULL), 398 desktop_session_connector_(NULL),
389 #endif // defined(REMOTING_MULTI_PROCESS) 399 #endif // defined(REMOTING_MULTI_PROCESS)
390 self_(this), 400 self_(this),
391 exit_code_out_(exit_code_out), 401 exit_code_out_(exit_code_out),
392 signal_parent_(false), 402 signal_parent_(false),
393 shutdown_watchdog_(shutdown_watchdog) { 403 shutdown_watchdog_(shutdown_watchdog) ,
404 weak_factory_for_network_task_runner_(this) {
394 StartOnUiThread(); 405 StartOnUiThread();
395 } 406 }
396 407
397 HostProcess::~HostProcess() { 408 HostProcess::~HostProcess() {
398 // Verify that UI components have been torn down. 409 // Verify that UI components have been torn down.
399 DCHECK(!config_watcher_); 410 DCHECK(!config_watcher_);
400 DCHECK(!daemon_channel_); 411 DCHECK(!daemon_channel_);
401 DCHECK(!desktop_environment_factory_); 412 DCHECK(!desktop_environment_factory_);
402 413
403 // We might be getting deleted on one of the threads the |host_context| owns, 414 // We might be getting deleted on one of the threads the |host_context| owns,
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 781
771 context_->network_task_runner()->PostTask( 782 context_->network_task_runner()->PostTask(
772 FROM_HERE, 783 FROM_HERE,
773 base::Bind(&HostProcess::StartOnNetworkThread, this)); 784 base::Bind(&HostProcess::StartOnNetworkThread, this));
774 } 785 }
775 786
776 void HostProcess::ShutdownOnUiThread() { 787 void HostProcess::ShutdownOnUiThread() {
777 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); 788 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
778 789
779 // Tear down resources that need to be torn down on the UI thread. 790 // Tear down resources that need to be torn down on the UI thread.
780 network_change_notifier_.reset();
781 daemon_channel_.reset(); 791 daemon_channel_.reset();
782 desktop_environment_factory_.reset(); 792 desktop_environment_factory_.reset();
783 793
784 // It is now safe for the HostProcess to be deleted. 794 // It is now safe for the HostProcess to be deleted.
785 self_ = NULL; 795 self_ = NULL;
786 796
787 #if defined(OS_LINUX) 797 #if defined(OS_LINUX)
788 // Cause the global AudioPipeReader to be freed, otherwise the audio 798 // Cause the global AudioPipeReader to be freed, otherwise the audio
789 // thread will remain in-use and prevent the process from exiting. 799 // thread will remain in-use and prevent the process from exiting.
790 // TODO(wez): DesktopEnvironmentFactory should own the pipe reader. 800 // TODO(wez): DesktopEnvironmentFactory should own the pipe reader.
791 // See crbug.com/161373 and crbug.com/104544. 801 // See crbug.com/161373 and crbug.com/104544.
792 AudioCapturerLinux::InitializePipeReader(NULL, base::FilePath()); 802 AudioCapturerLinux::InitializePipeReader(NULL, base::FilePath());
793 #endif 803 #endif
794 } 804 }
795 805
796 // Overridden from HeartbeatSender::Listener
797 void HostProcess::OnUnknownHostIdError() { 806 void HostProcess::OnUnknownHostIdError() {
798 LOG(ERROR) << "Host ID not found."; 807 LOG(ERROR) << "Host ID not found.";
799 ShutdownHost(kInvalidHostIdExitCode); 808 ShutdownHost(kInvalidHostIdExitCode);
800 } 809 }
801 810
802 void HostProcess::OnHeartbeatSuccessful() { 811 void HostProcess::OnHeartbeatSuccessful() {
803 HOST_LOG << "Host ready to receive connections."; 812 HOST_LOG << "Host ready to receive connections.";
804 #if defined(OS_POSIX) 813 #if defined(OS_POSIX)
805 if (signal_parent_) { 814 if (signal_parent_) {
806 kill(getppid(), SIGUSR1); 815 kill(getppid(), SIGUSR1);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 if (!config.GetString(kXmppLoginConfigPath, &xmpp_server_config_.username) || 901 if (!config.GetString(kXmppLoginConfigPath, &xmpp_server_config_.username) ||
893 !(config.GetString(kXmppAuthTokenConfigPath, 902 !(config.GetString(kXmppAuthTokenConfigPath,
894 &xmpp_server_config_.auth_token) || 903 &xmpp_server_config_.auth_token) ||
895 config.GetString(kOAuthRefreshTokenConfigPath, 904 config.GetString(kOAuthRefreshTokenConfigPath,
896 &oauth_refresh_token_))) { 905 &oauth_refresh_token_))) {
897 LOG(ERROR) << "XMPP credentials are not defined in the config."; 906 LOG(ERROR) << "XMPP credentials are not defined in the config.";
898 return false; 907 return false;
899 } 908 }
900 909
901 if (!oauth_refresh_token_.empty()) { 910 if (!oauth_refresh_token_.empty()) {
902 // SignalingConnector is responsible for getting OAuth token. 911 // SignalingConnector (inside HostSignalingManager) is responsible for
912 // getting OAuth token.
903 xmpp_server_config_.auth_token = ""; 913 xmpp_server_config_.auth_token = "";
904 xmpp_server_config_.auth_service = "oauth2"; 914 xmpp_server_config_.auth_service = "oauth2";
905 } else if (!config.GetString(kXmppAuthServiceConfigPath, 915 } else if (!config.GetString(kXmppAuthServiceConfigPath,
906 &xmpp_server_config_.auth_service)) { 916 &xmpp_server_config_.auth_service)) {
907 // For the me2me host, we default to ClientLogin token for chromiumsync 917 // For the me2me host, we default to ClientLogin token for chromiumsync
908 // because earlier versions of the host had no HTTP stack with which to 918 // because earlier versions of the host had no HTTP stack with which to
909 // request an OAuth2 access token. 919 // request an OAuth2 access token.
910 xmpp_server_config_.auth_service = kChromotingTokenDefaultServiceName; 920 xmpp_server_config_.auth_service = kChromotingTokenDefaultServiceName;
911 } 921 }
912 922
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 } else { 1282 } else {
1273 HOST_LOG << "Policy disables gnubby auth."; 1283 HOST_LOG << "Policy disables gnubby auth.";
1274 } 1284 }
1275 1285
1276 if (desktop_environment_factory_) 1286 if (desktop_environment_factory_)
1277 desktop_environment_factory_->SetEnableGnubbyAuth(enable_gnubby_auth_); 1287 desktop_environment_factory_->SetEnableGnubbyAuth(enable_gnubby_auth_);
1278 1288
1279 return true; 1289 return true;
1280 } 1290 }
1281 1291
1292 scoped_ptr<HostSignalingManager> HostProcess::CreateHostSignalingManager() {
1293 DCHECK(!host_id_.empty()); // |ApplyConfig| should already have been run.
1294
1295 scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials(
1296 new OAuthTokenGetter::OAuthCredentials(xmpp_server_config_.username,
1297 oauth_refresh_token_,
1298 use_service_account_));
1299
1300 return HostSignalingManager::Create(
1301 base::Bind(&HostProcess::OnHeartbeatSuccessful,
1302 weak_factory_for_network_task_runner_.GetWeakPtr()),
1303 base::Bind(&HostProcess::OnUnknownHostIdError,
1304 weak_factory_for_network_task_runner_.GetWeakPtr()),
1305 base::Bind(&HostProcess::OnAuthFailed,
1306 weak_factory_for_network_task_runner_.GetWeakPtr()),
1307 context_->network_task_runner(), context_->url_request_context_getter(),
1308 xmpp_server_config_, talkgadget_prefix_, host_id_, key_pair_,
1309 directory_bot_jid_, oauth_credentials.Pass());
1310 }
1311
1282 void HostProcess::StartHost() { 1312 void HostProcess::StartHost() {
1283 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); 1313 DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
1284 DCHECK(!host_); 1314 DCHECK(!host_);
1285 DCHECK(!signal_strategy_.get()); 1315 DCHECK(!host_signaling_manager_);
1316
1286 DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART || 1317 DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART ||
1287 state_ == HOST_STOPPED) << state_; 1318 state_ == HOST_STOPPED)
1319 << "state_ = " << state_;
1288 state_ = HOST_STARTED; 1320 state_ = HOST_STARTED;
1289 1321
1290 signal_strategy_.reset( 1322 host_signaling_manager_ = CreateHostSignalingManager();
1291 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(),
1292 context_->url_request_context_getter(),
1293 xmpp_server_config_));
1294
1295 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker(
1296 new DnsBlackholeChecker(context_->url_request_context_getter(),
1297 talkgadget_prefix_));
1298
1299 // Create a NetworkChangeNotifier for use by the signaling connector.
1300 network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
1301
1302 signaling_connector_.reset(new SignalingConnector(
1303 signal_strategy_.get(),
1304 dns_blackhole_checker.Pass(),
1305 base::Bind(&HostProcess::OnAuthFailed, this)));
1306
1307 if (!oauth_refresh_token_.empty()) {
1308 scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials;
1309 oauth_credentials.reset(
1310 new OAuthTokenGetter::OAuthCredentials(
1311 xmpp_server_config_.username, oauth_refresh_token_,
1312 use_service_account_));
1313
1314 oauth_token_getter_.reset(new OAuthTokenGetter(
1315 oauth_credentials.Pass(), context_->url_request_context_getter(),
1316 false));
1317
1318 signaling_connector_->EnableOAuth(oauth_token_getter_.get());
1319 }
1320 1323
1321 uint32 network_flags = 0; 1324 uint32 network_flags = 0;
1322 if (allow_nat_traversal_) { 1325 if (allow_nat_traversal_) {
1323 network_flags = NetworkSettings::NAT_TRAVERSAL_STUN | 1326 network_flags = NetworkSettings::NAT_TRAVERSAL_STUN |
1324 NetworkSettings::NAT_TRAVERSAL_OUTGOING; 1327 NetworkSettings::NAT_TRAVERSAL_OUTGOING;
1325 if (allow_relay_) 1328 if (allow_relay_)
1326 network_flags |= NetworkSettings::NAT_TRAVERSAL_RELAY; 1329 network_flags |= NetworkSettings::NAT_TRAVERSAL_RELAY;
1327 } 1330 }
1328 1331
1329 NetworkSettings network_settings(network_flags); 1332 NetworkSettings network_settings(network_flags);
1330 1333
1331 if (min_udp_port_ && max_udp_port_) { 1334 if (min_udp_port_ && max_udp_port_) {
1332 network_settings.min_port = min_udp_port_; 1335 network_settings.min_port = min_udp_port_;
1333 network_settings.max_port = max_udp_port_; 1336 network_settings.max_port = max_udp_port_;
1334 } else if (!allow_nat_traversal_) { 1337 } else if (!allow_nat_traversal_) {
1335 // For legacy reasons we have to restrict the port range to a set of default 1338 // For legacy reasons we have to restrict the port range to a set of default
1336 // values when nat traversal is disabled, even if the port range was not 1339 // values when nat traversal is disabled, even if the port range was not
1337 // set in policy. 1340 // set in policy.
1338 network_settings.min_port = NetworkSettings::kDefaultMinPort; 1341 network_settings.min_port = NetworkSettings::kDefaultMinPort;
1339 network_settings.max_port = NetworkSettings::kDefaultMaxPort; 1342 network_settings.max_port = NetworkSettings::kDefaultMaxPort;
1340 } 1343 }
1341 1344
1342 host_.reset(new ChromotingHost( 1345 host_.reset(new ChromotingHost(
1343 signal_strategy_.get(), 1346 host_signaling_manager_->signal_strategy(),
1344 desktop_environment_factory_.get(), 1347 desktop_environment_factory_.get(),
1345 CreateHostSessionManager(signal_strategy_.get(), network_settings, 1348 CreateHostSessionManager(host_signaling_manager_->signal_strategy(),
1349 network_settings,
1346 context_->url_request_context_getter()), 1350 context_->url_request_context_getter()),
1347 context_->audio_task_runner(), 1351 context_->audio_task_runner(), context_->input_task_runner(),
1348 context_->input_task_runner(),
1349 context_->video_capture_task_runner(), 1352 context_->video_capture_task_runner(),
1350 context_->video_encode_task_runner(), 1353 context_->video_encode_task_runner(), context_->network_task_runner(),
1351 context_->network_task_runner(),
1352 context_->ui_task_runner())); 1354 context_->ui_task_runner()));
1353 1355
1354 if (enable_vp9_) { 1356 if (enable_vp9_) {
1355 scoped_ptr<protocol::CandidateSessionConfig> config = 1357 scoped_ptr<protocol::CandidateSessionConfig> config =
1356 host_->protocol_config()->Clone(); 1358 host_->protocol_config()->Clone();
1357 config->EnableVideoCodec(protocol::ChannelConfig::CODEC_VP9); 1359 config->EnableVideoCodec(protocol::ChannelConfig::CODEC_VP9);
1358 host_->set_protocol_config(config.Pass()); 1360 host_->set_protocol_config(config.Pass());
1359 } 1361 }
1360 1362
1361 if (frame_recorder_buffer_size_ > 0) { 1363 if (frame_recorder_buffer_size_ > 0) {
1362 scoped_ptr<VideoFrameRecorderHostExtension> frame_recorder_extension( 1364 scoped_ptr<VideoFrameRecorderHostExtension> frame_recorder_extension(
1363 new VideoFrameRecorderHostExtension()); 1365 new VideoFrameRecorderHostExtension());
1364 frame_recorder_extension->SetMaxContentBytes(frame_recorder_buffer_size_); 1366 frame_recorder_extension->SetMaxContentBytes(frame_recorder_buffer_size_);
1365 host_->AddExtension(frame_recorder_extension.Pass()); 1367 host_->AddExtension(frame_recorder_extension.Pass());
1366 } 1368 }
1367 1369
1368 // TODO(simonmorris): Get the maximum session duration from a policy. 1370 // TODO(simonmorris): Get the maximum session duration from a policy.
1369 #if defined(OS_LINUX) 1371 #if defined(OS_LINUX)
1370 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); 1372 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20));
1371 #endif 1373 #endif
1372 1374
1373 heartbeat_sender_.reset(new HeartbeatSender( 1375 host_change_notification_listener_.reset(new HostChangeNotificationListener(
1374 base::Bind(&HostProcess::OnHeartbeatSuccessful, base::Unretained(this)), 1376 this, host_id_, host_signaling_manager_->signal_strategy(),
1375 base::Bind(&HostProcess::OnUnknownHostIdError, base::Unretained(this)), 1377 directory_bot_jid_));
1376 host_id_, signal_strategy_.get(), key_pair_, directory_bot_jid_));
1377 1378
1378 host_change_notification_listener_.reset(new HostChangeNotificationListener( 1379 host_status_logger_.reset(new HostStatusLogger(
1379 this, host_id_, signal_strategy_.get(), directory_bot_jid_)); 1380 host_->AsWeakPtr(), ServerLogEntry::ME2ME,
1380 1381 host_signaling_manager_->signal_strategy(), directory_bot_jid_));
1381 host_status_logger_.reset(
1382 new HostStatusLogger(host_->AsWeakPtr(), ServerLogEntry::ME2ME,
1383 signal_strategy_.get(), directory_bot_jid_));
1384 1382
1385 // Set up reporting the host status notifications. 1383 // Set up reporting the host status notifications.
1386 #if defined(REMOTING_MULTI_PROCESS) 1384 #if defined(REMOTING_MULTI_PROCESS)
1387 host_event_logger_.reset( 1385 host_event_logger_.reset(
1388 new IpcHostEventLogger(host_->AsWeakPtr(), daemon_channel_.get())); 1386 new IpcHostEventLogger(host_->AsWeakPtr(), daemon_channel_.get()));
1389 #else // !defined(REMOTING_MULTI_PROCESS) 1387 #else // !defined(REMOTING_MULTI_PROCESS)
1390 host_event_logger_ = 1388 host_event_logger_ =
1391 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); 1389 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName);
1392 #endif // !defined(REMOTING_MULTI_PROCESS) 1390 #endif // !defined(REMOTING_MULTI_PROCESS)
1393 1391
1394 host_->SetEnableCurtaining(curtain_required_); 1392 host_->SetEnableCurtaining(curtain_required_);
1395 host_->Start(host_owner_email_); 1393 host_->Start(host_owner_email_);
1396 1394
1397 CreateAuthenticatorFactory(); 1395 CreateAuthenticatorFactory();
1398 } 1396 }
1399 1397
1400 void HostProcess::OnAuthFailed() { 1398 void HostProcess::OnAuthFailed() {
1401 ShutdownHost(kInvalidOauthCredentialsExitCode); 1399 ShutdownHost(kInvalidOauthCredentialsExitCode);
1402 } 1400 }
1403 1401
1404 void HostProcess::RestartHost() { 1402 void HostProcess::RestartHost() {
1405 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); 1403 DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
1406 DCHECK_EQ(state_, HOST_STARTED); 1404 DCHECK_EQ(state_, HOST_STARTED);
1407 1405
1408 state_ = HOST_STOPPING_TO_RESTART; 1406 state_ = HOST_STOPPING_TO_RESTART;
1409 ShutdownOnNetworkThread(); 1407 ShutdownOnNetworkThread();
1410 } 1408 }
1411 1409
1410 void HostProcess::SendOfflineReasonAndShutdownOnNetworkThread(
1411 HostExitCodes exit_code) {
1412 DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
1413 DCHECK(host_signaling_manager_);
1414 host_signaling_manager_.release()->SendHostOfflineReasonAndDelete(
1415 ExitCodeToString(exit_code),
1416 base::TimeDelta::FromSeconds(kHostOfflineReasonTimeoutSeconds));
1417 ShutdownOnNetworkThread();
1418 }
1419
1412 void HostProcess::ShutdownHost(HostExitCodes exit_code) { 1420 void HostProcess::ShutdownHost(HostExitCodes exit_code) {
1413 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); 1421 DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
1414 1422
1415 *exit_code_out_ = exit_code; 1423 *exit_code_out_ = exit_code;
1416 1424
1417 switch (state_) { 1425 switch (state_) {
1418 case HOST_INITIALIZING: 1426 case HOST_INITIALIZING:
1419 state_ = HOST_STOPPING; 1427 state_ = HOST_STOPPING;
1420 ShutdownOnNetworkThread(); 1428 DCHECK(!host_signaling_manager_);
1429 host_signaling_manager_ = CreateHostSignalingManager();
1430 SendOfflineReasonAndShutdownOnNetworkThread(exit_code);
1421 break; 1431 break;
1422 1432
1423 case HOST_STARTED: 1433 case HOST_STARTED:
1424 state_ = HOST_STOPPING; 1434 state_ = HOST_STOPPING;
1425 heartbeat_sender_->SetHostOfflineReason( 1435 SendOfflineReasonAndShutdownOnNetworkThread(exit_code);
1426 ExitCodeToString(exit_code), base::Bind(base::DoNothing));
1427 ScheduleHostShutdown();
1428 break; 1436 break;
1429 1437
1430 case HOST_STOPPING_TO_RESTART: 1438 case HOST_STOPPING_TO_RESTART:
1431 state_ = HOST_STOPPING; 1439 state_ = HOST_STOPPING;
1432 break; 1440 break;
1433 1441
1434 case HOST_STOPPING: 1442 case HOST_STOPPING:
1435 case HOST_STOPPED: 1443 case HOST_STOPPED:
1436 // Host is already stopped or being stopped. No action is required. 1444 // Host is already stopped or being stopped. No action is required.
1437 break; 1445 break;
1438 } 1446 }
1439 } 1447 }
1440 1448
1441 // TODO(weitaosu): shut down the host once we get an ACK for the offline status
1442 // XMPP message.
1443 void HostProcess::ScheduleHostShutdown() {
1444 // Delay the shutdown by 2 second to allow SendOfflineStatus to complete.
1445 context_->network_task_runner()->PostDelayedTask(
1446 FROM_HERE,
1447 base::Bind(&HostProcess::ShutdownOnNetworkThread, base::Unretained(this)),
1448 base::TimeDelta::FromSeconds(2));
1449 }
1450
1451 void HostProcess::ShutdownOnNetworkThread() { 1449 void HostProcess::ShutdownOnNetworkThread() {
1452 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); 1450 DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
1453 1451
1452 // Need to invalidate WeakPtrs on the same thread where they are dereferenced.
1453 weak_factory_for_network_task_runner_.InvalidateWeakPtrs();
1454
1454 host_.reset(); 1455 host_.reset();
1455 host_event_logger_.reset(); 1456 host_event_logger_.reset();
1456 host_status_logger_.reset(); 1457 host_status_logger_.reset();
1457 heartbeat_sender_.reset(); 1458 host_signaling_manager_.reset();
1458 host_change_notification_listener_.reset(); 1459 host_change_notification_listener_.reset();
1459 signaling_connector_.reset();
1460 oauth_token_getter_.reset();
1461 signal_strategy_.reset();
1462 network_change_notifier_.reset();
1463 1460
1464 if (state_ == HOST_STOPPING_TO_RESTART) { 1461 if (state_ == HOST_STOPPING_TO_RESTART) {
1465 StartHost(); 1462 StartHost();
1466 } else if (state_ == HOST_STOPPING) { 1463 } else if (state_ == HOST_STOPPING) {
1467 state_ = HOST_STOPPED; 1464 state_ = HOST_STOPPED;
1468 1465
1469 shutdown_watchdog_->SetExitCode(*exit_code_out_); 1466 shutdown_watchdog_->SetExitCode(*exit_code_out_);
1470 shutdown_watchdog_->Arm(); 1467 shutdown_watchdog_->Arm();
1471 1468
1472 if (policy_watcher_.get()) { 1469 if (policy_watcher_.get()) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1536 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); 1533 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds));
1537 new HostProcess(context.Pass(), &exit_code, &shutdown_watchdog); 1534 new HostProcess(context.Pass(), &exit_code, &shutdown_watchdog);
1538 1535
1539 // Run the main (also UI) message loop until the host no longer needs it. 1536 // Run the main (also UI) message loop until the host no longer needs it.
1540 message_loop.Run(); 1537 message_loop.Run();
1541 1538
1542 return exit_code; 1539 return exit_code;
1543 } 1540 }
1544 1541
1545 } // namespace remoting 1542 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698