1 // Copyright 2013 The Chromium Authors 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 <utility> 6 7 #include "base/command_line.h" 8 #include "base/feature_list.h" 9 #include "base/message_loop/message_pump_type.h" 10 #include "base/power_monitor/power_monitor.h" 11 #include "base/power_monitor/power_monitor_source.h" 12 #include "base/task/single_thread_task_executor.h" 13 #include "base/timer/hi_res_timer_manager.h" 14 #include "build/build_config.h" 15 #include "components/nacl/loader/nacl_listener.h" 16 #include "components/nacl/loader/nacl_main_platform_delegate.h" 17 #include "components/power_monitor/make_power_monitor_device_source.h" 18 #include "content/public/common/main_function_params.h" 19 #include "mojo/core/embedder/embedder.h" 20 #include "sandbox/policy/switches.h" 21 22 // main() routine for the NaCl loader process. NaClMain(content::MainFunctionParams parameters)23int NaClMain(content::MainFunctionParams parameters) { 24 const base::CommandLine& parsed_command_line = *parameters.command_line; 25 26 // The Mojo EDK must be initialized before using IPC. 27 mojo::core::InitFeatures(); 28 mojo::core::Init(); 29 30 // The main thread of the plugin services IO. 31 base::SingleThreadTaskExecutor main_task_executor(base::MessagePumpType::IO); 32 base::PlatformThread::SetName("CrNaClMain"); 33 34 base::PowerMonitor::Initialize(MakePowerMonitorDeviceSource()); 35 base::HighResolutionTimerManager hi_res_timer_manager; 36 37 #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) 38 NaClMainPlatformDelegate platform; 39 bool no_sandbox = 40 parsed_command_line.HasSwitch(sandbox::policy::switches::kNoSandbox); 41 42 #if BUILDFLAG(IS_POSIX) 43 // The number of cores must be obtained before the invocation of 44 // platform.EnableSandbox(), so cannot simply be inlined below. 45 int number_of_cores = sysconf(_SC_NPROCESSORS_ONLN); 46 #endif 47 48 if (!no_sandbox) { 49 platform.EnableSandbox(parameters); 50 } 51 NaClListener listener; 52 #if BUILDFLAG(IS_POSIX) 53 listener.set_number_of_cores(number_of_cores); 54 #endif 55 56 listener.Listen(); 57 #else 58 NOTIMPLEMENTED() << " not implemented startup, plugin startup dialog etc."; 59 #endif 60 return 0; 61 } 62