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.
5 #ifndef REMOTING_HOST_WIN_WORKER_PROCESS_LAUNCHER_H_
6 #define REMOTING_HOST_WIN_WORKER_PROCESS_LAUNCHER_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/win/scoped_handle.h"
13 #include "ipc/ipc_sender.h"
16 class SingleThreadTaskRunner
;
26 class WorkerProcessIpcDelegate
;
28 // Launches a worker process that is controlled via an IPC channel. All
29 // interaction with the spawned process is through WorkerProcessIpcDelegate and
30 // Send() method. In case of error the channel is closed and the worker process
32 class WorkerProcessLauncher
{
34 class Delegate
: public IPC::Sender
{
38 // Returns PID of the worker process or 0 if it is not available.
39 virtual DWORD
GetProcessId() const = 0;
41 // Returns true if the worker process should not be restarted any more.
42 virtual bool IsPermanentError(int failure_count
) const = 0;
44 // Terminates the worker process with the given exit code. Destroys the IPC
45 // channel created by LaunchProcess().
46 virtual void KillProcess(DWORD exit_code
) = 0;
48 // Starts the worker process and creates an IPC channel it can connect to.
49 // |delegate| specifies the object that will receive notifications from
50 // the IPC channel. |process_exit_event_out| receives a handle that becomes
51 // signalled once the launched process has been terminated.
52 virtual bool LaunchProcess(
53 IPC::Listener
* delegate
,
54 base::win::ScopedHandle
* process_exit_event_out
) = 0;
57 // Creates the launcher that will use |launcher_delegate| to manage the worker
58 // process and |worker_delegate| to handle IPCs. The caller must ensure that
59 // |worker_delegate| remains valid until Stoppable::Stop() method has been
62 // The caller should call all the methods on this class on
63 // the |caller_task_runner| thread. Methods of both delegate interfaces are
64 // called on the |caller_task_runner| thread as well.
65 WorkerProcessLauncher(
66 scoped_refptr
<base::SingleThreadTaskRunner
> caller_task_runner
,
67 scoped_ptr
<Delegate
> launcher_delegate
,
68 WorkerProcessIpcDelegate
* worker_delegate
);
69 ~WorkerProcessLauncher();
71 // Sends an IPC message to the worker process. The message will be silently
72 // dropped if Send() is called before Start() or after stutdown has been
74 void Send(IPC::Message
* message
);
77 // The actual implementation resides in WorkerProcessLauncher::Core class.
79 scoped_refptr
<Core
> core_
;
81 DISALLOW_COPY_AND_ASSIGN(WorkerProcessLauncher
);
84 } // namespace remoting
86 #endif // REMOTING_HOST_WIN_WORKER_PROCESS_LAUNCHER_H_