Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: remoting/host/win/worker_process_launcher.h

Issue 10828181: [Chromoting] Moving common logic responsible for launching child processes to WorkerProcessLauncher… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CR feedback. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_WORKER_PROCESS_LAUNCHER_H_
6 #define REMOTING_HOST_WIN_WORKER_PROCESS_LAUNCHER_H_
7
8 #include <windows.h>
9
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/process.h"
15 #include "base/win/scoped_handle.h"
16 #include "base/win/object_watcher.h"
17 #include "ipc/ipc_channel.h"
18 #include "remoting/base/stoppable.h"
19
20 namespace base {
21 class SingleThreadTaskRunner;
22 } // namespace base
23
24 namespace IPC {
25 class ChannelProxy;
26 class Message;
27 } // namespace IPC
28
29 namespace remoting {
30
31 // Launches a worker process that is controlled via an IPC channel. All
32 // interaction with the spawned process is through the IPC::Listener and Send()
33 // method. In case of error the channel is closed and the worker process is
34 // terminated.
35 //
36 // WorkerProcessLauncher object is good for one process launch attempt only.
37 class WorkerProcessLauncher
38 : public Stoppable,
39 public base::win::ObjectWatcher::Delegate,
40 public IPC::Listener {
41 public:
42 class Delegate {
43 public:
44 virtual ~Delegate();
45
46 // Starts the worker process and passes |channel_name| to it.
47 // |process_exit_event_out| receives a handle that becomes signalled once
48 // the launched process has been terminated.
49 virtual bool DoLaunchProcess(
50 const std::string& channel_name,
51 base::win::ScopedHandle* process_exit_event_out) = 0;
52
53 // Terminates the worker process with the given exit code.
54 virtual void DoKillProcess(DWORD exit_code) = 0;
55
56 // Notifies that a client has been connected to the channel. |peer_pid|
57 // is the peer process's ID that the delegate can use to verify identity of
58 // the client. The verification code has to make sure that the client
59 // process's PID will not be assigned to another process (for instance by
60 // keeping an opened handle of the client process).
61 virtual void OnChannelConnected(DWORD peer_pid) = 0;
62
63 // Processes messages sent by the client.
64 virtual bool OnMessageReceived(const IPC::Message& message) = 0;
65 };
66
67 // Creates the launcher.
68 // |delegate| will be able to receive messages sent over the channel once
69 // the worker has been started and until it is stopped by Stop() or an error
70 // occurs.
71 //
72 // |stopped_callback| and |main_task_runner| are passed to the underlying
73 // |Stoppable| implementation. The caller should call all the methods on this
74 // class on the |main_task_runner| thread. |ipc_task_runner| is used to
75 // perform background IPC I/O.
76 WorkerProcessLauncher(
77 Delegate* delegate,
78 const base::Closure& stopped_callback,
79 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
80 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner);
81 virtual ~WorkerProcessLauncher();
82
83 // Starts the worker process.
84 void Start(const std::string& pipe_sddl);
85
86 // Sends an IPC message to the worker process. This method can be called only
87 // after successful Start() and until Stop() is called or an error occurred.
88 void Send(IPC::Message* message);
89
90 // base::win::ObjectWatcher::Delegate implementation.
91 virtual void OnObjectSignaled(HANDLE object) OVERRIDE;
92
93 // IPC::Listener implementation.
94 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
95 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
96 virtual void OnChannelError() OVERRIDE;
97
98 protected:
99 // Stoppable implementation.
100 virtual void DoStop() OVERRIDE;
101
102 private:
103 // Creates the server end of the Chromoting IPC channel.
104 bool CreatePipeForIpcChannel(const std::string& channel_name,
105 const std::string& pipe_sddl,
106 base::win::ScopedHandle* pipe_out);
107
108 // Generates random channel ID.
109 std::string GenerateRandomChannelId();
110
111 Delegate* delegate_;
112
113 // The main service message loop.
114 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
115
116 // Message loop used by the IPC channel.
117 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_;
118
119 // Used to determine when the launched process terminates.
120 base::win::ObjectWatcher process_watcher_;
121
122 // A waiting handle that becomes signalled once the launched process has
123 // been terminated.
124 base::win::ScopedHandle process_exit_event_;
125
126 // The IPC channel connecting to the launched process.
127 scoped_ptr<IPC::ChannelProxy> ipc_channel_;
128
129 // The server end of the pipe.
130 base::win::ScopedHandle pipe_;
131
132 DISALLOW_COPY_AND_ASSIGN(WorkerProcessLauncher);
133 };
134
135 } // namespace remoting
136
137 #endif // REMOTING_HOST_WIN_WORKER_PROCESS_LAUNCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698