| 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/base_switches.h" | 14 #include "base/base_switches.h" |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/bind_helpers.h" | 16 #include "base/bind_helpers.h" |
| 17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/message_loop_proxy.h" | 19 #include "base/message_loop_proxy.h" |
| 20 #include "base/process_util.h" | 20 #include "base/process_util.h" |
| 21 #include "base/rand_util.h" | 21 #include "base/rand_util.h" |
| 22 #include "base/string16.h" | 22 #include "base/string16.h" |
| 23 #include "base/stringize_macros.h" | 23 #include "base/stringize_macros.h" |
| 24 #include "base/stringprintf.h" | 24 #include "base/stringprintf.h" |
| 25 #include "base/win/scoped_handle.h" | 25 #include "base/win/scoped_handle.h" |
| 26 #include "base/win/scoped_process_information.h" | 26 #include "base/win/scoped_process_information.h" |
| 27 #include "ipc/ipc_channel_proxy.h" | 27 #include "ipc/ipc_channel_proxy.h" |
| 28 #include "ipc/ipc_message.h" | 28 #include "ipc/ipc_message.h" |
| 29 #include "ipc/ipc_message_macros.h" | 29 #include "ipc/ipc_message_macros.h" |
| 30 | 30 #include "remoting/host/constants.h" |
| 31 #include "remoting/host/chromoting_messages.h" | 31 #include "remoting/host/chromoting_messages.h" |
| 32 #include "remoting/host/sas_injector.h" | 32 #include "remoting/host/sas_injector.h" |
| 33 #include "remoting/host/wts_console_monitor_win.h" | 33 #include "remoting/host/wts_console_monitor_win.h" |
| 34 | 34 |
| 35 using base::win::ScopedHandle; | 35 using base::win::ScopedHandle; |
| 36 using base::TimeDelta; | 36 using base::TimeDelta; |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 // The exit code returned by the host process when its configuration is not | |
| 41 // valid. | |
| 42 const int kInvalidHostConfigurationExitCode = 1; | |
| 43 | |
| 44 // The minimum and maximum delays between attempts to inject host process into | 40 // The minimum and maximum delays between attempts to inject host process into |
| 45 // a session. | 41 // a session. |
| 46 const int kMaxLaunchDelaySeconds = 60; | 42 const int kMaxLaunchDelaySeconds = 60; |
| 47 const int kMinLaunchDelaySeconds = 1; | 43 const int kMinLaunchDelaySeconds = 1; |
| 48 | 44 |
| 49 // Name of the default session desktop. | 45 // Name of the default session desktop. |
| 50 char16 kDefaultDesktopName[] = TO_L_STRING("winsta0\\default"); | 46 char16 kDefaultDesktopName[] = TO_L_STRING("winsta0\\default"); |
| 51 | 47 |
| 52 // Match the pipe name prefix used by Chrome IPC channels. | 48 // Match the pipe name prefix used by Chrome IPC channels. |
| 53 const char16 kChromePipeNamePrefix[] = TO_L_STRING("\\\\.\\pipe\\chrome."); | 49 const char16 kChromePipeNamePrefix[] = TO_L_STRING("\\\\.\\pipe\\chrome."); |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 return; | 341 return; |
| 346 } | 342 } |
| 347 | 343 |
| 348 DCHECK(!timer_.IsRunning()); | 344 DCHECK(!timer_.IsRunning()); |
| 349 DCHECK(process_.handle() != NULL); | 345 DCHECK(process_.handle() != NULL); |
| 350 DCHECK(process_watcher_.GetWatchedObject() == NULL); | 346 DCHECK(process_watcher_.GetWatchedObject() == NULL); |
| 351 DCHECK(chromoting_channel_.get() != NULL); | 347 DCHECK(chromoting_channel_.get() != NULL); |
| 352 | 348 |
| 353 // Stop trying to restart the host if its process exited due to | 349 // Stop trying to restart the host if its process exited due to |
| 354 // misconfiguration. | 350 // misconfiguration. |
| 355 DWORD exit_code; | 351 int exit_code; |
| 356 bool stop_trying = GetExitCodeProcess(process_.handle(), &exit_code) && | 352 bool stop_trying = |
| 357 exit_code == kInvalidHostConfigurationExitCode; | 353 base::WaitForExitCodeWithTimeout(process_.handle(), &exit_code, 0) && |
| 354 kMinPermanentErrorExitCode <= exit_code && |
| 355 exit_code <= kMaxPermanentErrorExitCode; |
| 358 | 356 |
| 359 // The host process has been terminated for some reason. The handle can now be | 357 // The host process has been terminated for some reason. The handle can now be |
| 360 // closed. | 358 // closed. |
| 361 process_.Close(); | 359 process_.Close(); |
| 362 chromoting_channel_.reset(); | 360 chromoting_channel_.reset(); |
| 363 state_ = StateStarting; | 361 state_ = StateStarting; |
| 364 | 362 |
| 365 if (stop_trying) { | 363 if (stop_trying) { |
| 366 OnSessionDetached(); | 364 OnSessionDetached(); |
| 367 | 365 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 process_watcher_.StopWatching(); | 488 process_watcher_.StopWatching(); |
| 491 process_.Terminate(0); | 489 process_.Terminate(0); |
| 492 process_.Close(); | 490 process_.Close(); |
| 493 chromoting_channel_.reset(); | 491 chromoting_channel_.reset(); |
| 494 state_ = StateDetached; | 492 state_ = StateDetached; |
| 495 break; | 493 break; |
| 496 } | 494 } |
| 497 } | 495 } |
| 498 | 496 |
| 499 } // namespace remoting | 497 } // namespace remoting |
| OLD | NEW |