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