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

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

Issue 9705065: Introducing the WorkerProcessLauncher class implementing the common logic for spawning a worker pro… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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_WORKER_PROCESS_LAUNCHER_H_
6 #define REMOTING_HOST_WORKER_PROCESS_LAUNCHER_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/process.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "ipc/ipc_channel.h"
17
18 namespace base {
19
20 class MessageLoopProxy;
21
22 } // namespace base
23
24 namespace IPC {
25
26 class ChannelProxy;
27 class Message;
28
29 } // namespace IPC
30
31 namespace remoting {
32
33 // Launches a worker process that is controlled via an IPC channel. The caller
34 // is expected to provide the platform-specific code for allocation of a channel
35 // handle and creation of the process.
36 //
37 // WorkerProcessLauncher objects are good for one process launch attempt only.
38 // If anything went wrong and the caller wants to retry, another instance of
Wez 2012/03/15 23:24:31 nit: This makes it sound like the object might be
alexeypa (please no reviews) 2012/03/16 17:43:50 Done.
39 // WorkerProcessLauncher must be created.
40 //
41 // For the caller all interaction with the spawned process is through
42 // IPC::Listener interface and Send() method. In case of any error the channel
43 // is closed and the workern process is terminated.
Wez 2012/03/15 23:24:31 typo: workern
alexeypa (please no reviews) 2012/03/16 17:43:50 Done.
44 class WorkerProcessLauncher : public IPC::Channel::Listener {
45 public:
46 virtual ~WorkerProcessLauncher();
47
48 // Takes the channel name and returns a channel handle for the server end of
49 // the channel.
50 typedef base::Callback<bool(const std::string&, IPC::ChannelHandle*)>
51 CreateChannelHandleCallback;
Wez 2012/03/15 23:24:31 Why implement these as callbacks rather than as me
alexeypa (please no reviews) 2012/03/16 17:43:50 I've tried to make them pure virtual methods. It d
Wez 2012/03/27 16:45:45 What I meant was an interface, not pure-virtual in
52
53 // Launches a worker process passing the IPC channel name to it.
54 typedef base::Callback<bool(const std::string&, base::Process*)>
55 LaunchWorkerCallback;
56
57 // Starts the worker process. Returns true if the process was launched
58 // successfully. Once the process is launched and until Stop() is called
59 // channel events are delivered to |listener|. If an error occurs the channel
Wez 2012/03/15 23:24:31 nit: Reword: "Channel events are delivered to |lis
alexeypa (please no reviews) 2012/03/16 17:43:50 Done.
60 // is closed immediately after delivering the error notification to
61 // |listener|. |listener| must remain alive until Stop() is called or
62 // the final error notification is delivered.
63 //
64 // The |create_channel_handle| and |launch_worker| callbacks hide
65 // implementation details of non-portable code.
66 // |listener| must remain alive until Stop() is called.
Wez 2012/03/15 23:24:31 nit: You mentioned that requirement earlier. :)
alexeypa (please no reviews) 2012/03/16 17:43:50 Done.
67 virtual bool Start(IPC::Channel::Listener* listener,
68 const CreateChannelHandleCallback& create_channel_handle,
69 const LaunchWorkerCallback& launch_worker);
70
71 // Stops the worker process. Stop() can be called multiple times.
72 virtual void Stop();
73
74 // Sends an IPC message to the worker process. This method can be called only
75 // after successfull Start() and until Stop() method is called or an error
Wez 2012/03/15 23:24:31 nit: Remove "method" after "Stop()".
Wez 2012/03/15 23:24:31 typo: successfull
alexeypa (please no reviews) 2012/03/16 17:43:50 Done.
alexeypa (please no reviews) 2012/03/16 17:43:50 Done.
76 // occured in the channel.
Wez 2012/03/15 23:24:31 typo: occured
alexeypa (please no reviews) 2012/03/16 17:43:50 Done.
77 void Send(IPC::Message* message);
78
79 // IPC::Channel::Listener implementation.
80 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
81 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
82 virtual void OnChannelError() OVERRIDE;
83
84 #if defined(OS_POSIX)
85 virtual void OnChannelDenied() OVERRIDE;
86 virtual void OnChannelListenError() OVERRIDE;
87 #endif // OS_POSIX
88
89 static scoped_ptr<WorkerProcessLauncher> Create(
Wez 2012/03/15 23:24:31 Put the Create() method earlier, with a comment ex
alexeypa (please no reviews) 2012/03/16 17:43:50 Create() was removed after making this class Windo
90 base::MessageLoopProxy* ipc_message_loop);
91
92 protected:
93 WorkerProcessLauncher(base::MessageLoopProxy* ipc_message_loop);
94
95 base::Process& get_process();
96
97 private:
98 // The IPC channel to talk to the elevated process.
99 scoped_ptr<IPC::ChannelProxy> ipc_channel_;
100
101 // Message loop used by |ipc_channel_|.
102 scoped_refptr<base::MessageLoopProxy> ipc_message_loop_;
103
104 IPC::Channel::Listener* listener_;
105
106 // The handle of the worker process.
107 base::Process process_;
108
109 DISALLOW_COPY_AND_ASSIGN(WorkerProcessLauncher);
110 };
111
112 } // namespace remoting
113
114 #endif // REMOTING_HOST_WORKER_PROCESS_LAUNCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698