diff options
author | scottmg <scottmg@chromium.org> | 2015-11-25 13:55:47 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-25 21:57:07 +0000 |
commit | aaa2ff656f9fcabcbdd9e9964e3b2bdc8f5102ed (patch) | |
tree | 28f1fef91043cd3f7a30c85ce59e56b057102207 /chrome | |
parent | cbc1cd295bc85219ad89326457cd7f5cf003d41c (diff) | |
download | chromium_src-aaa2ff656f9fcabcbdd9e9964e3b2bdc8f5102ed.zip chromium_src-aaa2ff656f9fcabcbdd9e9964e3b2bdc8f5102ed.tar.gz chromium_src-aaa2ff656f9fcabcbdd9e9964e3b2bdc8f5102ed.tar.bz2 |
Crashpad Windows: Use the Crashpad client instead of Breakpad on Windows
Crashpad is always compiled into chrome and its handler is always
enabled. It only uploads in Official builds.
On Windows, the crash handler is chrome.exe run with a
--crashpad-handler argument. This is due to concern about
incompatibilities of shipping an additional new different binary for AV,
firewalls, etc.
Sample renderer crash/1aed2bc785e28995
Sample browser: crash/66c822815474a5d8
See also http://crbug.com/427611 .
R=mark@chromium.org,cpu@chromium.org
BUG=447073,546288, 456193
Review URL: https://codereview.chromium.org/1416133003
Cr-Commit-Position: refs/heads/master@{#361742}
Diffstat (limited to 'chrome')
26 files changed, 129 insertions, 271 deletions
diff --git a/chrome/BUILD.gn b/chrome/BUILD.gn index 161cf0d..33f9136 100644 --- a/chrome/BUILD.gn +++ b/chrome/BUILD.gn @@ -158,6 +158,7 @@ if (!is_android) { "//content/public/common:static_switches", "//crypto", "//sandbox", + "//third_party/crashpad/crashpad/handler:handler_lib", "//ui/gfx", "//win8/delegate_execute", "//win8/metro_driver", @@ -404,6 +405,8 @@ if (is_mac || is_win) { shared_library("chrome_child") { sources = [ + "app/chrome_crash_reporter_client.cc", + "app/chrome_crash_reporter_client.h", "app/chrome_main.cc", "app/chrome_main_delegate.cc", "app/chrome_main_delegate.h", @@ -421,6 +424,8 @@ if (is_mac || is_win) { "//base/allocator", "//build/config/sanitizers:deps", "//chrome/browser/policy:path_parser", + "//components/browser_watcher:browser_watcher_client", + "//components/crash/content/app", "//content/public/app:child", ] diff --git a/chrome/app/DEPS b/chrome/app/DEPS index cd3a112..f306bcb 100644 --- a/chrome/app/DEPS +++ b/chrome/app/DEPS @@ -30,4 +30,5 @@ include_rules = [ "+remoting/client/plugin", "+sandbox", "+syzygy/kasko/api", + "+third_party/crashpad/crashpad", ] diff --git a/chrome/app/chrome_crash_reporter_client.cc b/chrome/app/chrome_crash_reporter_client.cc index 49c8c49..2663a08 100644 --- a/chrome/app/chrome_crash_reporter_client.cc +++ b/chrome/app/chrome_crash_reporter_client.cc @@ -292,17 +292,7 @@ bool ChromeCrashReporterClient::GetCrashDumpLocation( } size_t ChromeCrashReporterClient::RegisterCrashKeys() { - // Note: On Windows this only affects the EXE. A separate invocation from - // child_process_logging_win.cc registers crash keys for Chrome.dll. -#if defined(OS_WIN) && defined(COMPONENT_BUILD) - // On Windows, this is not called in a component build, as in that case a - // single copy of 'base' is shared by the EXE and the various DLLs, and that - // copy is configured by child_process_logging_win.cc. - NOTREACHED(); - return 0; -#else return crash_keys::RegisterChromeCrashKeys(); -#endif } bool ChromeCrashReporterClient::IsRunningUnattended() { diff --git a/chrome/app/chrome_exe_main_win.cc b/chrome/app/chrome_exe_main_win.cc index e3e1754..cf91743 100644 --- a/chrome/app/chrome_exe_main_win.cc +++ b/chrome/app/chrome_exe_main_win.cc @@ -7,12 +7,14 @@ #include <shellscalingapi.h> #include <tchar.h> +#include <algorithm> #include <string> #include "base/at_exit.h" #include "base/command_line.h" #include "base/files/file_path.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/main_dll_loader_win.h" @@ -22,7 +24,9 @@ #include "chrome/common/chrome_switches.h" #include "chrome_elf/chrome_elf_main.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" +#include "third_party/crashpad/crashpad/handler/handler_main.h" #include "ui/gfx/win/dpi.h" namespace { @@ -121,6 +125,35 @@ 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; + } + return false; +} + } // namespace #if !defined(WIN_CONSOLE_APP) @@ -129,6 +162,10 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { int main() { HINSTANCE instance = GetModuleHandle(NULL); #endif + int rc; + if (RunAsCrashpadHandler(GetCommandLine(), &rc)) + return rc; + SwitchToLFHeap(); startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now()); @@ -153,7 +190,7 @@ int main() { // Load and launch the chrome dll. *Everything* happens inside. VLOG(1) << "About to load main DLL."; MainDllLoader* loader = MakeMainDllLoader(); - int rc = loader->Launch(instance); + rc = loader->Launch(instance); loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); delete loader; return rc; diff --git a/chrome/app/chrome_main_delegate.cc b/chrome/app/chrome_main_delegate.cc index cb27994..eef47b8 100644 --- a/chrome/app/chrome_main_delegate.cc +++ b/chrome/app/chrome_main_delegate.cc @@ -20,6 +20,7 @@ #include "base/time/time.h" #include "base/trace_event/trace_event_impl.h" #include "build/build_config.h" +#include "chrome/app/chrome_crash_reporter_client.h" #include "chrome/browser/chrome_content_browser_client.h" #include "chrome/browser/defaults.h" #include "chrome/common/channel_info.h" @@ -40,6 +41,7 @@ #include "chrome/utility/chrome_content_utility_client.h" #include "components/component_updater/component_updater_paths.h" #include "components/content_settings/core/common/content_settings_pattern.h" +#include "components/crash/content/app/crash_reporter_client.h" #include "components/version_info/version_info.h" #include "content/public/common/content_client.h" #include "content/public/common/content_paths.h" @@ -55,6 +57,7 @@ #include "chrome/app/close_handle_hook_win.h" #include "chrome/common/child_process_logging.h" #include "chrome/common/v8_breakpad_support_win.h" +#include "components/crash/content/app/crashpad.h" #include "sandbox/win/src/sandbox.h" #include "ui/base/resource/resource_bundle_win.h" #endif @@ -64,7 +67,7 @@ #include "chrome/app/chrome_main_mac.h" #include "chrome/browser/mac/relauncher.h" #include "chrome/common/mac/cfbundle_blocker.h" -#include "components/crash/content/app/crashpad_mac.h" +#include "components/crash/content/app/crashpad.h" #include "components/crash/core/common/objc_zombie.h" #include "ui/base/l10n/l10n_util_mac.h" #endif @@ -72,8 +75,6 @@ #if defined(OS_POSIX) #include <locale.h> #include <signal.h> -#include "chrome/app/chrome_crash_reporter_client.h" -#include "components/crash/content/app/crash_reporter_client.h" #endif #if !defined(DISABLE_NACL) && defined(OS_LINUX) @@ -145,7 +146,7 @@ base::LazyInstance<ChromeContentBrowserClient> g_chrome_content_browser_client = LAZY_INSTANCE_INITIALIZER; #endif -#if defined(OS_POSIX) +#if defined(OS_POSIX) || defined(OS_WIN) base::LazyInstance<ChromeCrashReporterClient>::Leaky g_chrome_crash_client = LAZY_INSTANCE_INITIALIZER; #endif @@ -448,7 +449,6 @@ bool ChromeMainDelegate::BasicStartupComplete(int* exit_code) { const base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); - #if defined(OS_WIN) // Browser should not be sandboxed. const bool is_browser = !command_line.HasSwitch(switches::kProcessType); @@ -665,7 +665,7 @@ void ChromeMainDelegate::PreSandboxStartup() { std::string process_type = command_line.GetSwitchValueASCII(switches::kProcessType); -#if defined(OS_POSIX) +#if defined(OS_POSIX) || defined(OS_WIN) crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer()); #endif @@ -680,6 +680,16 @@ void ChromeMainDelegate::PreSandboxStartup() { #endif #if defined(OS_WIN) + // TODO(scottmg): It would be nice to do this earlier to catch early crashes, + // perhaps as early as WinMain in chrome.exe. This would require some code + // restructuring to have paths and command lines set up, and also to handle + // having some of the code live in chrome.exe, while having the database be + // accessed by browser code in chrome.dll (to get a list of uploaded crashes + // for chrome://crashes). + crash_reporter::InitializeCrashpad(process_type.empty(), process_type); +#endif // OS_WIN + +#if defined(OS_WIN) child_process_logging::Init(); #endif #if defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX)) diff --git a/chrome/app/main_dll_loader_win.cc b/chrome/app/main_dll_loader_win.cc index ba14dba..08ce848 100644 --- a/chrome/app/main_dll_loader_win.cc +++ b/chrome/app/main_dll_loader_win.cc @@ -21,6 +21,7 @@ #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "base/trace_event/trace_event.h" +#include "base/win/metro.h" #include "base/win/scoped_handle.h" #include "base/win/windows_version.h" #include "chrome/app/chrome_crash_reporter_client.h" @@ -39,8 +40,8 @@ #include "chrome/installer/util/install_util.h" #include "chrome/installer/util/module_util_win.h" #include "chrome/installer/util/util_constants.h" -#include "components/crash/content/app/breakpad_win.h" #include "components/crash/content/app/crash_reporter_client.h" +#include "components/crash/content/app/crashpad.h" #include "content/public/app/sandbox_helper_win.h" #include "content/public/common/content_switches.h" #include "sandbox/win/src/sandbox.h" @@ -51,9 +52,6 @@ typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*); typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)(); -base::LazyInstance<ChromeCrashReporterClient>::Leaky g_chrome_crash_client = - LAZY_INSTANCE_INITIALIZER; - // Loads |module| after setting the CWD to |module|'s directory. Returns a // reference to the loaded module on success, or null on error. HMODULE LoadModuleWithDirectory(const base::FilePath& module, bool pre_read) { @@ -80,11 +78,6 @@ void ClearDidRun(const base::FilePath& dll_path) { GoogleUpdateSettings::UpdateDidRunState(false, system_level); } -bool InMetroMode() { - return (wcsstr( - ::GetCommandLineW(), L" -ServerName:DefaultBrowserServer") != nullptr); -} - typedef int (*InitMetro)(); } // namespace @@ -92,7 +85,7 @@ typedef int (*InitMetro)(); //============================================================================= MainDllLoader::MainDllLoader() - : dll_(nullptr), metro_mode_(InMetroMode()) { + : dll_(nullptr), metro_mode_(base::win::IsMetroProcess()) { } MainDllLoader::~MainDllLoader() { @@ -204,18 +197,6 @@ int MainDllLoader::Launch(HINSTANCE instance) { sandbox::SandboxInterfaceInfo sandbox_info = {0}; content::InitializeSandboxInfo(&sandbox_info); - crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer()); - bool exit_now = true; - if (process_type_.empty()) { - if (breakpad::ShowRestartDialogIfCrashed(&exit_now)) { - // We restarted because of a previous crash. Ask user if we should - // Relaunch. Only for the browser process. See crbug.com/132119. - if (exit_now) - return content::RESULT_CODE_NORMAL_EXIT; - } - } - breakpad::InitCrashReporter(process_type_); - dll_ = Load(&version, &file); if (!dll_) return chrome::RESULT_CODE_MISSING_DATA; @@ -228,12 +209,6 @@ int MainDllLoader::Launch(HINSTANCE instance) { reinterpret_cast<DLL_MAIN>(::GetProcAddress(dll_, "ChromeMain")); int rc = chrome_main(instance, &sandbox_info); rc = OnBeforeExit(rc, file); - // Sandboxed processes close some system DLL handles after lockdown so ignore - // EXCEPTION_INVALID_HANDLE generated on Windows 10 during shutdown of these - // processes. - // TODO(wfh): Check whether MS have fixed this in Win10 RTM. crbug.com/456193 - if (base::win::GetVersion() >= base::win::VERSION_WIN10) - breakpad::ConsumeInvalidHandleExceptions(); return rc; } @@ -275,7 +250,13 @@ void ChromeDllLoader::OnBeforeLaunch(const std::string& process_type, RecordDidRun(dll_path); // Launch the watcher process if stats collection consent has been granted. - if (g_chrome_crash_client.Get().GetCollectStatsConsent()) { +#if defined(GOOGLE_CHROME_BUILD) + const bool stats_collection_consent = + GoogleUpdateSettings::GetCollectStatsConsent(); +#else + const bool stats_collection_consent = false; +#endif + if (stats_collection_consent) { base::FilePath exe_path; if (PathService::Get(base::FILE_EXE, &exe_path)) { chrome_watcher_client_.reset(new ChromeWatcherClient( diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn index d09b1f2..5ac3616 100644 --- a/chrome/browser/BUILD.gn +++ b/chrome/browser/BUILD.gn @@ -612,7 +612,7 @@ source_set("browser") { } else { sources -= [ "password_manager/password_store_x.cc" ] } - if (is_posix && !is_mac && !is_ios) { + if ((is_posix && !is_mac && !is_ios) || is_win) { sources += [ "//chrome/app/chrome_crash_reporter_client.cc", "//chrome/app/chrome_crash_reporter_client.h", diff --git a/chrome/browser/chrome_browser_main_mac.mm b/chrome/browser/chrome_browser_main_mac.mm index 5423f6d..4b8d76b 100644 --- a/chrome/browser/chrome_browser_main_mac.mm +++ b/chrome/browser/chrome_browser_main_mac.mm @@ -24,7 +24,7 @@ #include "chrome/browser/ui/app_list/app_list_service.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" -#include "components/crash/content/app/crashpad_mac.h" +#include "components/crash/content/app/crashpad.h" #include "components/metrics/metrics_service.h" #include "content/public/common/main_function_params.h" #include "content/public/common/result_codes.h" diff --git a/chrome/browser/crash_upload_list.cc b/chrome/browser/crash_upload_list.cc index 82e17d4..9e30d84 100644 --- a/chrome/browser/crash_upload_list.cc +++ b/chrome/browser/crash_upload_list.cc @@ -11,10 +11,8 @@ #include "chrome/common/chrome_paths.h" #include "content/public/browser/browser_thread.h" -#if defined(OS_WIN) -#include "chrome/browser/crash_upload_list_win.h" -#elif defined(OS_MACOSX) -#include "chrome/browser/crash_upload_list_mac.h" +#if defined(OS_MACOSX) || defined(OS_WIN) +#include "chrome/browser/crash_upload_list_crashpad.h" #endif scoped_refptr<CrashUploadList> CreateCrashUploadList( @@ -23,12 +21,9 @@ scoped_refptr<CrashUploadList> CreateCrashUploadList( PathService::Get(chrome::DIR_CRASH_DUMPS, &crash_dir_path); base::FilePath upload_log_path = crash_dir_path.AppendASCII(CrashUploadList::kReporterLogFilename); -#if defined(OS_WIN) - return new CrashUploadListWin(delegate, upload_log_path, - content::BrowserThread::GetBlockingPool()); -#elif defined(OS_MACOSX) - return new CrashUploadListMac(delegate, upload_log_path, - content::BrowserThread::GetBlockingPool()); +#if defined(OS_MACOSX) || defined(OS_WIN) + return new CrashUploadListCrashpad(delegate, upload_log_path, + content::BrowserThread::GetBlockingPool()); #else return new CrashUploadList(delegate, upload_log_path, content::BrowserThread::GetBlockingPool()); diff --git a/chrome/browser/crash_upload_list_mac.cc b/chrome/browser/crash_upload_list_crashpad.cc index 8148847..a2a4bbd 100644 --- a/chrome/browser/crash_upload_list_mac.cc +++ b/chrome/browser/crash_upload_list_crashpad.cc @@ -2,23 +2,21 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/crash_upload_list_mac.h" +#include "chrome/browser/crash_upload_list_crashpad.h" #include "base/threading/sequenced_worker_pool.h" #include "base/time/time.h" -#include "components/crash/content/app/crashpad_mac.h" +#include "components/crash/content/app/crashpad.h" -CrashUploadListMac::CrashUploadListMac( +CrashUploadListCrashpad::CrashUploadListCrashpad( Delegate* delegate, const base::FilePath& upload_log_path, const scoped_refptr<base::SequencedWorkerPool>& worker_pool) - : CrashUploadList(delegate, upload_log_path, worker_pool) { -} + : CrashUploadList(delegate, upload_log_path, worker_pool) {} -CrashUploadListMac::~CrashUploadListMac() { -} +CrashUploadListCrashpad::~CrashUploadListCrashpad() {} -void CrashUploadListMac::LoadUploadList() { +void CrashUploadListCrashpad::LoadUploadList() { std::vector<crash_reporter::UploadedReport> uploaded_reports; crash_reporter::GetUploadedReports(&uploaded_reports); @@ -28,7 +26,6 @@ void CrashUploadListMac::LoadUploadList() { AppendUploadInfo( UploadInfo(uploaded_report.remote_id, base::Time::FromTimeT(uploaded_report.creation_time), - uploaded_report.local_id, - base::Time())); + uploaded_report.local_id, base::Time())); } } diff --git a/chrome/browser/crash_upload_list_mac.h b/chrome/browser/crash_upload_list_crashpad.h index f7fb4f1..d884640 100644 --- a/chrome/browser/crash_upload_list_mac.h +++ b/chrome/browser/crash_upload_list_crashpad.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_CRASH_UPLOAD_LIST_MAC_H_ -#define CHROME_BROWSER_CRASH_UPLOAD_LIST_MAC_H_ +#ifndef CHROME_BROWSER_CRASH_UPLOAD_LIST_CRASHPAD_H_ +#define CHROME_BROWSER_CRASH_UPLOAD_LIST_CRASHPAD_H_ #include "base/macros.h" #include "components/upload_list/crash_upload_list.h" @@ -15,23 +15,23 @@ class SequencedWorkerPool; // A CrashUploadList that retrieves the list of uploaded reports from the // Crashpad database. -class CrashUploadListMac : public CrashUploadList { +class CrashUploadListCrashpad : public CrashUploadList { public: // The |upload_log_path| argument is unused. It is only accepted because the // base class constructor requires it, although it is entirely unused with // LoadUploadList() being overridden. - CrashUploadListMac( + CrashUploadListCrashpad( Delegate* delegate, const base::FilePath& upload_log_path, const scoped_refptr<base::SequencedWorkerPool>& worker_pool); protected: - ~CrashUploadListMac() override; + ~CrashUploadListCrashpad() override; // Called on a blocking pool thread. void LoadUploadList() override; - DISALLOW_COPY_AND_ASSIGN(CrashUploadListMac); + DISALLOW_COPY_AND_ASSIGN(CrashUploadListCrashpad); }; -#endif // CHROME_BROWSER_CRASH_UPLOAD_LIST_MAC_H_ +#endif // CHROME_BROWSER_CRASH_UPLOAD_LIST_CRASHPAD_H_ diff --git a/chrome/browser/crash_upload_list_win.cc b/chrome/browser/crash_upload_list_win.cc deleted file mode 100644 index a85e321..0000000 --- a/chrome/browser/crash_upload_list_win.cc +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/crash_upload_list_win.h" - -#include "base/strings/string_util.h" -#include "base/strings/stringprintf.h" -#include "base/strings/sys_string_conversions.h" -#include "base/threading/sequenced_worker_pool.h" - -CrashUploadListWin::CrashUploadListWin( - Delegate* delegate, - const base::FilePath& upload_log_path, - const scoped_refptr<base::SequencedWorkerPool>& worker_pool) - : CrashUploadList(delegate, upload_log_path, worker_pool) {} - -void CrashUploadListWin::LoadUploadList() { - std::vector<uint8> buffer(1024); - HANDLE event_log = OpenEventLog(NULL, L"Application"); - if (event_log) { - ClearUploads(); - while (true) { - DWORD bytes_read; - DWORD bytes_needed; - BOOL success = - ReadEventLog(event_log, - EVENTLOG_SEQUENTIAL_READ | EVENTLOG_BACKWARDS_READ, - 0, - &buffer[0], - buffer.size(), - &bytes_read, - &bytes_needed); - if (success) { - DWORD record_offset = 0; - // The ReadEventLog() API docs imply, but do not explicitly state that - // partial records will not be returned. Use DCHECK() to affirm this. - while (record_offset < bytes_read) { - DCHECK(record_offset + sizeof(EVENTLOGRECORD) <= bytes_read); - EVENTLOGRECORD* record = (EVENTLOGRECORD*)&buffer[record_offset]; - DCHECK(record_offset + record->Length <= bytes_read); - if (IsPossibleCrashLogRecord(record)) - ProcessPossibleCrashLogRecord(record); - record_offset += record->Length; - } - } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { - // Resize buffer to the required minimum size. - buffer.resize(bytes_needed); - } else { - // Stop on any other error, including the expected case - // of ERROR_HANDLE_EOF. - DCHECK(GetLastError() == ERROR_HANDLE_EOF); - break; - } - } - CloseEventLog(event_log); - } -} - -CrashUploadListWin::~CrashUploadListWin() { -} - -bool CrashUploadListWin::IsPossibleCrashLogRecord( - EVENTLOGRECORD* record) const { - LPWSTR provider_name = (LPWSTR)((uint8*)record + sizeof(EVENTLOGRECORD)); - return !wcscmp(L"Chrome", provider_name) && - record->EventType == EVENTLOG_INFORMATION_TYPE && - record->NumStrings >= 1; -} - -void CrashUploadListWin::ProcessPossibleCrashLogRecord(EVENTLOGRECORD* record) { - // Add the crash if the message matches the expected pattern. - const std::wstring pattern_prefix(L"Id="); - const std::wstring pattern_suffix(L"."); - std::wstring message((LPWSTR)((uint8*)record + record->StringOffset)); - size_t start_index = message.find(pattern_prefix); - if (start_index != std::wstring::npos) { - start_index += pattern_prefix.size(); - size_t end_index = message.find(pattern_suffix, start_index); - if (end_index != std::wstring::npos) { - std::wstring crash_id = - message.substr(start_index, end_index - start_index); - AppendUploadInfo( - UploadInfo(base::SysWideToUTF8(crash_id), - base::Time::FromDoubleT(record->TimeGenerated))); - } - } -} diff --git a/chrome/browser/crash_upload_list_win.h b/chrome/browser/crash_upload_list_win.h deleted file mode 100644 index 40d8ccf..0000000 --- a/chrome/browser/crash_upload_list_win.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_CRASH_UPLOAD_LIST_WIN_H_ -#define CHROME_BROWSER_CRASH_UPLOAD_LIST_WIN_H_ - -#include "base/macros.h" -#include "components/upload_list/crash_upload_list.h" - -namespace base { -class FilePath; -class SequencedWorkerPool; -} - -// A CrashUploadList that retrieves the list of reported crashes -// from the Windows Event Log. -class CrashUploadListWin : public CrashUploadList { - public: - CrashUploadListWin( - Delegate* delegate, - const base::FilePath& upload_log_path, - const scoped_refptr<base::SequencedWorkerPool>& worker_pool); - - protected: - // Loads the list of crashes from the Windows Event Log. - void LoadUploadList() override; - - private: - ~CrashUploadListWin() override; - - // Returns whether the event record is likely a Chrome crash log. - bool IsPossibleCrashLogRecord(EVENTLOGRECORD* record) const; - - // Parses the event record and adds it to the crash list. - void ProcessPossibleCrashLogRecord(EVENTLOGRECORD* record); - - DISALLOW_COPY_AND_ASSIGN(CrashUploadListWin); -}; - -#endif // CHROME_BROWSER_CRASH_UPLOAD_LIST_WIN_H_ diff --git a/chrome/browser/google/google_update_settings_posix.cc b/chrome/browser/google/google_update_settings_posix.cc index 8cfadc8..c75f806 100644 --- a/chrome/browser/google/google_update_settings_posix.cc +++ b/chrome/browser/google/google_update_settings_posix.cc @@ -13,7 +13,7 @@ #include "chrome/common/chrome_paths.h" #if defined(OS_MACOSX) -#include "components/crash/content/app/crashpad_mac.h" +#include "components/crash/content/app/crashpad.h" #endif namespace { diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 6653fee..f043321 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -428,10 +428,6 @@ 'browser/component_updater/swiftshader_component_installer.h', 'browser/crash_upload_list.cc', 'browser/crash_upload_list.h', - 'browser/crash_upload_list_mac.cc', - 'browser/crash_upload_list_mac.h', - 'browser/crash_upload_list_win.cc', - 'browser/crash_upload_list_win.h', 'browser/custom_handlers/protocol_handler_registry.cc', 'browser/custom_handlers/protocol_handler_registry.h', 'browser/custom_handlers/protocol_handler_registry_factory.cc', @@ -1345,6 +1341,8 @@ ], # Sources (generally "desktop OS importers") used only on Mac & Windows. 'chrome_browser_win_mac_sources': [ + 'browser/crash_upload_list_crashpad.cc', + 'browser/crash_upload_list_crashpad.h', 'browser/media_galleries/fileapi/file_path_watcher_util.cc', 'browser/media_galleries/fileapi/file_path_watcher_util.h', 'browser/media_galleries/fileapi/iapps_data_provider.cc', diff --git a/chrome/chrome_dll.gypi b/chrome/chrome_dll.gypi index 0ea9690..09c93d5 100644 --- a/chrome/chrome_dll.gypi +++ b/chrome/chrome_dll.gypi @@ -123,7 +123,9 @@ ], 'dependencies': [ '<@(chromium_browser_dependencies)', + '../components/components.gyp:crash_component', '../content/content.gyp:content_app_browser', + '../third_party/crashpad/crashpad/handler/handler.gyp:crashpad_handler', ], 'conditions': [ ['OS=="win"', { @@ -163,6 +165,8 @@ ], 'sources': [ 'app/chrome_dll.rc', + 'app/chrome_crash_reporter_client.cc', + 'app/chrome_crash_reporter_client.h', # ETW Manifest. '<(SHARED_INTERMEDIATE_DIR)/base/trace_event/etw_manifest/chrome_events_win.rc', @@ -350,6 +354,8 @@ }, 'dependencies': [ '<@(chromium_child_dependencies)', + '../components/components.gyp:browser_watcher_client', + '../components/components.gyp:crash_component', '../content/content.gyp:content_app_child', 'chrome_version_resources', 'policy_path_parser', @@ -359,6 +365,8 @@ ], 'sources': [ '<(SHARED_INTERMEDIATE_DIR)/chrome_version/chrome_dll_version.rc', + 'app/chrome_crash_reporter_client.cc', + 'app/chrome_crash_reporter_client.h', 'app/chrome_main.cc', 'app/chrome_main_delegate.cc', 'app/chrome_main_delegate.h', @@ -392,6 +400,11 @@ }], ] }], + ['OS=="win" and configuration_policy==1', { + 'dependencies': [ + '<(DEPTH)/components/components.gyp:policy', + ], + }], ['enable_plugins==1', { 'dependencies': [ '../pdf/pdf.gyp:pdf', diff --git a/chrome/chrome_exe.gypi b/chrome/chrome_exe.gypi index 286db96..1fd5b77 100644 --- a/chrome/chrome_exe.gypi +++ b/chrome/chrome_exe.gypi @@ -105,6 +105,7 @@ 'chrome_watcher', 'chrome_watcher_client', '../components/components.gyp:browser_watcher_client', + '../third_party/crashpad/crashpad/handler/handler.gyp:crashpad_handler_lib', ], 'conditions': [ ['kasko==1', { @@ -432,8 +433,6 @@ ], 'sources': [ '<(SHARED_INTERMEDIATE_DIR)/chrome_version/chrome_exe_version.rc', - 'app/chrome_crash_reporter_client.cc', - 'app/chrome_crash_reporter_client.h', 'app/chrome_exe.rc', 'common/crash_keys.cc', 'common/crash_keys.h', diff --git a/chrome/chrome_installer.gypi b/chrome/chrome_installer.gypi index 12cbc5c..c9620cc 100644 --- a/chrome/chrome_installer.gypi +++ b/chrome/chrome_installer.gypi @@ -220,7 +220,7 @@ '../chrome/common_constants.gyp:common_constants', '../chrome/common_constants.gyp:version_header', '../chrome_elf/chrome_elf.gyp:chrome_elf_constants', - '../components/components.gyp:crash_component', + '../components/components.gyp:crash_component_breakpad_to_be_deleted', '../rlz/rlz.gyp:rlz_lib', '../third_party/zlib/zlib.gyp:zlib', ], diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index f43ce67..ab44161 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -2059,13 +2059,13 @@ 'include_dirs': [ '<(DEPTH)/third_party/wtl/include', ], - 'conditions': [ - ['use_aura==1', { - 'dependencies': [ - '../win8/win8.gyp:test_registrar_constants', - '../win8/win8.gyp:test_support_win8', - ], - }], + 'dependencies': [ + '../components/components.gyp:crash_component', + '../win8/win8.gyp:test_registrar_constants', + '../win8/win8.gyp:test_support_win8', + ], + 'sources': [ + 'app/chrome_crash_reporter_client.cc', ], }], ['OS=="win" or OS=="mac"', { diff --git a/chrome/common/child_process_logging_win.cc b/chrome/common/child_process_logging_win.cc index 9571701..4e3177c 100644 --- a/chrome/common/child_process_logging_win.cc +++ b/chrome/common/child_process_logging_win.cc @@ -16,57 +16,7 @@ namespace child_process_logging { -namespace { - -// exported in breakpad_win.cc: -// void __declspec(dllexport) __cdecl SetCrashKeyValueImpl. -typedef void (__cdecl *SetCrashKeyValue)(const wchar_t*, const wchar_t*); - -// exported in breakpad_win.cc: -// void __declspec(dllexport) __cdecl ClearCrashKeyValueImpl. -typedef void (__cdecl *ClearCrashKeyValue)(const wchar_t*); - -void SetCrashKeyValueTrampoline(const base::StringPiece& key, - const base::StringPiece& value) { - static SetCrashKeyValue set_crash_key = NULL; - if (!set_crash_key) { - HMODULE exe_module = GetModuleHandle(chrome::kBrowserProcessExecutableName); - if (!exe_module) - return; - set_crash_key = reinterpret_cast<SetCrashKeyValue>( - GetProcAddress(exe_module, "SetCrashKeyValueImpl")); - } - - if (set_crash_key) { - (set_crash_key)(base::UTF8ToWide(key).data(), - base::UTF8ToWide(value).data()); - } -} - -void ClearCrashKeyValueTrampoline(const base::StringPiece& key) { - static ClearCrashKeyValue clear_crash_key = NULL; - if (!clear_crash_key) { - HMODULE exe_module = GetModuleHandle(chrome::kBrowserProcessExecutableName); - if (!exe_module) - return; - clear_crash_key = reinterpret_cast<ClearCrashKeyValue>( - GetProcAddress(exe_module, "ClearCrashKeyValueImpl")); - } - - if (clear_crash_key) - (clear_crash_key)(base::UTF8ToWide(key).data()); -} - -} // namespace - void Init() { - // Note: on other platforms, this is set up during Breakpad initialization, - // in ChromeBreakpadClient. But on Windows, that is before the DLL module is - // loaded, which is a prerequisite of the crash key system. - crash_keys::RegisterChromeCrashKeys(); - base::debug::SetCrashKeyReportingFunctions( - &SetCrashKeyValueTrampoline, &ClearCrashKeyValueTrampoline); - // This would be handled by BreakpadClient::SetCrashClientIdFromGUID(), but // because of the aforementioned issue, crash keys aren't ready yet at the // time of Breakpad initialization, load the client id backed up in Google diff --git a/chrome/common/chrome_paths.cc b/chrome/common/chrome_paths.cc index f17ba29..66c7bf2 100644 --- a/chrome/common/chrome_paths.cc +++ b/chrome/common/chrome_paths.cc @@ -210,7 +210,7 @@ bool PathProvider(int key, base::FilePath* result) { if (!GetDefaultUserDataDirectory(&cur)) return false; #endif -#if defined(OS_MACOSX) +#if defined(OS_MACOSX) || defined(OS_WIN) cur = cur.Append(FILE_PATH_LITERAL("Crashpad")); #else cur = cur.Append(FILE_PATH_LITERAL("Crash Reports")); diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index c4f324d..5cd5b8e 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -1238,6 +1238,14 @@ const char kRelauncherProcessDMGDevice[] = "dmg-device"; #endif // defined(OS_MACOSX) #if defined(OS_WIN) +// A process type (switches::kProcessType) that indicates chrome.exe is being +// launched as crashpad_handler. This is only used on Windows. We bundle the +// handler into chrome.exe on Windows because there is high probability of a +// "new" .exe being blocked or interfered with by application firewalls, AV +// software, etc. On other platforms, crashpad_handler is a standalone +// executable. +const char kCrashpadHandler[] = "crashpad-handler"; + // Fallback to XPS. By default connector uses CDD. const char kEnableCloudPrintXps[] = "enable-cloud-print-xps"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index ce53949..b8c5eb8 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -353,6 +353,7 @@ extern const char kRelauncherProcessDMGDevice[]; #endif // defined(OS_MACOSX) #if defined(OS_WIN) +extern const char kCrashpadHandler[]; extern const char kEnableCloudPrintXps[]; extern const char kEnableProfileShortcutManager[]; extern const char kForceDesktop[]; diff --git a/chrome/common/crash_keys.cc b/chrome/common/crash_keys.cc index ad3fb13..1a670fb 100644 --- a/chrome/common/crash_keys.cc +++ b/chrome/common/crash_keys.cc @@ -87,7 +87,7 @@ size_t RegisterChromeCrashKeys() { // The following keys may be chunked by the underlying crash logging system, // but ultimately constitute a single key-value pair. base::debug::CrashKey fixed_keys[] = { -#if defined(OS_MACOSX) +#if defined(OS_MACOSX) || defined(OS_WIN) { kMetricsClientId, kSmallSize }, #else { kClientId, kSmallSize }, diff --git a/chrome/installer/setup/BUILD.gn b/chrome/installer/setup/BUILD.gn index c078292..9507e94 100644 --- a/chrome/installer/setup/BUILD.gn +++ b/chrome/installer/setup/BUILD.gn @@ -25,6 +25,7 @@ if (is_win) { "//base/allocator", "//build/config/sanitizers:deps", "//components/crash/content/app", + "//components/crash/content/app:app_breakpad_mac_win_to_be_deleted", ] } diff --git a/chrome/interactive_ui_tests.isolate b/chrome/interactive_ui_tests.isolate index d5af58e..5aa6cb5 100644 --- a/chrome/interactive_ui_tests.isolate +++ b/chrome/interactive_ui_tests.isolate @@ -95,6 +95,7 @@ 'variables': { 'files': [ '<(PRODUCT_DIR)/chrome_elf.dll', + '<(PRODUCT_DIR)/crashpad_handler.exe', '<(PRODUCT_DIR)/d3dcompiler_47.dll', '<(PRODUCT_DIR)/libEGL.dll', '<(PRODUCT_DIR)/libGLESv2.dll', |