1// Copyright (c) 2011 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 CHROME_BROWSER_NACL_HOST_NACL_PROCESS_HOST_H_ 6#define CHROME_BROWSER_NACL_HOST_NACL_PROCESS_HOST_H_ 7#pragma once 8 9#include "build/build_config.h" 10 11#include "base/memory/ref_counted.h" 12#include "chrome/common/nacl_types.h" 13#include "content/browser/browser_child_process_host.h" 14 15class ChromeRenderMessageFilter; 16 17// Represents the browser side of the browser <--> NaCl communication 18// channel. There will be one NaClProcessHost per NaCl process 19// The browser is responsible for starting the NaCl process 20// when requested by the renderer. 21// After that, most of the communication is directly between NaCl plugin 22// running in the renderer and NaCl processes. 23class NaClProcessHost : public BrowserChildProcessHost { 24 public: 25 explicit NaClProcessHost(const std::wstring& url); 26 ~NaClProcessHost(); 27 28 // Initialize the new NaCl process, returning true on success. 29 bool Launch(ChromeRenderMessageFilter* chrome_render_message_filter, 30 int socket_count, 31 IPC::Message* reply_msg); 32 33 virtual bool OnMessageReceived(const IPC::Message& msg); 34 35 void OnProcessLaunchedByBroker(base::ProcessHandle handle); 36 37 protected: 38 virtual base::TerminationStatus GetChildTerminationStatus(int* exit_code); 39 virtual void OnChildDied(); 40 41 private: 42 // Internal class that holds the nacl::Handle objecs so that 43 // nacl_process_host.h doesn't include NaCl headers. Needed since it's 44 // included by src\content, which can't depend on the NaCl gyp file because it 45 // depends on chrome.gyp (circular dependency). 46 struct NaClInternal; 47 48 bool LaunchSelLdr(); 49 50 void SendStartMessage(); 51 52 virtual void OnProcessLaunched(); 53 54 virtual bool CanShutdown(); 55 56 private: 57 // The ChromeRenderMessageFilter that requested this NaCl process. We use 58 // this for sending the reply once the process has started. 59 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter_; 60 61 // The reply message to send. 62 IPC::Message* reply_msg_; 63 64 // Socket pairs for the NaCl process and renderer. 65 scoped_ptr<NaClInternal> internal_; 66 67 // Windows platform flag 68 bool running_on_wow64_; 69 70 DISALLOW_COPY_AND_ASSIGN(NaClProcessHost); 71}; 72 73#endif // CHROME_BROWSER_NACL_HOST_NACL_PROCESS_HOST_H_ 74