Chromium Code Reviews| 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 the Windows service controlling Me2Me host processes | 5 // This file implements the Windows service controlling Me2Me host processes |
| 6 // running within user sessions. | 6 // running within user sessions. |
| 7 | 7 |
| 8 #include "remoting/host/wts_session_process_launcher_win.h" | 8 #include "remoting/host/wts_session_process_launcher_win.h" |
| 9 | 9 |
| 10 #include <windows.h> | 10 #include <windows.h> |
| 11 #include <sddl.h> | 11 #include <sddl.h> |
| 12 #include <limits> | 12 #include <limits> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
| 16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/message_loop_proxy.h" | 18 #include "base/message_loop_proxy.h" |
| 19 #include "base/process_util.h" | 19 #include "base/process_util.h" |
| 20 #include "base/rand_util.h" | 20 #include "base/rand_util.h" |
| 21 #include "base/string16.h" | 21 #include "base/string16.h" |
| 22 #include "base/stringize_macros.h" | 22 #include "base/stringize_macros.h" |
| 23 #include "base/stringprintf.h" | 23 #include "base/stringprintf.h" |
| 24 #include "base/win/scoped_handle.h" | 24 #include "base/win/scoped_handle.h" |
| 25 #include "base/win/scoped_process_information.h" | 25 #include "base/win/scoped_process_information.h" |
| 26 #include "ipc/ipc_channel_proxy.h" | 26 #include "ipc/ipc_channel_proxy.h" |
| 27 #include "ipc/ipc_message.h" | 27 #include "ipc/ipc_message.h" |
| 28 #include "ipc/ipc_message_macros.h" | 28 #include "ipc/ipc_message_macros.h" |
| 29 | 29 #include "remoting/host/constants.h" |
| 30 #include "remoting/host/chromoting_messages.h" | 30 #include "remoting/host/chromoting_messages.h" |
| 31 #include "remoting/host/sas_injector.h" | 31 #include "remoting/host/sas_injector.h" |
| 32 #include "remoting/host/wts_console_monitor_win.h" | 32 #include "remoting/host/wts_console_monitor_win.h" |
| 33 | 33 |
| 34 using base::win::ScopedHandle; | 34 using base::win::ScopedHandle; |
| 35 using base::TimeDelta; | 35 using base::TimeDelta; |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 // The exit code returned by the host process when its configuration is not | 39 // The range of host exit codes that should be interpreted as a permanent error |
| 40 // valid. | 40 // condition. |
| 41 const int kInvalidHostConfigurationExitCode = 1; | 41 enum { |
| 42 kHostPermanentErrorMin = remoting::kInvalidHostConfigurationExitCode, | |
| 43 kHostPermanentErrorMax = remoting::kInvalidOauthCredentialsExitCode | |
| 44 }; | |
|
simonmorris
2012/04/17 19:52:30
It would be safer to define these alongside the ex
alexeypa (please no reviews)
2012/04/17 20:01:05
Done.
| |
| 42 | 45 |
| 43 // The minimum and maximum delays between attempts to inject host process into | 46 // The minimum and maximum delays between attempts to inject host process into |
| 44 // a session. | 47 // a session. |
| 45 const int kMaxLaunchDelaySeconds = 60; | 48 const int kMaxLaunchDelaySeconds = 60; |
| 46 const int kMinLaunchDelaySeconds = 1; | 49 const int kMinLaunchDelaySeconds = 1; |
| 47 | 50 |
| 48 // Name of the default session desktop. | 51 // Name of the default session desktop. |
| 49 char16 kDefaultDesktopName[] = TO_L_STRING("winsta0\\default"); | 52 char16 kDefaultDesktopName[] = TO_L_STRING("winsta0\\default"); |
| 50 | 53 |
| 51 // Match the pipe name prefix used by Chrome IPC channels. | 54 // Match the pipe name prefix used by Chrome IPC channels. |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 return; | 346 return; |
| 344 } | 347 } |
| 345 | 348 |
| 346 DCHECK(!timer_.IsRunning()); | 349 DCHECK(!timer_.IsRunning()); |
| 347 DCHECK(process_.handle() != NULL); | 350 DCHECK(process_.handle() != NULL); |
| 348 DCHECK(process_watcher_.GetWatchedObject() == NULL); | 351 DCHECK(process_watcher_.GetWatchedObject() == NULL); |
| 349 DCHECK(chromoting_channel_.get() != NULL); | 352 DCHECK(chromoting_channel_.get() != NULL); |
| 350 | 353 |
| 351 // Stop trying to restart the host if its process exited due to | 354 // Stop trying to restart the host if its process exited due to |
| 352 // misconfiguration. | 355 // misconfiguration. |
| 353 DWORD exit_code; | 356 int exit_code; |
| 354 bool stop_trying = GetExitCodeProcess(process_.handle(), &exit_code) && | 357 bool stop_trying = |
| 355 exit_code == kInvalidHostConfigurationExitCode; | 358 base::WaitForExitCodeWithTimeout(process_.handle(), &exit_code, 0) && |
| 359 kHostPermanentErrorMin <= exit_code && | |
| 360 exit_code <= kHostPermanentErrorMax; | |
| 356 | 361 |
| 357 // The host process has been terminated for some reason. The handle can now be | 362 // The host process has been terminated for some reason. The handle can now be |
| 358 // closed. | 363 // closed. |
| 359 process_.Close(); | 364 process_.Close(); |
| 360 chromoting_channel_.reset(); | 365 chromoting_channel_.reset(); |
| 361 state_ = StateStarting; | 366 state_ = StateStarting; |
| 362 | 367 |
| 363 if (stop_trying) { | 368 if (stop_trying) { |
| 364 OnSessionDetached(); | 369 OnSessionDetached(); |
| 365 | 370 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 488 process_watcher_.StopWatching(); | 493 process_watcher_.StopWatching(); |
| 489 process_.Terminate(0); | 494 process_.Terminate(0); |
| 490 process_.Close(); | 495 process_.Close(); |
| 491 chromoting_channel_.reset(); | 496 chromoting_channel_.reset(); |
| 492 state_ = StateDetached; | 497 state_ = StateDetached; |
| 493 break; | 498 break; |
| 494 } | 499 } |
| 495 } | 500 } |
| 496 | 501 |
| 497 } // namespace remoting | 502 } // namespace remoting |
| OLD | NEW |