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

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: Addressing a couple more comments. Created 9 years, 8 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
« no previous file with comments | « chrome/browser/crash_upload_list_win.h ('k') | chrome/browser/ui/webui/crashes_ui.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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::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];
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
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.
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.
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();
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
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 }
OLDNEW
« no previous file with comments | « chrome/browser/crash_upload_list_win.h ('k') | chrome/browser/ui/webui/crashes_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698