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 CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_
6 #define CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/process/kill.h"
11 #include "base/process/launch.h"
12 #include "base/process/process.h"
13 #include "content/common/content_export.h"
20 class SandboxedProcessLauncherDelegate
;
22 // Launches a process asynchronously and notifies the client of the process
23 // handle when it's available. It's used to avoid blocking the calling thread
24 // on the OS since often it can take > 100 ms to create the process.
25 class CONTENT_EXPORT ChildProcessLauncher
{
27 class CONTENT_EXPORT Client
{
29 // Will be called on the thread that the ChildProcessLauncher was
31 virtual void OnProcessLaunched() = 0;
33 virtual void OnProcessLaunchFailed() {};
39 // Launches the process asynchronously, calling the client when the result is
40 // ready. Deleting this object before the process is created is safe, since
41 // the callback won't be called. If the process is still running by the time
42 // this object destructs, it will be terminated.
43 // Takes ownership of cmd_line.
45 SandboxedProcessLauncherDelegate
* delegate
,
46 base::CommandLine
* cmd_line
,
49 ~ChildProcessLauncher();
51 // True if the process is being launched and so the handle isn't available.
54 // Getter for the process. Only call after the process has started.
55 const base::Process
& GetProcess() const;
57 // Call this when the child process exits to know what happened to it.
58 // |known_dead| can be true if we already know the process is dead as it can
59 // help the implemention figure the proper TerminationStatus.
60 // On Linux, the use of |known_dead| is subtle and can be crucial if an
61 // accurate status is important. With |known_dead| set to false, a dead
62 // process could be seen as running. With |known_dead| set to true, the
63 // process will be killed if it was still running. See ZygoteHostImpl for
64 // more discussion of Linux implementation details.
65 // |exit_code| is the exit code of the process if it exited (e.g. status from
66 // waitpid if on posix, from GetExitCodeProcess on Windows). |exit_code| may
68 base::TerminationStatus
GetChildTerminationStatus(bool known_dead
,
71 // Changes whether the process runs in the background or not. Only call
72 // this after the process has started.
73 void SetProcessBackgrounded(bool background
);
75 // Controls whether the child process should be terminated on browser
77 void SetTerminateChildOnShutdown(bool terminate_on_shutdown
);
82 scoped_refptr
<Context
> context_
;
84 DISALLOW_COPY_AND_ASSIGN(ChildProcessLauncher
);
87 } // namespace content
89 #endif // CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_