[email protected] | 6fdb60c | 2013-07-31 05:06:59 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | 08a3ef6 | 2009-09-26 01:22:10 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
dcheng | 51ace48a | 2015-12-26 22:45:17 | [diff] [blame] | 5 | #include <utility> |
[email protected] | 08a3ef6 | 2009-09-26 01:22:10 | [diff] [blame] | 6 | |
[email protected] | 08a3ef6 | 2009-09-26 01:22:10 | [diff] [blame] | 7 | #include "base/command_line.h" |
[email protected] | 6827510 | 2013-07-17 23:54:20 | [diff] [blame] | 8 | #include "base/message_loop/message_loop.h" |
[email protected] | 6c5905b7 | 2013-04-03 19:06:51 | [diff] [blame] | 9 | #include "base/power_monitor/power_monitor.h" |
[email protected] | 9dd9015 | 2013-08-02 22:09:13 | [diff] [blame] | 10 | #include "base/power_monitor/power_monitor_device_source.h" |
[email protected] | 89bf27e | 2013-06-27 18:04:56 | [diff] [blame] | 11 | #include "base/timer/hi_res_timer_manager.h" |
dcheng | 51ace48a | 2015-12-26 22:45:17 | [diff] [blame] | 12 | #include "build/build_config.h" |
[email protected] | 6fdb60c | 2013-07-31 05:06:59 | [diff] [blame] | 13 | #include "components/nacl/loader/nacl_listener.h" |
14 | #include "components/nacl/loader/nacl_main_platform_delegate.h" | ||||
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 15 | #include "content/public/common/main_function_params.h" |
rockot | 6d7be62 | 2016-06-15 18:25:19 | [diff] [blame] | 16 | #include "mojo/edk/embedder/embedder.h" |
Jay Civelli | 3ae893e | 2018-04-17 20:07:05 | [diff] [blame^] | 17 | #include "services/service_manager/sandbox/switches.h" |
[email protected] | 103607e | 2010-02-01 18:57:09 | [diff] [blame] | 18 | |
[email protected] | 103607e | 2010-02-01 18:57:09 | [diff] [blame] | 19 | // main() routine for the NaCl loader process. |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 20 | int NaClMain(const content::MainFunctionParams& parameters) { |
kkosztyo.u-szeged | b33617c | 2014-12-04 09:54:36 | [diff] [blame] | 21 | const base::CommandLine& parsed_command_line = parameters.command_line; |
[email protected] | 599e664 | 2010-01-27 18:52:13 | [diff] [blame] | 22 | |
rockot | 6d7be62 | 2016-06-15 18:25:19 | [diff] [blame] | 23 | // The Mojo EDK must be initialized before using IPC. |
24 | mojo::edk::Init(); | ||||
25 | |||||
[email protected] | 08a3ef6 | 2009-09-26 01:22:10 | [diff] [blame] | 26 | // The main thread of the plugin services IO. |
[email protected] | bb024fe | 2013-05-10 21:33:26 | [diff] [blame] | 27 | base::MessageLoopForIO main_message_loop; |
[email protected] | ce072a7 | 2010-12-31 20:02:16 | [diff] [blame] | 28 | base::PlatformThread::SetName("CrNaClMain"); |
[email protected] | 08a3ef6 | 2009-09-26 01:22:10 | [diff] [blame] | 29 | |
dcheng | 24f43a5e9 | 2016-04-22 18:29:09 | [diff] [blame] | 30 | std::unique_ptr<base::PowerMonitorSource> power_monitor_source( |
[email protected] | 9dd9015 | 2013-08-02 22:09:13 | [diff] [blame] | 31 | new base::PowerMonitorDeviceSource()); |
dcheng | 51ace48a | 2015-12-26 22:45:17 | [diff] [blame] | 32 | base::PowerMonitor power_monitor(std::move(power_monitor_source)); |
[email protected] | 89bf27e | 2013-06-27 18:04:56 | [diff] [blame] | 33 | base::HighResolutionTimerManager hi_res_timer_manager; |
[email protected] | 08a3ef6 | 2009-09-26 01:22:10 | [diff] [blame] | 34 | |
[email protected] | d33d222 | 2014-06-04 15:39:58 | [diff] [blame] | 35 | #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \ |
36 | defined(OS_ANDROID) | ||||
mlamouri | c5317ce | 2015-07-06 22:57:01 | [diff] [blame] | 37 | NaClMainPlatformDelegate platform; |
Jay Civelli | 3ae893e | 2018-04-17 20:07:05 | [diff] [blame^] | 38 | bool no_sandbox = |
39 | parsed_command_line.HasSwitch(service_manager::switches::kNoSandbox); | ||||
[email protected] | 599e664 | 2010-01-27 18:52:13 | [diff] [blame] | 40 | |
[email protected] | 4e7199b | 2013-06-21 03:57:58 | [diff] [blame] | 41 | #if defined(OS_POSIX) |
42 | // The number of cores must be obtained before the invocation of | ||||
43 | // platform.EnableSandbox(), so cannot simply be inlined below. | ||||
44 | int number_of_cores = sysconf(_SC_NPROCESSORS_ONLN); | ||||
45 | #endif | ||||
46 | |||||
[email protected] | 23acfc0 | 2010-07-15 23:02:52 | [diff] [blame] | 47 | if (!no_sandbox) { |
mlamouri | c5317ce | 2015-07-06 22:57:01 | [diff] [blame] | 48 | platform.EnableSandbox(parameters); |
[email protected] | 23acfc0 | 2010-07-15 23:02:52 | [diff] [blame] | 49 | } |
[email protected] | 913d206 | 2013-08-13 05:39:55 | [diff] [blame] | 50 | NaClListener listener; |
[email protected] | 4e7199b | 2013-06-21 03:57:58 | [diff] [blame] | 51 | #if defined(OS_POSIX) |
[email protected] | 913d206 | 2013-08-13 05:39:55 | [diff] [blame] | 52 | listener.set_number_of_cores(number_of_cores); |
[email protected] | 4e7199b | 2013-06-21 03:57:58 | [diff] [blame] | 53 | #endif |
[email protected] | 913d206 | 2013-08-13 05:39:55 | [diff] [blame] | 54 | |
55 | listener.Listen(); | ||||
[email protected] | 08a3ef6 | 2009-09-26 01:22:10 | [diff] [blame] | 56 | #else |
[email protected] | 599e664 | 2010-01-27 18:52:13 | [diff] [blame] | 57 | NOTIMPLEMENTED() << " not implemented startup, plugin startup dialog etc."; |
[email protected] | 08a3ef6 | 2009-09-26 01:22:10 | [diff] [blame] | 58 | #endif |
[email protected] | 08a3ef6 | 2009-09-26 01:22:10 | [diff] [blame] | 59 | return 0; |
60 | } |