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"
26 class BrowserChildProcessHostDelegate;
27 class ChildProcessHost;
28 class SandboxedProcessLauncherDelegate;
29 struct ChildProcessData;
31 // This represents child processes of the browser process, i.e. plugins. They
32 // will get terminated at browser shutdown.
33 class CONTENT_EXPORT BrowserChildProcessHost : public IPC::Sender {
35 // Used to create a child process host. The delegate must outlive this object.
36 // |process_type| needs to be either an enum value from ProcessType or an
37 // embedder-defined value.
38 static BrowserChildProcessHost* Create(
40 BrowserChildProcessHostDelegate* delegate);
42 virtual ~BrowserChildProcessHost() {}
44 // Derived classes call this to launch the child process asynchronously.
45 // Takes ownership of |cmd_line| and |delegate|.
48 SandboxedProcessLauncherDelegate* delegate,
49 #elif defined(OS_POSIX)
51 const base::EnvironmentMap& environ,
53 CommandLine* cmd_line) = 0;
55 virtual const ChildProcessData& GetData() const = 0;
57 // Returns the ChildProcessHost object used by this object.
58 virtual ChildProcessHost* GetHost() const = 0;
60 // Returns the termination status of a child. |exit_code| is the
61 // status returned when the process exited (for posix, as returned
62 // from waitpid(), for Windows, as returned from
63 // GetExitCodeProcess()). |exit_code| may be NULL.
64 // |known_dead| indicates that the child is already dead. On Linux, this
65 // information is necessary to retrieve accurate information. See
66 // ChildProcessLauncher::GetChildTerminationStatus() for more details.
67 virtual base::TerminationStatus GetTerminationStatus(
68 bool known_dead, int* exit_code) = 0;
70 // Sets the user-visible name of the process.
71 virtual void SetName(const base::string16& name) = 0;
73 // Set the handle of the process. BrowserChildProcessHost will do this when
74 // the Launch method is used to start the process. However if the owner
75 // of this object doesn't call Launch and starts the process in another way,
76 // they need to call this method so that the process handle is associated with
78 virtual void SetHandle(base::ProcessHandle handle) = 0;
80 // Set the nacl debug stub port of the process.
81 virtual void SetNaClDebugStubPort(int port) = 0;
83 #if defined(OS_MACOSX) && !defined(OS_IOS)
84 // Returns a PortProvider used to get process metrics for child processes.
85 static base::ProcessMetrics::PortProvider* GetPortProvider();
89 }; // namespace content
91 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_