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

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

Issue 1481703002: win: Move Crashpad all into chrome.exe (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix and rebase Created 5 years 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
« no previous file with comments | « chrome/app/chrome_crash_reporter_client.cc ('k') | chrome/app/chrome_main_delegate.cc » ('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) 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"
23 #include "chrome/common/chrome_paths_internal.h" 25 #include "chrome/common/chrome_paths_internal.h"
24 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
25 #include "chrome_elf/chrome_elf_main.h" 27 #include "chrome_elf/chrome_elf_main.h"
28 #include "components/crash/content/app/crash_reporter_client.h"
29 #include "components/crash/content/app/crashpad.h"
26 #include "components/startup_metric_utils/browser/startup_metric_utils.h" 30 #include "components/startup_metric_utils/browser/startup_metric_utils.h"
27 #include "content/public/common/content_switches.h" 31 #include "content/public/common/content_switches.h"
28 #include "content/public/common/result_codes.h" 32 #include "content/public/common/result_codes.h"
29 #include "third_party/crashpad/crashpad/handler/handler_main.h" 33 #include "third_party/crashpad/crashpad/handler/handler_main.h"
30 #include "ui/gfx/win/dpi.h" 34 #include "ui/gfx/win/dpi.h"
31 35
32 namespace { 36 namespace {
37
38 base::LazyInstance<ChromeCrashReporterClient>::Leaky g_chrome_crash_client =
39 LAZY_INSTANCE_INITIALIZER;
40
41 base::LazyInstance<std::vector<crash_reporter::UploadedReport>>::Leaky
42 g_uploaded_reports = LAZY_INSTANCE_INITIALIZER;
43
33 // List of switches that it's safe to rendezvous early with. Fast start should 44 // 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. 45 // 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 46 // 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 47 // to iterate over this small array than building a map for constant time
37 // lookups. 48 // lookups.
38 const char* const kFastStartSwitches[] = { 49 const char* const kFastStartSwitches[] = {
39 switches::kProfileDirectory, 50 switches::kProfileDirectory,
40 switches::kShowAppList, 51 switches::kShowAppList,
41 }; 52 };
42 53
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 // Only needed on XP but harmless on other Windows flavors. 129 // Only needed on XP but harmless on other Windows flavors.
119 auto crt_heap = _get_heap_handle(); 130 auto crt_heap = _get_heap_handle();
120 ULONG enable_LFH = 2; 131 ULONG enable_LFH = 2;
121 if (HeapSetInformation(reinterpret_cast<HANDLE>(crt_heap), 132 if (HeapSetInformation(reinterpret_cast<HANDLE>(crt_heap),
122 HeapCompatibilityInformation, 133 HeapCompatibilityInformation,
123 &enable_LFH, sizeof(enable_LFH))) { 134 &enable_LFH, sizeof(enable_LFH))) {
124 VLOG(1) << "Low fragmentation heap enabled."; 135 VLOG(1) << "Low fragmentation heap enabled.";
125 } 136 }
126 } 137 }
127 138
128 bool RunAsCrashpadHandler(wchar_t* command_line, int* rc) { 139 int RunAsCrashpadHandler(const base::CommandLine& command_line) {
129 const base::CommandLine cmdline = base::CommandLine::FromString(command_line); 140 std::vector<base::string16> argv = command_line.argv();
130 if (cmdline.GetSwitchValueASCII(switches::kProcessType) == 141 base::string16 process_type =
131 switches::kCrashpadHandler) { 142 L"--" + base::UTF8ToUTF16(switches::kProcessType) + L"=";
132 std::vector<base::string16> argv = cmdline.argv(); 143 argv.erase(std::remove_if(argv.begin(), argv.end(),
133 base::string16 process_type = 144 [&process_type](const base::string16& str) {
134 L"--" + base::UTF8ToUTF16(switches::kProcessType) + L"="; 145 return str.compare(0, process_type.size(),
135 argv.erase(std::remove_if(argv.begin(), argv.end(), 146 process_type) == 0;
136 [&process_type](const base::string16& str) { 147 }),
137 return str.compare(0, process_type.size(), 148 argv.end());
138 process_type) == 0;
139 }),
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;
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. Note that we do not pass an std::vector here,
166 // because we do not want to allocate/free in different modules. The returned
167 // pointer is read-only.
168 extern "C" __declspec(dllexport) void GetUploadedReportsImpl(
169 const crash_reporter::UploadedReport** reports,
170 size_t* report_count) {
171 crash_reporter::GetUploadedReports(g_uploaded_reports.Pointer());
172 *reports = g_uploaded_reports.Pointer()->data();
173 *report_count = g_uploaded_reports.Pointer()->size();
174 }
175
159 #if !defined(WIN_CONSOLE_APP) 176 #if !defined(WIN_CONSOLE_APP)
160 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { 177 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) {
161 #else 178 #else
162 int main() { 179 int main() {
163 HINSTANCE instance = GetModuleHandle(NULL); 180 HINSTANCE instance = GetModuleHandle(nullptr);
164 #endif 181 #endif
165 int rc; 182 // Initialize the CommandLine singleton from the environment.
166 if (RunAsCrashpadHandler(GetCommandLine(), &rc)) 183 base::CommandLine::Init(0, nullptr);
167 return rc; 184
185 std::string process_type =
186 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
187 switches::kProcessType);
188
189 if (process_type == switches::kCrashpadHandler)
190 return RunAsCrashpadHandler(*base::CommandLine::ForCurrentProcess());
191
192 crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer());
193 crash_reporter::InitializeCrashpad(process_type.empty(), process_type);
168 194
169 SwitchToLFHeap(); 195 SwitchToLFHeap();
170 196
171 startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now()); 197 startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now());
172 198
173 // Signal Chrome Elf that Chrome has begun to start. 199 // Signal Chrome Elf that Chrome has begun to start.
174 SignalChromeElf(); 200 SignalChromeElf();
175 201
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. 202 // The exit manager is in charge of calling the dtors of singletons.
179 base::AtExitManager exit_manager; 203 base::AtExitManager exit_manager;
180 204
181 // We don't want to set DPI awareness on pre-Win7 because we don't support 205 // 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 206 // DirectWrite there. GDI fonts are kerned very badly, so better to leave
183 // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite(). 207 // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite().
184 if (base::win::GetVersion() >= base::win::VERSION_WIN7) 208 if (base::win::GetVersion() >= base::win::VERSION_WIN7)
185 EnableHighDPISupport(); 209 EnableHighDPISupport();
186 210
187 if (AttemptFastNotify(*base::CommandLine::ForCurrentProcess())) 211 if (AttemptFastNotify(*base::CommandLine::ForCurrentProcess()))
188 return 0; 212 return 0;
189 213
190 // Load and launch the chrome dll. *Everything* happens inside. 214 // Load and launch the chrome dll. *Everything* happens inside.
191 VLOG(1) << "About to load main DLL."; 215 VLOG(1) << "About to load main DLL.";
192 MainDllLoader* loader = MakeMainDllLoader(); 216 MainDllLoader* loader = MakeMainDllLoader();
193 rc = loader->Launch(instance); 217 int rc = loader->Launch(instance);
194 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); 218 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded();
195 delete loader; 219 delete loader;
196 return rc; 220 return rc;
197 } 221 }
OLDNEW
« no previous file with comments | « chrome/app/chrome_crash_reporter_client.cc ('k') | chrome/app/chrome_main_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698