Chromium Code Reviews| 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() { | |
|
stuartmorgan
2011/03/30 16:28:10
As with the other LoadCrashList function, this wou
Alexei Svitkine (slow)
2011/03/30 18:54:37
I've refactored this into a couple of helpers. My
| |
| 15 const std::wstring pattern_prefix(L"Crash uploaded. Id="); | |
| 16 const std::wstring pattern_suffix(L"."); | |
| 17 const unsigned int pattern_length = | |
| 18 pattern_prefix.size() + pattern_suffix.size(); | |
| 19 std::vector<uint8> buffer(1024); | |
| 20 HANDLE event_log = OpenEventLog(NULL, L"Application"); | |
| 21 if (event_log) { | |
| 22 while (true) { | |
| 23 DWORD bytes_read; | |
| 24 DWORD bytes_needed; | |
| 25 BOOL success = | |
| 26 ReadEventLog(event_log, | |
| 27 EVENTLOG_SEQUENTIAL_READ | EVENTLOG_BACKWARDS_READ, | |
| 28 0, | |
| 29 &buffer[0], | |
| 30 buffer.size(), | |
| 31 &bytes_read, | |
| 32 &bytes_needed); | |
| 33 if (success) { | |
|
stuartmorgan
2011/03/30 16:28:10
For example, everything in here could easily be sp
| |
| 34 DWORD record_offset = 0; | |
| 35 while (record_offset < bytes_read) { | |
| 36 uint8* record_ptr = &buffer[record_offset]; | |
| 37 EVENTLOGRECORD* record = (EVENTLOGRECORD*)record_ptr; | |
| 38 LPWSTR provider_name = (LPWSTR)(record_ptr + sizeof(EVENTLOGRECORD)); | |
| 39 // Check whether the record has the expected values of an Omaha | |
| 40 // crash report for Chrome. | |
| 41 if (!wcscmp(L"Chrome", provider_name) && | |
| 42 record->EventType == EVENTLOG_INFORMATION_TYPE && | |
| 43 record->NumStrings >= 1) { | |
|
stuartmorgan
2011/03/30 16:28:10
Another possibility: everything from "LPWSTR provi
| |
| 44 std::wstring message((LPWSTR)(record_ptr + record->StringOffset)); | |
| 45 // Only handle entries matching the expected message pattern. | |
| 46 if (StartsWith(message, pattern_prefix, false) && | |
| 47 EndsWith(message, pattern_suffix, false)) { | |
| 48 std::wstring crash_id = | |
| 49 message.substr(pattern_prefix.size(), pattern_length); | |
| 50 crashes().push_back( | |
| 51 CrashInfo(base::SysWideToUTF8(crash_id), | |
| 52 base::Time::FromDoubleT(record->TimeGenerated))); | |
| 53 } | |
|
stuartmorgan
2011/03/30 16:28:10
This whole block is another possibility for splitt
| |
| 54 } | |
| 55 record_offset += record->Length; | |
| 56 } | |
| 57 } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { | |
| 58 // Resize buffer to the required minimum size. | |
| 59 buffer.resize(bytes_needed); | |
| 60 } else { | |
| 61 // Stop on any other error, including the expected case | |
| 62 // of ERROR_HANDLE_EOF. | |
| 63 break; | |
| 64 } | |
| 65 } | |
| 66 CloseEventLog(event_log); | |
| 67 } | |
| 68 } | |
| OLD | NEW |