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 <stddef.h> | 8 #include <stddef.h> |
9 #include <tchar.h> | 9 #include <tchar.h> |
10 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/at_exit.h" | 14 #include "base/at_exit.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
17 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
18 #include "base/logging.h" | 18 #include "base/logging.h" |
19 #include "base/macros.h" | 19 #include "base/macros.h" |
20 #include "base/strings/string_util.h" | |
20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
21 #include "base/time/time.h" | 22 #include "base/time/time.h" |
22 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
23 #include "chrome/app/chrome_crash_reporter_client.h" | 24 #include "chrome/app/chrome_crash_reporter_client.h" |
24 #include "chrome/app/main_dll_loader_win.h" | 25 #include "chrome/app/main_dll_loader_win.h" |
26 #include "chrome/app/prefetch_argument_win.h" | |
25 #include "chrome/browser/chrome_process_finder_win.h" | 27 #include "chrome/browser/chrome_process_finder_win.h" |
26 #include "chrome/browser/policy/policy_path_parser.h" | 28 #include "chrome/browser/policy/policy_path_parser.h" |
27 #include "chrome/common/chrome_paths_internal.h" | 29 #include "chrome/common/chrome_paths_internal.h" |
28 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
31 #include "chrome/installer/util/browser_distribution.h" | |
29 #include "chrome_elf/chrome_elf_main.h" | 32 #include "chrome_elf/chrome_elf_main.h" |
30 #include "components/crash/content/app/crash_reporter_client.h" | 33 #include "components/crash/content/app/crash_reporter_client.h" |
31 #include "components/crash/content/app/crashpad.h" | 34 #include "components/crash/content/app/crashpad.h" |
32 #include "components/startup_metric_utils/browser/startup_metric_utils.h" | 35 #include "components/startup_metric_utils/browser/startup_metric_utils.h" |
36 #include "components/startup_metric_utils/common/pre_read_field_trial_utils_win. h" | |
33 #include "content/public/common/content_switches.h" | 37 #include "content/public/common/content_switches.h" |
34 #include "content/public/common/result_codes.h" | 38 #include "content/public/common/result_codes.h" |
35 #include "third_party/crashpad/crashpad/handler/handler_main.h" | 39 #include "third_party/crashpad/crashpad/handler/handler_main.h" |
36 #include "ui/gfx/win/dpi.h" | 40 #include "ui/gfx/win/dpi.h" |
37 | 41 |
38 namespace { | 42 namespace { |
39 | 43 |
40 base::LazyInstance<ChromeCrashReporterClient>::Leaky g_chrome_crash_client = | 44 base::LazyInstance<ChromeCrashReporterClient>::Leaky g_chrome_crash_client = |
41 LAZY_INSTANCE_INITIALIZER; | 45 LAZY_INSTANCE_INITIALIZER; |
42 | 46 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 argv.erase(std::remove_if(argv.begin(), argv.end(), | 149 argv.erase(std::remove_if(argv.begin(), argv.end(), |
146 [&process_type](const base::string16& str) { | 150 [&process_type](const base::string16& str) { |
147 return str.compare(0, process_type.size(), | 151 return str.compare(0, process_type.size(), |
148 process_type) == 0; | 152 process_type) == 0; |
149 }), | 153 }), |
150 argv.end()); | 154 argv.end()); |
151 | 155 |
152 scoped_ptr<char* []> argv_as_utf8(new char*[argv.size() + 1]); | 156 scoped_ptr<char* []> argv_as_utf8(new char*[argv.size() + 1]); |
153 std::vector<std::string> storage; | 157 std::vector<std::string> storage; |
154 storage.reserve(argv.size()); | 158 storage.reserve(argv.size()); |
159 | |
160 size_t arg_append_index = 0; | |
155 for (size_t i = 0; i < argv.size(); ++i) { | 161 for (size_t i = 0; i < argv.size(); ++i) { |
162 // Remove the /prefetch:# argument as it is not supported by Crashpad. | |
163 if (base::StartsWith(argv[i], L"/prefetch:", base::CompareCase::SENSITIVE)) | |
164 continue; | |
165 | |
156 storage.push_back(base::UTF16ToUTF8(argv[i])); | 166 storage.push_back(base::UTF16ToUTF8(argv[i])); |
157 argv_as_utf8[i] = &storage[i][0]; | 167 argv_as_utf8[arg_append_index] = &storage[arg_append_index][0]; |
168 ++arg_append_index; | |
158 } | 169 } |
159 argv_as_utf8[argv.size()] = nullptr; | 170 argv_as_utf8[arg_append_index] = nullptr; |
160 return crashpad::HandlerMain(static_cast<int>(argv.size()), | 171 |
172 return crashpad::HandlerMain(static_cast<int>(storage.size()), | |
161 argv_as_utf8.get()); | 173 argv_as_utf8.get()); |
162 } | 174 } |
163 | 175 |
164 } // namespace | 176 } // namespace |
165 | 177 |
166 // This helper is looked up in the browser to retrieve the crash reports. See | 178 // This helper is looked up in the browser to retrieve the crash reports. See |
167 // CrashUploadListCrashpad. Note that we do not pass an std::vector here, | 179 // CrashUploadListCrashpad. Note that we do not pass an std::vector here, |
168 // because we do not want to allocate/free in different modules. The returned | 180 // because we do not want to allocate/free in different modules. The returned |
169 // pointer is read-only. | 181 // pointer is read-only. |
170 extern "C" __declspec(dllexport) void GetUploadedReportsImpl( | 182 extern "C" __declspec(dllexport) void GetUploadedReportsImpl( |
171 const crash_reporter::UploadedReport** reports, | 183 const crash_reporter::UploadedReport** reports, |
172 size_t* report_count) { | 184 size_t* report_count) { |
173 crash_reporter::GetUploadedReports(g_uploaded_reports.Pointer()); | 185 crash_reporter::GetUploadedReports(g_uploaded_reports.Pointer()); |
174 *reports = g_uploaded_reports.Pointer()->data(); | 186 *reports = g_uploaded_reports.Pointer()->data(); |
175 *report_count = g_uploaded_reports.Pointer()->size(); | 187 *report_count = g_uploaded_reports.Pointer()->size(); |
176 } | 188 } |
177 | 189 |
178 #if !defined(WIN_CONSOLE_APP) | 190 #if !defined(WIN_CONSOLE_APP) |
179 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { | 191 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { |
180 #else | 192 #else |
181 int main() { | 193 int main() { |
182 HINSTANCE instance = GetModuleHandle(nullptr); | 194 HINSTANCE instance = GetModuleHandle(nullptr); |
183 #endif | 195 #endif |
184 // Initialize the CommandLine singleton from the environment. | 196 // Initialize the CommandLine singleton from the environment. |
185 base::CommandLine::Init(0, nullptr); | 197 base::CommandLine::Init(0, nullptr); |
198 const base::CommandLine* command_line = | |
199 base::CommandLine::ForCurrentProcess(); | |
186 | 200 |
187 std::string process_type = | 201 const std::string process_type = |
188 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 202 command_line->GetSwitchValueASCII(switches::kProcessType); |
189 switches::kProcessType); | 203 |
204 startup_metric_utils::InitializePreReadOptions( | |
205 BrowserDistribution::GetDistribution()->GetRegistryPath()); | |
206 | |
207 // Confirm that an explicit prefetch profile is used for all process types | |
208 // except for the browser process. Any new process type will have to assign | |
209 // itself a prefetch id (see kPrefetchArgument* constants in | |
210 // content_switches.cc). | |
gab
2016/01/29 12:46:25
s/)/ for details)/
fdoray
2016/01/29 15:33:30
Done.
| |
211 DCHECK(!startup_metric_utils::GetPreReadOptions().use_prefetch_argument || | |
212 process_type.empty() || | |
213 HasValidWindowsPrefetchArgument(*command_line)); | |
190 | 214 |
191 if (process_type == switches::kCrashpadHandler) | 215 if (process_type == switches::kCrashpadHandler) |
192 return RunAsCrashpadHandler(*base::CommandLine::ForCurrentProcess()); | 216 return RunAsCrashpadHandler(*base::CommandLine::ForCurrentProcess()); |
193 | 217 |
194 crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer()); | 218 crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer()); |
195 crash_reporter::InitializeCrashpad(process_type.empty(), process_type); | 219 crash_reporter::InitializeCrashpad(process_type.empty(), process_type); |
196 | 220 |
197 SwitchToLFHeap(); | 221 SwitchToLFHeap(); |
198 | 222 |
199 startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now()); | 223 startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now()); |
200 | 224 |
201 // Signal Chrome Elf that Chrome has begun to start. | 225 // Signal Chrome Elf that Chrome has begun to start. |
202 SignalChromeElf(); | 226 SignalChromeElf(); |
203 | 227 |
204 // The exit manager is in charge of calling the dtors of singletons. | 228 // The exit manager is in charge of calling the dtors of singletons. |
205 base::AtExitManager exit_manager; | 229 base::AtExitManager exit_manager; |
206 | 230 |
207 // We don't want to set DPI awareness on pre-Win7 because we don't support | 231 // We don't want to set DPI awareness on pre-Win7 because we don't support |
208 // DirectWrite there. GDI fonts are kerned very badly, so better to leave | 232 // DirectWrite there. GDI fonts are kerned very badly, so better to leave |
209 // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite(). | 233 // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite(). |
210 if (base::win::GetVersion() >= base::win::VERSION_WIN7) | 234 if (base::win::GetVersion() >= base::win::VERSION_WIN7) |
211 EnableHighDPISupport(); | 235 EnableHighDPISupport(); |
212 | 236 |
213 if (AttemptFastNotify(*base::CommandLine::ForCurrentProcess())) | 237 if (AttemptFastNotify(*command_line)) |
214 return 0; | 238 return 0; |
215 | 239 |
216 // Load and launch the chrome dll. *Everything* happens inside. | 240 // Load and launch the chrome dll. *Everything* happens inside. |
217 VLOG(1) << "About to load main DLL."; | 241 VLOG(1) << "About to load main DLL."; |
218 MainDllLoader* loader = MakeMainDllLoader(); | 242 MainDllLoader* loader = MakeMainDllLoader(); |
219 int rc = loader->Launch(instance); | 243 int rc = loader->Launch(instance); |
220 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); | 244 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); |
221 delete loader; | 245 delete loader; |
222 return rc; | 246 return rc; |
223 } | 247 } |
OLD | NEW |