Chromium Code Reviews| Index: chrome/browser/crash_upload_list_win.cc |
| diff --git a/chrome/browser/crash_upload_list_win.cc b/chrome/browser/crash_upload_list_win.cc |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..cb66f995c33f663bada44127e8d36e3801a09327 |
| --- /dev/null |
| +++ b/chrome/browser/crash_upload_list_win.cc |
| @@ -0,0 +1,73 @@ |
| +// 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/stringprintf.h" |
| +#include "base/string_util.h" |
| +#include "base/sys_string_conversions.h" |
| + |
| +CrashUploadListWin::CrashUploadListWin(Delegate* delegate) |
| + : CrashUploadList(delegate) {} |
| + |
| +void CrashUploadListWin::LoadCrashList() { |
| + std::vector<uint8> buffer(1024); |
| + HANDLE event_log = OpenEventLog(NULL, L"Application"); |
| + if (event_log) { |
| + 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; |
| + while (record_offset < bytes_read) { |
| + EVENTLOGRECORD* record = (EVENTLOGRECORD*)&buffer[record_offset]; |
|
MAD
2011/03/31 14:07:58
I'm not sure this works... What if the beginning o
Alexei Svitkine (slow)
2011/03/31 14:36:47
It's not explicitly clarified in the API docs:
ht
MAD
2011/03/31 14:42:51
Good point, I forgot about the dynamic size allowi
|
| + 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. |
|
MAD
2011/03/31 14:07:58
I think we should DCHECK that we actually got ERRO
Alexei Svitkine (slow)
2011/03/31 14:36:47
Good idea! Done.
|
| + break; |
| + } |
| + } |
| + CloseEventLog(event_log); |
| + } |
| +} |
| + |
| +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"Crash uploaded. Id="); |
| + const std::wstring pattern_suffix(L"."); |
| + const unsigned int pattern_length = |
| + pattern_prefix.size() + pattern_suffix.size(); |
|
MAD
2011/03/31 14:07:58
Are you sure about this? I think you need to find
Alexei Svitkine (slow)
2011/03/31 14:36:47
Good catch! I think I got this wrong after refacto
|
| + std::wstring message((LPWSTR)((uint8*)record + record->StringOffset)); |
| + if (StartsWith(message, pattern_prefix, false) && |
| + EndsWith(message, pattern_suffix, false)) { |
| + std::wstring crash_id = |
| + message.substr(pattern_prefix.size(), pattern_length); |
| + crashes().push_back( |
| + CrashInfo(base::SysWideToUTF8(crash_id), |
| + base::Time::FromDoubleT(record->TimeGenerated))); |
| + } |
| +} |