• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/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"
17 
18 class CommandLine;
19 
20 namespace base {
21 class FilePath;
22 }
23 
24 namespace content {
25 
26 class BrowserChildProcessHostDelegate;
27 class ChildProcessHost;
28 class SandboxedProcessLauncherDelegate;
29 struct ChildProcessData;
30 
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 {
34  public:
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(
39       int process_type,
40       BrowserChildProcessHostDelegate* delegate);
41 
~BrowserChildProcessHost()42   virtual ~BrowserChildProcessHost() {}
43 
44   // Derived classes call this to launch the child process asynchronously.
45   // Takes ownership of |cmd_line| and |delegate|.
46   virtual void Launch(
47 #if defined(OS_WIN)
48       SandboxedProcessLauncherDelegate* delegate,
49 #elif defined(OS_POSIX)
50       bool use_zygote,
51       const base::EnvironmentMap& environ,
52 #endif
53       CommandLine* cmd_line) = 0;
54 
55   virtual const ChildProcessData& GetData() const = 0;
56 
57   // Returns the ChildProcessHost object used by this object.
58   virtual ChildProcessHost* GetHost() const = 0;
59 
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;
69 
70   // Sets the user-visible name of the process.
71   virtual void SetName(const base::string16& name) = 0;
72 
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
77   // this object.
78   virtual void SetHandle(base::ProcessHandle handle) = 0;
79 
80 #if defined(OS_MACOSX) && !defined(OS_IOS)
81   // Returns a PortProvider used to get process metrics for child processes.
82   static base::ProcessMetrics::PortProvider* GetPortProvider();
83 #endif
84 };
85 
86 };  // namespace content
87 
88 #endif  // CONTENT_PUBLIC_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_
89