child_process_host.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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_PULIC_COMMON_CHILD_PROCESS_HOST_H_
6#define CONTENT_PULIC_COMMON_CHILD_PROCESS_HOST_H_
7
8#include "build/build_config.h"
9#include "content/common/content_export.h"
10#include "ipc/ipc_channel_proxy.h"
11
12class FilePath;
13
14namespace content {
15
16class ChildProcessHostDelegate;
17
18// This represents a non-browser process. This can include traditional child
19// processes like plugins, or an embedder could even use this for long lived
20// processes that run independent of the browser process.
21class CONTENT_EXPORT ChildProcessHost : public IPC::Sender {
22 public:
23  virtual ~ChildProcessHost() {}
24
25  // Used to create a child process host. The delegate must outlive this object.
26  static ChildProcessHost* Create(
27      ChildProcessHostDelegate* delegate);
28
29  // These flags may be passed to GetChildPath in order to alter its behavior,
30  // causing it to return a child path more suited to a specific task.
31  enum {
32    // No special behavior requested.
33    CHILD_NORMAL = 0,
34
35#if defined(OS_LINUX)
36    // Indicates that the child execed after forking may be execced from
37    // /proc/self/exe rather than using the "real" app path. This prevents
38    // autoupdate from confusing us if it changes the file out from under us.
39    // You will generally want to set this on Linux, except when there is an
40    // override to the command line (for example, we're forking a renderer in
41    // gdb). In this case, you'd use GetChildPath to get the real executable
42    // file name, and then prepend the GDB command to the command line.
43    CHILD_ALLOW_SELF = 1 << 0,
44#elif defined(OS_MACOSX)
45
46    // Requests that the child run in a process that does not have the
47    // PIE (position-independent executable) bit set, effectively disabling
48    // ASLR. For process types that need to allocate a large contiguous
49    // region, ASLR may not leave a large enough "hole" for the purpose. This
50    // option should be used sparingly, and only when absolutely necessary.
51    // This option is currently incompatible with CHILD_ALLOW_HEAP_EXECUTION.
52    CHILD_NO_PIE = 1 << 1,
53
54    // Requests that the child run in a process that does not protect the
55    // heap against execution. Normally, heap pages may be made executable
56    // with mprotect, so this mode should be used sparingly. It is intended
57    // for processes that may host plug-ins that expect an executable heap
58    // without having to call mprotect. This option is currently incompatible
59    // with CHILD_NO_PIE.
60    CHILD_ALLOW_HEAP_EXECUTION = 1 << 2,
61#endif
62  };
63
64  // Returns the pathname to be used for a child process.  If a subprocess
65  // pathname was specified on the command line, that will be used.  Otherwise,
66  // the default child process pathname will be returned.  On most platforms,
67  // this will be the same as the currently-executing process.
68  //
69  // The |flags| argument accepts one or more flags such as CHILD_ALLOW_SELF
70  // and CHILD_ALLOW_HEAP_EXECUTION as defined above. Pass only CHILD_NORMAL
71  // if none of these special behaviors are required.
72  //
73  // On failure, returns an empty FilePath.
74  static FilePath GetChildPath(int flags);
75
76  // Send the shutdown message to the child process.
77  // Does not check with the delegate's CanShutdown.
78  virtual void ForceShutdown() = 0;
79
80  // Creates the IPC channel.  Returns the channel id if it succeeded, an
81  // empty string otherwise
82  virtual std::string CreateChannel() = 0;
83
84  // Returns true iff the IPC channel is currently being opened;
85  virtual bool IsChannelOpening() = 0;
86
87  // Adds an IPC message filter.  A reference will be kept to the filter.
88  virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
89
90#if defined(OS_POSIX)
91  // See IPC::Channel::TakeClientFileDescriptor.
92  virtual int TakeClientFileDescriptor() = 0;
93#endif
94};
95
96};  // namespace content
97
98#endif  // CONTENT_PULIC_COMMON_CHILD_PROCESS_HOST_H_
99