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

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

Powered by Google App Engine
This is Rietveld 408576698