OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <malloc.h> | 6 #include <malloc.h> |
7 #include <shellscalingapi.h> | 7 #include <shellscalingapi.h> |
8 #include <tchar.h> | 8 #include <tchar.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/at_exit.h" | 12 #include "base/at_exit.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/strings/utf_string_conversions.h" | |
16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
17 #include "base/win/windows_version.h" | 18 #include "base/win/windows_version.h" |
18 #include "chrome/app/main_dll_loader_win.h" | 19 #include "chrome/app/main_dll_loader_win.h" |
19 #include "chrome/browser/chrome_process_finder_win.h" | 20 #include "chrome/browser/chrome_process_finder_win.h" |
20 #include "chrome/browser/policy/policy_path_parser.h" | 21 #include "chrome/browser/policy/policy_path_parser.h" |
21 #include "chrome/common/chrome_paths_internal.h" | 22 #include "chrome/common/chrome_paths_internal.h" |
22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
23 #include "chrome_elf/chrome_elf_main.h" | 24 #include "chrome_elf/chrome_elf_main.h" |
24 #include "components/startup_metric_utils/startup_metric_utils.h" | 25 #include "components/startup_metric_utils/startup_metric_utils.h" |
25 #include "content/public/common/result_codes.h" | 26 #include "content/public/common/result_codes.h" |
27 #include "third_party/crashpad/crashpad/handler/handler_main.h" | |
26 #include "ui/gfx/win/dpi.h" | 28 #include "ui/gfx/win/dpi.h" |
27 | 29 |
28 namespace { | 30 namespace { |
29 // List of switches that it's safe to rendezvous early with. Fast start should | 31 // List of switches that it's safe to rendezvous early with. Fast start should |
30 // not be done if a command line contains a switch not in this set. | 32 // not be done if a command line contains a switch not in this set. |
31 // Note this is currently stored as a list of two because it's probably faster | 33 // Note this is currently stored as a list of two because it's probably faster |
32 // to iterate over this small array than building a map for constant time | 34 // to iterate over this small array than building a map for constant time |
33 // lookups. | 35 // lookups. |
34 const char* const kFastStartSwitches[] = { | 36 const char* const kFastStartSwitches[] = { |
35 switches::kProfileDirectory, | 37 switches::kProfileDirectory, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 // Only needed on XP but harmless on other Windows flavors. | 116 // Only needed on XP but harmless on other Windows flavors. |
115 auto crt_heap = _get_heap_handle(); | 117 auto crt_heap = _get_heap_handle(); |
116 ULONG enable_LFH = 2; | 118 ULONG enable_LFH = 2; |
117 if (HeapSetInformation(reinterpret_cast<HANDLE>(crt_heap), | 119 if (HeapSetInformation(reinterpret_cast<HANDLE>(crt_heap), |
118 HeapCompatibilityInformation, | 120 HeapCompatibilityInformation, |
119 &enable_LFH, sizeof(enable_LFH))) { | 121 &enable_LFH, sizeof(enable_LFH))) { |
120 VLOG(1) << "Low fragmentation heap enabled."; | 122 VLOG(1) << "Low fragmentation heap enabled."; |
121 } | 123 } |
122 } | 124 } |
123 | 125 |
126 bool RunAsCrashpadHandler(int* rc) { | |
127 const base::CommandLine command_line = | |
128 base::CommandLine::FromString(GetCommandLine()); | |
129 if (command_line.HasSwitch("crashpad_handler")) { | |
Mark Mentovai
2015/11/10 17:21:17
If you’re using command_line, should this go into
Mark Mentovai
2015/11/10 17:21:17
--type=crashpad_handler would probably be more Chr
Mark Mentovai
2015/11/10 17:21:17
I know Carlos asked you to change this, but since
scottmg
2015/11/16 21:48:39
Went with --type=crashpad-handler (_ seems pretty
scottmg
2015/11/16 21:48:39
Done.
scottmg
2015/11/16 21:48:39
Switching to base::CommandLine ended up being less
Mark Mentovai
2015/11/16 22:11:13
scottmg wrote:
| |
130 std::vector<base::string16> argv = command_line.argv(); | |
131 argv.erase(std::remove(argv.begin(), argv.end(), L"--crashpad_handler"), | |
132 argv.end()); | |
133 | |
134 scoped_ptr<char* []> argv_as_utf8(new char*[argv.size() + 1]); | |
135 std::vector<std::string> storage; | |
136 storage.reserve(argv.size()); | |
137 for (size_t i = 0; i < argv.size(); ++i) { | |
138 storage.push_back(base::UTF16ToUTF8(argv[i])); | |
139 argv_as_utf8[i] = &storage[i][0]; | |
140 } | |
141 argv_as_utf8[argv.size()] = nullptr; | |
142 *rc = crashpad::HandlerMain(argv.size(), argv_as_utf8.get()); | |
143 return true; | |
144 } | |
145 return false; | |
146 } | |
147 | |
124 } // namespace | 148 } // namespace |
125 | 149 |
126 #if !defined(ADDRESS_SANITIZER) | 150 #if !defined(ADDRESS_SANITIZER) |
127 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { | 151 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { |
128 #else | 152 #else |
129 // The AddressSanitizer build should be a console program as it prints out stuff | 153 // The AddressSanitizer build should be a console program as it prints out stuff |
130 // on stderr. | 154 // on stderr. |
131 int main() { | 155 int main() { |
132 HINSTANCE instance = GetModuleHandle(NULL); | 156 HINSTANCE instance = GetModuleHandle(NULL); |
133 #endif | 157 #endif |
158 int rc; | |
159 if (RunAsCrashpadHandler(&rc)) | |
Mark Mentovai
2015/11/10 17:21:17
Carry the wchar_t* argument to RunAsCrashpadHandle
scottmg
2015/11/16 21:48:39
wWinMain's "command line" argument doesn't include
| |
160 return rc; | |
Mark Mentovai
2015/11/10 17:21:17
It’d be cool to someday put the client init right
scottmg
2015/11/16 21:48:39
Yeah, I'm not sure if there's anything stopping us
| |
161 | |
134 SwitchToLFHeap(); | 162 SwitchToLFHeap(); |
135 | 163 |
136 startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now()); | 164 startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now()); |
137 | 165 |
138 // Signal Chrome Elf that Chrome has begun to start. | 166 // Signal Chrome Elf that Chrome has begun to start. |
139 SignalChromeElf(); | 167 SignalChromeElf(); |
140 | 168 |
141 // Initialize the commandline singleton from the environment. | 169 // Initialize the commandline singleton from the environment. |
142 base::CommandLine::Init(0, NULL); | 170 base::CommandLine::Init(0, NULL); |
Mark Mentovai
2015/11/10 17:21:17
If you moved this above RunAsCrashpadHandler(), it
scottmg
2015/11/16 21:48:39
Yeah, I moved it up, but then moved it back down a
| |
143 // The exit manager is in charge of calling the dtors of singletons. | 171 // The exit manager is in charge of calling the dtors of singletons. |
144 base::AtExitManager exit_manager; | 172 base::AtExitManager exit_manager; |
145 | 173 |
146 // We don't want to set DPI awareness on pre-Win7 because we don't support | 174 // We don't want to set DPI awareness on pre-Win7 because we don't support |
147 // DirectWrite there. GDI fonts are kerned very badly, so better to leave | 175 // DirectWrite there. GDI fonts are kerned very badly, so better to leave |
148 // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite(). | 176 // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite(). |
149 if (base::win::GetVersion() >= base::win::VERSION_WIN7) | 177 if (base::win::GetVersion() >= base::win::VERSION_WIN7) |
150 EnableHighDPISupport(); | 178 EnableHighDPISupport(); |
151 | 179 |
152 if (AttemptFastNotify(*base::CommandLine::ForCurrentProcess())) | 180 if (AttemptFastNotify(*base::CommandLine::ForCurrentProcess())) |
153 return 0; | 181 return 0; |
154 | 182 |
155 // Load and launch the chrome dll. *Everything* happens inside. | 183 // Load and launch the chrome dll. *Everything* happens inside. |
156 VLOG(1) << "About to load main DLL."; | 184 VLOG(1) << "About to load main DLL."; |
157 MainDllLoader* loader = MakeMainDllLoader(); | 185 MainDllLoader* loader = MakeMainDllLoader(); |
158 int rc = loader->Launch(instance); | 186 rc = loader->Launch(instance); |
159 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); | 187 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); |
160 delete loader; | 188 delete loader; |
161 return rc; | 189 return rc; |
162 } | 190 } |
OLD | NEW |