Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / crash_upload_list_win.cc
blobf60dfc2f8c35dcd9ccaa210e52e238230c63956c
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.
5 #include "chrome/browser/crash_upload_list_win.h"
7 #include "base/strings/string_util.h"
8 #include "base/strings/stringprintf.h"
9 #include "base/strings/sys_string_conversions.h"
11 CrashUploadListWin::CrashUploadListWin(Delegate* delegate,
12 const base::FilePath& upload_log_path)
13 : CrashUploadList(delegate, upload_log_path) {}
15 void CrashUploadListWin::LoadUploadList() {
16 std::vector<uint8> buffer(1024);
17 HANDLE event_log = OpenEventLog(NULL, L"Application");
18 if (event_log) {
19 ClearUploads();
20 while (true) {
21 DWORD bytes_read;
22 DWORD bytes_needed;
23 BOOL success =
24 ReadEventLog(event_log,
25 EVENTLOG_SEQUENTIAL_READ | EVENTLOG_BACKWARDS_READ,
27 &buffer[0],
28 buffer.size(),
29 &bytes_read,
30 &bytes_needed);
31 if (success) {
32 DWORD record_offset = 0;
33 // The ReadEventLog() API docs imply, but do not explicitly state that
34 // partial records will not be returned. Use DCHECK() to affirm this.
35 while (record_offset < bytes_read) {
36 DCHECK(record_offset + sizeof(EVENTLOGRECORD) <= bytes_read);
37 EVENTLOGRECORD* record = (EVENTLOGRECORD*)&buffer[record_offset];
38 DCHECK(record_offset + record->Length <= bytes_read);
39 if (IsPossibleCrashLogRecord(record))
40 ProcessPossibleCrashLogRecord(record);
41 record_offset += record->Length;
43 } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
44 // Resize buffer to the required minimum size.
45 buffer.resize(bytes_needed);
46 } else {
47 // Stop on any other error, including the expected case
48 // of ERROR_HANDLE_EOF.
49 DCHECK(GetLastError() == ERROR_HANDLE_EOF);
50 break;
53 CloseEventLog(event_log);
57 CrashUploadListWin::~CrashUploadListWin() {
60 bool CrashUploadListWin::IsPossibleCrashLogRecord(
61 EVENTLOGRECORD* record) const {
62 LPWSTR provider_name = (LPWSTR)((uint8*)record + sizeof(EVENTLOGRECORD));
63 return !wcscmp(L"Chrome", provider_name) &&
64 record->EventType == EVENTLOG_INFORMATION_TYPE &&
65 record->NumStrings >= 1;
68 void CrashUploadListWin::ProcessPossibleCrashLogRecord(EVENTLOGRECORD* record) {
69 // Add the crash if the message matches the expected pattern.
70 const std::wstring pattern_prefix(L"Id=");
71 const std::wstring pattern_suffix(L".");
72 std::wstring message((LPWSTR)((uint8*)record + record->StringOffset));
73 size_t start_index = message.find(pattern_prefix);
74 if (start_index != std::wstring::npos) {
75 start_index += pattern_prefix.size();
76 size_t end_index = message.find(pattern_suffix, start_index);
77 if (end_index != std::wstring::npos) {
78 std::wstring crash_id =
79 message.substr(start_index, end_index - start_index);
80 AppendUploadInfo(
81 UploadInfo(base::SysWideToUTF8(crash_id),
82 base::Time::FromDoubleT(record->TimeGenerated)));