blob: 7efac59cff5c273aeeec953395ad7ca7f3faa418 [file] [log] [blame]
[email protected]f573ed6b2012-02-10 15:58:521// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
grta237cc42016-09-20 22:56:195#include <stdint.h>
[email protected]86671a32011-10-06 21:15:206
Sebastien Marchandf1349f52019-01-25 03:16:417#include "base/bind.h"
brucedawson695bdb6e2017-06-27 22:45:598#include "base/callback_helpers.h"
skyostilb354f882016-12-13 18:42:459#include "base/command_line.h"
grta237cc42016-09-20 22:56:1910#include "base/time/time.h"
mfomitchevca35d832017-02-09 22:41:2911#include "build/build_config.h"
grta237cc42016-09-20 22:56:1912#include "chrome/app/chrome_main_delegate.h"
Scott Violet6200d332018-02-23 21:29:2313#include "chrome/common/buildflags.h"
mfomitchevca35d832017-02-09 22:41:2914#include "chrome/common/chrome_switches.h"
Alexei Svitkinea40cefb2019-06-05 05:14:2215#include "chrome/common/profiler/main_thread_stack_sampling_profiler.h"
[email protected]f573ed6b2012-02-10 15:58:5216#include "content/public/app/content_main.h"
skyostilb354f882016-12-13 18:42:4517#include "content/public/common/content_switches.h"
18#include "headless/public/headless_shell.h"
19#include "ui/gfx/switches.h"
initial.commit09911bf2008-07-26 23:55:2920
dvallet42a29e02017-03-01 22:34:5021#if defined(OS_MACOSX)
22#include "chrome/app/chrome_main_mac.h"
23#endif
24
[email protected]5c9587c2008-12-09 21:20:1625#if defined(OS_WIN)
[email protected]f0e90cf92014-07-21 17:13:5826#include "base/debug/dump_without_crashing.h"
[email protected]36a2f082013-08-27 05:33:5727#include "base/win/win_util.h"
Patrick Monette0196be22019-05-10 03:33:1528#include "chrome/chrome_elf/chrome_elf_main.h"
[email protected]f0e90cf92014-07-21 17:13:5829#include "chrome/common/chrome_constants.h"
grta47e8652017-01-18 23:45:0630#include "chrome/install_static/initialize_from_primary_module.h"
grte29f8ab2016-11-15 22:26:3031#include "chrome/install_static/install_details.h"
[email protected]36a2f082013-08-27 05:33:5732
[email protected]9c50aa42008-08-01 15:54:3533#define DLLEXPORT __declspec(dllexport)
34
35// We use extern C for the prototype DLLEXPORT to avoid C++ name mangling.
36extern "C" {
37DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance,
grta237cc42016-09-20 22:56:1938 sandbox::SandboxInterfaceInfo* sandbox_info,
39 int64_t exe_entry_point_ticks);
[email protected]9c50aa42008-08-01 15:54:3540}
[email protected]5c9587c2008-12-09 21:20:1641#elif defined(OS_POSIX)
42extern "C" {
[email protected]e14a9f92009-08-05 19:26:0743__attribute__((visibility("default")))
[email protected]5629e0c2011-09-12 22:07:3644int ChromeMain(int argc, const char** argv);
[email protected]5c9587c2008-12-09 21:20:1645}
46#endif
[email protected]9c50aa42008-08-01 15:54:3547
[email protected]5c9587c2008-12-09 21:20:1648#if defined(OS_WIN)
49DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance,
grta237cc42016-09-20 22:56:1950 sandbox::SandboxInterfaceInfo* sandbox_info,
51 int64_t exe_entry_point_ticks) {
[email protected]8a820c82014-03-09 18:06:5852#elif defined(OS_POSIX)
53int ChromeMain(int argc, const char** argv) {
grta237cc42016-09-20 22:56:1954 int64_t exe_entry_point_ticks = 0;
[email protected]8a820c82014-03-09 18:06:5855#endif
scottmg255cf552014-12-04 00:25:2056
grte29f8ab2016-11-15 22:26:3057#if defined(OS_WIN)
grta47e8652017-01-18 23:45:0658 install_static::InitializeFromPrimaryModule();
grte29f8ab2016-11-15 22:26:3059#endif
60
grta237cc42016-09-20 22:56:1961 ChromeMainDelegate chrome_main_delegate(
62 base::TimeTicks::FromInternalValue(exe_entry_point_ticks));
[email protected]8a820c82014-03-09 18:06:5863 content::ContentMainParams params(&chrome_main_delegate);
64
65#if defined(OS_WIN)
brucedawson695bdb6e2017-06-27 22:45:5966 // The process should crash when going through abnormal termination, but we
67 // must be sure to reset this setting when ChromeMain returns normally.
68 auto crash_on_detach_resetter = base::ScopedClosureRunner(
69 base::Bind(&base::win::SetShouldCrashOnProcessDetach,
70 base::win::ShouldCrashOnProcessDetach()));
[email protected]36a2f082013-08-27 05:33:5771 base::win::SetShouldCrashOnProcessDetach(true);
72 base::win::SetAbortBehaviorForCrashReporting();
[email protected]8a820c82014-03-09 18:06:5873 params.instance = instance;
74 params.sandbox_info = sandbox_info;
[email protected]f0e90cf92014-07-21 17:13:5875
wfh93846272017-06-28 11:50:4776 // Pass chrome_elf's copy of DumpProcessWithoutCrash resolved via load-time
77 // dynamic linking.
78 base::debug::SetDumpWithoutCrashingFunction(&DumpProcessWithoutCrash);
grte29f8ab2016-11-15 22:26:3079
80 // Verify that chrome_elf and this module (chrome.dll and chrome_child.dll)
81 // have the same version.
82 if (install_static::InstallDetails::Get().VersionMismatch())
83 base::debug::DumpWithoutCrashing();
[email protected]8a820c82014-03-09 18:06:5884#else
85 params.argc = argc;
86 params.argv = argv;
skyd6439ec2016-02-23 23:18:2487 base::CommandLine::Init(params.argc, params.argv);
dvallet8303a912017-05-13 01:18:1188#endif // defined(OS_WIN)
89 base::CommandLine::Init(0, nullptr);
skyostilb354f882016-12-13 18:42:4590 const base::CommandLine* command_line(base::CommandLine::ForCurrentProcess());
91 ALLOW_UNUSED_LOCAL(command_line);
sadrul59e835de2016-09-22 00:59:1592
Robert Sesek81ea4502018-09-04 15:12:1893#if defined(OS_MACOSX)
94 SetUpBundleOverrides();
95#endif
96
Alexei Svitkinea40cefb2019-06-05 05:14:2297 // Start the sampling profiler as early as possible - namely, once the command
98 // line data is available. Allocated as an object on the stack to ensure that
99 // the destructor runs on shutdown, which is important to avoid the profiler
100 // thread's destruction racing with main thread destruction.
101 MainThreadStackSamplingProfiler scoped_sampling_profiler;
102
Kunihiko Sakamoto7a079602018-08-03 05:19:12103 // Chrome-specific process modes.
Peter Collingbourne381beab32018-08-02 19:42:51104#if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN)
Kunihiko Sakamoto7a079602018-08-03 05:19:12105 if (command_line->HasSwitch(switches::kHeadless)) {
dvallet8303a912017-05-13 01:18:11106 return headless::HeadlessShellMain(params);
Kunihiko Sakamoto7a079602018-08-03 05:19:12107 }
dvallet8303a912017-05-13 01:18:11108#endif // defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN)
skyostilb354f882016-12-13 18:42:45109
[email protected]8a820c82014-03-09 18:06:58110 int rv = content::ContentMain(params);
111
[email protected]8a820c82014-03-09 18:06:58112 return rv;
initial.commit09911bf2008-07-26 23:55:29113}