From 6f8c46d2f436bdcc70b71d0bb692dc20b85acdf5 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 24 Nov 2013 17:35:58 +0800 Subject: [PATCH] win: Start as crash service when ATOM_SHELL_INTERNAL_CRASH_SERVICE is set. --- app/atom_main.cc | 7 ++++- atom.gyp | 1 + .../crash_reporter/win/crash_service_main.cc | 31 +++++++++++++++++-- .../crash_reporter/win/crash_service_main.h | 2 +- 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/app/atom_main.cc b/app/atom_main.cc index 2b0366da8ab..c673fdab67d 100644 --- a/app/atom_main.cc +++ b/app/atom_main.cc @@ -17,6 +17,7 @@ #include "app/atom_main_delegate.h" #include "base/environment.h" +#include "common/crash_reporter/win/crash_service_main.h" #include "content/public/app/startup_helper_win.h" #include "sandbox/win/src/sandbox_types.h" #else // defined(OS_WIN) @@ -47,7 +48,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) { freopen_s(&dontcare, "CON", "r", stdin); } - std::string node_indicator; + std::string node_indicator, crash_service_indicator; if (env->GetVar("ATOM_SHELL_INTERNAL_RUN_AS_NODE", &node_indicator) && node_indicator == "1") { // Convert argv to to UTF8 @@ -85,6 +86,10 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) { } // Now that conversion is done, we can finally start. return node::Start(argc, argv); + } else if (env->GetVar("ATOM_SHELL_INTERNAL_CRASH_SERVICE", + &crash_service_indicator) && + crash_service_indicator == "1") { + return crash_service::Main(cmd); } sandbox::SandboxInterfaceInfo sandbox_info = {0}; diff --git a/atom.gyp b/atom.gyp index 253f7b183f4..4bb0dfce9b6 100644 --- a/atom.gyp +++ b/atom.gyp @@ -340,6 +340,7 @@ '-limm32.lib', '-loleacc.lib', '-lComdlg32.lib', + '-lWininet.lib', '<(atom_source_root)/<(libchromiumcontent_library_dir)/chromiumviews.lib', ], }, diff --git a/common/crash_reporter/win/crash_service_main.cc b/common/crash_reporter/win/crash_service_main.cc index 172a8e05eea..fa2f450dfae 100644 --- a/common/crash_reporter/win/crash_service_main.cc +++ b/common/crash_reporter/win/crash_service_main.cc @@ -4,10 +4,37 @@ #include "common/crash_reporter/win/crash_service_main.h" +#include "base/at_exit.h" +#include "base/command_line.h" +#include "base/files/file_path.h" +#include "base/path_service.h" +#include "base/logging.h" +#include "common/crash_reporter/win/crash_service.h" + namespace crash_service { -int Main() { - return 0; +int Main(const wchar_t* cmd_line) { + // Initialize all Chromium things. + base::AtExitManager exit_manager; + CommandLine::Init(0, NULL); + + VLOG(1) << "Session start. cmdline is [" << cmd_line << "]"; + + wchar_t temp_dir[MAX_PATH] = { 0 }; + ::GetTempPathW(MAX_PATH, temp_dir); + base::FilePath temp_path(temp_dir); + + breakpad::CrashService crash_service; + if (!crash_service.Initialize(temp_path, temp_path)) + return 1; + + VLOG(1) << "Ready to process crash requests"; + + // Enter the message loop. + int retv = crash_service.ProcessingLoop(); + // Time to exit. + VLOG(1) << "Session end. return code is " << retv; + return retv; } } // namespace crash_service diff --git a/common/crash_reporter/win/crash_service_main.h b/common/crash_reporter/win/crash_service_main.h index 27af5d746be..3dd06f207f2 100644 --- a/common/crash_reporter/win/crash_service_main.h +++ b/common/crash_reporter/win/crash_service_main.h @@ -8,7 +8,7 @@ namespace crash_service { // Program entry, should be called by main(); -int Main(); +int Main(const wchar_t* cmd_line); } // namespace crash_service