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/memory/ref_counted.h" | |
14 #include "base/memory/scoped_ptr.h" | |
13 #include "base/process.h" | 15 #include "base/process.h" |
14 #include "base/time.h" | 16 #include "base/time.h" |
15 #include "base/timer.h" | 17 #include "base/timer.h" |
16 #include "base/win/scoped_handle.h" | 18 #include "base/win/scoped_handle.h" |
17 #include "base/win/object_watcher.h" | 19 #include "base/win/object_watcher.h" |
18 #include "ipc/ipc_channel.h" | 20 #include "ipc/ipc_channel.h" |
19 | 21 |
20 #include "remoting/host/wts_console_observer_win.h" | 22 #include "remoting/host/wts_console_observer_win.h" |
21 | 23 |
22 namespace base { | 24 namespace base { |
23 | 25 |
24 class Thread; | 26 class MessageLoopProxy; |
25 | 27 |
26 } // namespace base | 28 } // namespace base |
27 | 29 |
28 namespace IPC { | 30 namespace IPC { |
29 | 31 |
30 class ChannelProxy; | 32 class ChannelProxy; |
31 class Message; | 33 class Message; |
32 | 34 |
33 } // namespace IPC | 35 } // namespace IPC |
34 | 36 |
35 namespace remoting { | 37 namespace remoting { |
36 | 38 |
37 class SasInjector; | 39 class SasInjector; |
38 class WtsConsoleMonitor; | 40 class WtsConsoleMonitor; |
41 class WorkerProcessLauncher; | |
39 | 42 |
40 class WtsSessionProcessLauncher | 43 class WtsSessionProcessLauncher |
41 : public base::win::ObjectWatcher::Delegate, | 44 : public IPC::Channel::Listener, |
42 public IPC::Channel::Listener, | |
43 public WtsConsoleObserver { | 45 public WtsConsoleObserver { |
44 public: | 46 public: |
45 // Constructs a WtsSessionProcessLauncher object. |monitor| and |io_thread| | 47 // Constructs a WtsSessionProcessLauncher object. |monitor| must outlive this |
46 // must outlive this object. |host_binary| is the name of the executable to | 48 // object. |host_binary| is the name of the executable to be launched in |
47 // be launched in the console session. | 49 // the console session. |
48 WtsSessionProcessLauncher(WtsConsoleMonitor* monitor, | 50 WtsSessionProcessLauncher(WtsConsoleMonitor* monitor, |
49 const FilePath& host_binary, | 51 const FilePath& host_binary, |
50 base::Thread* io_thread); | 52 base::MessageLoopProxy* ipc_message_loop); |
Wez
2012/03/15 23:24:31
scoped_refptr<MessageLoopProxy>
alexeypa (please no reviews)
2012/03/16 17:43:50
Done.
| |
51 | 53 |
52 virtual ~WtsSessionProcessLauncher(); | 54 virtual ~WtsSessionProcessLauncher(); |
53 | 55 |
54 // base::win::ObjectWatcher::Delegate implementation. | |
55 virtual void OnObjectSignaled(HANDLE object) OVERRIDE; | |
56 | |
57 // IPC::Channel::Listener implementation. | 56 // IPC::Channel::Listener implementation. |
58 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 57 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
58 virtual void OnChannelError() OVERRIDE; | |
59 | 59 |
60 // WtsConsoleObserver implementation. | 60 // WtsConsoleObserver implementation. |
61 virtual void OnSessionAttached(uint32 session_id) OVERRIDE; | 61 virtual void OnSessionAttached(uint32 session_id) OVERRIDE; |
62 virtual void OnSessionDetached() OVERRIDE; | 62 virtual void OnSessionDetached() OVERRIDE; |
63 | 63 |
64 private: | 64 private: |
65 // Takes the channel name and returns a channel handle for the server end of | |
66 // the channel. | |
67 bool CreateChannelHandle(const std::string& channel_name, | |
68 IPC::ChannelHandle* channel_handle_out); | |
69 | |
70 // Launches a worker process passing the IPC channel name to it. | |
71 bool LaunchWorker(const std::string& channel_name, | |
72 base::Process* process_out); | |
73 | |
65 // Attempts to launch the host process in the current console session. | 74 // Attempts to launch the host process in the current console session. |
66 // Schedules next launch attempt if creation of the process fails for any | 75 // Schedules next launch attempt if creation of the process fails for any |
67 // reason. | 76 // reason. |
68 void LaunchProcess(); | 77 void LaunchProcess(); |
69 | 78 |
70 // Sends the Secure Attention Sequence to the session represented by | 79 // Sends the Secure Attention Sequence to the session represented by |
71 // |session_token_|. | 80 // |session_token_|. |
72 void OnSendSasToConsole(); | 81 void OnSendSasToConsole(); |
73 | 82 |
74 // Name of the host executable. | 83 // Name of the host executable. |
75 FilePath host_binary_; | 84 FilePath host_binary_; |
76 | 85 |
86 // Message loop used by the IPC channel. | |
87 scoped_refptr<base::MessageLoopProxy> ipc_message_loop_; | |
88 | |
89 // This is a place to store pipe handle until the host process has been | |
90 // started. | |
91 base::win::ScopedHandle ipc_pipe_; | |
92 | |
77 // Time of the last launch attempt. | 93 // Time of the last launch attempt. |
78 base::Time launch_time_; | 94 base::Time launch_time_; |
79 | 95 |
80 // Current backoff delay. | 96 // Current backoff delay. |
81 base::TimeDelta launch_backoff_; | 97 base::TimeDelta launch_backoff_; |
82 | 98 |
99 scoped_ptr<WorkerProcessLauncher> launcher_; | |
100 | |
83 // Timer used to schedule the next attempt to launch the process. | 101 // Timer used to schedule the next attempt to launch the process. |
84 base::OneShotTimer<WtsSessionProcessLauncher> timer_; | 102 base::OneShotTimer<WtsSessionProcessLauncher> timer_; |
85 | 103 |
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 | |
90 // This pointer is used to unsubscribe from session attach and detach events. | 104 // This pointer is used to unsubscribe from session attach and detach events. |
91 WtsConsoleMonitor* monitor_; | 105 WtsConsoleMonitor* monitor_; |
92 | 106 |
93 // Impersonation token that has the SE_TCB_NAME privilege enabled. | 107 // Impersonation token that has the SE_TCB_NAME privilege enabled. |
94 base::win::ScopedHandle privileged_token_; | 108 base::win::ScopedHandle privileged_token_; |
95 | 109 |
96 // The handle of the process injected into the console session. | |
97 base::Process process_; | |
98 | |
99 // Used to determine when the launched process terminates. | |
100 base::win::ObjectWatcher process_watcher_; | |
101 | |
102 // The token to be used to launch a process in a different session. | 110 // The token to be used to launch a process in a different session. |
103 base::win::ScopedHandle session_token_; | 111 base::win::ScopedHandle session_token_; |
104 | 112 |
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_; | 113 scoped_ptr<SasInjector> sas_injector_; |
120 | 114 |
121 DISALLOW_COPY_AND_ASSIGN(WtsSessionProcessLauncher); | 115 DISALLOW_COPY_AND_ASSIGN(WtsSessionProcessLauncher); |
122 }; | 116 }; |
123 | 117 |
124 } // namespace remoting | 118 } // namespace remoting |
125 | 119 |
126 #endif // REMOTING_HOST_WTS_SESSION_PROCESS_LAUNCHER_WIN_H_ | 120 #endif // REMOTING_HOST_WTS_SESSION_PROCESS_LAUNCHER_WIN_H_ |
OLD | NEW |