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