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 <algorithm> | 10 #include <algorithm> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/at_exit.h" | 13 #include "base/at_exit.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/lazy_instance.h" | |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
19 #include "base/win/windows_version.h" | 20 #include "base/win/windows_version.h" |
21 #include "chrome/app/chrome_crash_reporter_client.h" | |
20 #include "chrome/app/main_dll_loader_win.h" | 22 #include "chrome/app/main_dll_loader_win.h" |
21 #include "chrome/browser/chrome_process_finder_win.h" | 23 #include "chrome/browser/chrome_process_finder_win.h" |
22 #include "chrome/browser/policy/policy_path_parser.h" | 24 #include "chrome/browser/policy/policy_path_parser.h" |
25 #include "chrome/common/chrome_paths.h" | |
23 #include "chrome/common/chrome_paths_internal.h" | 26 #include "chrome/common/chrome_paths_internal.h" |
24 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
25 #include "chrome_elf/chrome_elf_main.h" | 28 #include "chrome_elf/chrome_elf_main.h" |
29 #include "components/crash/content/app/crash_reporter_client.h" | |
30 #include "components/crash/content/app/crashpad.h" | |
26 #include "components/startup_metric_utils/browser/startup_metric_utils.h" | 31 #include "components/startup_metric_utils/browser/startup_metric_utils.h" |
27 #include "content/public/common/content_switches.h" | 32 #include "content/public/common/content_switches.h" |
28 #include "content/public/common/result_codes.h" | 33 #include "content/public/common/result_codes.h" |
29 #include "third_party/crashpad/crashpad/handler/handler_main.h" | 34 #include "third_party/crashpad/crashpad/handler/handler_main.h" |
30 #include "ui/gfx/win/dpi.h" | 35 #include "ui/gfx/win/dpi.h" |
31 | 36 |
32 namespace { | 37 namespace { |
38 | |
39 base::LazyInstance<ChromeCrashReporterClient>::Leaky g_chrome_crash_client = | |
40 LAZY_INSTANCE_INITIALIZER; | |
41 | |
33 // List of switches that it's safe to rendezvous early with. Fast start should | 42 // List of switches that it's safe to rendezvous early with. Fast start should |
34 // not be done if a command line contains a switch not in this set. | 43 // not be done if a command line contains a switch not in this set. |
35 // Note this is currently stored as a list of two because it's probably faster | 44 // Note this is currently stored as a list of two because it's probably faster |
36 // to iterate over this small array than building a map for constant time | 45 // to iterate over this small array than building a map for constant time |
37 // lookups. | 46 // lookups. |
38 const char* const kFastStartSwitches[] = { | 47 const char* const kFastStartSwitches[] = { |
39 switches::kProfileDirectory, | 48 switches::kProfileDirectory, |
40 switches::kShowAppList, | 49 switches::kShowAppList, |
41 }; | 50 }; |
42 | 51 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 // Only needed on XP but harmless on other Windows flavors. | 127 // Only needed on XP but harmless on other Windows flavors. |
119 auto crt_heap = _get_heap_handle(); | 128 auto crt_heap = _get_heap_handle(); |
120 ULONG enable_LFH = 2; | 129 ULONG enable_LFH = 2; |
121 if (HeapSetInformation(reinterpret_cast<HANDLE>(crt_heap), | 130 if (HeapSetInformation(reinterpret_cast<HANDLE>(crt_heap), |
122 HeapCompatibilityInformation, | 131 HeapCompatibilityInformation, |
123 &enable_LFH, sizeof(enable_LFH))) { | 132 &enable_LFH, sizeof(enable_LFH))) { |
124 VLOG(1) << "Low fragmentation heap enabled."; | 133 VLOG(1) << "Low fragmentation heap enabled."; |
125 } | 134 } |
126 } | 135 } |
127 | 136 |
128 bool RunAsCrashpadHandler(wchar_t* command_line, int* rc) { | 137 int RunAsCrashpadHandler(const base::CommandLine& command_line) { |
129 const base::CommandLine cmdline = base::CommandLine::FromString(command_line); | 138 DCHECK_EQ(command_line.GetSwitchValueASCII(switches::kProcessType), |
cpu_(ooo_6.6-7.5)
2015/12/02 19:12:26
I don't know if we can use dchecks here since the
scottmg
2015/12/02 21:57:29
Oh good point. It's definitely not initialized at
Mark Mentovai
2015/12/02 22:01:04
scottmg wrote:
scottmg
2015/12/02 22:28:28
In practice in a debug build on Windows, it logs t
| |
130 if (cmdline.GetSwitchValueASCII(switches::kProcessType) == | 139 switches::kCrashpadHandler); |
131 switches::kCrashpadHandler) { | 140 std::vector<base::string16> argv = command_line.argv(); |
132 std::vector<base::string16> argv = cmdline.argv(); | 141 base::string16 process_type = |
133 base::string16 process_type = | 142 L"--" + base::UTF8ToUTF16(switches::kProcessType) + L"="; |
134 L"--" + base::UTF8ToUTF16(switches::kProcessType) + L"="; | 143 argv.erase(std::remove_if(argv.begin(), argv.end(), |
135 argv.erase(std::remove_if(argv.begin(), argv.end(), | 144 [&process_type](const base::string16& str) { |
136 [&process_type](const base::string16& str) { | 145 return str.compare(0, process_type.size(), |
137 return str.compare(0, process_type.size(), | 146 process_type) == 0; |
138 process_type) == 0; | 147 }), |
139 }), | 148 argv.end()); |
140 argv.end()); | |
141 | 149 |
142 scoped_ptr<char* []> argv_as_utf8(new char*[argv.size() + 1]); | 150 scoped_ptr<char* []> argv_as_utf8(new char*[argv.size() + 1]); |
143 std::vector<std::string> storage; | 151 std::vector<std::string> storage; |
144 storage.reserve(argv.size()); | 152 storage.reserve(argv.size()); |
145 for (size_t i = 0; i < argv.size(); ++i) { | 153 for (size_t i = 0; i < argv.size(); ++i) { |
146 storage.push_back(base::UTF16ToUTF8(argv[i])); | 154 storage.push_back(base::UTF16ToUTF8(argv[i])); |
147 argv_as_utf8[i] = &storage[i][0]; | 155 argv_as_utf8[i] = &storage[i][0]; |
148 } | |
149 argv_as_utf8[argv.size()] = nullptr; | |
150 *rc = crashpad::HandlerMain(static_cast<int>(argv.size()), | |
151 argv_as_utf8.get()); | |
152 return true; | |
153 } | 156 } |
154 return false; | 157 argv_as_utf8[argv.size()] = nullptr; |
cpu_(ooo_6.6-7.5)
2015/12/02 19:12:26
the above reads funny, as if you are zeroing one-p
scottmg
2015/12/02 21:57:29
Yeah, it looks funny, but I think it's OK. It's al
| |
158 return crashpad::HandlerMain(static_cast<int>(argv.size()), | |
159 argv_as_utf8.get()); | |
155 } | 160 } |
156 | 161 |
157 } // namespace | 162 } // namespace |
158 | 163 |
164 // This helper is looked up in the browser to retrieve the crash reports. See | |
165 // CrashUploadListCrashpad. | |
166 extern "C" __declspec(dllexport) void GetUploadedReportsImpl( | |
167 std::vector<crash_reporter::UploadedReport>* uploaded_reports) { | |
Mark Mentovai
2015/12/02 14:59:23
Is there also precedent for moving C++ types acros
cpu_(ooo_6.6-7.5)
2015/12/02 19:12:26
This is somewhat safe as long as there is no exe a
scottmg
2015/12/02 21:57:29
Since I need to store the returned list in the exe
| |
168 crash_reporter::GetUploadedReports(uploaded_reports); | |
169 } | |
170 | |
159 #if !defined(WIN_CONSOLE_APP) | 171 #if !defined(WIN_CONSOLE_APP) |
160 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { | 172 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { |
161 #else | 173 #else |
162 int main() { | 174 int main() { |
163 HINSTANCE instance = GetModuleHandle(NULL); | 175 HINSTANCE instance = GetModuleHandle(nullptr); |
164 #endif | 176 #endif |
165 int rc; | 177 // Initialize the CommandLine singleton from the environment. |
166 if (RunAsCrashpadHandler(GetCommandLine(), &rc)) | 178 base::CommandLine::Init(0, nullptr); |
167 return rc; | 179 |
180 // The exit manager is in charge of calling the dtors of singletons. | |
181 base::AtExitManager exit_manager; | |
182 | |
183 std::string process_type = | |
184 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
185 switches::kProcessType); | |
186 | |
187 if (process_type == switches::kCrashpadHandler) | |
188 return RunAsCrashpadHandler(*base::CommandLine::ForCurrentProcess()); | |
189 | |
190 // TODO(scottmg): This and the AtExitManager above are required so the crash | |
191 // reporter knows where to store its dumps. We could potentially avoid this by | |
192 // modifying ChromeCrashReporterClient to do that somehow else more manually | |
193 // on Windows. https://code.google.com/p/chromium/issues/detail?id=564398. | |
cpu_(ooo_6.6-7.5)
2015/12/02 19:12:26
yeah, once you start using the path providers you
scottmg
2015/12/02 21:57:29
The whole thing is kind of a pain. I'm not really
| |
194 chrome::RegisterPathProvider(); | |
195 | |
196 crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer()); | |
197 crash_reporter::InitializeCrashpad(process_type.empty(), process_type); | |
168 | 198 |
169 SwitchToLFHeap(); | 199 SwitchToLFHeap(); |
170 | 200 |
171 startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now()); | 201 startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now()); |
172 | 202 |
173 // Signal Chrome Elf that Chrome has begun to start. | 203 // Signal Chrome Elf that Chrome has begun to start. |
174 SignalChromeElf(); | 204 SignalChromeElf(); |
175 | 205 |
176 // Initialize the commandline singleton from the environment. | |
177 base::CommandLine::Init(0, NULL); | |
178 // The exit manager is in charge of calling the dtors of singletons. | |
179 base::AtExitManager exit_manager; | |
180 | |
181 // We don't want to set DPI awareness on pre-Win7 because we don't support | 206 // We don't want to set DPI awareness on pre-Win7 because we don't support |
182 // DirectWrite there. GDI fonts are kerned very badly, so better to leave | 207 // DirectWrite there. GDI fonts are kerned very badly, so better to leave |
183 // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite(). | 208 // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite(). |
184 if (base::win::GetVersion() >= base::win::VERSION_WIN7) | 209 if (base::win::GetVersion() >= base::win::VERSION_WIN7) |
185 EnableHighDPISupport(); | 210 EnableHighDPISupport(); |
186 | 211 |
187 if (AttemptFastNotify(*base::CommandLine::ForCurrentProcess())) | 212 if (AttemptFastNotify(*base::CommandLine::ForCurrentProcess())) |
188 return 0; | 213 return 0; |
189 | 214 |
190 // Load and launch the chrome dll. *Everything* happens inside. | 215 // Load and launch the chrome dll. *Everything* happens inside. |
191 VLOG(1) << "About to load main DLL."; | 216 VLOG(1) << "About to load main DLL."; |
192 MainDllLoader* loader = MakeMainDllLoader(); | 217 MainDllLoader* loader = MakeMainDllLoader(); |
193 rc = loader->Launch(instance); | 218 int rc = loader->Launch(instance); |
194 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); | 219 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); |
195 delete loader; | 220 delete loader; |
196 return rc; | 221 return rc; |
197 } | 222 } |
OLD | NEW |