690a015f4f2d97e8eccb1a1fd4347da0423e91a2
[platform/framework/web/crosswalk.git] / src / content / public / browser / browser_child_process_host.h
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
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       bool run_elevated,
50 #elif defined(OS_POSIX)
51       bool use_zygote,
52       const base::EnvironmentMap& environ,
53 #endif
54       CommandLine* cmd_line) = 0;
55
56   virtual const ChildProcessData& GetData() const = 0;
57
58   // Returns the ChildProcessHost object used by this object.
59   virtual ChildProcessHost* GetHost() const = 0;
60
61   // Returns the termination status of a child.  |exit_code| is the
62   // status returned when the process exited (for posix, as returned
63   // from waitpid(), for Windows, as returned from
64   // GetExitCodeProcess()).  |exit_code| may be NULL.
65   // |known_dead| indicates that the child is already dead. On Linux, this
66   // information is necessary to retrieve accurate information. See
67   // ChildProcessLauncher::GetChildTerminationStatus() for more details.
68   virtual base::TerminationStatus GetTerminationStatus(
69       bool known_dead, int* exit_code) = 0;
70
71   // Sets the user-visible name of the process.
72   virtual void SetName(const base::string16& name) = 0;
73
74   // Set the handle of the process. BrowserChildProcessHost will do this when
75   // the Launch method is used to start the process. However if the owner
76   // of this object doesn't call Launch and starts the process in another way,
77   // they need to call this method so that the process handle is associated with
78   // this object.
79   virtual void SetHandle(base::ProcessHandle handle) = 0;
80
81   // Set the nacl debug stub port of the process.
82   virtual void SetNaClDebugStubPort(int port) = 0;
83
84 #if defined(OS_MACOSX) && !defined(OS_IOS)
85   // Returns a PortProvider used to get process metrics for child processes.
86   static base::ProcessMetrics::PortProvider* GetPortProvider();
87 #endif
88 };
89
90 };  // namespace content
91
92 #endif  // CONTENT_PUBLIC_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_