| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/crash_upload_list_win.h" |
| 6 |
| 7 #include "base/stringprintf.h" |
| 8 #include "base/string_util.h" |
| 9 #include "base/sys_string_conversions.h" |
| 10 |
| 11 CrashUploadListWin::CrashUploadListWin(Delegate* delegate) |
| 12 : CrashUploadList(delegate) {} |
| 13 |
| 14 void CrashUploadListWin::LoadCrashList() { |
| 15 std::vector<uint8> buffer(1024); |
| 16 HANDLE event_log = OpenEventLog(NULL, L"Application"); |
| 17 if (event_log) { |
| 18 while (true) { |
| 19 DWORD bytes_read; |
| 20 DWORD bytes_needed; |
| 21 BOOL success = |
| 22 ReadEventLog(event_log, |
| 23 EVENTLOG_SEQUENTIAL_READ | EVENTLOG_BACKWARDS_READ, |
| 24 0, |
| 25 &buffer[0], |
| 26 buffer.size(), |
| 27 &bytes_read, |
| 28 &bytes_needed); |
| 29 if (success) { |
| 30 DWORD record_offset = 0; |
| 31 while (record_offset < bytes_read) { |
| 32 EVENTLOGRECORD* record = (EVENTLOGRECORD*)&buffer[record_offset]; |
| 33 if (IsPossibleCrashLogRecord(record)) |
| 34 ProcessPossibleCrashLogRecord(record); |
| 35 record_offset += record->Length; |
| 36 } |
| 37 } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { |
| 38 // Resize buffer to the required minimum size. |
| 39 buffer.resize(bytes_needed); |
| 40 } else { |
| 41 // Stop on any other error, including the expected case |
| 42 // of ERROR_HANDLE_EOF. |
| 43 break; |
| 44 } |
| 45 } |
| 46 CloseEventLog(event_log); |
| 47 } |
| 48 } |
| 49 |
| 50 bool CrashUploadListWin::IsPossibleCrashLogRecord( |
| 51 EVENTLOGRECORD* record) const { |
| 52 LPWSTR provider_name = (LPWSTR)((uint8*)record + sizeof(EVENTLOGRECORD)); |
| 53 return !wcscmp(L"Chrome", provider_name) && |
| 54 record->EventType == EVENTLOG_INFORMATION_TYPE && |
| 55 record->NumStrings >= 1; |
| 56 } |
| 57 |
| 58 void CrashUploadListWin::ProcessPossibleCrashLogRecord(EVENTLOGRECORD* record) { |
| 59 // Add the crash if the message matches the expected pattern. |
| 60 const std::wstring pattern_prefix(L"Crash uploaded. Id="); |
| 61 const std::wstring pattern_suffix(L"."); |
| 62 const unsigned int pattern_length = |
| 63 pattern_prefix.size() + pattern_suffix.size(); |
| 64 std::wstring message((LPWSTR)((uint8*)record + record->StringOffset)); |
| 65 if (StartsWith(message, pattern_prefix, false) && |
| 66 EndsWith(message, pattern_suffix, false)) { |
| 67 std::wstring crash_id = |
| 68 message.substr(pattern_prefix.size(), pattern_length); |
| 69 crashes().push_back( |
| 70 CrashInfo(base::SysWideToUTF8(crash_id), |
| 71 base::Time::FromDoubleT(record->TimeGenerated))); |
| 72 } |
| 73 } |
| OLD | NEW |