Re-enable index-basics-workers test to see if still times
[chromium-blink-merge.git] / content / browser / child_process_launcher.h
blobf1c8f0df0f4ad178d08c970e565ec51d21069a16
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"
13 class CommandLine;
15 namespace content {
16 class SandboxedProcessLauncherDelegate;
18 // Launches a process asynchronously and notifies the client of the process
19 // handle when it's available. It's used to avoid blocking the calling thread
20 // on the OS since often it can take > 100 ms to create the process.
21 class CONTENT_EXPORT ChildProcessLauncher {
22 public:
23 class CONTENT_EXPORT Client {
24 public:
25 // Will be called on the thread that the ChildProcessLauncher was
26 // constructed on.
27 virtual void OnProcessLaunched() = 0;
29 protected:
30 virtual ~Client() {}
33 // Launches the process asynchronously, calling the client when the result is
34 // ready. Deleting this object before the process is created is safe, since
35 // the callback won't be called. If the process is still running by the time
36 // this object destructs, it will be terminated.
37 // Takes ownership of cmd_line.
38 ChildProcessLauncher(
39 #if defined(OS_WIN)
40 SandboxedProcessLauncherDelegate* delegate,
41 #elif defined(OS_POSIX)
42 bool use_zygote,
43 const base::EnvironmentVector& environ,
44 int ipcfd,
45 #endif
46 CommandLine* cmd_line,
47 int child_process_id,
48 Client* client);
49 ~ChildProcessLauncher();
51 // True if the process is being launched and so the handle isn't available.
52 bool IsStarting();
54 // Getter for the process handle. Only call after the process has started.
55 base::ProcessHandle GetHandle();
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 // |exit_code| is the exit code of the process if it exited (e.g. status from
61 // waitpid if on posix, from GetExitCodeProcess on Windows). |exit_code| may
62 // be NULL.
63 base::TerminationStatus GetChildTerminationStatus(bool known_dead,
64 int* exit_code);
66 // Changes whether the process runs in the background or not. Only call
67 // this after the process has started.
68 void SetProcessBackgrounded(bool background);
70 // Controls whether the child process should be terminated on browser
71 // shutdown.
72 void SetTerminateChildOnShutdown(bool terminate_on_shutdown);
74 private:
75 class Context;
77 scoped_refptr<Context> context_;
79 DISALLOW_COPY_AND_ASSIGN(ChildProcessLauncher);
82 } // namespace content
84 #endif // CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_