summaryrefslogtreecommitdiffstats
path: root/chrome/browser/nacl_host/nacl_broker_host.cc
blob: 8abc228f51af1a099f7c3d98d0ee808ffa100a12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/nacl_host/nacl_broker_host.h"

#include "base/command_line.h"
#include "ipc/ipc_switches.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/nacl_host/nacl_broker_service.h"
#include "chrome/browser/nacl_process_host.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/nacl_cmd_line.h"
#include "chrome/common/nacl_messages.h"

NaClBrokerHost::NaClBrokerHost(
    ResourceDispatcherHost* resource_dispatcher_host)
    : ChildProcessHost(NACL_BROKER_PROCESS, resource_dispatcher_host) {
}

NaClBrokerHost::~NaClBrokerHost() {
}

URLRequestContext* NaClBrokerHost::GetRequestContext(
    uint32 request_id,
    const ViewHostMsg_Resource_Request& request_data) {
  return NULL;
}

bool NaClBrokerHost::Init() {
  // Create the channel that will be used for communicating with the broker.
  if (!CreateChannel())
    return false;

  // Create the path to the nacl broker/loader executable.
  FilePath exe_path = GetChildPath(false);
  if (exe_path.empty())
    return false;

  FilePath nacl_path = exe_path.DirName().Append(chrome::kNaClAppName);
  CommandLine* cmd_line = new CommandLine(nacl_path);
  nacl::CopyNaClCommandLineArguments(cmd_line);

  cmd_line->AppendSwitchWithValue(switches::kProcessType,
      switches::kNaClBrokerProcess);

  cmd_line->AppendSwitchWithValue(switches::kProcessChannelID,
      ASCIIToWide(channel_id()));

  ChildProcessHost::Launch(FilePath(), cmd_line);
  return true;
}

void NaClBrokerHost::OnMessageReceived(const IPC::Message& msg) {
  IPC_BEGIN_MESSAGE_MAP(NaClBrokerHost, msg)
    IPC_MESSAGE_HANDLER(NaClProcessMsg_BrokerReady, OnBrokerReady)
    IPC_MESSAGE_HANDLER(NaClProcessMsg_LoaderLaunched, OnLoaderLaunched)
  IPC_END_MESSAGE_MAP()
}

void NaClBrokerHost::OnBrokerReady() {
  NaClBrokerService::GetInstance()->OnBrokerStarted();
}

bool NaClBrokerHost::LaunchLoader(
    const std::wstring& loader_channel_id) {
  return Send(new NaClProcessMsg_LaunchLoaderThroughBroker(loader_channel_id));
}

void NaClBrokerHost::OnLoaderLaunched(const std::wstring& loader_channel_id,
                                      base::ProcessHandle handle) {
  NaClBrokerService::GetInstance()->OnLoaderLaunched(loader_channel_id, handle);
}