Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: chrome/browser/crash_upload_list_win.cc

Issue 6771021: Implement CrashUploadListWin to enable chrome://crashes on Windows. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fix max_count logic. Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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::LoadUploadLog() {
15 std::vector<uint8> buffer(1024);
16 HANDLE eventLog = OpenEventLog(NULL, L"Application");
17 if (eventLog) {
18 while (true) {
19 DWORD bytesRead;
20 DWORD bytesNeeded;
21 BOOL success =
22 ReadEventLog(eventLog,
23 EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ,
24 0,
25 &buffer[0],
26 buffer.size(),
27 &bytesRead,
28 &bytesNeeded);
29 if (success) {
30 DWORD recordOffset = 0;
31 while (recordOffset < bytesRead) {
32 uint8* recordPtr = &buffer[recordOffset];
33 EVENTLOGRECORD* record = (EVENTLOGRECORD*)recordPtr;
34 LPWSTR providerName = (LPWSTR)(recordPtr + sizeof(EVENTLOGRECORD));
35 // Check whether the record has the expected values of an Omaha
36 // crash report for Chrome.
37 if (!wcscmp(L"Chrome", providerName) &&
38 record->EventType == EVENTLOG_INFORMATION_TYPE &&
39 record->NumStrings >= 1) {
40 std::string messageString =
41 base::SysWideToUTF8((LPWSTR)(recordPtr + record->StringOffset));
42 // Only handle entries matching the expected message pattern.
43 // NOTE: If the pattern is changed, make sure to change the substr()
44 // parameters below.
45 if (MatchPattern(messageString, "Crash uploaded. Id=*.")) {
46 std::string crashId =
47 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,
48 log_entries().push_back(base::StringPrintf("%d,%s",
49 record->TimeGenerated,
50 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
51 }
52 }
53 recordOffset += record->Length;
54 }
55 } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
56 // Resize buffer to the required minimum size.
57 buffer.resize(bytesNeeded);
58 } else {
59 // Stop on any other error, including the expected case
60 // of ERROR_HANDLE_EOF.
61 break;
62 }
63 }
64 CloseEventLog(eventLog);
65 }
66 InformDelegateOfCompletionAsynchronously();
67 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698