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/path_service.h" | 19 #include "base/path_service.h" |
20 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
21 #include "base/strings/string_split.h" | 21 #include "base/strings/string_split.h" |
22 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
23 #include "base/time/time.h" | 23 #include "base/time/time.h" |
24 #include "base/win/registry.h" | 24 #include "base/win/registry.h" |
25 #include "base/win/windows_version.h" | 25 #include "base/win/windows_version.h" |
26 #include "chrome/app/chrome_crash_reporter_client_win.h" | |
27 #include "chrome/app/main_dll_loader_win.h" | 26 #include "chrome/app/main_dll_loader_win.h" |
28 #include "chrome/browser/policy/policy_path_parser.h" | 27 #include "chrome/browser/policy/policy_path_parser.h" |
29 #include "chrome/browser/win/chrome_process_finder.h" | 28 #include "chrome/browser/win/chrome_process_finder.h" |
30 #include "chrome/common/chrome_paths_internal.h" | 29 #include "chrome/common/chrome_paths_internal.h" |
31 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
32 #include "chrome/installer/util/browser_distribution.h" | 31 #include "chrome/installer/util/browser_distribution.h" |
33 #include "chrome_elf/chrome_elf_main.h" | 32 #include "chrome_elf/chrome_elf_main.h" |
34 #include "components/crash/content/app/crash_reporter_client.h" | |
35 #include "components/crash/content/app/crash_switches.h" | 33 #include "components/crash/content/app/crash_switches.h" |
36 #include "components/crash/content/app/crashpad.h" | 34 #include "components/crash/content/app/crashpad.h" |
37 #include "components/crash/content/app/run_as_crashpad_handler_win.h" | 35 #include "components/crash/content/app/run_as_crashpad_handler_win.h" |
38 #include "components/startup_metric_utils/browser/startup_metric_utils.h" | 36 #include "components/startup_metric_utils/browser/startup_metric_utils.h" |
39 #include "components/startup_metric_utils/common/pre_read_field_trial_utils_win.
h" | 37 #include "components/startup_metric_utils/common/pre_read_field_trial_utils_win.
h" |
40 #include "content/public/common/content_switches.h" | 38 #include "content/public/common/content_switches.h" |
41 #include "content/public/common/result_codes.h" | 39 #include "content/public/common/result_codes.h" |
42 | 40 |
43 namespace { | 41 namespace { |
44 | 42 |
45 base::LazyInstance<ChromeCrashReporterClient>::Leaky g_chrome_crash_client = | |
46 LAZY_INSTANCE_INITIALIZER; | |
47 | |
48 base::LazyInstance<std::vector<crash_reporter::Report>>::Leaky g_crash_reports = | |
49 LAZY_INSTANCE_INITIALIZER; | |
50 | |
51 // List of switches that it's safe to rendezvous early with. Fast start should | 43 // List of switches that it's safe to rendezvous early with. Fast start should |
52 // not be done if a command line contains a switch not in this set. | 44 // not be done if a command line contains a switch not in this set. |
53 // Note this is currently stored as a list of two because it's probably faster | 45 // Note this is currently stored as a list of two because it's probably faster |
54 // to iterate over this small array than building a map for constant time | 46 // to iterate over this small array than building a map for constant time |
55 // lookups. | 47 // lookups. |
56 const char* const kFastStartSwitches[] = { | 48 const char* const kFastStartSwitches[] = { |
57 switches::kProfileDirectory, | 49 switches::kProfileDirectory, |
58 switches::kShowAppList, | 50 switches::kShowAppList, |
59 }; | 51 }; |
60 | 52 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 194 |
203 // Return if we changed anything so that we can restart. | 195 // Return if we changed anything so that we can restart. |
204 return tokens.size() != initial_size && result == ERROR_SUCCESS; | 196 return tokens.size() != initial_size && result == ERROR_SUCCESS; |
205 } | 197 } |
206 } | 198 } |
207 return false; | 199 return false; |
208 } | 200 } |
209 | 201 |
210 } // namespace | 202 } // namespace |
211 | 203 |
212 // This helper is looked up in the browser to retrieve the crash reports. See | |
213 // CrashUploadListCrashpad. Note that we do not pass an std::vector here, | |
214 // because we do not want to allocate/free in different modules. The returned | |
215 // pointer is read-only. | |
216 extern "C" __declspec(dllexport) void GetCrashReportsImpl( | |
217 const crash_reporter::Report** reports, | |
218 size_t* report_count) { | |
219 crash_reporter::GetReports(g_crash_reports.Pointer()); | |
220 *reports = g_crash_reports.Pointer()->data(); | |
221 *report_count = g_crash_reports.Pointer()->size(); | |
222 } | |
223 | |
224 #if !defined(WIN_CONSOLE_APP) | 204 #if !defined(WIN_CONSOLE_APP) |
225 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { | 205 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { |
226 #else | 206 #else |
227 int main() { | 207 int main() { |
228 HINSTANCE instance = GetModuleHandle(nullptr); | 208 HINSTANCE instance = GetModuleHandle(nullptr); |
229 #endif | 209 #endif |
230 // Initialize the CommandLine singleton from the environment. | 210 // Initialize the CommandLine singleton from the environment. |
231 base::CommandLine::Init(0, nullptr); | 211 base::CommandLine::Init(0, nullptr); |
232 const base::CommandLine* command_line = | 212 const base::CommandLine* command_line = |
233 base::CommandLine::ForCurrentProcess(); | 213 base::CommandLine::ForCurrentProcess(); |
234 | 214 |
235 const std::string process_type = | 215 const std::string process_type = |
236 command_line->GetSwitchValueASCII(switches::kProcessType); | 216 command_line->GetSwitchValueASCII(switches::kProcessType); |
237 | 217 |
238 startup_metric_utils::InitializePreReadOptions( | 218 startup_metric_utils::InitializePreReadOptions( |
239 BrowserDistribution::GetDistribution()->GetRegistryPath()); | 219 BrowserDistribution::GetDistribution()->GetRegistryPath()); |
240 | 220 |
241 // Confirm that an explicit prefetch profile is used for all process types | 221 // Confirm that an explicit prefetch profile is used for all process types |
242 // except for the browser process. Any new process type will have to assign | 222 // except for the browser process. Any new process type will have to assign |
243 // itself a prefetch id. See kPrefetchArgument* constants in | 223 // itself a prefetch id. See kPrefetchArgument* constants in |
244 // content_switches.cc for details. | 224 // content_switches.cc for details. |
245 DCHECK(process_type.empty() || | 225 DCHECK(process_type.empty() || |
246 HasValidWindowsPrefetchArgument(*command_line)); | 226 HasValidWindowsPrefetchArgument(*command_line)); |
247 | 227 |
248 if (process_type == crash_reporter::switches::kCrashpadHandler) { | 228 if (process_type == crash_reporter::switches::kCrashpadHandler) { |
249 return crash_reporter::RunAsCrashpadHandler( | 229 return crash_reporter::RunAsCrashpadHandler( |
250 *base::CommandLine::ForCurrentProcess()); | 230 *base::CommandLine::ForCurrentProcess()); |
251 } | 231 } |
252 | 232 |
253 crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer()); | |
254 crash_reporter::InitializeCrashpadWithEmbeddedHandler(process_type.empty(), | |
255 process_type); | |
256 | |
257 startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now()); | 233 startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now()); |
258 | 234 |
259 // Signal Chrome Elf that Chrome has begun to start. | 235 // Signal Chrome Elf that Chrome has begun to start. |
260 SignalChromeElf(); | 236 SignalChromeElf(); |
261 | 237 |
262 // The exit manager is in charge of calling the dtors of singletons. | 238 // The exit manager is in charge of calling the dtors of singletons. |
263 base::AtExitManager exit_manager; | 239 base::AtExitManager exit_manager; |
264 | 240 |
265 EnableHighDPISupport(); | 241 EnableHighDPISupport(); |
266 | 242 |
267 if (AttemptFastNotify(*command_line)) | 243 if (AttemptFastNotify(*command_line)) |
268 return 0; | 244 return 0; |
269 | 245 |
270 RemoveAppCompatFlagsEntry(); | 246 RemoveAppCompatFlagsEntry(); |
271 | 247 |
272 // Load and launch the chrome dll. *Everything* happens inside. | 248 // Load and launch the chrome dll. *Everything* happens inside. |
273 VLOG(1) << "About to load main DLL."; | 249 VLOG(1) << "About to load main DLL."; |
274 MainDllLoader* loader = MakeMainDllLoader(); | 250 MainDllLoader* loader = MakeMainDllLoader(); |
275 int rc = loader->Launch(instance); | 251 int rc = loader->Launch(instance); |
276 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); | 252 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); |
277 delete loader; | 253 delete loader; |
278 return rc; | 254 return rc; |
279 } | 255 } |
OLD | NEW |