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