| 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_WIN_WTS_SESSION_PROCESS_LAUNCHER_H_ | 5 #ifndef REMOTING_HOST_WIN_WTS_SESSION_PROCESS_LAUNCHER_H_ |
| 6 #define REMOTING_HOST_WIN_WTS_SESSION_PROCESS_LAUNCHER_H_ | 6 #define REMOTING_HOST_WIN_WTS_SESSION_PROCESS_LAUNCHER_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/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/process.h" | 14 #include "base/process.h" |
| 15 #include "base/time.h" | 15 #include "base/time.h" |
| 16 #include "base/timer.h" | 16 #include "base/timer.h" |
| 17 #include "base/win/scoped_handle.h" | 17 #include "base/win/scoped_handle.h" |
| 18 #include "base/win/object_watcher.h" | |
| 19 #include "ipc/ipc_channel.h" | 18 #include "ipc/ipc_channel.h" |
| 20 #include "remoting/base/stoppable.h" | 19 #include "remoting/base/stoppable.h" |
| 20 #include "remoting/host/win/worker_process_launcher.h" |
| 21 #include "remoting/host/win/wts_console_observer.h" | 21 #include "remoting/host/win/wts_console_observer.h" |
| 22 | 22 |
| 23 namespace base { | 23 namespace base { |
| 24 class SingleThreadTaskRunner; | 24 class SingleThreadTaskRunner; |
| 25 } // namespace base | 25 } // namespace base |
| 26 | 26 |
| 27 namespace IPC { | 27 namespace IPC { |
| 28 class ChannelProxy; | 28 class ChannelProxy; |
| 29 class Message; | 29 class Message; |
| 30 } // namespace IPC | 30 } // namespace IPC |
| 31 | 31 |
| 32 namespace remoting { | 32 namespace remoting { |
| 33 | 33 |
| 34 class SasInjector; | 34 class SasInjector; |
| 35 class WtsConsoleMonitor; | 35 class WtsConsoleMonitor; |
| 36 | 36 |
| 37 class WtsSessionProcessLauncher | 37 class WtsSessionProcessLauncher |
| 38 : public Stoppable, | 38 : public Stoppable, |
| 39 public base::win::ObjectWatcher::Delegate, | 39 public WorkerProcessLauncher::Delegate, |
| 40 public IPC::Listener, | |
| 41 public WtsConsoleObserver { | 40 public WtsConsoleObserver { |
| 42 public: | 41 public: |
| 43 // Constructs a WtsSessionProcessLauncher object. All interaction with | 42 // Constructs a WtsSessionProcessLauncher object. |stopped_callback| and |
| 44 // |monitor| should happen on |main_message_loop|. |ipc_message_loop| has | 43 // |main_message_loop| are passed to the undelying |Stoppable| implementation. |
| 45 // to be an I/O message loop. | 44 // All interaction with |monitor| should happen on |main_message_loop|. |
| 45 // |ipc_message_loop| must be an I/O message loop. |
| 46 WtsSessionProcessLauncher( | 46 WtsSessionProcessLauncher( |
| 47 const base::Closure& stopped_callback, | 47 const base::Closure& stopped_callback, |
| 48 WtsConsoleMonitor* monitor, | 48 WtsConsoleMonitor* monitor, |
| 49 scoped_refptr<base::SingleThreadTaskRunner> main_message_loop, | 49 scoped_refptr<base::SingleThreadTaskRunner> main_message_loop, |
| 50 scoped_refptr<base::SingleThreadTaskRunner> ipc_message_loop); | 50 scoped_refptr<base::SingleThreadTaskRunner> ipc_message_loop); |
| 51 | 51 |
| 52 virtual ~WtsSessionProcessLauncher(); | 52 virtual ~WtsSessionProcessLauncher(); |
| 53 | 53 |
| 54 // base::win::ObjectWatcher::Delegate implementation. | 54 // WorkerProcessLauncher::Delegate implementation. |
| 55 virtual void OnObjectSignaled(HANDLE object) OVERRIDE; | 55 virtual bool DoLaunchProcess( |
| 56 | 56 const std::string& channel_name, |
| 57 // IPC::Listener implementation. | 57 base::win::ScopedHandle* process_exit_event_out) OVERRIDE; |
| 58 virtual void DoKillProcess(DWORD exit_code) OVERRIDE; |
| 59 virtual void OnChannelConnected(DWORD peer_pid) OVERRIDE; |
| 58 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 60 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 59 | 61 |
| 60 // WtsConsoleObserver implementation. | 62 // WtsConsoleObserver implementation. |
| 61 virtual void OnSessionAttached(uint32 session_id) OVERRIDE; | 63 virtual void OnSessionAttached(uint32 session_id) OVERRIDE; |
| 62 virtual void OnSessionDetached() OVERRIDE; | 64 virtual void OnSessionDetached() OVERRIDE; |
| 63 | 65 |
| 64 protected: | 66 protected: |
| 65 // Stoppable implementation. | 67 // Stoppable implementation. |
| 66 virtual void DoStop() OVERRIDE; | 68 virtual void DoStop() OVERRIDE; |
| 67 | 69 |
| 68 private: | 70 private: |
| 69 // Attempts to launch the host process in the current console session. | 71 // Attempts to launch the host process in the current console session. |
| 70 // Schedules next launch attempt if creation of the process fails for any | 72 // Schedules next launch attempt if creation of the process fails for any |
| 71 // reason. | 73 // reason. |
| 72 void LaunchProcess(); | 74 void LaunchProcess(); |
| 73 | 75 |
| 76 // Called when the launcher reports the process to be stopped. |
| 77 void OnLauncherStopped(); |
| 78 |
| 74 // Sends the Secure Attention Sequence to the session represented by | 79 // Sends the Secure Attention Sequence to the session represented by |
| 75 // |session_token_|. | 80 // |session_token_|. |
| 76 void OnSendSasToConsole(); | 81 void OnSendSasToConsole(); |
| 77 | 82 |
| 83 // |true| if this object is currently attached to the console session. |
| 84 bool attached_; |
| 85 |
| 78 // Time of the last launch attempt. | 86 // Time of the last launch attempt. |
| 79 base::Time launch_time_; | 87 base::Time launch_time_; |
| 80 | 88 |
| 81 // Current backoff delay. | 89 // Current backoff delay. |
| 82 base::TimeDelta launch_backoff_; | 90 base::TimeDelta launch_backoff_; |
| 83 | 91 |
| 84 // Timer used to schedule the next attempt to launch the process. | 92 // Timer used to schedule the next attempt to launch the process. |
| 85 base::OneShotTimer<WtsSessionProcessLauncher> timer_; | 93 base::OneShotTimer<WtsSessionProcessLauncher> timer_; |
| 86 | 94 |
| 87 // The main service message loop. | 95 // The main service message loop. |
| 88 scoped_refptr<base::SingleThreadTaskRunner> main_message_loop_; | 96 scoped_refptr<base::SingleThreadTaskRunner> main_message_loop_; |
| 89 | 97 |
| 90 // Message loop used by the IPC channel. | 98 // Message loop used by the IPC channel. |
| 91 scoped_refptr<base::SingleThreadTaskRunner> ipc_message_loop_; | 99 scoped_refptr<base::SingleThreadTaskRunner> ipc_message_loop_; |
| 92 | 100 |
| 93 // This pointer is used to unsubscribe from session attach and detach events. | 101 // This pointer is used to unsubscribe from session attach and detach events. |
| 94 WtsConsoleMonitor* monitor_; | 102 WtsConsoleMonitor* monitor_; |
| 95 | 103 |
| 96 // The handle of the process injected into the console session. | 104 scoped_ptr<WorkerProcessLauncher> launcher_; |
| 97 base::Process process_; | |
| 98 | 105 |
| 99 // Used to determine when the launched process terminates. | 106 base::win::ScopedHandle worker_process_; |
| 100 base::win::ObjectWatcher process_watcher_; | |
| 101 | 107 |
| 102 // The token to be used to launch a process in a different session. | 108 // The token to be used to launch a process in a different session. |
| 103 base::win::ScopedHandle session_token_; | 109 base::win::ScopedHandle session_token_; |
| 104 | 110 |
| 105 // Defines the states the process launcher can be in. | |
| 106 enum State { | |
| 107 StateDetached, | |
| 108 StateStarting, | |
| 109 StateAttached, | |
| 110 }; | |
| 111 | |
| 112 // Current state of the process launcher. | |
| 113 State state_; | |
| 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_; | 111 scoped_ptr<SasInjector> sas_injector_; |
| 120 | 112 |
| 121 DISALLOW_COPY_AND_ASSIGN(WtsSessionProcessLauncher); | 113 DISALLOW_COPY_AND_ASSIGN(WtsSessionProcessLauncher); |
| 122 }; | 114 }; |
| 123 | 115 |
| 124 } // namespace remoting | 116 } // namespace remoting |
| 125 | 117 |
| 126 #endif // REMOTING_HOST_WIN_WTS_SESSION_PROCESS_LAUNCHER_H_ | 118 #endif // REMOTING_HOST_WIN_WTS_SESSION_PROCESS_LAUNCHER_H_ |
| OLD | NEW |