browser_child_process_host.h revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
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.
4
5#ifndef CONTENT_PUBLIC_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_
6#define CONTENT_PUBLIC_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_
7
8#include "base/process_util.h"
9#include "base/strings/string16.h"
10#include "build/build_config.h"
11#include "content/common/content_export.h"
12#include "content/public/common/process_type.h"
13#include "ipc/ipc_sender.h"
14
15class CommandLine;
16
17namespace base {
18class FilePath;
19}
20
21namespace content {
22
23class BrowserChildProcessHostDelegate;
24class ChildProcessHost;
25class SandboxedProcessLauncherDelegate;
26struct ChildProcessData;
27
28// This represents child processes of the browser process, i.e. plugins. They
29// will get terminated at browser shutdown.
30class CONTENT_EXPORT BrowserChildProcessHost : public IPC::Sender {
31 public:
32  // Used to create a child process host. The delegate must outlive this object.
33  // |process_type| needs to be either an enum value from ProcessType or an
34  // embedder-defined value.
35  static BrowserChildProcessHost* Create(
36      int process_type,
37      BrowserChildProcessHostDelegate* delegate);
38
39  virtual ~BrowserChildProcessHost() {}
40
41  // Derived classes call this to launch the child process asynchronously.
42  // Takes ownership of |cmd_line| and |delegate|.
43  virtual void Launch(
44#if defined(OS_WIN)
45      SandboxedProcessLauncherDelegate* delegate,
46#elif defined(OS_POSIX)
47      bool use_zygote,
48      const base::EnvironmentVector& environ,
49#endif
50      CommandLine* cmd_line) = 0;
51
52  virtual const ChildProcessData& GetData() const = 0;
53
54  // Returns the ChildProcessHost object used by this object.
55  virtual ChildProcessHost* GetHost() const = 0;
56
57  // Returns the termination status of a child.  |exit_code| is the
58  // status returned when the process exited (for posix, as returned
59  // from waitpid(), for Windows, as returned from
60  // GetExitCodeProcess()).  |exit_code| may be NULL.
61  virtual base::TerminationStatus GetTerminationStatus(int* exit_code) = 0;
62
63  // Sets the user-visible name of the process.
64  virtual void SetName(const string16& name) = 0;
65
66  // Set the handle of the process. BrowserChildProcessHost will do this when
67  // the Launch method is used to start the process. However if the owner
68  // of this object doesn't call Launch and starts the process in another way,
69  // they need to call this method so that the process handle is associated with
70  // this object.
71  virtual void SetHandle(base::ProcessHandle handle) = 0;
72
73#if defined(OS_MACOSX) && !defined(OS_IOS)
74  // Returns a PortProvider used to get process metrics for child processes.
75  static base::ProcessMetrics::PortProvider* GetPortProvider();
76#endif
77};
78
79};  // namespace content
80
81#endif  // CONTENT_PUBLIC_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_
82