OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // This file implements a standalone host process for Me2Me. | 5 // This file implements a standalone host process for Me2Me. |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 #include "remoting/host/host_main.h" | 54 #include "remoting/host/host_main.h" |
55 #include "remoting/host/host_status_logger.h" | 55 #include "remoting/host/host_status_logger.h" |
56 #include "remoting/host/ipc_constants.h" | 56 #include "remoting/host/ipc_constants.h" |
57 #include "remoting/host/ipc_desktop_environment.h" | 57 #include "remoting/host/ipc_desktop_environment.h" |
58 #include "remoting/host/ipc_host_event_logger.h" | 58 #include "remoting/host/ipc_host_event_logger.h" |
59 #include "remoting/host/logging.h" | 59 #include "remoting/host/logging.h" |
60 #include "remoting/host/me2me_desktop_environment.h" | 60 #include "remoting/host/me2me_desktop_environment.h" |
61 #include "remoting/host/pairing_registry_delegate.h" | 61 #include "remoting/host/pairing_registry_delegate.h" |
62 #include "remoting/host/policy_hack/policy_watcher.h" | 62 #include "remoting/host/policy_hack/policy_watcher.h" |
63 #include "remoting/host/session_manager_factory.h" | 63 #include "remoting/host/session_manager_factory.h" |
64 #include "remoting/host/shutdown_watchdog.h" | |
64 #include "remoting/host/signaling_connector.h" | 65 #include "remoting/host/signaling_connector.h" |
65 #include "remoting/host/single_window_desktop_environment.h" | 66 #include "remoting/host/single_window_desktop_environment.h" |
66 #include "remoting/host/token_validator_factory_impl.h" | 67 #include "remoting/host/token_validator_factory_impl.h" |
67 #include "remoting/host/usage_stats_consent.h" | 68 #include "remoting/host/usage_stats_consent.h" |
68 #include "remoting/host/username.h" | 69 #include "remoting/host/username.h" |
69 #include "remoting/host/video_frame_recorder_host_extension.h" | 70 #include "remoting/host/video_frame_recorder_host_extension.h" |
70 #include "remoting/protocol/me2me_host_authenticator_factory.h" | 71 #include "remoting/protocol/me2me_host_authenticator_factory.h" |
71 #include "remoting/protocol/network_settings.h" | 72 #include "remoting/protocol/network_settings.h" |
72 #include "remoting/protocol/pairing_registry.h" | 73 #include "remoting/protocol/pairing_registry.h" |
73 #include "remoting/protocol/token_validator.h" | 74 #include "remoting/protocol/token_validator.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 | 128 |
128 // Command line switch used to enable and configure the frame-recorder. | 129 // Command line switch used to enable and configure the frame-recorder. |
129 const char kFrameRecorderBufferKbName[] = "frame-recorder-buffer-kb"; | 130 const char kFrameRecorderBufferKbName[] = "frame-recorder-buffer-kb"; |
130 | 131 |
131 // Value used for --host-config option to indicate that the path must be read | 132 // Value used for --host-config option to indicate that the path must be read |
132 // from stdin. | 133 // from stdin. |
133 const char kStdinConfigPath[] = "-"; | 134 const char kStdinConfigPath[] = "-"; |
134 | 135 |
135 const char kWindowIdSwitchName[] = "window-id"; | 136 const char kWindowIdSwitchName[] = "window-id"; |
136 | 137 |
138 // Maximum time to wait for clean shutdown to occur, before forcing termination | |
139 // of the process. | |
140 const int kShutdownTimeoutSeconds = 15; | |
Łukasz Anforowicz
2014/12/10 23:20:48
Thanks. I'll make similar change to MinimumHeartb
| |
141 | |
137 } // namespace | 142 } // namespace |
138 | 143 |
139 namespace remoting { | 144 namespace remoting { |
140 | 145 |
141 class HostProcess | 146 class HostProcess |
142 : public ConfigWatcher::Delegate, | 147 : public ConfigWatcher::Delegate, |
143 public HostChangeNotificationListener::Listener, | 148 public HostChangeNotificationListener::Listener, |
144 public IPC::Listener, | 149 public IPC::Listener, |
145 public base::RefCountedThreadSafe<HostProcess> { | 150 public base::RefCountedThreadSafe<HostProcess> { |
146 public: | 151 public: |
152 // |shutdown_watchdog| is armed when shutdown is started, and should be kept | |
153 // alive as long as possible until the process exits (since destroying the | |
154 // watchdog disarms it). | |
147 HostProcess(scoped_ptr<ChromotingHostContext> context, | 155 HostProcess(scoped_ptr<ChromotingHostContext> context, |
148 int* exit_code_out); | 156 int* exit_code_out, |
157 ShutdownWatchdog* shutdown_watchdog); | |
149 | 158 |
150 // ConfigWatcher::Delegate interface. | 159 // ConfigWatcher::Delegate interface. |
151 void OnConfigUpdated(const std::string& serialized_config) override; | 160 void OnConfigUpdated(const std::string& serialized_config) override; |
152 void OnConfigWatcherError() override; | 161 void OnConfigWatcherError() override; |
153 | 162 |
154 // IPC::Listener implementation. | 163 // IPC::Listener implementation. |
155 bool OnMessageReceived(const IPC::Message& message) override; | 164 bool OnMessageReceived(const IPC::Message& message) override; |
156 void OnChannelError() override; | 165 void OnChannelError() override; |
157 | 166 |
158 // HostChangeNotificationListener::Listener overrides. | 167 // HostChangeNotificationListener::Listener overrides. |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 scoped_refptr<HostProcess> self_; | 342 scoped_refptr<HostProcess> self_; |
334 | 343 |
335 #if defined(REMOTING_MULTI_PROCESS) | 344 #if defined(REMOTING_MULTI_PROCESS) |
336 DesktopSessionConnector* desktop_session_connector_; | 345 DesktopSessionConnector* desktop_session_connector_; |
337 #endif // defined(REMOTING_MULTI_PROCESS) | 346 #endif // defined(REMOTING_MULTI_PROCESS) |
338 | 347 |
339 int* exit_code_out_; | 348 int* exit_code_out_; |
340 bool signal_parent_; | 349 bool signal_parent_; |
341 | 350 |
342 scoped_ptr<PairingRegistry::Delegate> pairing_registry_delegate_; | 351 scoped_ptr<PairingRegistry::Delegate> pairing_registry_delegate_; |
352 | |
353 ShutdownWatchdog* shutdown_watchdog_; | |
343 }; | 354 }; |
344 | 355 |
345 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, | 356 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, |
346 int* exit_code_out) | 357 int* exit_code_out, |
358 ShutdownWatchdog* shutdown_watchdog) | |
347 : context_(context.Pass()), | 359 : context_(context.Pass()), |
348 state_(HOST_INITIALIZING), | 360 state_(HOST_INITIALIZING), |
349 use_service_account_(false), | 361 use_service_account_(false), |
350 enable_vp9_(false), | 362 enable_vp9_(false), |
351 frame_recorder_buffer_size_(0), | 363 frame_recorder_buffer_size_(0), |
352 host_username_match_required_(false), | 364 host_username_match_required_(false), |
353 allow_nat_traversal_(true), | 365 allow_nat_traversal_(true), |
354 allow_relay_(true), | 366 allow_relay_(true), |
355 min_udp_port_(0), | 367 min_udp_port_(0), |
356 max_udp_port_(0), | 368 max_udp_port_(0), |
357 allow_pairing_(true), | 369 allow_pairing_(true), |
358 curtain_required_(false), | 370 curtain_required_(false), |
359 enable_gnubby_auth_(false), | 371 enable_gnubby_auth_(false), |
360 enable_window_capture_(false), | 372 enable_window_capture_(false), |
361 window_id_(0), | 373 window_id_(0), |
362 #if defined(REMOTING_MULTI_PROCESS) | 374 #if defined(REMOTING_MULTI_PROCESS) |
363 desktop_session_connector_(NULL), | 375 desktop_session_connector_(NULL), |
364 #endif // defined(REMOTING_MULTI_PROCESS) | 376 #endif // defined(REMOTING_MULTI_PROCESS) |
365 self_(this), | 377 self_(this), |
366 exit_code_out_(exit_code_out), | 378 exit_code_out_(exit_code_out), |
367 signal_parent_(false) { | 379 signal_parent_(false), |
380 shutdown_watchdog_(shutdown_watchdog) { | |
368 StartOnUiThread(); | 381 StartOnUiThread(); |
369 } | 382 } |
370 | 383 |
371 HostProcess::~HostProcess() { | 384 HostProcess::~HostProcess() { |
372 // Verify that UI components have been torn down. | 385 // Verify that UI components have been torn down. |
373 DCHECK(!config_watcher_); | 386 DCHECK(!config_watcher_); |
374 DCHECK(!daemon_channel_); | 387 DCHECK(!daemon_channel_); |
375 DCHECK(!desktop_environment_factory_); | 388 DCHECK(!desktop_environment_factory_); |
376 | 389 |
377 // We might be getting deleted on one of the threads the |host_context| owns, | 390 // We might be getting deleted on one of the threads the |host_context| owns, |
(...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1409 signaling_connector_.reset(); | 1422 signaling_connector_.reset(); |
1410 oauth_token_getter_.reset(); | 1423 oauth_token_getter_.reset(); |
1411 signal_strategy_.reset(); | 1424 signal_strategy_.reset(); |
1412 network_change_notifier_.reset(); | 1425 network_change_notifier_.reset(); |
1413 | 1426 |
1414 if (state_ == HOST_STOPPING_TO_RESTART) { | 1427 if (state_ == HOST_STOPPING_TO_RESTART) { |
1415 StartHost(); | 1428 StartHost(); |
1416 } else if (state_ == HOST_STOPPING) { | 1429 } else if (state_ == HOST_STOPPING) { |
1417 state_ = HOST_STOPPED; | 1430 state_ = HOST_STOPPED; |
1418 | 1431 |
1432 shutdown_watchdog_->SetExitCode(*exit_code_out_); | |
1433 shutdown_watchdog_->Arm(); | |
1434 | |
1419 if (policy_watcher_.get()) { | 1435 if (policy_watcher_.get()) { |
1420 policy_watcher_->StopWatching( | 1436 policy_watcher_->StopWatching( |
1421 base::Bind(&HostProcess::OnPolicyWatcherShutdown, this)); | 1437 base::Bind(&HostProcess::OnPolicyWatcherShutdown, this)); |
1422 } else { | 1438 } else { |
1423 OnPolicyWatcherShutdown(); | 1439 OnPolicyWatcherShutdown(); |
1424 } | 1440 } |
1425 } else { | 1441 } else { |
1426 // This method is only called in STOPPING_TO_RESTART and STOPPING states. | 1442 // This method is only called in STOPPING_TO_RESTART and STOPPING states. |
1427 NOTREACHED(); | 1443 NOTREACHED(); |
1428 } | 1444 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1472 scoped_ptr<ChromotingHostContext> context = | 1488 scoped_ptr<ChromotingHostContext> context = |
1473 ChromotingHostContext::Create(new AutoThreadTaskRunner( | 1489 ChromotingHostContext::Create(new AutoThreadTaskRunner( |
1474 message_loop.message_loop_proxy(), base::MessageLoop::QuitClosure())); | 1490 message_loop.message_loop_proxy(), base::MessageLoop::QuitClosure())); |
1475 if (!context) | 1491 if (!context) |
1476 return kInitializationFailed; | 1492 return kInitializationFailed; |
1477 | 1493 |
1478 // Create & start the HostProcess using these threads. | 1494 // Create & start the HostProcess using these threads. |
1479 // TODO(wez): The HostProcess holds a reference to itself until Shutdown(). | 1495 // TODO(wez): The HostProcess holds a reference to itself until Shutdown(). |
1480 // Remove this hack as part of the multi-process refactoring. | 1496 // Remove this hack as part of the multi-process refactoring. |
1481 int exit_code = kSuccessExitCode; | 1497 int exit_code = kSuccessExitCode; |
1482 new HostProcess(context.Pass(), &exit_code); | 1498 ShutdownWatchdog shutdown_watchdog( |
1499 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); | |
1500 new HostProcess(context.Pass(), &exit_code, &shutdown_watchdog); | |
1483 | 1501 |
1484 // Run the main (also UI) message loop until the host no longer needs it. | 1502 // Run the main (also UI) message loop until the host no longer needs it. |
1485 message_loop.Run(); | 1503 message_loop.Run(); |
1486 | 1504 |
1487 return exit_code; | 1505 return exit_code; |
1488 } | 1506 } |
1489 | 1507 |
1490 } // namespace remoting | 1508 } // namespace remoting |
OLD | NEW |