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. All interaction with |
44 // |monitor| should happen on |main_message_loop|. |ipc_message_loop| has | 43 // |monitor| should happen on |main_message_loop|. |ipc_message_loop| has |
45 // to be an I/O message loop. | 44 // to be an I/O message loop. |
Wez
2012/08/08 20:13:41
Clarify the semantics of "stopped_callback", which
alexeypa (please no reviews)
2012/08/08 21:49:58
Done.
| |
46 WtsSessionProcessLauncher( | 45 WtsSessionProcessLauncher( |
47 const base::Closure& stopped_callback, | 46 const base::Closure& stopped_callback, |
48 WtsConsoleMonitor* monitor, | 47 WtsConsoleMonitor* monitor, |
49 scoped_refptr<base::SingleThreadTaskRunner> main_message_loop, | 48 scoped_refptr<base::SingleThreadTaskRunner> main_message_loop, |
50 scoped_refptr<base::SingleThreadTaskRunner> ipc_message_loop); | 49 scoped_refptr<base::SingleThreadTaskRunner> ipc_message_loop); |
51 | 50 |
52 virtual ~WtsSessionProcessLauncher(); | 51 virtual ~WtsSessionProcessLauncher(); |
53 | 52 |
54 // base::win::ObjectWatcher::Delegate implementation. | 53 // WorkerProcessLauncher::Delegate implementation. |
55 virtual void OnObjectSignaled(HANDLE object) OVERRIDE; | 54 virtual bool DoLaunchProcess(const std::string& channel_name, |
56 | 55 base::win::ScopedHandle* wait_out) OVERRIDE; |
57 // IPC::Listener implementation. | 56 virtual void DoKillProcess(DWORD exit_code) OVERRIDE; |
57 virtual void OnChannelConnected(base::win::ScopedHandle peer) OVERRIDE; | |
58 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 58 virtual bool OnMessageReceived(const IPC::Message& message) 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 protected: | 64 protected: |
65 // Stoppable implementation. | 65 // Stoppable implementation. |
66 virtual void DoStop() OVERRIDE; | 66 virtual void DoStop() OVERRIDE; |
67 | 67 |
68 private: | 68 private: |
69 // Attempts to launch the host process in the current console session. | 69 // Attempts to launch the host process in the current console session. |
70 // Schedules next launch attempt if creation of the process fails for any | 70 // Schedules next launch attempt if creation of the process fails for any |
71 // reason. | 71 // reason. |
72 void LaunchProcess(); | 72 void LaunchProcess(); |
73 | 73 |
74 // Called when the launcher reports the process to be stopped. | |
75 void OnLauncherStopped(); | |
76 | |
74 // Sends the Secure Attention Sequence to the session represented by | 77 // Sends the Secure Attention Sequence to the session represented by |
75 // |session_token_|. | 78 // |session_token_|. |
76 void OnSendSasToConsole(); | 79 void OnSendSasToConsole(); |
77 | 80 |
81 // Tracks whether the object is attached to the console session. | |
Wez
2012/08/08 20:13:41
nit: "True if this object is currently attached to
alexeypa (please no reviews)
2012/08/08 21:49:58
Done.
| |
82 bool attached_; | |
Wez
2012/08/08 20:13:41
nit: Consider storing the ID of the session to whi
alexeypa (please no reviews)
2012/08/08 21:49:58
It will not be used so there is no point is storin
| |
83 | |
78 // Time of the last launch attempt. | 84 // Time of the last launch attempt. |
79 base::Time launch_time_; | 85 base::Time launch_time_; |
80 | 86 |
81 // Current backoff delay. | 87 // Current backoff delay. |
82 base::TimeDelta launch_backoff_; | 88 base::TimeDelta launch_backoff_; |
83 | 89 |
84 // Timer used to schedule the next attempt to launch the process. | 90 // Timer used to schedule the next attempt to launch the process. |
85 base::OneShotTimer<WtsSessionProcessLauncher> timer_; | 91 base::OneShotTimer<WtsSessionProcessLauncher> timer_; |
86 | 92 |
87 // The main service message loop. | 93 // The main service message loop. |
88 scoped_refptr<base::SingleThreadTaskRunner> main_message_loop_; | 94 scoped_refptr<base::SingleThreadTaskRunner> main_message_loop_; |
89 | 95 |
90 // Message loop used by the IPC channel. | 96 // Message loop used by the IPC channel. |
91 scoped_refptr<base::SingleThreadTaskRunner> ipc_message_loop_; | 97 scoped_refptr<base::SingleThreadTaskRunner> ipc_message_loop_; |
92 | 98 |
93 // This pointer is used to unsubscribe from session attach and detach events. | 99 // This pointer is used to unsubscribe from session attach and detach events. |
94 WtsConsoleMonitor* monitor_; | 100 WtsConsoleMonitor* monitor_; |
95 | 101 |
96 // The handle of the process injected into the console session. | 102 scoped_ptr<WorkerProcessLauncher> launcher_; |
Wez
2012/08/08 20:13:41
nit: worker_process_launcher_
alexeypa (please no reviews)
2012/08/08 21:49:58
No, I think it is OK to keep it |launcher_| just l
| |
97 base::Process process_; | |
98 | 103 |
99 // Used to determine when the launched process terminates. | 104 base::win::ScopedHandle worker_process_; |
100 base::win::ObjectWatcher process_watcher_; | |
101 | 105 |
102 // The token to be used to launch a process in a different session. | 106 // The token to be used to launch a process in a different session. |
103 base::win::ScopedHandle session_token_; | 107 base::win::ScopedHandle session_token_; |
104 | 108 |
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_; | 109 scoped_ptr<SasInjector> sas_injector_; |
120 | 110 |
121 DISALLOW_COPY_AND_ASSIGN(WtsSessionProcessLauncher); | 111 DISALLOW_COPY_AND_ASSIGN(WtsSessionProcessLauncher); |
122 }; | 112 }; |
123 | 113 |
124 } // namespace remoting | 114 } // namespace remoting |
125 | 115 |
126 #endif // REMOTING_HOST_WIN_WTS_SESSION_PROCESS_LAUNCHER_H_ | 116 #endif // REMOTING_HOST_WIN_WTS_SESSION_PROCESS_LAUNCHER_H_ |
OLD | NEW |