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

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

Issue 1416133003: Crashpad Windows: Use the Crashpad client instead of Breakpad on Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 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
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 <shellapi.h>
7 #include <shellscalingapi.h> 8 #include <shellscalingapi.h>
8 #include <tchar.h> 9 #include <tchar.h>
9 10
10 #include <string> 11 #include <string>
11 12
12 #include "base/at_exit.h" 13 #include "base/at_exit.h"
13 #include "base/command_line.h" 14 #include "base/command_line.h"
14 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
15 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/strings/utf_string_conversions.h"
16 #include "base/time/time.h" 18 #include "base/time/time.h"
17 #include "base/win/windows_version.h" 19 #include "base/win/windows_version.h"
18 #include "chrome/app/main_dll_loader_win.h" 20 #include "chrome/app/main_dll_loader_win.h"
19 #include "chrome/browser/chrome_process_finder_win.h" 21 #include "chrome/browser/chrome_process_finder_win.h"
20 #include "chrome/browser/policy/policy_path_parser.h" 22 #include "chrome/browser/policy/policy_path_parser.h"
21 #include "chrome/common/chrome_paths_internal.h" 23 #include "chrome/common/chrome_paths_internal.h"
22 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
23 #include "chrome_elf/chrome_elf_main.h" 25 #include "chrome_elf/chrome_elf_main.h"
24 #include "components/startup_metric_utils/browser/startup_metric_utils.h" 26 #include "components/startup_metric_utils/browser/startup_metric_utils.h"
25 #include "content/public/common/result_codes.h" 27 #include "content/public/common/result_codes.h"
28 #include "third_party/crashpad/crashpad/handler/handler_main.h"
29 #include "third_party/crashpad/crashpad/util/win/scoped_local_alloc.h"
26 #include "ui/gfx/win/dpi.h" 30 #include "ui/gfx/win/dpi.h"
27 31
28 namespace { 32 namespace {
29 // List of switches that it's safe to rendezvous early with. Fast start should 33 // 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. 34 // 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 35 // 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 36 // to iterate over this small array than building a map for constant time
33 // lookups. 37 // lookups.
34 const char* const kFastStartSwitches[] = { 38 const char* const kFastStartSwitches[] = {
35 switches::kProfileDirectory, 39 switches::kProfileDirectory,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // Only needed on XP but harmless on other Windows flavors. 118 // Only needed on XP but harmless on other Windows flavors.
115 auto crt_heap = _get_heap_handle(); 119 auto crt_heap = _get_heap_handle();
116 ULONG enable_LFH = 2; 120 ULONG enable_LFH = 2;
117 if (HeapSetInformation(reinterpret_cast<HANDLE>(crt_heap), 121 if (HeapSetInformation(reinterpret_cast<HANDLE>(crt_heap),
118 HeapCompatibilityInformation, 122 HeapCompatibilityInformation,
119 &enable_LFH, sizeof(enable_LFH))) { 123 &enable_LFH, sizeof(enable_LFH))) {
120 VLOG(1) << "Low fragmentation heap enabled."; 124 VLOG(1) << "Low fragmentation heap enabled.";
121 } 125 }
122 } 126 }
123 127
128 bool RunAsCrashpadHandlerIfSpecified(int* rc) {
cpu_(ooo_6.6-7.5) 2015/11/06 23:16:48 don't like the "IfSpecified"
scottmg 2015/11/07 00:39:43 Done.
129 int num_args;
130 wchar_t** args = CommandLineToArgvW(GetCommandLine(), &num_args);
131 crashpad::ScopedLocalAlloc scoped_args(args); // Take ownership.
132 PCHECK(args) << "CommandLineToArgvW";
133
134 for (int i = 1; i < num_args; ++i) {
135 if (wcscmp(args[i], L"--crashpad_handler") == 0) {
136 // We're dropping args[i], so reserve one less than num_args for the
cpu_(ooo_6.6-7.5) 2015/11/06 23:16:48 is this not possible with base/command_line ?
scottmg 2015/11/07 00:39:42 I have trust issues with how much that code does.
137 // arrays, but add an extra trailing null for the getopt implementation.
138 scoped_ptr<char* []> argv_as_utf8(new char*[num_args]);
139 std::vector<std::string> storage;
140 storage.reserve(num_args - 1);
141 for (int j = 0; j < num_args; ++j) {
142 if (j == i)
143 continue;
144 storage.push_back(base::UTF16ToUTF8(args[j]));
145 }
146 DCHECK_EQ(storage.size(), static_cast<size_t>(num_args - 1));
147 for (size_t j = 0; j < storage.size(); ++j)
148 argv_as_utf8[j] = &storage[j][0];
149 argv_as_utf8[num_args - 1] = nullptr;
150 *rc = crashpad::HandlerMain(num_args - 1, argv_as_utf8.get());
151 return true;
152 }
153 }
154 return false;
155 }
156
124 } // namespace 157 } // namespace
125 158
126 #if !defined(ADDRESS_SANITIZER) 159 #if !defined(ADDRESS_SANITIZER)
127 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { 160 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) {
128 #else 161 #else
129 // The AddressSanitizer build should be a console program as it prints out stuff 162 // The AddressSanitizer build should be a console program as it prints out stuff
130 // on stderr. 163 // on stderr.
131 int main() { 164 int main() {
132 HINSTANCE instance = GetModuleHandle(NULL); 165 HINSTANCE instance = GetModuleHandle(NULL);
133 #endif 166 #endif
167 int rc;
168 if (RunAsCrashpadHandlerIfSpecified(&rc)) {
169 return rc;
170 }
171
134 SwitchToLFHeap(); 172 SwitchToLFHeap();
135 173
136 startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now()); 174 startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now());
137 175
138 // Signal Chrome Elf that Chrome has begun to start. 176 // Signal Chrome Elf that Chrome has begun to start.
139 SignalChromeElf(); 177 SignalChromeElf();
140 178
141 // Initialize the commandline singleton from the environment. 179 // Initialize the commandline singleton from the environment.
142 base::CommandLine::Init(0, NULL); 180 base::CommandLine::Init(0, NULL);
143 // The exit manager is in charge of calling the dtors of singletons. 181 // The exit manager is in charge of calling the dtors of singletons.
144 base::AtExitManager exit_manager; 182 base::AtExitManager exit_manager;
145 183
146 // We don't want to set DPI awareness on pre-Win7 because we don't support 184 // 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 185 // DirectWrite there. GDI fonts are kerned very badly, so better to leave
148 // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite(). 186 // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite().
149 if (base::win::GetVersion() >= base::win::VERSION_WIN7) 187 if (base::win::GetVersion() >= base::win::VERSION_WIN7)
150 EnableHighDPISupport(); 188 EnableHighDPISupport();
151 189
152 if (AttemptFastNotify(*base::CommandLine::ForCurrentProcess())) 190 if (AttemptFastNotify(*base::CommandLine::ForCurrentProcess()))
153 return 0; 191 return 0;
154 192
155 // Load and launch the chrome dll. *Everything* happens inside. 193 // Load and launch the chrome dll. *Everything* happens inside.
156 VLOG(1) << "About to load main DLL."; 194 VLOG(1) << "About to load main DLL.";
157 MainDllLoader* loader = MakeMainDllLoader(); 195 MainDllLoader* loader = MakeMainDllLoader();
158 int rc = loader->Launch(instance); 196 rc = loader->Launch(instance);
159 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); 197 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded();
160 delete loader; 198 delete loader;
161 return rc; 199 return rc;
162 } 200 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698