| 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 #ifndef REMOTING_HOST_WTS_SESSION_PROCESS_LAUNCHER_WIN_H_ | 5 #ifndef REMOTING_HOST_WTS_SESSION_PROCESS_LAUNCHER_WIN_H_ |
| 6 #define REMOTING_HOST_WTS_SESSION_PROCESS_LAUNCHER_WIN_H_ | 6 #define REMOTING_HOST_WTS_SESSION_PROCESS_LAUNCHER_WIN_H_ |
| 7 | 7 |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/process.h" | 13 #include "base/process.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "base/timer.h" | 15 #include "base/timer.h" |
| 16 #include "base/win/scoped_handle.h" | 16 #include "base/win/scoped_handle.h" |
| 17 #include "base/win/object_watcher.h" | 17 #include "base/win/object_watcher.h" |
| 18 #include "ipc/ipc_channel.h" |
| 18 | 19 |
| 19 #include "remoting/host/wts_console_observer_win.h" | 20 #include "remoting/host/wts_console_observer_win.h" |
| 20 | 21 |
| 22 namespace base { |
| 23 |
| 24 class Thread; |
| 25 |
| 26 } // namespace base |
| 27 |
| 28 namespace IPC { |
| 29 |
| 30 class ChannelProxy; |
| 31 class Message; |
| 32 |
| 33 } // namespace IPC |
| 34 |
| 21 namespace remoting { | 35 namespace remoting { |
| 22 | 36 |
| 37 class SasInjector; |
| 23 class WtsConsoleMonitor; | 38 class WtsConsoleMonitor; |
| 24 | 39 |
| 25 class WtsSessionProcessLauncher | 40 class WtsSessionProcessLauncher |
| 26 : public base::win::ObjectWatcher::Delegate, | 41 : public base::win::ObjectWatcher::Delegate, |
| 42 public IPC::Channel::Listener, |
| 27 public WtsConsoleObserver { | 43 public WtsConsoleObserver { |
| 28 public: | 44 public: |
| 29 // Constructs a WtsSessionProcessLauncher object. |monitor| must outlive this | 45 // Constructs a WtsSessionProcessLauncher object. |monitor| and |io_thread| |
| 30 // class. |host_binary| is the name of the executable to be launched in | 46 // must outlive this object. |host_binary| is the name of the executable to |
| 31 // the console session. | 47 // be launched in the console session. |
| 32 WtsSessionProcessLauncher(WtsConsoleMonitor* monitor, | 48 WtsSessionProcessLauncher(WtsConsoleMonitor* monitor, |
| 33 const FilePath& host_binary); | 49 const FilePath& host_binary, |
| 50 base::Thread* io_thread); |
| 34 | 51 |
| 35 virtual ~WtsSessionProcessLauncher(); | 52 virtual ~WtsSessionProcessLauncher(); |
| 36 | 53 |
| 37 // base::win::ObjectWatcher::Delegate implementation | 54 // base::win::ObjectWatcher::Delegate implementation. |
| 38 virtual void OnObjectSignaled(HANDLE object) OVERRIDE; | 55 virtual void OnObjectSignaled(HANDLE object) OVERRIDE; |
| 39 | 56 |
| 40 // WtsConsoleObserver implementation | 57 // IPC::Channel::Listener implementation. |
| 58 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 59 |
| 60 // WtsConsoleObserver implementation. |
| 41 virtual void OnSessionAttached(uint32 session_id) OVERRIDE; | 61 virtual void OnSessionAttached(uint32 session_id) OVERRIDE; |
| 42 virtual void OnSessionDetached() OVERRIDE; | 62 virtual void OnSessionDetached() OVERRIDE; |
| 43 | 63 |
| 44 private: | 64 private: |
| 45 // Attempts to launch the host process in the current console session. | 65 // Attempts to launch the host process in the current console session. |
| 46 // Schedules next launch attempt if creation of the process fails for any | 66 // Schedules next launch attempt if creation of the process fails for any |
| 47 // reason. | 67 // reason. |
| 48 void LaunchProcess(); | 68 void LaunchProcess(); |
| 49 | 69 |
| 70 // Sends the Secure Attention Sequence to the session represented by |
| 71 // |session_token_|. |
| 72 void OnSendSasToConsole(); |
| 73 |
| 50 // Name of the host executable. | 74 // Name of the host executable. |
| 51 FilePath host_binary_; | 75 FilePath host_binary_; |
| 52 | 76 |
| 53 // Time of the last launch attempt. | 77 // Time of the last launch attempt. |
| 54 base::Time launch_time_; | 78 base::Time launch_time_; |
| 55 | 79 |
| 56 // Current backoff delay. | 80 // Current backoff delay. |
| 57 base::TimeDelta launch_backoff_; | 81 base::TimeDelta launch_backoff_; |
| 58 | 82 |
| 59 // Timer used to schedule the next attempt to launch the process. | 83 // Timer used to schedule the next attempt to launch the process. |
| 60 base::OneShotTimer<WtsSessionProcessLauncher> timer_; | 84 base::OneShotTimer<WtsSessionProcessLauncher> timer_; |
| 61 | 85 |
| 86 // The I/O thread hosts the Chromoting IPC channel and any other code |
| 87 // requiring an I/O message loop. |
| 88 base::Thread* io_thread_; |
| 89 |
| 62 // This pointer is used to unsubscribe from session attach and detach events. | 90 // This pointer is used to unsubscribe from session attach and detach events. |
| 63 WtsConsoleMonitor* monitor_; | 91 WtsConsoleMonitor* monitor_; |
| 64 | 92 |
| 65 // Impersonation token that has the SE_TCB_NAME privilege enabled. | 93 // Impersonation token that has the SE_TCB_NAME privilege enabled. |
| 66 base::win::ScopedHandle privileged_token_; | 94 base::win::ScopedHandle privileged_token_; |
| 67 | 95 |
| 68 // The handle of the process injected into the console session. | 96 // The handle of the process injected into the console session. |
| 69 base::Process process_; | 97 base::Process process_; |
| 70 | 98 |
| 71 // Used to determine when the launched process terminates. | 99 // Used to determine when the launched process terminates. |
| 72 base::win::ObjectWatcher process_watcher_; | 100 base::win::ObjectWatcher process_watcher_; |
| 73 | 101 |
| 74 // The token to be used to launch a process in a different session. | 102 // The token to be used to launch a process in a different session. |
| 75 base::win::ScopedHandle session_token_; | 103 base::win::ScopedHandle session_token_; |
| 76 | 104 |
| 77 // Defines the states the process launcher can be in. | 105 // Defines the states the process launcher can be in. |
| 78 enum State { | 106 enum State { |
| 79 StateDetached, | 107 StateDetached, |
| 80 StateStarting, | 108 StateStarting, |
| 81 StateAttached, | 109 StateAttached, |
| 82 }; | 110 }; |
| 83 | 111 |
| 84 // Current state of the process launcher. | 112 // Current state of the process launcher. |
| 85 State state_; | 113 State state_; |
| 86 | 114 |
| 115 // The Chromoting IPC channel connecting the service to the per-session |
| 116 // process. |
| 117 scoped_ptr<IPC::ChannelProxy> chromoting_channel_; |
| 118 |
| 119 scoped_ptr<SasInjector> sas_injector_; |
| 120 |
| 87 DISALLOW_COPY_AND_ASSIGN(WtsSessionProcessLauncher); | 121 DISALLOW_COPY_AND_ASSIGN(WtsSessionProcessLauncher); |
| 88 }; | 122 }; |
| 89 | 123 |
| 90 } // namespace remoting | 124 } // namespace remoting |
| 91 | 125 |
| 92 #endif // REMOTING_HOST_WTS_SESSION_PROCESS_LAUNCHER_WIN_H_ | 126 #endif // REMOTING_HOST_WTS_SESSION_PROCESS_LAUNCHER_WIN_H_ |
| OLD | NEW |