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..693d13de71f3b610a3f2ebf4cfe6e3c6c7e6ae46 |
| --- /dev/null |
| +++ b/chrome/browser/crash_upload_list_win.cc |
| @@ -0,0 +1,67 @@ |
| +// 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::LoadUploadLog() { |
| + std::vector<uint8> buffer(1024); |
| + HANDLE eventLog = OpenEventLog(NULL, L"Application"); |
| + if (eventLog) { |
| + while (true) { |
| + DWORD bytesRead; |
| + DWORD bytesNeeded; |
| + BOOL success = |
| + ReadEventLog(eventLog, |
| + EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ, |
| + 0, |
| + &buffer[0], |
| + buffer.size(), |
| + &bytesRead, |
| + &bytesNeeded); |
| + if (success) { |
| + DWORD recordOffset = 0; |
| + while (recordOffset < bytesRead) { |
| + uint8* recordPtr = &buffer[recordOffset]; |
| + EVENTLOGRECORD* record = (EVENTLOGRECORD*)recordPtr; |
| + LPWSTR providerName = (LPWSTR)(recordPtr + sizeof(EVENTLOGRECORD)); |
| + // Check whether the record has the expected values of an Omaha |
| + // crash report for Chrome. |
| + if (!wcscmp(L"Chrome", providerName) && |
| + record->EventType == EVENTLOG_INFORMATION_TYPE && |
| + record->NumStrings >= 1) { |
| + std::string messageString = |
| + base::SysWideToUTF8((LPWSTR)(recordPtr + record->StringOffset)); |
| + // Only handle entries matching the expected message pattern. |
| + // NOTE: If the pattern is changed, make sure to change the substr() |
| + // parameters below. |
| + if (MatchPattern(messageString, "Crash uploaded. Id=*.")) { |
| + std::string crashId = |
| + messageString.substr(19, crashId.length() - 20); |
|
stuartmorgan
2011/03/29 21:19:57
Can you turn the prefix into a static string, and
Alexei Svitkine (slow)
2011/03/30 15:36:40
Done. The resulting code is unfortunately uglier,
|
| + log_entries().push_back(base::StringPrintf("%d,%s", |
| + record->TimeGenerated, |
| + crashId.c_str())); |
|
stuartmorgan
2011/03/29 21:19:57
It's odd that the subclass is serializing the cras
Alexei Svitkine (slow)
2011/03/30 15:36:40
Good point. I've refactored the code to have the b
|
| + } |
| + } |
| + recordOffset += record->Length; |
| + } |
| + } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { |
| + // Resize buffer to the required minimum size. |
| + buffer.resize(bytesNeeded); |
| + } else { |
| + // Stop on any other error, including the expected case |
| + // of ERROR_HANDLE_EOF. |
| + break; |
| + } |
| + } |
| + CloseEventLog(eventLog); |
| + } |
| + InformDelegateOfCompletionAsynchronously(); |
| +} |