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_WORKER_PROCESS_LAUNCHER_WIN_H_ | |
6 #define REMOTING_HOST_WORKER_PROCESS_LAUNCHER_WIN_H_ | |
7 | |
8 #include <windows.h> | |
9 #include <string> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/callback.h" | |
13 #include "base/compiler_specific.h" | |
14 #include "base/process.h" | |
15 #include "base/memory/ref_counted.h" | |
16 #include "base/memory/scoped_ptr.h" | |
17 #include "base/win/object_watcher.h" | |
18 #include "ipc/ipc_channel.h" | |
19 | |
20 | |
21 namespace base { | |
22 | |
23 class MessageLoopProxy; | |
24 | |
25 } // namespace base | |
26 | |
27 namespace IPC { | |
28 | |
29 class ChannelProxy; | |
30 class Message; | |
31 | |
32 } // namespace IPC | |
33 | |
34 namespace remoting { | |
35 | |
36 // Launches a worker process that is controlled via an IPC channel. The caller | |
37 // is expected to provide the platform-specific code for allocation of a channel | |
38 // handle and creation of the process. | |
Wez
2012/03/27 16:45:45
nit: platform-specific -> application-specific?
| |
39 // | |
40 // WorkerProcessLauncherWin objects are good for one process launch attempt | |
41 // only. | |
42 // | |
43 // For the caller all interaction with the spawned process is through | |
Wez
2012/03/27 16:45:45
nit: ... is through the IPC::Listener ...
| |
44 // 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 ...
| |
45 // is closed and the worker process is terminated. | |
46 class WorkerProcessLauncherWin : public base::win::ObjectWatcher::Delegate, | |
47 public IPC::Channel::Listener { | |
48 public: | |
49 WorkerProcessLauncherWin( | |
50 scoped_refptr<base::MessageLoopProxy> ipc_message_loop); | |
51 virtual ~WorkerProcessLauncherWin(); | |
52 | |
53 // Takes the channel name and returns a channel handle for the server end of | |
54 // the channel. | |
55 typedef base::Callback<bool(const std::string&, IPC::ChannelHandle*)> | |
56 CreateChannelHandleCallback; | |
57 | |
58 // Launches a worker process passing the IPC channel name to it. | |
59 typedef base::Callback<bool(const std::string&, base::Process*)> | |
60 LaunchWorkerCallback; | |
61 | |
62 // Starts the worker process. Returns true if the process was launched | |
63 // successfully. | |
64 // | |
65 // |listener| can receive channel events once the worked has been started and | |
Wez
2012/03/27 16:45:45
typo: worked -> worker
| |
66 // until it was stopped by Stop() or due to an error. If an error occurs | |
67 // the channel is closed immediately after delivering the first error | |
68 // notification to |listener|. | |
69 // | |
70 // The |create_channel_handle| and |launch_worker| callbacks hide | |
71 // implementation details of the channel handle and worker process creation. | |
72 bool Start(IPC::Channel::Listener* listener, | |
73 const CreateChannelHandleCallback& create_channel_handle, | |
74 const LaunchWorkerCallback& launch_worker); | |
75 | |
76 // Stops the worker process. Stop() can be called multiple times. | |
77 void Stop(); | |
78 | |
79 // Sends an IPC message to the worker process. This method can be called only | |
80 // after successful Start() and until Stop() is called or an error occurred | |
81 // in the channel. | |
82 void Send(IPC::Message* message); | |
83 | |
84 // base::win::ObjectWatcher::Delegate implementation. | |
85 virtual void OnObjectSignaled(HANDLE object) OVERRIDE; | |
86 | |
87 // IPC::Channel::Listener implementation. | |
88 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
89 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | |
90 virtual void OnChannelError() OVERRIDE; | |
91 | |
92 protected: | |
93 base::Process& get_process(); | |
Wez
2012/03/27 16:45:45
Does this still need to be protected, not private?
| |
94 | |
95 private: | |
96 // Generates random channel ID. | |
97 std::string GenerateRandomChannelId(); | |
98 | |
99 // The IPC channel to talk to the elevated process. | |
100 scoped_ptr<IPC::ChannelProxy> ipc_channel_; | |
101 | |
102 // Message loop used by |ipc_channel_|. | |
103 scoped_refptr<base::MessageLoopProxy> ipc_message_loop_; | |
104 | |
105 IPC::Channel::Listener* listener_; | |
106 | |
107 // The handle of the worker process. | |
108 base::Process process_; | |
109 | |
110 // Used to determine when the launched process terminates. | |
111 base::win::ObjectWatcher process_watcher_; | |
112 | |
113 DISALLOW_COPY_AND_ASSIGN(WorkerProcessLauncherWin); | |
114 }; | |
115 | |
116 } // namespace remoting | |
117 | |
118 #endif // REMOTING_HOST_WORKER_PROCESS_LAUNCHER_WIN_H_ | |
OLD | NEW |