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

Side by Side Diff: components/nacl/browser/nacl_process_host.cc

Issue 75463005: Move more files from chrome/browser/nacl_host/ to components/nacl/browser/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_process_host.h" 5 #include "components/nacl/browser/nacl_process_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/base_switches.h" 11 #include "base/base_switches.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/path_service.h" 17 #include "base/path_service.h"
18 #include "base/process/launch.h" 18 #include "base/process/launch.h"
19 #include "base/process/process_iterator.h" 19 #include "base/process/process_iterator.h"
20 #include "base/rand_util.h" 20 #include "base/rand_util.h"
21 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/string_split.h" 22 #include "base/strings/string_split.h"
23 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
24 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
25 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
26 #include "base/win/windows_version.h" 26 #include "base/win/windows_version.h"
27 #include "build/build_config.h" 27 #include "build/build_config.h"
28 #include "chrome/browser/nacl_host/nacl_host_message_filter.h"
29 #include "chrome/common/chrome_switches.h"
30 #include "components/nacl/browser/nacl_browser.h" 28 #include "components/nacl/browser/nacl_browser.h"
29 #include "components/nacl/browser/nacl_host_message_filter.h"
31 #include "components/nacl/common/nacl_cmd_line.h" 30 #include "components/nacl/common/nacl_cmd_line.h"
32 #include "components/nacl/common/nacl_host_messages.h" 31 #include "components/nacl/common/nacl_host_messages.h"
33 #include "components/nacl/common/nacl_messages.h" 32 #include "components/nacl/common/nacl_messages.h"
34 #include "components/nacl/common/nacl_process_type.h" 33 #include "components/nacl/common/nacl_process_type.h"
35 #include "components/nacl/common/nacl_switches.h" 34 #include "components/nacl/common/nacl_switches.h"
36 #include "content/public/browser/browser_child_process_host.h" 35 #include "content/public/browser/browser_child_process_host.h"
37 #include "content/public/browser/browser_ppapi_host.h" 36 #include "content/public/browser/browser_ppapi_host.h"
38 #include "content/public/browser/child_process_data.h" 37 #include "content/public/browser/child_process_data.h"
39 #include "content/public/common/child_process_host.h" 38 #include "content/public/common/child_process_host.h"
40 #include "content/public/common/content_switches.h" 39 #include "content/public/common/content_switches.h"
(...skipping 10 matching lines...) Expand all
51 50
52 #if defined(OS_POSIX) 51 #if defined(OS_POSIX)
53 #include <fcntl.h> 52 #include <fcntl.h>
54 53
55 #include "ipc/ipc_channel_posix.h" 54 #include "ipc/ipc_channel_posix.h"
56 #elif defined(OS_WIN) 55 #elif defined(OS_WIN)
57 #include <windows.h> 56 #include <windows.h>
58 57
59 #include "base/threading/thread.h" 58 #include "base/threading/thread.h"
60 #include "base/win/scoped_handle.h" 59 #include "base/win/scoped_handle.h"
61 #include "chrome/browser/nacl_host/nacl_broker_service_win.h" 60 #include "components/nacl/browser/nacl_broker_service_win.h"
62 #include "components/nacl/common/nacl_debug_exception_handler_win.h" 61 #include "components/nacl/common/nacl_debug_exception_handler_win.h"
63 #include "content/public/common/sandbox_init.h" 62 #include "content/public/common/sandbox_init.h"
64 #include "content/public/common/sandboxed_process_launcher_delegate.h" 63 #include "content/public/common/sandboxed_process_launcher_delegate.h"
65 #endif 64 #endif
66 65
67 using content::BrowserThread; 66 using content::BrowserThread;
68 using content::ChildProcessData; 67 using content::ChildProcessData;
69 using content::ChildProcessHost; 68 using content::ChildProcessHost;
70 using ppapi::proxy::SerializedHandle; 69 using ppapi::proxy::SerializedHandle;
71 70
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 ppapi::PpapiPermissions GetNaClPermissions(uint32 permission_bits) { 192 ppapi::PpapiPermissions GetNaClPermissions(uint32 permission_bits) {
194 // Only allow NaCl plugins to request certain permissions. We don't want 193 // Only allow NaCl plugins to request certain permissions. We don't want
195 // a compromised renderer to be able to start a nacl plugin with e.g. Flash 194 // a compromised renderer to be able to start a nacl plugin with e.g. Flash
196 // permissions which may expand the surface area of the sandbox. 195 // permissions which may expand the surface area of the sandbox.
197 uint32 masked_bits = permission_bits & ppapi::PERMISSION_DEV; 196 uint32 masked_bits = permission_bits & ppapi::PERMISSION_DEV;
198 return ppapi::PpapiPermissions::GetForCommandLine(masked_bits); 197 return ppapi::PpapiPermissions::GetForCommandLine(masked_bits);
199 } 198 }
200 199
201 } // namespace 200 } // namespace
202 201
202 namespace nacl {
203
203 struct NaClProcessHost::NaClInternal { 204 struct NaClProcessHost::NaClInternal {
204 NaClHandle socket_for_renderer; 205 NaClHandle socket_for_renderer;
205 NaClHandle socket_for_sel_ldr; 206 NaClHandle socket_for_sel_ldr;
206 207
207 NaClInternal() 208 NaClInternal()
208 : socket_for_renderer(NACL_INVALID_HANDLE), 209 : socket_for_renderer(NACL_INVALID_HANDLE),
209 socket_for_sel_ldr(NACL_INVALID_HANDLE) { } 210 socket_for_sel_ldr(NACL_INVALID_HANDLE) { }
210 }; 211 };
211 212
212 // ----------------------------------------------------------------------------- 213 // -----------------------------------------------------------------------------
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 } 291 }
291 292
292 if (reply_msg_) { 293 if (reply_msg_) {
293 // The process failed to launch for some reason. 294 // The process failed to launch for some reason.
294 // Don't keep the renderer hanging. 295 // Don't keep the renderer hanging.
295 reply_msg_->set_reply_error(); 296 reply_msg_->set_reply_error();
296 nacl_host_message_filter_->Send(reply_msg_); 297 nacl_host_message_filter_->Send(reply_msg_);
297 } 298 }
298 #if defined(OS_WIN) 299 #if defined(OS_WIN)
299 if (process_launched_by_broker_) { 300 if (process_launched_by_broker_) {
300 NaClBrokerService::GetInstance()->OnLoaderDied(); 301 nacl::NaClBrokerService::GetInstance()->OnLoaderDied();
Mark Seaborn 2013/11/21 23:47:34 Same here, and below...
301 } 302 }
302 #endif 303 #endif
303 } 304 }
304 305
305 void NaClProcessHost::OnProcessCrashed(int exit_status) { 306 void NaClProcessHost::OnProcessCrashed(int exit_status) {
306 if (enable_crash_throttling_ && 307 if (enable_crash_throttling_ &&
307 !CommandLine::ForCurrentProcess()->HasSwitch( 308 !CommandLine::ForCurrentProcess()->HasSwitch(
308 switches::kDisablePnaclCrashThrottling)) { 309 switches::kDisablePnaclCrashThrottling)) {
309 nacl::NaClBrowser::GetInstance()->OnProcessCrashed(); 310 nacl::NaClBrowser::GetInstance()->OnProcessCrashed();
310 } 311 }
(...skipping 16 matching lines...) Expand all
327 "NaCl.nacl-gdb-script", 328 "NaCl.nacl-gdb-script",
328 !cmd->GetSwitchValuePath(switches::kNaClGdbScript).empty()); 329 !cmd->GetSwitchValuePath(switches::kNaClGdbScript).empty());
329 UMA_HISTOGRAM_BOOLEAN( 330 UMA_HISTOGRAM_BOOLEAN(
330 "NaCl.enable-nacl-debug", 331 "NaCl.enable-nacl-debug",
331 cmd->HasSwitch(switches::kEnableNaClDebug)); 332 cmd->HasSwitch(switches::kEnableNaClDebug));
332 nacl::NaClBrowser::GetDelegate()->SetDebugPatterns( 333 nacl::NaClBrowser::GetDelegate()->SetDebugPatterns(
333 cmd->GetSwitchValueASCII(switches::kNaClDebugMask)); 334 cmd->GetSwitchValueASCII(switches::kNaClDebugMask));
334 } 335 }
335 336
336 void NaClProcessHost::Launch( 337 void NaClProcessHost::Launch(
337 NaClHostMessageFilter* nacl_host_message_filter, 338 nacl::NaClHostMessageFilter* nacl_host_message_filter,
338 IPC::Message* reply_msg, 339 IPC::Message* reply_msg,
339 const base::FilePath& manifest_path) { 340 const base::FilePath& manifest_path) {
340 nacl_host_message_filter_ = nacl_host_message_filter; 341 nacl_host_message_filter_ = nacl_host_message_filter;
341 reply_msg_ = reply_msg; 342 reply_msg_ = reply_msg;
342 manifest_path_ = manifest_path; 343 manifest_path_ = manifest_path;
343 344
344 // Do not launch the requested NaCl module if NaCl is marked "unstable" due 345 // Do not launch the requested NaCl module if NaCl is marked "unstable" due
345 // to too many crashes within a given time period. 346 // to too many crashes within a given time period.
346 if (enable_crash_throttling_ && 347 if (enable_crash_throttling_ &&
347 !CommandLine::ForCurrentProcess()->HasSwitch( 348 !CommandLine::ForCurrentProcess()->HasSwitch(
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); 528 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id);
528 if (nacl::NaClBrowser::GetDelegate()->DialogsAreSuppressed()) 529 if (nacl::NaClBrowser::GetDelegate()->DialogsAreSuppressed())
529 cmd_line->AppendSwitch(switches::kNoErrorDialogs); 530 cmd_line->AppendSwitch(switches::kNoErrorDialogs);
530 531
531 if (!nacl_loader_prefix.empty()) 532 if (!nacl_loader_prefix.empty())
532 cmd_line->PrependWrapper(nacl_loader_prefix); 533 cmd_line->PrependWrapper(nacl_loader_prefix);
533 534
534 // On Windows we might need to start the broker process to launch a new loader 535 // On Windows we might need to start the broker process to launch a new loader
535 #if defined(OS_WIN) 536 #if defined(OS_WIN)
536 if (RunningOnWOW64()) { 537 if (RunningOnWOW64()) {
537 if (!NaClBrokerService::GetInstance()->LaunchLoader( 538 if (!nacl::NaClBrokerService::GetInstance()->LaunchLoader(
538 weak_factory_.GetWeakPtr(), channel_id)) { 539 weak_factory_.GetWeakPtr(), channel_id)) {
539 SendErrorToRenderer("broker service did not launch process"); 540 SendErrorToRenderer("broker service did not launch process");
540 return false; 541 return false;
541 } 542 }
542 } else { 543 } else {
543 process_->Launch(new NaClSandboxedProcessLauncherDelegate, 544 process_->Launch(new NaClSandboxedProcessLauncherDelegate,
544 cmd_line.release()); 545 cmd_line.release());
545 } 546 }
546 #elif defined(OS_POSIX) 547 #elif defined(OS_POSIX)
547 process_->Launch(nacl_loader_prefix.empty(), // use_zygote 548 process_->Launch(nacl_loader_prefix.empty(), // use_zygote
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 LOG(ERROR) << "Failed to get process handle"; 1003 LOG(ERROR) << "Failed to get process handle";
1003 return false; 1004 return false;
1004 } 1005 }
1005 1006
1006 attach_debug_exception_handler_reply_msg_.reset(reply_msg); 1007 attach_debug_exception_handler_reply_msg_.reset(reply_msg);
1007 // If the NaCl loader is 64-bit, the process running its debug 1008 // If the NaCl loader is 64-bit, the process running its debug
1008 // exception handler must be 64-bit too, so we use the 64-bit NaCl 1009 // exception handler must be 64-bit too, so we use the 64-bit NaCl
1009 // broker process for this. Otherwise, on a 32-bit system, we use 1010 // broker process for this. Otherwise, on a 32-bit system, we use
1010 // the 32-bit browser process to run the debug exception handler. 1011 // the 32-bit browser process to run the debug exception handler.
1011 if (RunningOnWOW64()) { 1012 if (RunningOnWOW64()) {
1012 return NaClBrokerService::GetInstance()->LaunchDebugExceptionHandler( 1013 return nacl::NaClBrokerService::GetInstance()->LaunchDebugExceptionHandler(
1013 weak_factory_.GetWeakPtr(), nacl_pid, process_handle, info); 1014 weak_factory_.GetWeakPtr(), nacl_pid, process_handle, info);
1014 } else { 1015 } else {
1015 NaClStartDebugExceptionHandlerThread( 1016 NaClStartDebugExceptionHandlerThread(
1016 process_handle.Take(), info, 1017 process_handle.Take(), info,
1017 base::MessageLoopProxy::current(), 1018 base::MessageLoopProxy::current(),
1018 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, 1019 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker,
1019 weak_factory_.GetWeakPtr())); 1020 weak_factory_.GetWeakPtr()));
1020 return true; 1021 return true;
1021 } 1022 }
1022 } 1023 }
1023 #endif 1024 #endif
1025
1026 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698