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/message_loop.h" | |
14 #include "base/process.h" | 15 #include "base/process.h" |
15 #include "base/time.h" | 16 #include "base/time.h" |
16 #include "base/timer.h" | 17 #include "base/timer.h" |
17 #include "base/win/scoped_handle.h" | 18 #include "base/win/scoped_handle.h" |
18 #include "ipc/ipc_channel.h" | 19 #include "ipc/ipc_channel.h" |
19 #include "remoting/base/stoppable.h" | 20 #include "remoting/base/stoppable.h" |
20 #include "remoting/host/win/worker_process_launcher.h" | 21 #include "remoting/host/win/worker_process_launcher.h" |
21 #include "remoting/host/win/wts_console_observer.h" | 22 #include "remoting/host/win/wts_console_observer.h" |
22 | 23 |
23 namespace base { | 24 namespace base { |
24 class SingleThreadTaskRunner; | 25 class SingleThreadTaskRunner; |
25 } // namespace base | 26 } // namespace base |
26 | 27 |
27 namespace IPC { | 28 namespace IPC { |
28 class ChannelProxy; | 29 class ChannelProxy; |
29 class Message; | 30 class Message; |
30 } // namespace IPC | 31 } // namespace IPC |
31 | 32 |
32 namespace remoting { | 33 namespace remoting { |
33 | 34 |
34 class SasInjector; | 35 class SasInjector; |
35 class WtsConsoleMonitor; | 36 class WtsConsoleMonitor; |
36 | 37 |
37 class WtsSessionProcessLauncher | 38 class WtsSessionProcessLauncher |
38 : public Stoppable, | 39 : public base::MessagePumpForIO::IOHandler, |
40 public Stoppable, | |
39 public WorkerProcessLauncher::Delegate, | 41 public WorkerProcessLauncher::Delegate, |
40 public WtsConsoleObserver { | 42 public WtsConsoleObserver { |
41 public: | 43 public: |
42 // Constructs a WtsSessionProcessLauncher object. |stopped_callback| and | 44 // Constructs a WtsSessionProcessLauncher object. |stopped_callback| and |
43 // |main_message_loop| are passed to the undelying |Stoppable| implementation. | 45 // |main_message_loop| are passed to the undelying |Stoppable| implementation. |
44 // All interaction with |monitor| should happen on |main_message_loop|. | 46 // All interaction with |monitor| should happen on |main_message_loop|. |
45 // |ipc_message_loop| must be an I/O message loop. | 47 // |ipc_message_loop| must be an I/O message loop. |
46 WtsSessionProcessLauncher( | 48 WtsSessionProcessLauncher( |
47 const base::Closure& stopped_callback, | 49 const base::Closure& stopped_callback, |
48 WtsConsoleMonitor* monitor, | 50 WtsConsoleMonitor* monitor, |
49 scoped_refptr<base::SingleThreadTaskRunner> main_message_loop, | 51 scoped_refptr<base::SingleThreadTaskRunner> main_message_loop, |
50 scoped_refptr<base::SingleThreadTaskRunner> ipc_message_loop); | 52 scoped_refptr<base::SingleThreadTaskRunner> ipc_message_loop); |
51 | 53 |
52 virtual ~WtsSessionProcessLauncher(); | 54 virtual ~WtsSessionProcessLauncher(); |
53 | 55 |
56 // base::MessagePumpForIO::IOHandler implementation. | |
57 virtual void OnIOCompleted(base::MessagePumpForIO::IOContext* context, | |
58 DWORD bytes_transfered, | |
59 DWORD error) OVERRIDE; | |
60 | |
54 // WorkerProcessLauncher::Delegate implementation. | 61 // WorkerProcessLauncher::Delegate implementation. |
55 virtual bool DoLaunchProcess( | 62 virtual bool DoLaunchProcess( |
56 const std::string& channel_name, | 63 const std::string& channel_name, |
57 base::win::ScopedHandle* process_exit_event_out) OVERRIDE; | 64 base::win::ScopedHandle* process_exit_event_out) OVERRIDE; |
58 virtual void DoKillProcess(DWORD exit_code) OVERRIDE; | 65 virtual void DoKillProcess(DWORD exit_code) OVERRIDE; |
59 virtual void OnChannelConnected(DWORD peer_pid) OVERRIDE; | 66 virtual void OnChannelConnected(DWORD peer_pid) OVERRIDE; |
60 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 67 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
61 | 68 |
62 // WtsConsoleObserver implementation. | 69 // WtsConsoleObserver implementation. |
63 virtual void OnSessionAttached(uint32 session_id) OVERRIDE; | 70 virtual void OnSessionAttached(uint32 session_id) OVERRIDE; |
64 virtual void OnSessionDetached() OVERRIDE; | 71 virtual void OnSessionDetached() OVERRIDE; |
65 | 72 |
66 protected: | 73 protected: |
67 // Stoppable implementation. | 74 // Stoppable implementation. |
68 virtual void DoStop() OVERRIDE; | 75 virtual void DoStop() OVERRIDE; |
69 | 76 |
77 // Drains the completion port queue to make sure that all job object | |
78 // notifications has been received. | |
79 void DrainSandboxNotifications(); | |
rvargas (doing something else)
2012/08/13 18:54:12
Avoid naming a job object a "sandbox". Everywhere.
alexeypa (please no reviews)
2012/08/13 20:02:23
Done.
| |
80 | |
81 // Notifies that the completion port queue has been drained. | |
82 void DrainSandboxNotificationsCompleted(); | |
83 | |
84 // Creates and initializes the job object that will sandbox the launched child | |
85 // processes. | |
86 void InitializeSandbox(); | |
87 | |
88 // Notifies that the sandbox initialization is complete. | |
89 void InitializeSandboxCompleted(scoped_ptr<base::win::ScopedHandle> job); | |
90 | |
70 private: | 91 private: |
71 // Attempts to launch the host process in the current console session. | 92 // Attempts to launch the host process in the current console session. |
72 // Schedules next launch attempt if creation of the process fails for any | 93 // Schedules next launch attempt if creation of the process fails for any |
73 // reason. | 94 // reason. |
74 void LaunchProcess(); | 95 void LaunchProcess(); |
75 | 96 |
76 // Called when the launcher reports the process to be stopped. | 97 // Called when the launcher reports the process to be stopped. |
77 void OnLauncherStopped(); | 98 void OnLauncherStopped(); |
78 | 99 |
79 // Sends the Secure Attention Sequence to the session represented by | 100 // Sends the Secure Attention Sequence to the session represented by |
(...skipping 16 matching lines...) Expand all Loading... | |
96 scoped_refptr<base::SingleThreadTaskRunner> main_message_loop_; | 117 scoped_refptr<base::SingleThreadTaskRunner> main_message_loop_; |
97 | 118 |
98 // Message loop used by the IPC channel. | 119 // Message loop used by the IPC channel. |
99 scoped_refptr<base::SingleThreadTaskRunner> ipc_message_loop_; | 120 scoped_refptr<base::SingleThreadTaskRunner> ipc_message_loop_; |
100 | 121 |
101 // This pointer is used to unsubscribe from session attach and detach events. | 122 // This pointer is used to unsubscribe from session attach and detach events. |
102 WtsConsoleMonitor* monitor_; | 123 WtsConsoleMonitor* monitor_; |
103 | 124 |
104 scoped_ptr<WorkerProcessLauncher> launcher_; | 125 scoped_ptr<WorkerProcessLauncher> launcher_; |
105 | 126 |
127 // The job object used to control the lifetime of child processes. | |
128 base::win::ScopedHandle job_; | |
129 | |
130 // A waiting handle that becomes signalled once all process associated with | |
131 // the job have been terminated. | |
132 base::win::ScopedHandle process_exit_event_; | |
133 | |
134 enum SandboxState { | |
135 kSandboxUninitialized, | |
136 kSandboxRunning, | |
137 kSandboxStopping, | |
138 kSandboxStopped | |
139 }; | |
140 | |
141 SandboxState sandbox_state_; | |
142 | |
106 base::win::ScopedHandle worker_process_; | 143 base::win::ScopedHandle worker_process_; |
107 | 144 |
108 // The token to be used to launch a process in a different session. | 145 // The token to be used to launch a process in a different session. |
109 base::win::ScopedHandle session_token_; | 146 base::win::ScopedHandle session_token_; |
110 | 147 |
111 scoped_ptr<SasInjector> sas_injector_; | 148 scoped_ptr<SasInjector> sas_injector_; |
112 | 149 |
113 DISALLOW_COPY_AND_ASSIGN(WtsSessionProcessLauncher); | 150 DISALLOW_COPY_AND_ASSIGN(WtsSessionProcessLauncher); |
114 }; | 151 }; |
115 | 152 |
116 } // namespace remoting | 153 } // namespace remoting |
117 | 154 |
118 #endif // REMOTING_HOST_WIN_WTS_SESSION_PROCESS_LAUNCHER_H_ | 155 #endif // REMOTING_HOST_WIN_WTS_SESSION_PROCESS_LAUNCHER_H_ |
OLD | NEW |