diff options
author | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-04 03:39:22 +0000 |
---|---|---|
committer | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-04 03:39:22 +0000 |
commit | 4512f3acc3dab73e7fdcb8371d13f7bf46d8484b (patch) | |
tree | b422b0d7be3ae72a1b53ce5822054a440bcc668f /chrome/app/chrome_exe_main.cc | |
parent | 3002a3d7dd1cf42d481c8fd626d872e93677a789 (diff) | |
download | chromium_src-4512f3acc3dab73e7fdcb8371d13f7bf46d8484b.zip chromium_src-4512f3acc3dab73e7fdcb8371d13f7bf46d8484b.tar.gz chromium_src-4512f3acc3dab73e7fdcb8371d13f7bf46d8484b.tar.bz2 |
Rewrite of chrome.exe startup code
A lot of cruft and repeated code has deposited over the years on chrome's initialization code.
This CL makes it all much more clear and straightforward. There is no fundamental change of
behavior except the order of certain things is different but it should not alter the observed
operation.
- chrome's and chromium load is fundamentally the same but most of the code was repeated
- chrome's way to load the dll was incorrect: using a relative path with LOAD_WITH_ALTERED_SEARCH_PATH
- Use of SearchPath() was dangerous and not needed
- removed google_update_client.cc and .h
- removed bunch of #ifdefs
TEST=all convered by UI tests already except [1]
BUG=none
[1] The only thing I don't see convered by test is the restart dialog ('woa! chrome crashed').
Review URL: http://codereview.chromium.org/345036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30934 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/app/chrome_exe_main.cc')
-rw-r--r-- | chrome/app/chrome_exe_main.cc | 95 |
1 files changed, 19 insertions, 76 deletions
diff --git a/chrome/app/chrome_exe_main.cc b/chrome/app/chrome_exe_main.cc index 33fc669..c0d1769 100644 --- a/chrome/app/chrome_exe_main.cc +++ b/chrome/app/chrome_exe_main.cc @@ -6,103 +6,46 @@ #include <tchar.h> #include "base/at_exit.h" -#include "base/base_switches.h" #include "base/command_line.h" -#include "base/debug_on_start.h" -#include "base/process_util.h" #include "base/win_util.h" #include "chrome/app/breakpad_win.h" #include "chrome/app/client_util.h" -#include "chrome/app/google_update_client.h" -#include "chrome/common/chrome_switches.h" #include "chrome/common/result_codes.h" -#include "sandbox/src/sandbox_factory.h" #include "sandbox/src/dep.h" +#include "sandbox/src/sandbox_factory.h" -// Generataed header containing the Google Update appid. -#include "appid.h" -int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev_instance, - wchar_t* command_line, int) { +int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) { base::EnableTerminationOnHeapCorruption(); // The exit manager is in charge of calling the dtors of singletons. base::AtExitManager exit_manager; - win_util::WinVersion win_version = win_util::GetWinVersion(); - if (win_version < win_util::WINVERSION_VISTA) { - // On Vista, this is unnecessary since it is controlled through the - // /NXCOMPAT linker flag. - // Enforces strong DEP support. - sandbox::SetCurrentProcessDEP(sandbox::DEP_ENABLED); + bool exit_now = true; + // We restarted because of a previous crash. Ask user if we should relaunch. + if (ShowRestartDialogIfCrashed(&exit_now)) { + if (exit_now) + return ResultCodes::NORMAL_EXIT; } - // Get the interface pointer to the BrokerServices or TargetServices, - // depending who we are. + // Initialize the commandline singleton from the environment. + CommandLine::Init(0, NULL); + + // 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(); - CommandLine::Init(0, NULL); - - const wchar_t* dll_name = L"chrome.dll"; - std::wstring dll_full_path; - std::wstring versionned_path; - -#if defined(GOOGLE_CHROME_BUILD) - google_update::GoogleUpdateClient client; - - // TODO(erikkay): verify client.Init() return value for official builds - client.Init(google_update::kChromeGuid, dll_name); - dll_full_path = client.GetDLLFullPath(); - versionned_path = client.GetDLLPath(); -#else - std::wstring exe_path = client_util::GetExecutablePath(); - wchar_t *version; - if (client_util::GetChromiumVersion(exe_path.c_str(), L"Software\\Chromium", - &version)) { - versionned_path = exe_path; - versionned_path.append(version); - delete[] version; - } - - dll_full_path = client_util::GetDLLPath(dll_name, versionned_path); -#endif - - // If the versionned path exists, we set the current directory to this path. - if (client_util::FileExists(versionned_path)) { - ::SetCurrentDirectory(versionned_path.c_str()); - } - - HINSTANCE dll_handle = ::LoadLibraryEx(dll_name, NULL, - LOAD_WITH_ALTERED_SEARCH_PATH); - - // Initialize the crash reporter. - InitCrashReporterWithDllPath(dll_full_path); - - bool exit_now = true; - if (ShowRestartDialogIfCrashed(&exit_now)) { - // We have restarted because of a previous crash. The user might - // decide that he does not want to continue. - if (exit_now) - return ResultCodes::NORMAL_EXIT; + if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) { + // Enforces strong DEP support. Vista uses the NXCOMPAT flag in the exe. + sandbox::SetCurrentProcessDEP(sandbox::DEP_ENABLED); } -#if defined(GOOGLE_CHROME_BUILD) - int ret = 0; - if (client.Launch(instance, &sandbox_info, command_line, "ChromeMain", - &ret)) { - return ret; - } -#else - if (NULL != dll_handle) { - client_util::DLL_MAIN entry = reinterpret_cast<client_util::DLL_MAIN>( - ::GetProcAddress(dll_handle, "ChromeMain")); - if (NULL != entry) - return (entry)(instance, &sandbox_info, command_line); - } -#endif + // Load and launch the chrome dll. *Everything* happens inside. + MainDllLoader* loader = MakeMainDllLoader(); + int rc = loader->Launch(instance, &sandbox_info); + delete loader; - return ResultCodes::GOOGLE_UPDATE_LAUNCH_FAILED; + return rc; } |