Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: chrome/app/chrome_exe_main.cc

Issue 345036: Rewrite of chrome.exe startup code... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/app/breakpad_win.cc ('k') | chrome/app/client_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <windows.h> 5 #include <windows.h>
6 #include <tchar.h> 6 #include <tchar.h>
7 7
8 #include "base/at_exit.h" 8 #include "base/at_exit.h"
9 #include "base/base_switches.h"
10 #include "base/command_line.h" 9 #include "base/command_line.h"
11 #include "base/debug_on_start.h"
12 #include "base/process_util.h"
13 #include "base/win_util.h" 10 #include "base/win_util.h"
14 #include "chrome/app/breakpad_win.h" 11 #include "chrome/app/breakpad_win.h"
15 #include "chrome/app/client_util.h" 12 #include "chrome/app/client_util.h"
16 #include "chrome/app/google_update_client.h"
17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/result_codes.h" 13 #include "chrome/common/result_codes.h"
14 #include "sandbox/src/dep.h"
19 #include "sandbox/src/sandbox_factory.h" 15 #include "sandbox/src/sandbox_factory.h"
20 #include "sandbox/src/dep.h"
21 16
22 // Generataed header containing the Google Update appid.
23 #include "appid.h"
24 17
25 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev_instance, 18 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) {
26 wchar_t* command_line, int) {
27 base::EnableTerminationOnHeapCorruption(); 19 base::EnableTerminationOnHeapCorruption();
28 20
29 // The exit manager is in charge of calling the dtors of singletons. 21 // The exit manager is in charge of calling the dtors of singletons.
30 base::AtExitManager exit_manager; 22 base::AtExitManager exit_manager;
31 23
32 win_util::WinVersion win_version = win_util::GetWinVersion(); 24 bool exit_now = true;
33 if (win_version < win_util::WINVERSION_VISTA) { 25 // We restarted because of a previous crash. Ask user if we should relaunch.
34 // On Vista, this is unnecessary since it is controlled through the 26 if (ShowRestartDialogIfCrashed(&exit_now)) {
35 // /NXCOMPAT linker flag. 27 if (exit_now)
36 // Enforces strong DEP support. 28 return ResultCodes::NORMAL_EXIT;
37 sandbox::SetCurrentProcessDEP(sandbox::DEP_ENABLED);
38 } 29 }
39 30
40 // Get the interface pointer to the BrokerServices or TargetServices, 31 // Initialize the commandline singleton from the environment.
41 // depending who we are. 32 CommandLine::Init(0, NULL);
33
34 // Initialize the sandbox services.
42 sandbox::SandboxInterfaceInfo sandbox_info = {0}; 35 sandbox::SandboxInterfaceInfo sandbox_info = {0};
43 sandbox_info.broker_services = sandbox::SandboxFactory::GetBrokerServices(); 36 sandbox_info.broker_services = sandbox::SandboxFactory::GetBrokerServices();
44 if (!sandbox_info.broker_services) 37 if (!sandbox_info.broker_services)
45 sandbox_info.target_services = sandbox::SandboxFactory::GetTargetServices(); 38 sandbox_info.target_services = sandbox::SandboxFactory::GetTargetServices();
46 39
47 CommandLine::Init(0, NULL); 40 if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) {
48 41 // Enforces strong DEP support. Vista uses the NXCOMPAT flag in the exe.
49 const wchar_t* dll_name = L"chrome.dll"; 42 sandbox::SetCurrentProcessDEP(sandbox::DEP_ENABLED);
50 std::wstring dll_full_path;
51 std::wstring versionned_path;
52
53 #if defined(GOOGLE_CHROME_BUILD)
54 google_update::GoogleUpdateClient client;
55
56 // TODO(erikkay): verify client.Init() return value for official builds
57 client.Init(google_update::kChromeGuid, dll_name);
58 dll_full_path = client.GetDLLFullPath();
59 versionned_path = client.GetDLLPath();
60 #else
61 std::wstring exe_path = client_util::GetExecutablePath();
62 wchar_t *version;
63 if (client_util::GetChromiumVersion(exe_path.c_str(), L"Software\\Chromium",
64 &version)) {
65 versionned_path = exe_path;
66 versionned_path.append(version);
67 delete[] version;
68 } 43 }
69 44
70 dll_full_path = client_util::GetDLLPath(dll_name, versionned_path); 45 // Load and launch the chrome dll. *Everything* happens inside.
71 #endif 46 MainDllLoader* loader = MakeMainDllLoader();
47 int rc = loader->Launch(instance, &sandbox_info);
48 delete loader;
72 49
73 // If the versionned path exists, we set the current directory to this path. 50 return rc;
74 if (client_util::FileExists(versionned_path)) {
75 ::SetCurrentDirectory(versionned_path.c_str());
76 }
77
78 HINSTANCE dll_handle = ::LoadLibraryEx(dll_name, NULL,
79 LOAD_WITH_ALTERED_SEARCH_PATH);
80
81 // Initialize the crash reporter.
82 InitCrashReporterWithDllPath(dll_full_path);
83
84 bool exit_now = true;
85 if (ShowRestartDialogIfCrashed(&exit_now)) {
86 // We have restarted because of a previous crash. The user might
87 // decide that he does not want to continue.
88 if (exit_now)
89 return ResultCodes::NORMAL_EXIT;
90 }
91
92 #if defined(GOOGLE_CHROME_BUILD)
93 int ret = 0;
94 if (client.Launch(instance, &sandbox_info, command_line, "ChromeMain",
95 &ret)) {
96 return ret;
97 }
98 #else
99 if (NULL != dll_handle) {
100 client_util::DLL_MAIN entry = reinterpret_cast<client_util::DLL_MAIN>(
101 ::GetProcAddress(dll_handle, "ChromeMain"));
102 if (NULL != entry)
103 return (entry)(instance, &sandbox_info, command_line);
104 }
105 #endif
106
107 return ResultCodes::GOOGLE_UPDATE_LAUNCH_FAILED;
108 } 51 }
OLDNEW
« no previous file with comments | « chrome/app/breakpad_win.cc ('k') | chrome/app/client_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698