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

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: add some stub gn files 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 <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"
27 #include "content/public/common/content_switches.h"
25 #include "content/public/common/result_codes.h" 28 #include "content/public/common/result_codes.h"
29 #include "third_party/crashpad/crashpad/handler/handler_main.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 RunAsCrashpadHandler(wchar_t* command_line, int* rc) {
129 const base::CommandLine cmdline = base::CommandLine::FromString(command_line);
130 if (cmdline.GetSwitchValueASCII(switches::kProcessType) ==
131 switches::kCrashpadHandler) {
132 std::vector<base::string16> argv = cmdline.argv();
133 base::string16 process_type =
134 L"--" + base::UTF8ToUTF16(switches::kProcessType) + L"=";
135 argv.erase(std::remove_if(argv.begin(), argv.end(),
136 [&process_type](const base::string16& str) {
137 return str.compare(0, process_type.size(),
138 process_type) == 0;
139 }),
140 argv.end());
141
142 scoped_ptr<char* []> argv_as_utf8(new char*[argv.size() + 1]);
143 std::vector<std::string> storage;
144 storage.reserve(argv.size());
145 for (size_t i = 0; i < argv.size(); ++i) {
146 storage.push_back(base::UTF16ToUTF8(argv[i]));
147 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 }
154 return false;
155 }
156
124 } // namespace 157 } // namespace
125 158
126 #if !defined(WIN_CONSOLE_APP) 159 #if !defined(WIN_CONSOLE_APP)
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 int main() { 162 int main() {
130 HINSTANCE instance = GetModuleHandle(NULL); 163 HINSTANCE instance = GetModuleHandle(NULL);
131 #endif 164 #endif
165 int rc;
166 if (RunAsCrashpadHandler(GetCommandLine(), &rc))
167 return rc;
168
132 SwitchToLFHeap(); 169 SwitchToLFHeap();
133 170
134 startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now()); 171 startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now());
135 172
136 // Signal Chrome Elf that Chrome has begun to start. 173 // Signal Chrome Elf that Chrome has begun to start.
137 SignalChromeElf(); 174 SignalChromeElf();
138 175
139 // Initialize the commandline singleton from the environment. 176 // Initialize the commandline singleton from the environment.
140 base::CommandLine::Init(0, NULL); 177 base::CommandLine::Init(0, NULL);
141 // The exit manager is in charge of calling the dtors of singletons. 178 // The exit manager is in charge of calling the dtors of singletons.
142 base::AtExitManager exit_manager; 179 base::AtExitManager exit_manager;
143 180
144 // We don't want to set DPI awareness on pre-Win7 because we don't support 181 // We don't want to set DPI awareness on pre-Win7 because we don't support
145 // DirectWrite there. GDI fonts are kerned very badly, so better to leave 182 // DirectWrite there. GDI fonts are kerned very badly, so better to leave
146 // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite(). 183 // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite().
147 if (base::win::GetVersion() >= base::win::VERSION_WIN7) 184 if (base::win::GetVersion() >= base::win::VERSION_WIN7)
148 EnableHighDPISupport(); 185 EnableHighDPISupport();
149 186
150 if (AttemptFastNotify(*base::CommandLine::ForCurrentProcess())) 187 if (AttemptFastNotify(*base::CommandLine::ForCurrentProcess()))
151 return 0; 188 return 0;
152 189
153 // Load and launch the chrome dll. *Everything* happens inside. 190 // Load and launch the chrome dll. *Everything* happens inside.
154 VLOG(1) << "About to load main DLL."; 191 VLOG(1) << "About to load main DLL.";
155 MainDllLoader* loader = MakeMainDllLoader(); 192 MainDllLoader* loader = MakeMainDllLoader();
156 int rc = loader->Launch(instance); 193 rc = loader->Launch(instance);
157 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); 194 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded();
158 delete loader; 195 delete loader;
159 return rc; 196 return rc;
160 } 197 }
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