summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-01 15:51:53 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-01 15:51:53 +0000
commitd85d670009ad28c375fc0dbcd8f333ba00ef7327 (patch)
tree6c6e8ef196182a36ab8b1a0f547874e5ee4c049e /chrome
parente601bd195eea2dfb27dc590d6f122f5715087769 (diff)
downloadchromium_src-d85d670009ad28c375fc0dbcd8f333ba00ef7327.zip
chromium_src-d85d670009ad28c375fc0dbcd8f333ba00ef7327.tar.gz
chromium_src-d85d670009ad28c375fc0dbcd8f333ba00ef7327.tar.bz2
Start moving ChromeMain code to content so it can be reused by other embedders. I've only moved a little bit of the code for now, and will do the rest in followup changes.
BUG=90445 Review URL: http://codereview.chromium.org/7817015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99193 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/app/chrome_exe_main_win.cc12
-rw-r--r--chrome/app/chrome_main.cc122
-rw-r--r--chrome/app/chrome_main.h9
-rw-r--r--chrome/app/chrome_main_posix.cc76
-rw-r--r--chrome/app/chrome_main_win.cc47
-rw-r--r--chrome/app/client_util.cc4
-rw-r--r--chrome/chrome.gyp1
-rw-r--r--chrome/chrome_dll.gypi1
-rw-r--r--chrome/chrome_exe.gypi5
9 files changed, 73 insertions, 204 deletions
diff --git a/chrome/app/chrome_exe_main_win.cc b/chrome/app/chrome_exe_main_win.cc
index ccb32fb..659ce16 100644
--- a/chrome/app/chrome_exe_main_win.cc
+++ b/chrome/app/chrome_exe_main_win.cc
@@ -7,11 +7,10 @@
#include "base/at_exit.h"
#include "base/command_line.h"
-#include "base/win/windows_version.h"
#include "chrome/app/breakpad_win.h"
#include "chrome/app/client_util.h"
+#include "content/app/sandbox_helper_win.h"
#include "content/common/result_codes.h"
-#include "sandbox/src/dep.h"
#include "sandbox/src/sandbox_factory.h"
int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) {
@@ -24,14 +23,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) {
// Initialize the sandbox services.
sandbox::SandboxInterfaceInfo sandbox_info = {0};
- sandbox_info.broker_services = sandbox::SandboxFactory::GetBrokerServices();
- if (!sandbox_info.broker_services)
- sandbox_info.target_services = sandbox::SandboxFactory::GetTargetServices();
-
- if (base::win::GetVersion() < base::win::VERSION_VISTA) {
- // Enforces strong DEP support. Vista uses the NXCOMPAT flag in the exe.
- sandbox::SetCurrentProcessDEP(sandbox::DEP_ENABLED);
- }
+ content::InitializeSandboxInfo(&sandbox_info);
// The exit manager is in charge of calling the dtors of singletons.
base::AtExitManager exit_manager;
diff --git a/chrome/app/chrome_main.cc b/chrome/app/chrome_main.cc
index afe6ad4..dd49732 100644
--- a/chrome/app/chrome_main.cc
+++ b/chrome/app/chrome_main.cc
@@ -4,12 +4,10 @@
#include "chrome/app/chrome_main.h"
-#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/debug/debugger.h"
#include "base/i18n/icu_util.h"
#include "base/lazy_instance.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/message_loop.h"
#include "base/metrics/stats_counters.h"
#include "base/metrics/stats_table.h"
@@ -34,6 +32,8 @@
#include "chrome/common/url_constants.h"
#include "chrome/renderer/chrome_content_renderer_client.h"
#include "chrome/utility/chrome_content_utility_client.h"
+#include "content/app/content_main.h"
+#include "content/app/content_main_delegate.h"
#include "content/browser/renderer_host/render_process_host.h"
#include "content/common/content_client.h"
#include "content/common/content_counters.h"
@@ -136,8 +136,7 @@ extern int ServiceProcessMain(const MainFunctionParams&);
// We use extern C for the prototype DLLEXPORT to avoid C++ name mangling.
extern "C" {
DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance,
- sandbox::SandboxInterfaceInfo* sandbox_info,
- TCHAR* command_line_unused);
+ sandbox::SandboxInterfaceInfo* sandbox_info);
}
#elif defined(OS_POSIX)
extern "C" {
@@ -574,75 +573,81 @@ int RunNamedProcessTypeMain(const std::string& process_type,
return 1;
}
-} // namespace
-
-#if defined(OS_WIN)
-DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance,
- sandbox::SandboxInterfaceInfo* sandbox_info,
- TCHAR* command_line_unused) {
- // argc/argv are ignored on Windows; see command_line.h for details.
- int argc = 0;
- char** argv = NULL;
-#elif defined(OS_POSIX)
-int ChromeMain(int argc, char** argv) {
- // There is no HINSTANCE on non-Windows.
- void* instance = NULL;
-#endif
-
- base::EnableTerminationOnHeapCorruption();
- base::EnableTerminationOnOutOfMemory();
-
- // LowLevelInit performs startup initialization before we
- // e.g. allocate any memory. It must be the first call on startup.
- chrome_main::LowLevelInit(instance);
-
- // The exit manager is in charge of calling the dtors of singleton objects.
- base::AtExitManager exit_manager;
-
- // We need this pool for all the objects created before we get to the
- // event loop, but we don't want to leave them hanging around until the
- // app quits. Each "main" needs to flush this pool right before it goes into
- // its main event loop to get rid of the cruft.
- base::mac::ScopedNSAutoreleasePool autorelease_pool;
-
+class ChromeMainDelegate : public content::ContentMainDelegate {
+ public:
+ virtual bool BasicStartupComplete(
+ int* exit_code,
+ base::mac::ScopedNSAutoreleasePool* autorelease_pool) OVERRIDE {
+ autorelease_pool_ = autorelease_pool;
#if defined(OS_CHROMEOS)
- chromeos::BootTimesLoader::Get()->SaveChromeMainStats();
+ chromeos::BootTimesLoader::Get()->SaveChromeMainStats();
#endif
#if defined(OS_MACOSX)
- chrome_main::SetUpBundleOverrides();
- chrome::common::mac::EnableCFBundleBlocker();
+ chrome_main::SetUpBundleOverrides();
+ chrome::common::mac::EnableCFBundleBlocker();
#endif
- CommandLine::Init(argc, argv);
- const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+ Profiling::ProcessStarted();
- Profiling::ProcessStarted();
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+ std::string process_type =
+ command_line.GetSwitchValueASCII(switches::kProcessType);
#if defined(OS_POSIX)
- if (HandleVersionSwitches(command_line))
- return 0; // Got a --version switch; exit with a success error code.
+ if (HandleVersionSwitches(command_line)) {
+ *exit_code = 0;
+ return true; // Got a --version switch; exit with a success error code.
+ }
#if !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
- // This will directly exit if the user asked for help.
- HandleHelpSwitches(command_line);
+ // This will directly exit if the user asked for help.
+ HandleHelpSwitches(command_line);
#endif
#endif // OS_POSIX
- std::string process_type =
- command_line.GetSwitchValueASCII(switches::kProcessType);
+ // If we are in diagnostics mode this is the end of the line. After the
+ // diagnostics are run the process will invariably exit.
+ if (command_line.HasSwitch(switches::kDiagnostics)) {
+ *exit_code = DiagnosticsMain(command_line);
+ return true;
+ }
+
+#if defined(OS_WIN)
+ // Must do this before any other usage of command line!
+ if (HasDeprecatedArguments(command_line.GetCommandLineString())) {
+ *exit_code = 1;
+ return true;
+ }
+#endif
- // If we are in diagnostics mode this is the end of the line. After the
- // diagnostics are run the process will invariably exit.
- if (command_line.HasSwitch(switches::kDiagnostics)) {
- return DiagnosticsMain(command_line);
+ return false;
}
+ base::mac::ScopedNSAutoreleasePool* autorelease_pool() {
+ return autorelease_pool_;
+ }
+
+ private:
+ base::mac::ScopedNSAutoreleasePool* autorelease_pool_;
+};
+
+} // namespace
+
#if defined(OS_WIN)
- // Must do this before any other usage of command line!
- if (HasDeprecatedArguments(command_line.GetCommandLineString()))
- return 1;
+DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance,
+ sandbox::SandboxInterfaceInfo* sandbox_info) {
+ ChromeMainDelegate chrome_main_delegate;
+ content::ContentMain(instance, sandbox_info, &chrome_main_delegate);
+#elif defined(OS_POSIX)
+int ChromeMain(int argc, char** argv) {
+ ChromeMainDelegate chrome_main_delegate;
+ content::ContentMain(argc, argv, &chrome_main_delegate);
#endif
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+ std::string process_type =
+ command_line.GetSwitchValueASCII(switches::kProcessType);
+
#if defined(OS_MACOSX)
// We need to allocate the IO Ports before the Sandbox is initialized or
// the first instance of SystemMonitor is created.
@@ -927,7 +932,7 @@ int ChromeMain(int argc, char** argv) {
startup_timer.Stop(); // End of Startup Time Measurement.
MainFunctionParams main_params(command_line, sandbox_wrapper,
- &autorelease_pool);
+ chrome_main_delegate.autorelease_pool());
// Note: If you are adding a new process type below, be sure to adjust the
// AdjustLinuxOOMScore function too.
@@ -946,7 +951,12 @@ int ChromeMain(int argc, char** argv) {
logging::CleanupChromeLogging();
- chrome_main::LowLevelShutdown();
+#if defined(OS_MACOSX) && defined(GOOGLE_CHROME_BUILD)
+ // TODO(mark): See the TODO(mark) at InitCrashReporter.
+ DestructCrashReporter();
+#endif // OS_MACOSX && GOOGLE_CHROME_BUILD
+
+ content::ContentMainEnd();
return exit_code;
}
diff --git a/chrome/app/chrome_main.h b/chrome/app/chrome_main.h
index 518cb7a..4a95c26 100644
--- a/chrome/app/chrome_main.h
+++ b/chrome/app/chrome_main.h
@@ -18,15 +18,6 @@ class FilePath;
namespace chrome_main {
-// Perform low-level initialization that occurs before we set up any
-// objects or even consider the command line; for example, make us
-// abort if we run out of memory.
-// On Windows, hinstance is the instance parameter to ChromeMain (WinMain).
-void LowLevelInit(void* hinstance);
-
-// Perform last-second shutdown work. Partner of LowLevelInit().
-void LowLevelShutdown();
-
// Checks if the UserDataDir policy has been set and returns its value in the
// |user_data_dir| parameter. If no policy is set the parameter is not changed.
void CheckUserDataDirPolicy(FilePath* user_data_dir);
diff --git a/chrome/app/chrome_main_posix.cc b/chrome/app/chrome_main_posix.cc
index 8a6262d..74b08d1 100644
--- a/chrome/app/chrome_main_posix.cc
+++ b/chrome/app/chrome_main_posix.cc
@@ -4,84 +4,8 @@
#include "chrome/app/chrome_main.h"
-#include <signal.h>
-
-#include "base/global_descriptors_posix.h"
-#include "base/logging.h"
-#include "content/common/chrome_descriptors.h"
-
-#if defined(OS_MACOSX)
-#include "chrome/app/breakpad_mac.h"
-#endif
-
-#if !defined(OS_MACOSX) && defined(USE_TCMALLOC)
-extern "C" {
-int tc_set_new_mode(int mode);
-}
-#endif
-
-namespace {
-
-// Setup signal-handling state: resanitize most signals, ignore SIGPIPE.
-void SetupSignalHandlers() {
- // Sanitise our signal handling state. Signals that were ignored by our
- // parent will also be ignored by us. We also inherit our parent's sigmask.
- sigset_t empty_signal_set;
- CHECK(0 == sigemptyset(&empty_signal_set));
- CHECK(0 == sigprocmask(SIG_SETMASK, &empty_signal_set, NULL));
-
- struct sigaction sigact;
- memset(&sigact, 0, sizeof(sigact));
- sigact.sa_handler = SIG_DFL;
- static const int signals_to_reset[] =
- {SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGSEGV,
- SIGALRM, SIGTERM, SIGCHLD, SIGBUS, SIGTRAP}; // SIGPIPE is set below.
- for (unsigned i = 0; i < arraysize(signals_to_reset); i++) {
- CHECK(0 == sigaction(signals_to_reset[i], &sigact, NULL));
- }
-
- // Always ignore SIGPIPE. We check the return value of write().
- CHECK(signal(SIGPIPE, SIG_IGN) != SIG_ERR);
-}
-
-} // anonymous namespace
-
namespace chrome_main {
-void LowLevelInit(void* instance) {
- // NOTE(willchan): One might ask why this call is done here rather than in
- // process_util_linux.cc with the definition of
- // EnableTerminationOnOutOfMemory(). That's because base shouldn't have a
- // dependency on TCMalloc. Really, we ought to have our allocator shim code
- // implement this EnableTerminationOnOutOfMemory() function. Whateverz. This
- // works for now.
-#if !defined(OS_MACOSX) && defined(USE_TCMALLOC)
- // For tcmalloc, we need to tell it to behave like new.
- tc_set_new_mode(1);
-#endif
-
- // Set C library locale to make sure CommandLine can parse argument values
- // in correct encoding.
- setlocale(LC_ALL, "");
-
- SetupSignalHandlers();
-
- base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance();
- g_fds->Set(kPrimaryIPCChannel,
- kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor);
-#if defined(OS_LINUX)
- g_fds->Set(kCrashDumpSignal,
- kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor);
-#endif
-}
-
-void LowLevelShutdown() {
-#if defined(OS_MACOSX) && defined(GOOGLE_CHROME_BUILD)
- // TODO(mark): See the TODO(mark) at InitCrashReporter.
- DestructCrashReporter();
-#endif // OS_MACOSX && GOOGLE_CHROME_BUILD
-}
-
#if !defined(OS_MACOSX)
// This policy is not implemented for Linux and ChromeOS. The win and mac ver-
// sions are implemented in the platform specific version of chrome_main.cc e.g.
diff --git a/chrome/app/chrome_main_win.cc b/chrome/app/chrome_main_win.cc
index 5ff3983..be4c205 100644
--- a/chrome/app/chrome_main_win.cc
+++ b/chrome/app/chrome_main_win.cc
@@ -4,12 +4,6 @@
#include "chrome/app/chrome_main.h"
-#include <atlbase.h>
-#include <atlapp.h>
-#include <malloc.h>
-#include <new.h>
-#include <shlobj.h>
-
#include "base/command_line.h"
#include "base/file_path.h"
#include "base/logging.h"
@@ -22,33 +16,6 @@
namespace {
-CAppModule _Module;
-
-#pragma optimize("", off)
-// Handlers for invalid parameter and pure call. They generate a breakpoint to
-// tell breakpad that it needs to dump the process.
-void InvalidParameter(const wchar_t* expression, const wchar_t* function,
- const wchar_t* file, unsigned int line,
- uintptr_t reserved) {
- __debugbreak();
- _exit(1);
-}
-
-void PureCall() {
- __debugbreak();
- _exit(1);
-}
-#pragma optimize("", on)
-
-// Register the invalid param handler and pure call handler to be able to
-// notify breakpad when it happens.
-void RegisterInvalidParamHandler() {
- _set_invalid_parameter_handler(InvalidParameter);
- _set_purecall_handler(PureCall);
- // Also enable the new handler for malloc() based failures.
- _set_new_mode(1);
-}
-
// Checks if the registry key exists in the given hive and expands any
// variables in the string.
bool LoadUserDataDirPolicyFromRegistry(HKEY hive,
@@ -68,20 +35,6 @@ bool LoadUserDataDirPolicyFromRegistry(HKEY hive,
namespace chrome_main {
-void LowLevelInit(void* instance) {
- RegisterInvalidParamHandler();
-
- _Module.Init(NULL, static_cast<HINSTANCE>(instance));
-}
-
-void LowLevelShutdown() {
-#ifdef _CRTDBG_MAP_ALLOC
- _CrtDumpMemoryLeaks();
-#endif // _CRTDBG_MAP_ALLOC
-
- _Module.Term();
-}
-
void CheckUserDataDirPolicy(FilePath* user_data_dir) {
DCHECK(user_data_dir);
// We are running as Chrome Frame if we were invoked with user-data-dir,
diff --git a/chrome/app/client_util.cc b/chrome/app/client_util.cc
index 07021e2..a6bf84e 100644
--- a/chrome/app/client_util.cc
+++ b/chrome/app/client_util.cc
@@ -31,7 +31,7 @@
namespace {
// The entry point signature of chrome.dll.
-typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*, wchar_t*);
+typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*);
typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)();
@@ -363,7 +363,7 @@ int MainDllLoader::Launch(HINSTANCE instance,
if (!entry_point)
return chrome::RESULT_CODE_BAD_PROCESS_TYPE;
- int rc = entry_point(instance, sbox_info, ::GetCommandLineW());
+ int rc = entry_point(instance, sbox_info);
return OnBeforeExit(rc, file);
}
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 13b7862..523db12 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -29,6 +29,7 @@
'syncapi_core',
'utility',
'service',
+ '../content/content.gyp:content_app',
'../content/content.gyp:content_gpu',
'../content/content.gyp:content_ppapi_plugin',
'../content/content.gyp:content_worker',
diff --git a/chrome/chrome_dll.gypi b/chrome/chrome_dll.gypi
index 5c7c964..eb8b8bd 100644
--- a/chrome/chrome_dll.gypi
+++ b/chrome/chrome_dll.gypi
@@ -716,6 +716,7 @@
# to avoid making common compile on 64 bit on Windows.
'../chrome/common/chrome_content_client.cc',
'../chrome/common/chrome_content_plugin_client.cc',
+ '../content/app/content_main.cc',
'../content/common/child_process.cc',
'../content/common/child_thread.cc',
'../content/common/content_client.cc',
diff --git a/chrome/chrome_exe.gypi b/chrome/chrome_exe.gypi
index a38ba8c..099e9d9 100644
--- a/chrome/chrome_exe.gypi
+++ b/chrome/chrome_exe.gypi
@@ -24,11 +24,8 @@
'app/hard_error_handler_win.cc',
'app/hard_error_handler_win.h',
'app/scoped_ole_initializer.h',
- # TODO(bradnelson): once automatic generation of 64 bit targets on
- # Windows is ready, take this out and add a dependency on
- # content_common.gypi.
+ '../content/app/sandbox_helper_win.cc',
'../content/common/content_switches.cc',
- '../content/common/content_switches.h',
],
'mac_bundle_resources': [
'app/app-Info.plist',