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

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: 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 // Used to launch a worker process that is controlled via an IPC channel. All
Wez 2012/08/08 20:13:41 nit: Used to launch a ... -> Launches a ...
alexeypa (please no reviews) 2012/08/08 21:49:58 Done.
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. |wait_out|
47 // receives a handle that becomes signalled once the launched process has
48 // been terminated.
49 virtual bool DoLaunchProcess(const std::string& channel_name,
50 base::win::ScopedHandle* wait_out) = 0;
51
52 // Terminates the worker process with the given exit code.
53 virtual void DoKillProcess(DWORD exit_code) = 0;
54
55 // Notifies that a client has been connected to the channel. |peer|
56 // is a handle of the peer process that can be used to verify identity of
57 // the client.
58 virtual void OnChannelConnected(base::win::ScopedHandle peer) = 0;
Wez 2012/08/08 20:13:41 The session process launcher checks the process ID
alexeypa (please no reviews) 2012/08/08 21:49:58 Done.
59
60 // Processes messages sent by the client.
61 virtual bool OnMessageReceived(const IPC::Message& message) = 0;
62 };
63
64 WorkerProcessLauncher(
65 const base::Closure& stopped_callback,
Wez 2012/08/08 20:13:41 nit: Clarify under what circumstances stopped_call
alexeypa (please no reviews) 2012/08/08 21:49:58 This is documented in Stoppable class description.
66 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
67 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner);
Wez 2012/08/08 20:13:41 nit: Clarify what the "main" TaskRunner is used fo
alexeypa (please no reviews) 2012/08/08 21:49:58 Done.
68 virtual ~WorkerProcessLauncher();
69
70 // Starts the worker process. Returns true if the process was launched
71 // successfully.
72 //
73 // |delegate| can receive messages sent over the channel the worker has been
74 // started and until it was stopped by Stop() or due to an error.
Wez 2012/08/08 20:13:41 Why pass Delegate in Start(), rather than to the c
alexeypa (please no reviews) 2012/08/08 21:49:58 Moved the delegate to the constructor because it e
75 void Start(Delegate* delegate, const std::string& pipe_sddl);
76
77 // Sends an IPC message to the worker process. This method can be called only
78 // after successful Start() and until Stop() is called or an error occurred.
79 void Send(IPC::Message* message);
80
81 // base::win::ObjectWatcher::Delegate implementation.
82 virtual void OnObjectSignaled(HANDLE object) OVERRIDE;
83
84 // IPC::Listener implementation.
85 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
86 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
87 virtual void OnChannelError() OVERRIDE;
88
89 protected:
90 // Stoppable implementation.
91 virtual void DoStop() OVERRIDE;
92
93 private:
94 // Creates the server end of the Chromoting IPC channel.
95 bool CreatePipeForIpcChannel(const std::string& channel_name,
96 const std::string& pipe_sddl,
97 base::win::ScopedHandle* pipe_out);
98
99 // Generates random channel ID.
100 std::string GenerateRandomChannelId();
101
102 Delegate* delegate_;
103
104 // The main service message loop.
105 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
106
107 // Message loop used by the IPC channel.
108 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_;
109
110 // Used to determine when the launched process terminates.
111 base::win::ObjectWatcher process_watcher_;
112
113 // |true| if |process_watcher_| is armed.
114 bool process_watcher_armed_;
115
116 // A waiting handle that remains signalled until the launched worked is
117 // terminated.
Wez 2012/08/08 20:13:41 This is the opposite of the behaviour documented o
alexeypa (please no reviews) 2012/08/08 21:49:58 Done.
118 base::win::ScopedHandle wait_;
Wez 2012/08/08 20:13:41 nit: Choose a more helpful name, e.g. process_exit
alexeypa (please no reviews) 2012/08/08 21:49:58 Done.
119
120 // The IPC channel connecting to the launched process.
121 scoped_ptr<IPC::ChannelProxy> ipc_channel_;
122
123 // The server end of the pipe.
124 base::win::ScopedHandle pipe_;
125
126 DISALLOW_COPY_AND_ASSIGN(WorkerProcessLauncher);
127 };
128
129 } // namespace remoting
130
131 #endif // REMOTING_HOST_WIN_WORKER_PROCESS_LAUNCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698