Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Side by Side Diff: chrome/browser/nacl_host/nacl_process_host.cc

Issue 8774040: Don't make classes derive from ChildProcessHost, and instead have them use it through composition... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/browser/nacl_host/nacl_process_host.h" 7 #include "chrome/browser/nacl_host/nacl_process_host.h"
8 8
9 #if defined(OS_POSIX) 9 #if defined(OS_POSIX)
10 #include <fcntl.h> 10 #include <fcntl.h>
11 #endif 11 #endif
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "base/win/windows_version.h" 18 #include "base/win/windows_version.h"
19 #include "chrome/common/chrome_paths.h" 19 #include "chrome/common/chrome_paths.h"
20 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/logging_chrome.h" 21 #include "chrome/common/logging_chrome.h"
22 #include "chrome/common/nacl_cmd_line.h" 22 #include "chrome/common/nacl_cmd_line.h"
23 #include "chrome/common/nacl_messages.h" 23 #include "chrome/common/nacl_messages.h"
24 #include "chrome/common/render_messages.h" 24 #include "chrome/common/render_messages.h"
25 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" 25 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
26 #include "content/common/child_process_host.h"
26 #include "ipc/ipc_switches.h" 27 #include "ipc/ipc_switches.h"
27 #include "native_client/src/shared/imc/nacl_imc.h" 28 #include "native_client/src/shared/imc/nacl_imc.h"
28 29
29 #if defined(OS_POSIX) 30 #if defined(OS_POSIX)
30 #include "ipc/ipc_channel_posix.h" 31 #include "ipc/ipc_channel_posix.h"
31 #elif defined(OS_WIN) 32 #elif defined(OS_WIN)
32 #include "chrome/browser/nacl_host/nacl_broker_service_win.h" 33 #include "chrome/browser/nacl_host/nacl_broker_service_win.h"
33 #endif 34 #endif
34 35
35 using content::BrowserThread; 36 using content::BrowserThread;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 110
110 NaClProcessHost::NaClProcessHost(const std::wstring& url) 111 NaClProcessHost::NaClProcessHost(const std::wstring& url)
111 : BrowserChildProcessHost(content::PROCESS_TYPE_NACL_LOADER), 112 : BrowserChildProcessHost(content::PROCESS_TYPE_NACL_LOADER),
112 reply_msg_(NULL), 113 reply_msg_(NULL),
113 internal_(new NaClInternal()), 114 internal_(new NaClInternal()),
114 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 115 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
115 set_name(WideToUTF16Hack(url)); 116 set_name(WideToUTF16Hack(url));
116 } 117 }
117 118
118 NaClProcessHost::~NaClProcessHost() { 119 NaClProcessHost::~NaClProcessHost() {
120 int exit_code;
121 GetChildTerminationStatus(&exit_code);
122 std::string message =
123 base::StringPrintf("NaCl process exited with status %i (0x%x)",
124 exit_code, exit_code);
125 if (exit_code == 0) {
126 LOG(INFO) << message;
127 } else {
128 LOG(ERROR) << message;
129 }
130
131 #if defined(OS_WIN)
132 NaClBrokerService::GetInstance()->OnLoaderDied();
133 #endif
134
119 for (size_t i = 0; i < internal_->sockets_for_renderer.size(); i++) { 135 for (size_t i = 0; i < internal_->sockets_for_renderer.size(); i++) {
120 if (nacl::Close(internal_->sockets_for_renderer[i]) != 0) { 136 if (nacl::Close(internal_->sockets_for_renderer[i]) != 0) {
121 LOG(ERROR) << "nacl::Close() failed"; 137 LOG(ERROR) << "nacl::Close() failed";
122 } 138 }
123 } 139 }
124 for (size_t i = 0; i < internal_->sockets_for_sel_ldr.size(); i++) { 140 for (size_t i = 0; i < internal_->sockets_for_sel_ldr.size(); i++) {
125 if (nacl::Close(internal_->sockets_for_sel_ldr[i]) != 0) { 141 if (nacl::Close(internal_->sockets_for_sel_ldr[i]) != 0) {
126 LOG(ERROR) << "nacl::Close() failed"; 142 LOG(ERROR) << "nacl::Close() failed";
127 } 143 }
128 } 144 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 if (!LaunchSelLdr()) { 221 if (!LaunchSelLdr()) {
206 return false; 222 return false;
207 } 223 }
208 chrome_render_message_filter_ = chrome_render_message_filter; 224 chrome_render_message_filter_ = chrome_render_message_filter;
209 reply_msg_ = reply_msg; 225 reply_msg_ = reply_msg;
210 226
211 return true; 227 return true;
212 } 228 }
213 229
214 bool NaClProcessHost::LaunchSelLdr() { 230 bool NaClProcessHost::LaunchSelLdr() {
215 if (!CreateChannel()) 231 if (!child_process_host()->CreateChannel())
216 return false; 232 return false;
217 233
218 CommandLine::StringType nacl_loader_prefix; 234 CommandLine::StringType nacl_loader_prefix;
219 #if defined(OS_POSIX) 235 #if defined(OS_POSIX)
220 nacl_loader_prefix = CommandLine::ForCurrentProcess()->GetSwitchValueNative( 236 nacl_loader_prefix = CommandLine::ForCurrentProcess()->GetSwitchValueNative(
221 switches::kNaClLoaderCmdPrefix); 237 switches::kNaClLoaderCmdPrefix);
222 #endif // defined(OS_POSIX) 238 #endif // defined(OS_POSIX)
223 239
224 // Build command line for nacl. 240 // Build command line for nacl.
225 241
226 #if defined(OS_MACOSX) 242 #if defined(OS_MACOSX)
227 // The Native Client process needs to be able to allocate a 1GB contiguous 243 // The Native Client process needs to be able to allocate a 1GB contiguous
228 // region to use as the client environment's virtual address space. ASLR 244 // region to use as the client environment's virtual address space. ASLR
229 // (PIE) interferes with this by making it possible that no gap large enough 245 // (PIE) interferes with this by making it possible that no gap large enough
230 // to accomodate this request will exist in the child process' address 246 // to accomodate this request will exist in the child process' address
231 // space. Disable PIE for NaCl processes. See http://crbug.com/90221 and 247 // space. Disable PIE for NaCl processes. See http://crbug.com/90221 and
232 // http://code.google.com/p/nativeclient/issues/detail?id=2043. 248 // http://code.google.com/p/nativeclient/issues/detail?id=2043.
233 int flags = CHILD_NO_PIE; 249 int flags = CHILD_NO_PIE;
234 #elif defined(OS_LINUX) 250 #elif defined(OS_LINUX)
235 int flags = nacl_loader_prefix.empty() ? CHILD_ALLOW_SELF : CHILD_NORMAL; 251 int flags = nacl_loader_prefix.empty() ? ChildProcessHost::CHILD_ALLOW_SELF :
252 ChildProcessHost::CHILD_NORMAL;
236 #else 253 #else
237 int flags = CHILD_NORMAL; 254 int flags = ChildProcessHost::CHILD_NORMAL;
238 #endif 255 #endif
239 256
240 FilePath exe_path = GetChildPath(flags); 257 FilePath exe_path = ChildProcessHost::GetChildPath(flags);
241 if (exe_path.empty()) 258 if (exe_path.empty())
242 return false; 259 return false;
243 260
244 CommandLine* cmd_line = new CommandLine(exe_path); 261 CommandLine* cmd_line = new CommandLine(exe_path);
245 nacl::CopyNaClCommandLineArguments(cmd_line); 262 nacl::CopyNaClCommandLineArguments(cmd_line);
246 263
247 cmd_line->AppendSwitchASCII(switches::kProcessType, 264 cmd_line->AppendSwitchASCII(switches::kProcessType,
248 switches::kNaClLoaderProcess); 265 switches::kNaClLoaderProcess);
249 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id()); 266 cmd_line->AppendSwitchASCII(switches::kProcessChannelID,
267 child_process_host()->channel_id());
250 if (logging::DialogsAreSuppressed()) 268 if (logging::DialogsAreSuppressed())
251 cmd_line->AppendSwitch(switches::kNoErrorDialogs); 269 cmd_line->AppendSwitch(switches::kNoErrorDialogs);
252 270
253 if (!nacl_loader_prefix.empty()) 271 if (!nacl_loader_prefix.empty())
254 cmd_line->PrependWrapper(nacl_loader_prefix); 272 cmd_line->PrependWrapper(nacl_loader_prefix);
255 273
256 // On Windows we might need to start the broker process to launch a new loader 274 // On Windows we might need to start the broker process to launch a new loader
257 #if defined(OS_WIN) 275 #if defined(OS_WIN)
258 if (RunningOnWOW64()) { 276 if (RunningOnWOW64()) {
259 return NaClBrokerService::GetInstance()->LaunchLoader( 277 return NaClBrokerService::GetInstance()->LaunchLoader(
260 this, ASCIIToWide(channel_id())); 278 this, ASCIIToWide(child_process_host()->channel_id()));
261 } else { 279 } else {
262 BrowserChildProcessHost::Launch(FilePath(), cmd_line); 280 BrowserChildProcessHost::Launch(FilePath(), cmd_line);
263 } 281 }
264 #elif defined(OS_POSIX) 282 #elif defined(OS_POSIX)
265 BrowserChildProcessHost::Launch(nacl_loader_prefix.empty(), // use_zygote 283 BrowserChildProcessHost::Launch(nacl_loader_prefix.empty(), // use_zygote
266 base::environment_vector(), 284 base::environment_vector(),
267 cmd_line); 285 cmd_line);
268 #endif 286 #endif
269 287
270 return true; 288 return true;
271 } 289 }
272 290
273 void NaClProcessHost::OnProcessLaunchedByBroker(base::ProcessHandle handle) { 291 void NaClProcessHost::OnProcessLaunchedByBroker(base::ProcessHandle handle) {
274 set_handle(handle); 292 set_handle(handle);
275 OnProcessLaunched(); 293 OnProcessLaunched();
276 } 294 }
277 295
278 base::TerminationStatus NaClProcessHost::GetChildTerminationStatus( 296 base::TerminationStatus NaClProcessHost::GetChildTerminationStatus(
279 int* exit_code) { 297 int* exit_code) {
280 if (RunningOnWOW64()) 298 if (RunningOnWOW64())
281 return base::GetTerminationStatus(handle(), exit_code); 299 return base::GetTerminationStatus(handle(), exit_code);
282 return BrowserChildProcessHost::GetChildTerminationStatus(exit_code); 300 return BrowserChildProcessHost::GetChildTerminationStatus(exit_code);
283 } 301 }
284 302
285 void NaClProcessHost::OnChildDied() {
286 int exit_code;
287 GetChildTerminationStatus(&exit_code);
288 std::string message =
289 base::StringPrintf("NaCl process exited with status %i (0x%x)",
290 exit_code, exit_code);
291 if (exit_code == 0) {
292 LOG(INFO) << message;
293 } else {
294 LOG(ERROR) << message;
295 }
296
297 #if defined(OS_WIN)
298 NaClBrokerService::GetInstance()->OnLoaderDied();
299 #endif
300 BrowserChildProcessHost::OnChildDied();
301 }
302
303 // This only ever runs on the BrowserThread::FILE thread. 303 // This only ever runs on the BrowserThread::FILE thread.
304 // If multiple tasks are posted, the later ones are no-ops. 304 // If multiple tasks are posted, the later ones are no-ops.
305 void NaClBrowser::OpenIrtLibraryFile() { 305 void NaClBrowser::OpenIrtLibraryFile() {
306 if (irt_platform_file_ != base::kInvalidPlatformFileValue) 306 if (irt_platform_file_ != base::kInvalidPlatformFileValue)
307 // We've already run. 307 // We've already run.
308 return; 308 return;
309 309
310 FilePath irt_filepath; 310 FilePath irt_filepath;
311 311
312 // Allow the IRT library to be overridden via an environment 312 // Allow the IRT library to be overridden via an environment
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 #endif 512 #endif
513 513
514 Send(new NaClProcessMsg_Start(handles_for_sel_ldr)); 514 Send(new NaClProcessMsg_Start(handles_for_sel_ldr));
515 internal_->sockets_for_sel_ldr.clear(); 515 internal_->sockets_for_sel_ldr.clear();
516 } 516 }
517 517
518 bool NaClProcessHost::OnMessageReceived(const IPC::Message& msg) { 518 bool NaClProcessHost::OnMessageReceived(const IPC::Message& msg) {
519 NOTREACHED() << "Invalid message with type = " << msg.type(); 519 NOTREACHED() << "Invalid message with type = " << msg.type();
520 return false; 520 return false;
521 } 521 }
522
523 bool NaClProcessHost::CanShutdown() {
524 return true;
525 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698