From 9a825c5cbd46f3fc963616a1191ff55bf84eb36f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 11 Nov 2014 16:38:16 +0800 Subject: [PATCH] win: Writes uploads.log --- .../crash_reporter/win/crash_service.cc | 27 +++++++++++++++++++ spec/api-crash-reporter-spec.coffee | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/atom/common/crash_reporter/win/crash_service.cc b/atom/common/crash_reporter/win/crash_service.cc index 5cb6f9835138..ee77eb07f668 100644 --- a/atom/common/crash_reporter/win/crash_service.cc +++ b/atom/common/crash_reporter/win/crash_service.cc @@ -13,6 +13,8 @@ #include "base/command_line.h" #include "base/file_util.h" #include "base/logging.h" +#include "base/strings/string_number_conversions.h" +#include "base/time/time.h" #include "base/win/windows_version.h" #include "vendor/breakpad/src/client/windows/crash_generation/client_info.h" #include "vendor/breakpad/src/client/windows/crash_generation/crash_generation_server.h" @@ -66,6 +68,30 @@ bool WriteCustomInfoToFile(const std::wstring& dump_path, const CrashMap& map) { return true; } +bool WriteReportIDToFile(const std::wstring& dump_path, + const std::wstring& report_id) { + std::wstring file_path(dump_path); + size_t last_slash = file_path.rfind(L'\\'); + if (last_slash == std::wstring::npos) + return false; + file_path.resize(last_slash); + file_path += L"\\uploads.log"; + + std::wofstream file(file_path.c_str(), + std::ios_base::out | std::ios_base::app | std::ios::binary); + if (!file.is_open()) + return false; + + int64 seconds_since_epoch = + (base::Time::Now() - base::Time::UnixEpoch()).InSeconds(); + std::wstring line = base::Int64ToString16(seconds_since_epoch); + line += L','; + line += report_id; + line += L'\n'; + file.write(line.c_str(), static_cast(line.length())); + return true; +} + // The window procedure task is to handle when a) the user logs off. // b) the system shuts down or c) when the user closes the window. LRESULT __stdcall CrashSvcWndProc(HWND hwnd, UINT message, @@ -422,6 +448,7 @@ DWORD CrashService::AsyncSendDump(void* context) { ++info->self->requests_sent_; ++info->self->requests_handled_; retry_round = 0; + WriteReportIDToFile(info->dump_path, report_id); break; case google_breakpad::RESULT_THROTTLED: report_id = L""; diff --git a/spec/api-crash-reporter-spec.coffee b/spec/api-crash-reporter-spec.coffee index 2dd1499edb7d..43f7b2f03508 100644 --- a/spec/api-crash-reporter-spec.coffee +++ b/spec/api-crash-reporter-spec.coffee @@ -32,7 +32,7 @@ describe 'crash-reporter module', -> assert.equal fields['_version'], require('remote').require('app').getVersion() assert files['upload_file_minidump']['name']? - res.end() + res.end('abc-123-def') server.close() done() server.listen 0, '127.0.0.1', ->