Index: chrome/app/chrome_exe_main_win.cc |
diff --git a/chrome/app/chrome_exe_main_win.cc b/chrome/app/chrome_exe_main_win.cc |
index cf91743ebc07f49865ce0bd1745edea04d4c4f38..85a59617ef382b7b5393718822d5edfa86cf84d7 100644 |
--- a/chrome/app/chrome_exe_main_win.cc |
+++ b/chrome/app/chrome_exe_main_win.cc |
@@ -13,16 +13,21 @@ |
#include "base/at_exit.h" |
#include "base/command_line.h" |
#include "base/files/file_path.h" |
+#include "base/lazy_instance.h" |
#include "base/logging.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/time/time.h" |
#include "base/win/windows_version.h" |
+#include "chrome/app/chrome_crash_reporter_client.h" |
#include "chrome/app/main_dll_loader_win.h" |
#include "chrome/browser/chrome_process_finder_win.h" |
#include "chrome/browser/policy/policy_path_parser.h" |
+#include "chrome/common/chrome_paths.h" |
#include "chrome/common/chrome_paths_internal.h" |
#include "chrome/common/chrome_switches.h" |
#include "chrome_elf/chrome_elf_main.h" |
+#include "components/crash/content/app/crash_reporter_client.h" |
+#include "components/crash/content/app/crashpad.h" |
#include "components/startup_metric_utils/browser/startup_metric_utils.h" |
#include "content/public/common/content_switches.h" |
#include "content/public/common/result_codes.h" |
@@ -30,6 +35,10 @@ |
#include "ui/gfx/win/dpi.h" |
namespace { |
+ |
+base::LazyInstance<ChromeCrashReporterClient>::Leaky g_chrome_crash_client = |
+ LAZY_INSTANCE_INITIALIZER; |
+ |
// List of switches that it's safe to rendezvous early with. Fast start should |
// not be done if a command line contains a switch not in this set. |
// Note this is currently stored as a list of two because it's probably faster |
@@ -125,46 +134,67 @@ void SwitchToLFHeap() { |
} |
} |
-bool RunAsCrashpadHandler(wchar_t* command_line, int* rc) { |
- const base::CommandLine cmdline = base::CommandLine::FromString(command_line); |
- if (cmdline.GetSwitchValueASCII(switches::kProcessType) == |
- switches::kCrashpadHandler) { |
- std::vector<base::string16> argv = cmdline.argv(); |
- base::string16 process_type = |
- L"--" + base::UTF8ToUTF16(switches::kProcessType) + L"="; |
- argv.erase(std::remove_if(argv.begin(), argv.end(), |
- [&process_type](const base::string16& str) { |
- return str.compare(0, process_type.size(), |
- process_type) == 0; |
- }), |
- argv.end()); |
- |
- scoped_ptr<char* []> argv_as_utf8(new char*[argv.size() + 1]); |
- std::vector<std::string> storage; |
- storage.reserve(argv.size()); |
- for (size_t i = 0; i < argv.size(); ++i) { |
- storage.push_back(base::UTF16ToUTF8(argv[i])); |
- argv_as_utf8[i] = &storage[i][0]; |
- } |
- argv_as_utf8[argv.size()] = nullptr; |
- *rc = crashpad::HandlerMain(static_cast<int>(argv.size()), |
- argv_as_utf8.get()); |
- return true; |
+int RunAsCrashpadHandler(const base::CommandLine& command_line) { |
+ DCHECK_EQ(command_line.GetSwitchValueASCII(switches::kProcessType), |
+ switches::kCrashpadHandler); |
+ std::vector<base::string16> argv = command_line.argv(); |
+ base::string16 process_type = |
+ L"--" + base::UTF8ToUTF16(switches::kProcessType) + L"="; |
+ argv.erase(std::remove_if(argv.begin(), argv.end(), |
+ [&process_type](const base::string16& str) { |
+ return str.compare(0, process_type.size(), |
+ process_type) == 0; |
+ }), |
+ argv.end()); |
+ |
+ scoped_ptr<char* []> argv_as_utf8(new char*[argv.size() + 1]); |
+ std::vector<std::string> storage; |
+ storage.reserve(argv.size()); |
+ for (size_t i = 0; i < argv.size(); ++i) { |
+ storage.push_back(base::UTF16ToUTF8(argv[i])); |
+ argv_as_utf8[i] = &storage[i][0]; |
} |
- return false; |
+ argv_as_utf8[argv.size()] = nullptr; |
+ return crashpad::HandlerMain(static_cast<int>(argv.size()), |
+ argv_as_utf8.get()); |
} |
} // namespace |
+// This helper is looked up in the browser to retrieve the crash reports. See |
+// CrashUploadListCrashpad. |
+extern "C" __declspec(dllexport) void GetUploadedReportsImpl( |
+ std::vector<crash_reporter::UploadedReport>* uploaded_reports) { |
+ crash_reporter::GetUploadedReports(uploaded_reports); |
+} |
+ |
#if !defined(WIN_CONSOLE_APP) |
int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { |
#else |
int main() { |
- HINSTANCE instance = GetModuleHandle(NULL); |
+ HINSTANCE instance = GetModuleHandle(nullptr); |
#endif |
- int rc; |
- if (RunAsCrashpadHandler(GetCommandLine(), &rc)) |
- return rc; |
+ // Initialize the CommandLine singleton from the environment. |
+ base::CommandLine::Init(0, nullptr); |
+ |
+ // The exit manager is in charge of calling the dtors of singletons. |
+ base::AtExitManager exit_manager; |
+ |
+ std::string process_type = |
+ base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
+ switches::kProcessType); |
+ |
+ if (process_type == switches::kCrashpadHandler) |
+ return RunAsCrashpadHandler(*base::CommandLine::ForCurrentProcess()); |
+ |
+ // TODO(scottmg): This and the AtExitManager above are required so the crash |
+ // reporter knows where to store its dumps. We could potentially avoid this by |
+ // modifying ChromeCrashReporterClient to do that somehow else more manually |
+ // on Windows. |
Mark Mentovai
2015/12/02 03:05:07
Worth associating a bug?
scottmg
2015/12/02 05:35:00
Done.
|
+ chrome::RegisterPathProvider(); |
+ |
+ crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer()); |
+ crash_reporter::InitializeCrashpad(process_type.empty(), process_type); |
SwitchToLFHeap(); |
@@ -173,11 +203,6 @@ int main() { |
// Signal Chrome Elf that Chrome has begun to start. |
SignalChromeElf(); |
- // Initialize the commandline singleton from the environment. |
- base::CommandLine::Init(0, NULL); |
- // The exit manager is in charge of calling the dtors of singletons. |
- base::AtExitManager exit_manager; |
- |
// We don't want to set DPI awareness on pre-Win7 because we don't support |
// DirectWrite there. GDI fonts are kerned very badly, so better to leave |
// DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite(). |
@@ -190,7 +215,7 @@ int main() { |
// Load and launch the chrome dll. *Everything* happens inside. |
VLOG(1) << "About to load main DLL."; |
MainDllLoader* loader = MakeMainDllLoader(); |
- rc = loader->Launch(instance); |
+ int rc = loader->Launch(instance); |
loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); |
delete loader; |
return rc; |