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