Simplify ChildProcessLauncher
[chromium-blink-merge.git] / content / public / browser / browser_child_process_host.h
blob2cd989660851acf52a6a344048a408838f6772b9
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_PUBLIC_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_
6 #define CONTENT_PUBLIC_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_
8 #include "base/environment.h"
9 #include "base/process/kill.h"
10 #include "base/process/process_handle.h"
11 #include "base/process/process_metrics.h"
12 #include "base/strings/string16.h"
13 #include "build/build_config.h"
14 #include "content/common/content_export.h"
15 #include "content/public/common/process_type.h"
16 #include "ipc/ipc_sender.h"
18 namespace base {
19 class CommandLine;
20 class FilePath;
23 namespace content {
25 class BrowserChildProcessHostDelegate;
26 class ChildProcessHost;
27 class SandboxedProcessLauncherDelegate;
28 struct ChildProcessData;
30 // This represents child processes of the browser process, i.e. plugins. They
31 // will get terminated at browser shutdown.
32 class CONTENT_EXPORT BrowserChildProcessHost : public IPC::Sender {
33 public:
34 // Used to create a child process host. The delegate must outlive this object.
35 // |process_type| needs to be either an enum value from ProcessType or an
36 // embedder-defined value.
37 static BrowserChildProcessHost* Create(
38 int process_type,
39 BrowserChildProcessHostDelegate* delegate);
41 ~BrowserChildProcessHost() override {}
43 // Derived classes call this to launch the child process asynchronously.
44 // Takes ownership of |cmd_line| and |delegate|.
45 virtual void Launch(
46 SandboxedProcessLauncherDelegate* delegate,
47 base::CommandLine* cmd_line,
48 bool terminate_on_shutdown) = 0;
50 virtual const ChildProcessData& GetData() const = 0;
52 // Returns the ChildProcessHost object used by this object.
53 virtual ChildProcessHost* GetHost() const = 0;
55 // Returns the termination status of a child. |exit_code| is the
56 // status returned when the process exited (for posix, as returned
57 // from waitpid(), for Windows, as returned from
58 // GetExitCodeProcess()). |exit_code| may be nullptr.
59 // |known_dead| indicates that the child is already dead. On Linux, this
60 // information is necessary to retrieve accurate information. See
61 // ChildProcessLauncher::GetChildTerminationStatus() for more details.
62 virtual base::TerminationStatus GetTerminationStatus(
63 bool known_dead, int* exit_code) = 0;
65 // Sets the user-visible name of the process.
66 virtual void SetName(const base::string16& name) = 0;
68 // Set the handle of the process. BrowserChildProcessHost will do this when
69 // the Launch method is used to start the process. However if the owner
70 // of this object doesn't call Launch and starts the process in another way,
71 // they need to call this method so that the process handle is associated with
72 // this object.
73 virtual void SetHandle(base::ProcessHandle handle) = 0;
75 #if defined(OS_MACOSX) && !defined(OS_IOS)
76 // Returns a PortProvider used to get process metrics for child processes.
77 static base::ProcessMetrics::PortProvider* GetPortProvider();
78 #endif
81 }; // namespace content
83 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_