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

Unified 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: Add class-level comment. 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 side-by-side diff with in-line comments
Download patch
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..9c3c44e09cf72d121d90ea4f2e54eb83854ee944
--- /dev/null
+++ b/chrome/browser/crash_upload_list_win.cc
@@ -0,0 +1,68 @@
+// 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::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
+ const std::wstring pattern_prefix(L"Crash uploaded. Id=");
+ const std::wstring pattern_suffix(L".");
+ const unsigned int pattern_length =
+ pattern_prefix.size() + pattern_suffix.size();
+ std::vector<uint8> buffer(1024);
+ HANDLE event_log = OpenEventLog(NULL, L"Application");
+ if (event_log) {
+ while (true) {
+ DWORD bytes_read;
+ DWORD bytes_needed;
+ BOOL success =
+ ReadEventLog(event_log,
+ EVENTLOG_SEQUENTIAL_READ | EVENTLOG_BACKWARDS_READ,
+ 0,
+ &buffer[0],
+ buffer.size(),
+ &bytes_read,
+ &bytes_needed);
+ if (success) {
stuartmorgan 2011/03/30 16:28:10 For example, everything in here could easily be sp
+ DWORD record_offset = 0;
+ while (record_offset < bytes_read) {
+ uint8* record_ptr = &buffer[record_offset];
+ EVENTLOGRECORD* record = (EVENTLOGRECORD*)record_ptr;
+ LPWSTR provider_name = (LPWSTR)(record_ptr + sizeof(EVENTLOGRECORD));
+ // Check whether the record has the expected values of an Omaha
+ // crash report for Chrome.
+ if (!wcscmp(L"Chrome", provider_name) &&
+ record->EventType == EVENTLOG_INFORMATION_TYPE &&
+ record->NumStrings >= 1) {
stuartmorgan 2011/03/30 16:28:10 Another possibility: everything from "LPWSTR provi
+ std::wstring message((LPWSTR)(record_ptr + record->StringOffset));
+ // Only handle entries matching the expected message pattern.
+ if (StartsWith(message, pattern_prefix, false) &&
+ EndsWith(message, pattern_suffix, false)) {
+ std::wstring crash_id =
+ message.substr(pattern_prefix.size(), pattern_length);
+ crashes().push_back(
+ CrashInfo(base::SysWideToUTF8(crash_id),
+ base::Time::FromDoubleT(record->TimeGenerated)));
+ }
stuartmorgan 2011/03/30 16:28:10 This whole block is another possibility for splitt
+ }
+ record_offset += record->Length;
+ }
+ } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
+ // Resize buffer to the required minimum size.
+ buffer.resize(bytes_needed);
+ } else {
+ // Stop on any other error, including the expected case
+ // of ERROR_HANDLE_EOF.
+ break;
+ }
+ }
+ CloseEventLog(event_log);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698