Home | History | Annotate | Download | only in browser
      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 namespace base {
     19 class CommandLine;
     20 class FilePath;
     21 }
     22 
     23 namespace content {
     24 
     25 class BrowserChildProcessHostDelegate;
     26 class ChildProcessHost;
     27 class SandboxedProcessLauncherDelegate;
     28 struct ChildProcessData;
     29 
     30 // This represents child processes of the browser process, i.e. plugins. They
     31 // will get terminated at browser shutdown.
     32 class CONTENT_EXPORT BrowserChildProcessHost : public IPC::Sender {
     33  public:
     34   // Used to create a child process host. The delegate must outlive this object.
     35   // |process_type| needs to be either an enum value from ProcessType or an
     36   // embedder-defined value.
     37   static BrowserChildProcessHost* Create(
     38       int process_type,
     39       BrowserChildProcessHostDelegate* delegate);
     40 
     41   virtual ~BrowserChildProcessHost() {}
     42 
     43   // Derived classes call this to launch the child process asynchronously.
     44   // Takes ownership of |cmd_line| and |delegate|.
     45   virtual void Launch(
     46       SandboxedProcessLauncherDelegate* delegate,
     47       base::CommandLine* cmd_line) = 0;
     48 
     49   virtual const ChildProcessData& GetData() const = 0;
     50 
     51   // Returns the ChildProcessHost object used by this object.
     52   virtual ChildProcessHost* GetHost() const = 0;
     53 
     54   // Returns the termination status of a child.  |exit_code| is the
     55   // status returned when the process exited (for posix, as returned
     56   // from waitpid(), for Windows, as returned from
     57   // GetExitCodeProcess()).  |exit_code| may be NULL.
     58   // |known_dead| indicates that the child is already dead. On Linux, this
     59   // information is necessary to retrieve accurate information. See
     60   // ChildProcessLauncher::GetChildTerminationStatus() for more details.
     61   virtual base::TerminationStatus GetTerminationStatus(
     62       bool known_dead, int* exit_code) = 0;
     63 
     64   // Sets the user-visible name of the process.
     65   virtual void SetName(const base::string16& name) = 0;
     66 
     67   // Set the handle of the process. BrowserChildProcessHost will do this when
     68   // the Launch method is used to start the process. However if the owner
     69   // of this object doesn't call Launch and starts the process in another way,
     70   // they need to call this method so that the process handle is associated with
     71   // this object.
     72   virtual void SetHandle(base::ProcessHandle handle) = 0;
     73 
     74 #if defined(OS_MACOSX) && !defined(OS_IOS)
     75   // Returns a PortProvider used to get process metrics for child processes.
     76   static base::ProcessMetrics::PortProvider* GetPortProvider();
     77 #endif
     78 };
     79 
     80 };  // namespace content
     81 
     82 #endif  // CONTENT_PUBLIC_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_
     83