Index: remoting/host/worker_process_launcher.h |
diff --git a/remoting/host/worker_process_launcher.h b/remoting/host/worker_process_launcher.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f06d3a84446678a238592da89be5ce4375760f6b |
--- /dev/null |
+++ b/remoting/host/worker_process_launcher.h |
@@ -0,0 +1,118 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef REMOTING_HOST_WORKER_PROCESS_LAUNCHER_WIN_H_ |
+#define REMOTING_HOST_WORKER_PROCESS_LAUNCHER_WIN_H_ |
+ |
+#include <windows.h> |
+#include <string> |
+ |
+#include "base/basictypes.h" |
+#include "base/callback.h" |
+#include "base/compiler_specific.h" |
+#include "base/process.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/win/object_watcher.h" |
+#include "ipc/ipc_channel.h" |
+ |
+ |
+namespace base { |
+ |
+class MessageLoopProxy; |
+ |
+} // namespace base |
+ |
+namespace IPC { |
+ |
+class ChannelProxy; |
+class Message; |
+ |
+} // namespace IPC |
+ |
+namespace remoting { |
+ |
+// Launches a worker process that is controlled via an IPC channel. The caller |
+// is expected to provide the platform-specific code for allocation of a channel |
+// handle and creation of the process. |
Wez
2012/03/27 16:45:45
nit: platform-specific -> application-specific?
|
+// |
+// WorkerProcessLauncherWin objects are good for one process launch attempt |
+// only. |
+// |
+// For the caller all interaction with the spawned process is through |
Wez
2012/03/27 16:45:45
nit: ... is through the IPC::Listener ...
|
+// IPC::Listener interface and Send() method. In case of any error the channel |
Wez
2012/03/27 16:45:45
nit: In case of error ...
|
+// is closed and the worker process is terminated. |
+class WorkerProcessLauncherWin : public base::win::ObjectWatcher::Delegate, |
+ public IPC::Channel::Listener { |
+ public: |
+ WorkerProcessLauncherWin( |
+ scoped_refptr<base::MessageLoopProxy> ipc_message_loop); |
+ virtual ~WorkerProcessLauncherWin(); |
+ |
+ // Takes the channel name and returns a channel handle for the server end of |
+ // the channel. |
+ typedef base::Callback<bool(const std::string&, IPC::ChannelHandle*)> |
+ CreateChannelHandleCallback; |
+ |
+ // Launches a worker process passing the IPC channel name to it. |
+ typedef base::Callback<bool(const std::string&, base::Process*)> |
+ LaunchWorkerCallback; |
+ |
+ // Starts the worker process. Returns true if the process was launched |
+ // successfully. |
+ // |
+ // |listener| can receive channel events once the worked has been started and |
Wez
2012/03/27 16:45:45
typo: worked -> worker
|
+ // until it was stopped by Stop() or due to an error. If an error occurs |
+ // the channel is closed immediately after delivering the first error |
+ // notification to |listener|. |
+ // |
+ // The |create_channel_handle| and |launch_worker| callbacks hide |
+ // implementation details of the channel handle and worker process creation. |
+ bool Start(IPC::Channel::Listener* listener, |
+ const CreateChannelHandleCallback& create_channel_handle, |
+ const LaunchWorkerCallback& launch_worker); |
+ |
+ // Stops the worker process. Stop() can be called multiple times. |
+ void Stop(); |
+ |
+ // Sends an IPC message to the worker process. This method can be called only |
+ // after successful Start() and until Stop() is called or an error occurred |
+ // in the channel. |
+ void Send(IPC::Message* message); |
+ |
+ // base::win::ObjectWatcher::Delegate implementation. |
+ virtual void OnObjectSignaled(HANDLE object) OVERRIDE; |
+ |
+ // IPC::Channel::Listener implementation. |
+ virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
+ virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
+ virtual void OnChannelError() OVERRIDE; |
+ |
+ protected: |
+ base::Process& get_process(); |
Wez
2012/03/27 16:45:45
Does this still need to be protected, not private?
|
+ |
+ private: |
+ // Generates random channel ID. |
+ std::string GenerateRandomChannelId(); |
+ |
+ // The IPC channel to talk to the elevated process. |
+ scoped_ptr<IPC::ChannelProxy> ipc_channel_; |
+ |
+ // Message loop used by |ipc_channel_|. |
+ scoped_refptr<base::MessageLoopProxy> ipc_message_loop_; |
+ |
+ IPC::Channel::Listener* listener_; |
+ |
+ // The handle of the worker process. |
+ base::Process process_; |
+ |
+ // Used to determine when the launched process terminates. |
+ base::win::ObjectWatcher process_watcher_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(WorkerProcessLauncherWin); |
+}; |
+ |
+} // namespace remoting |
+ |
+#endif // REMOTING_HOST_WORKER_PROCESS_LAUNCHER_WIN_H_ |