OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/nacl_host/nacl_broker_host_win.h" | 5 #include "chrome/browser/nacl_host/nacl_broker_host_win.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "ipc/ipc_switches.h" | 9 #include "ipc/ipc_switches.h" |
10 #include "chrome/browser/nacl_host/nacl_broker_service_win.h" | 10 #include "chrome/browser/nacl_host/nacl_broker_service_win.h" |
11 #include "chrome/browser/nacl_host/nacl_process_host.h" | 11 #include "chrome/browser/nacl_host/nacl_process_host.h" |
12 #include "chrome/common/chrome_constants.h" | 12 #include "chrome/common/chrome_constants.h" |
13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/common/logging_chrome.h" | 14 #include "chrome/common/logging_chrome.h" |
15 #include "chrome/common/nacl_cmd_line.h" | 15 #include "chrome/common/nacl_cmd_line.h" |
16 #include "chrome/common/nacl_messages.h" | 16 #include "chrome/common/nacl_messages.h" |
| 17 #include "content/public/browser/browser_child_process_host.h" |
17 #include "content/public/common/child_process_host.h" | 18 #include "content/public/common/child_process_host.h" |
18 | 19 |
19 NaClBrokerHost::NaClBrokerHost() | 20 NaClBrokerHost::NaClBrokerHost() |
20 : BrowserChildProcessHost(content::PROCESS_TYPE_NACL_BROKER), | 21 : stopping_(false) { |
21 stopping_(false) { | 22 process_.reset(content::BrowserChildProcessHost::Create( |
| 23 content::PROCESS_TYPE_NACL_BROKER, this)); |
22 } | 24 } |
23 | 25 |
24 NaClBrokerHost::~NaClBrokerHost() { | 26 NaClBrokerHost::~NaClBrokerHost() { |
25 } | 27 } |
26 | 28 |
27 bool NaClBrokerHost::Init() { | 29 bool NaClBrokerHost::Init() { |
28 // Create the channel that will be used for communicating with the broker. | 30 // Create the channel that will be used for communicating with the broker. |
29 std::string channel_id = child_process_host()->CreateChannel(); | 31 std::string channel_id = process_->GetHost()->CreateChannel(); |
30 if (channel_id.empty()) | 32 if (channel_id.empty()) |
31 return false; | 33 return false; |
32 | 34 |
33 // Create the path to the nacl broker/loader executable. | 35 // Create the path to the nacl broker/loader executable. |
34 FilePath module_path; | 36 FilePath module_path; |
35 if (!PathService::Get(base::FILE_MODULE, &module_path)) | 37 if (!PathService::Get(base::FILE_MODULE, &module_path)) |
36 return false; | 38 return false; |
37 | 39 |
38 FilePath nacl_path = module_path.DirName().Append(chrome::kNaClAppName); | 40 FilePath nacl_path = module_path.DirName().Append(chrome::kNaClAppName); |
39 CommandLine* cmd_line = new CommandLine(nacl_path); | 41 CommandLine* cmd_line = new CommandLine(nacl_path); |
40 nacl::CopyNaClCommandLineArguments(cmd_line); | 42 nacl::CopyNaClCommandLineArguments(cmd_line); |
41 | 43 |
42 cmd_line->AppendSwitchASCII(switches::kProcessType, | 44 cmd_line->AppendSwitchASCII(switches::kProcessType, |
43 switches::kNaClBrokerProcess); | 45 switches::kNaClBrokerProcess); |
44 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 46 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); |
45 if (logging::DialogsAreSuppressed()) | 47 if (logging::DialogsAreSuppressed()) |
46 cmd_line->AppendSwitch(switches::kNoErrorDialogs); | 48 cmd_line->AppendSwitch(switches::kNoErrorDialogs); |
47 | 49 |
48 BrowserChildProcessHost::Launch(FilePath(), cmd_line); | 50 process_->Launch(FilePath(), cmd_line); |
49 return true; | 51 return true; |
50 } | 52 } |
51 | 53 |
52 bool NaClBrokerHost::OnMessageReceived(const IPC::Message& msg) { | 54 bool NaClBrokerHost::OnMessageReceived(const IPC::Message& msg) { |
53 bool handled = true; | 55 bool handled = true; |
54 IPC_BEGIN_MESSAGE_MAP(NaClBrokerHost, msg) | 56 IPC_BEGIN_MESSAGE_MAP(NaClBrokerHost, msg) |
55 IPC_MESSAGE_HANDLER(NaClProcessMsg_LoaderLaunched, OnLoaderLaunched) | 57 IPC_MESSAGE_HANDLER(NaClProcessMsg_LoaderLaunched, OnLoaderLaunched) |
56 IPC_MESSAGE_UNHANDLED(handled = false) | 58 IPC_MESSAGE_UNHANDLED(handled = false) |
57 IPC_END_MESSAGE_MAP() | 59 IPC_END_MESSAGE_MAP() |
58 return handled; | 60 return handled; |
59 } | 61 } |
60 | 62 |
61 bool NaClBrokerHost::LaunchLoader( | 63 bool NaClBrokerHost::LaunchLoader( |
62 const std::wstring& loader_channel_id) { | 64 const std::wstring& loader_channel_id) { |
63 return Send(new NaClProcessMsg_LaunchLoaderThroughBroker(loader_channel_id)); | 65 return process_->Send( |
| 66 new NaClProcessMsg_LaunchLoaderThroughBroker(loader_channel_id)); |
64 } | 67 } |
65 | 68 |
66 void NaClBrokerHost::OnLoaderLaunched(const std::wstring& loader_channel_id, | 69 void NaClBrokerHost::OnLoaderLaunched(const std::wstring& loader_channel_id, |
67 base::ProcessHandle handle) { | 70 base::ProcessHandle handle) { |
68 NaClBrokerService::GetInstance()->OnLoaderLaunched(loader_channel_id, handle); | 71 NaClBrokerService::GetInstance()->OnLoaderLaunched(loader_channel_id, handle); |
69 } | 72 } |
70 | 73 |
71 void NaClBrokerHost::StopBroker() { | 74 void NaClBrokerHost::StopBroker() { |
72 stopping_ = true; | 75 stopping_ = true; |
73 Send(new NaClProcessMsg_StopBroker()); | 76 process_->Send(new NaClProcessMsg_StopBroker()); |
74 } | 77 } |
OLD | NEW |