| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef REMOTING_HOST_WIN_WTS_SESSION_PROCESS_LAUNCHER_H_ | |
| 6 #define REMOTING_HOST_WIN_WTS_SESSION_PROCESS_LAUNCHER_H_ | |
| 7 | |
| 8 #include <windows.h> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/file_path.h" | |
| 13 #include "base/file_util.h" | |
| 14 #include "base/memory/ref_counted.h" | |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "base/message_loop.h" | |
| 17 #include "base/process.h" | |
| 18 #include "base/time.h" | |
| 19 #include "base/timer.h" | |
| 20 #include "base/win/scoped_handle.h" | |
| 21 #include "ipc/ipc_channel.h" | |
| 22 #include "remoting/base/stoppable.h" | |
| 23 #include "remoting/host/win/worker_process_launcher.h" | |
| 24 #include "remoting/host/win/wts_console_observer.h" | |
| 25 #include "remoting/host/worker_process_ipc_delegate.h" | |
| 26 | |
| 27 namespace base { | |
| 28 class SingleThreadTaskRunner; | |
| 29 } // namespace base | |
| 30 | |
| 31 namespace remoting { | |
| 32 | |
| 33 class WtsConsoleMonitor; | |
| 34 class WtsSessionProcessLauncherImpl; | |
| 35 | |
| 36 class WtsSessionProcessLauncher | |
| 37 : public Stoppable, | |
| 38 public WorkerProcessIpcDelegate, | |
| 39 public WtsConsoleObserver { | |
| 40 public: | |
| 41 // Constructs a WtsSessionProcessLauncher object. |stopped_callback| and | |
| 42 // |main_message_loop| are passed to the undelying |Stoppable| implementation. | |
| 43 // All interaction with |monitor| should happen on |main_message_loop|. | |
| 44 // |ipc_message_loop| must be an I/O message loop. | |
| 45 WtsSessionProcessLauncher( | |
| 46 const base::Closure& stopped_callback, | |
| 47 WtsConsoleMonitor* monitor, | |
| 48 scoped_refptr<base::SingleThreadTaskRunner> main_message_loop, | |
| 49 scoped_refptr<base::SingleThreadTaskRunner> ipc_message_loop); | |
| 50 | |
| 51 virtual ~WtsSessionProcessLauncher(); | |
| 52 | |
| 53 // WorkerProcessIpcDelegate implementation. | |
| 54 virtual void OnChannelConnected() OVERRIDE; | |
| 55 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
| 56 | |
| 57 // WtsConsoleObserver implementation. | |
| 58 virtual void OnSessionAttached(uint32 session_id) OVERRIDE; | |
| 59 virtual void OnSessionDetached() OVERRIDE; | |
| 60 | |
| 61 protected: | |
| 62 // Stoppable implementation. | |
| 63 virtual void DoStop() OVERRIDE; | |
| 64 | |
| 65 private: | |
| 66 // Attempts to launch the host process in the current console session. | |
| 67 // Schedules next launch attempt if creation of the process fails for any | |
| 68 // reason. | |
| 69 void LaunchProcess(); | |
| 70 | |
| 71 // Called when the launcher reports the process to be stopped. | |
| 72 void OnLauncherStopped(); | |
| 73 | |
| 74 // |true| if this object is currently attached to the console session. | |
| 75 bool attached_; | |
| 76 | |
| 77 // Path to the host binary to launch. | |
| 78 FilePath host_binary_; | |
| 79 | |
| 80 // OS version dependent WorkerProcessLauncher::Delegate implementation | |
| 81 // instance for the currently-running child process. | |
| 82 scoped_refptr<WtsSessionProcessLauncherImpl> impl_; | |
| 83 | |
| 84 // WorkerProcessLauncher::Delegate implementation that will be used to launch | |
| 85 // the new child process after a session switch. | |
| 86 scoped_refptr<WtsSessionProcessLauncherImpl> new_impl_; | |
| 87 | |
| 88 // Time of the last launch attempt. | |
| 89 base::Time launch_time_; | |
| 90 | |
| 91 // Current backoff delay. | |
| 92 base::TimeDelta launch_backoff_; | |
| 93 | |
| 94 // Timer used to schedule the next attempt to launch the process. | |
| 95 base::OneShotTimer<WtsSessionProcessLauncher> timer_; | |
| 96 | |
| 97 // The main service message loop. | |
| 98 scoped_refptr<base::SingleThreadTaskRunner> main_message_loop_; | |
| 99 | |
| 100 // Message loop used by the IPC channel. | |
| 101 scoped_refptr<base::SingleThreadTaskRunner> ipc_message_loop_; | |
| 102 | |
| 103 // This pointer is used to unsubscribe from session attach and detach events. | |
| 104 WtsConsoleMonitor* monitor_; | |
| 105 | |
| 106 scoped_ptr<WorkerProcessLauncher> launcher_; | |
| 107 | |
| 108 DISALLOW_COPY_AND_ASSIGN(WtsSessionProcessLauncher); | |
| 109 }; | |
| 110 | |
| 111 } // namespace remoting | |
| 112 | |
| 113 #endif // REMOTING_HOST_WIN_WTS_SESSION_PROCESS_LAUNCHER_H_ | |
| OLD | NEW |