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/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" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/process.h" | 15 #include "base/process.h" |
16 #include "base/time.h" | 16 #include "base/time.h" |
17 #include "base/timer.h" | 17 #include "base/timer.h" |
18 #include "base/win/scoped_handle.h" | 18 #include "base/win/scoped_handle.h" |
19 #include "base/win/object_watcher.h" | 19 #include "base/win/object_watcher.h" |
20 #include "ipc/ipc_channel.h" | 20 #include "ipc/ipc_channel.h" |
21 | 21 #include "remoting/base/stoppable.h" |
22 #include "remoting/host/win/wts_console_observer.h" | 22 #include "remoting/host/win/wts_console_observer.h" |
23 | 23 |
24 namespace base { | 24 namespace base { |
25 class MessageLoopProxy; | 25 class SingleThreadTaskRunner; |
26 } // namespace base | 26 } // namespace base |
27 | 27 |
28 namespace IPC { | 28 namespace IPC { |
29 class ChannelProxy; | 29 class ChannelProxy; |
30 class Message; | 30 class Message; |
31 } // namespace IPC | 31 } // namespace IPC |
32 | 32 |
33 namespace remoting { | 33 namespace remoting { |
34 | 34 |
35 // Session id that does not represent any session. | 35 // Session id that does not represent any session. |
36 extern const uint32 kInvalidSessionId; | 36 extern const uint32 kInvalidSessionId; |
37 | 37 |
38 class SasInjector; | 38 class SasInjector; |
39 class WtsConsoleMonitor; | 39 class WtsConsoleMonitor; |
40 | 40 |
41 class WtsSessionProcessLauncher | 41 class WtsSessionProcessLauncher |
42 : public base::win::ObjectWatcher::Delegate, | 42 : public Stoppable, |
| 43 public base::win::ObjectWatcher::Delegate, |
43 public IPC::Listener, | 44 public IPC::Listener, |
44 public WtsConsoleObserver { | 45 public WtsConsoleObserver { |
45 public: | 46 public: |
46 // Constructs a WtsSessionProcessLauncher object. |host_binary| is the name of | 47 // Constructs a WtsSessionProcessLauncher object. |host_binary| is the name of |
47 // the executable to be launched in the console session. All interaction with | 48 // the executable to be launched in the console session. All interaction with |
48 // |monitor| should happen on |main_message_loop|. |ipc_message_loop| has | 49 // |monitor| should happen on |main_message_loop|. |ipc_message_loop| has |
49 // to be an I/O message loop. | 50 // to be an I/O message loop. |
50 WtsSessionProcessLauncher( | 51 WtsSessionProcessLauncher( |
| 52 const base::Closure& stopped_callback, |
51 WtsConsoleMonitor* monitor, | 53 WtsConsoleMonitor* monitor, |
52 const FilePath& host_binary, | 54 const FilePath& host_binary, |
53 scoped_refptr<base::MessageLoopProxy> main_message_loop, | 55 scoped_refptr<base::SingleThreadTaskRunner> main_message_loop, |
54 scoped_refptr<base::MessageLoopProxy> ipc_message_loop); | 56 scoped_refptr<base::SingleThreadTaskRunner> ipc_message_loop); |
55 | 57 |
56 virtual ~WtsSessionProcessLauncher(); | 58 virtual ~WtsSessionProcessLauncher(); |
57 | 59 |
58 // base::win::ObjectWatcher::Delegate implementation. | 60 // base::win::ObjectWatcher::Delegate implementation. |
59 virtual void OnObjectSignaled(HANDLE object) OVERRIDE; | 61 virtual void OnObjectSignaled(HANDLE object) OVERRIDE; |
60 | 62 |
61 // IPC::Listener implementation. | 63 // IPC::Listener implementation. |
62 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 64 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
63 | 65 |
64 // WtsConsoleObserver implementation. | 66 // WtsConsoleObserver implementation. |
65 virtual void OnSessionAttached(uint32 session_id) OVERRIDE; | 67 virtual void OnSessionAttached(uint32 session_id) OVERRIDE; |
66 virtual void OnSessionDetached() OVERRIDE; | 68 virtual void OnSessionDetached() OVERRIDE; |
67 | 69 |
| 70 protected: |
| 71 // Stoppable implementation. |
| 72 virtual void DoStop() OVERRIDE; |
| 73 |
68 private: | 74 private: |
69 // Attempts to launch the host process in the current console session. | 75 // Attempts to launch the host process in the current console session. |
70 // Schedules next launch attempt if creation of the process fails for any | 76 // Schedules next launch attempt if creation of the process fails for any |
71 // reason. | 77 // reason. |
72 void LaunchProcess(); | 78 void LaunchProcess(); |
73 | 79 |
74 // Sends the Secure Attention Sequence to the session represented by | 80 // Sends the Secure Attention Sequence to the session represented by |
75 // |session_token_|. | 81 // |session_token_|. |
76 void OnSendSasToConsole(); | 82 void OnSendSasToConsole(); |
77 | 83 |
78 // Name of the host executable. | 84 // Name of the host executable. |
79 FilePath host_binary_; | 85 FilePath host_binary_; |
80 | 86 |
81 // Time of the last launch attempt. | 87 // Time of the last launch attempt. |
82 base::Time launch_time_; | 88 base::Time launch_time_; |
83 | 89 |
84 // Current backoff delay. | 90 // Current backoff delay. |
85 base::TimeDelta launch_backoff_; | 91 base::TimeDelta launch_backoff_; |
86 | 92 |
87 // Timer used to schedule the next attempt to launch the process. | 93 // Timer used to schedule the next attempt to launch the process. |
88 base::OneShotTimer<WtsSessionProcessLauncher> timer_; | 94 base::OneShotTimer<WtsSessionProcessLauncher> timer_; |
89 | 95 |
90 // The main service message loop. | 96 // The main service message loop. |
91 scoped_refptr<base::MessageLoopProxy> main_message_loop_; | 97 scoped_refptr<base::SingleThreadTaskRunner> main_message_loop_; |
92 | 98 |
93 // Message loop used by the IPC channel. | 99 // Message loop used by the IPC channel. |
94 scoped_refptr<base::MessageLoopProxy> ipc_message_loop_; | 100 scoped_refptr<base::SingleThreadTaskRunner> ipc_message_loop_; |
95 | 101 |
96 // This pointer is used to unsubscribe from session attach and detach events. | 102 // This pointer is used to unsubscribe from session attach and detach events. |
97 WtsConsoleMonitor* monitor_; | 103 WtsConsoleMonitor* monitor_; |
98 | 104 |
99 // Impersonation token that has the SE_TCB_NAME privilege enabled. | 105 // Impersonation token that has the SE_TCB_NAME privilege enabled. |
100 base::win::ScopedHandle privileged_token_; | 106 base::win::ScopedHandle privileged_token_; |
101 | 107 |
102 // The handle of the process injected into the console session. | 108 // The handle of the process injected into the console session. |
103 base::Process process_; | 109 base::Process process_; |
104 | 110 |
(...skipping 18 matching lines...) Expand all Loading... |
123 scoped_ptr<IPC::ChannelProxy> chromoting_channel_; | 129 scoped_ptr<IPC::ChannelProxy> chromoting_channel_; |
124 | 130 |
125 scoped_ptr<SasInjector> sas_injector_; | 131 scoped_ptr<SasInjector> sas_injector_; |
126 | 132 |
127 DISALLOW_COPY_AND_ASSIGN(WtsSessionProcessLauncher); | 133 DISALLOW_COPY_AND_ASSIGN(WtsSessionProcessLauncher); |
128 }; | 134 }; |
129 | 135 |
130 } // namespace remoting | 136 } // namespace remoting |
131 | 137 |
132 #endif // REMOTING_HOST_WIN_WTS_SESSION_PROCESS_LAUNCHER_H_ | 138 #endif // REMOTING_HOST_WIN_WTS_SESSION_PROCESS_LAUNCHER_H_ |
OLD | NEW |