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/attachment_broker_privileged.h"
12 #include "ipc/ipc_channel_proxy.h"
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
{
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 // This value is used as the tracing id of the browser process for identifying
38 // cross-process shared memory segments when tracing.
39 // Note: In single-process mode all the clients of tracing will use this id.
40 static uint64 kBrowserTracingProcessId
;
42 // Used to create a child process host. The delegate must outlive this object.
43 static ChildProcessHost
* Create(ChildProcessHostDelegate
* delegate
);
45 // These flags may be passed to GetChildPath in order to alter its behavior,
46 // causing it to return a child path more suited to a specific task.
48 // No special behavior requested.
52 // Indicates that the child execed after forking may be execced from
53 // /proc/self/exe rather than using the "real" app path. This prevents
54 // autoupdate from confusing us if it changes the file out from under us.
55 // You will generally want to set this on Linux, except when there is an
56 // override to the command line (for example, we're forking a renderer in
57 // gdb). In this case, you'd use GetChildPath to get the real executable
58 // file name, and then prepend the GDB command to the command line.
59 CHILD_ALLOW_SELF
= 1 << 0,
60 #endif // defined(OS_LINUX)
63 // Returns the pathname to be used for a child process. If a subprocess
64 // pathname was specified on the command line, that will be used. Otherwise,
65 // the default child process pathname will be returned. On most platforms,
66 // this will be the same as the currently-executing process.
68 // The |flags| argument accepts one or more flags such as CHILD_ALLOW_SELF.
69 // Pass only CHILD_NORMAL if none of these special behaviors are required.
71 // On failure, returns an empty FilePath.
72 static base::FilePath
GetChildPath(int flags
);
74 // Send the shutdown message to the child process.
75 // Does not check with the delegate's CanShutdown.
76 virtual void ForceShutdown() = 0;
78 // Creates the IPC channel. Returns the channel id if it succeeded, an
79 // empty string otherwise
80 virtual std::string
CreateChannel() = 0;
82 // Returns true iff the IPC channel is currently being opened;
83 virtual bool IsChannelOpening() = 0;
85 // Adds an IPC message filter. A reference will be kept to the filter.
86 virtual void AddFilter(IPC::MessageFilter
* filter
) = 0;
89 // See IPC::Channel::TakeClientFileDescriptor.
90 virtual base::ScopedFD
TakeClientFileDescriptor() = 0;
94 }; // namespace content
96 #endif // CONTENT_PUBLIC_COMMON_CHILD_PROCESS_HOST_H_