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_util.h"
11 #include "content/common/content_export.h"
17 // Launches a process asynchronously and notifies the client of the process
18 // handle when it's available. It's used to avoid blocking the calling thread
19 // on the OS since often it can take > 100 ms to create the process.
20 class CONTENT_EXPORT ChildProcessLauncher
{
22 class CONTENT_EXPORT Client
{
24 // Will be called on the thread that the ChildProcessLauncher was
26 virtual void OnProcessLaunched() = 0;
32 // Launches the process asynchronously, calling the client when the result is
33 // ready. Deleting this object before the process is created is safe, since
34 // the callback won't be called. If the process is still running by the time
35 // this object destructs, it will be terminated.
36 // Takes ownership of cmd_line.
39 const FilePath
& exposed_dir
,
40 #elif defined(OS_POSIX)
42 const base::EnvironmentVector
& environ
,
45 CommandLine
* cmd_line
,
48 ~ChildProcessLauncher();
50 // True if the process is being launched and so the handle isn't available.
53 // Getter for the process handle. Only call after the process has started.
54 base::ProcessHandle
GetHandle();
56 // Call this when the child process exits to know what happened to it.
57 // |known_dead| can be true if we already know the process is dead as it can
58 // help the implemention figure the proper TerminationStatus.
59 // |exit_code| is the exit code of the process if it exited (e.g. status from
60 // waitpid if on posix, from GetExitCodeProcess on Windows). |exit_code| may
62 base::TerminationStatus
GetChildTerminationStatus(bool known_dead
,
65 // Changes whether the process runs in the background or not. Only call
66 // this after the process has started.
67 void SetProcessBackgrounded(bool background
);
69 // Controls whether the child process should be terminated on browser
71 void SetTerminateChildOnShutdown(bool terminate_on_shutdown
);
76 scoped_refptr
<Context
> context_
;
78 DISALLOW_COPY_AND_ASSIGN(ChildProcessLauncher
);
81 } // namespace content
83 #endif // CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_