nacl_broker_host_win.cc revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
1// Copyright (c) 2010 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#include "chrome/browser/nacl_host/nacl_broker_host_win.h" 6 7#include "base/command_line.h" 8#include "base/path_service.h" 9#include "ipc/ipc_switches.h" 10#include "chrome/browser/browser_process.h" 11#include "chrome/browser/nacl_host/nacl_broker_service_win.h" 12#include "chrome/browser/nacl_host/nacl_process_host.h" 13#include "chrome/common/chrome_constants.h" 14#include "chrome/common/chrome_switches.h" 15#include "chrome/common/nacl_cmd_line.h" 16#include "chrome/common/nacl_messages.h" 17 18NaClBrokerHost::NaClBrokerHost( 19 ResourceDispatcherHost* resource_dispatcher_host) 20 : BrowserChildProcessHost(NACL_BROKER_PROCESS, resource_dispatcher_host), 21 stopping_(false) { 22} 23 24NaClBrokerHost::~NaClBrokerHost() { 25} 26 27URLRequestContext* NaClBrokerHost::GetRequestContext( 28 uint32 request_id, 29 const ViewHostMsg_Resource_Request& request_data) { 30 return NULL; 31} 32 33bool NaClBrokerHost::Init() { 34 // Create the channel that will be used for communicating with the broker. 35 if (!CreateChannel()) 36 return false; 37 38 // Create the path to the nacl broker/loader executable. 39 FilePath module_path; 40 if (!PathService::Get(base::FILE_MODULE, &module_path)) 41 return false; 42 43 FilePath nacl_path = module_path.DirName().Append(chrome::kNaClAppName); 44 CommandLine* cmd_line = new CommandLine(nacl_path); 45 nacl::CopyNaClCommandLineArguments(cmd_line); 46 47 cmd_line->AppendSwitchASCII(switches::kProcessType, 48 switches::kNaClBrokerProcess); 49 50 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id()); 51 52 BrowserChildProcessHost::Launch(FilePath(), cmd_line); 53 return true; 54} 55 56void NaClBrokerHost::OnMessageReceived(const IPC::Message& msg) { 57 IPC_BEGIN_MESSAGE_MAP(NaClBrokerHost, msg) 58 IPC_MESSAGE_HANDLER(NaClProcessMsg_LoaderLaunched, OnLoaderLaunched) 59 IPC_END_MESSAGE_MAP() 60} 61 62bool NaClBrokerHost::LaunchLoader( 63 const std::wstring& loader_channel_id) { 64 return Send(new NaClProcessMsg_LaunchLoaderThroughBroker(loader_channel_id)); 65} 66 67void NaClBrokerHost::OnLoaderLaunched(const std::wstring& loader_channel_id, 68 base::ProcessHandle handle) { 69 NaClBrokerService::GetInstance()->OnLoaderLaunched(loader_channel_id, handle); 70} 71 72void NaClBrokerHost::StopBroker() { 73 stopping_ = true; 74 Send(new NaClProcessMsg_StopBroker()); 75} 76