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

Side by Side Diff: chrome/browser/feedback/system_logs/log_sources/crash_ids_source.cc

Issue 2242833003: Add the most recent crash report IDs to feedback reports (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revert back to a const rather than a constexpr Created 4 years, 3 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
OLDNEW
(Empty)
1 // Copyright 2016 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/feedback/system_logs/log_sources/crash_ids_source.h"
6
7 #include <string>
8
9 #include "base/bind.h"
10 #include "base/time/time.h"
11 #include "chrome/browser/crash_upload_list/crash_upload_list.h"
12 #include "components/feedback/feedback_report.h"
13
14 namespace system_logs {
15
16 namespace {
17
18 // The maximum number of crashes we retrieve from the crash list.
19 constexpr size_t kMaxCrashesCountToRetrieve = 10;
20
21 // The length of the crash ID string.
22 constexpr size_t kCrashIdStringSize = 16;
23
24 // We are only interested in crashes that took place within the last hour.
25 constexpr base::TimeDelta kOneHourTimeDelta = base::TimeDelta::FromHours(1);
26
27 } // namespace
28
29 CrashIdsSource::CrashIdsSource()
30 : SystemLogsSource("CrashId"),
31 crash_upload_list_(CreateCrashUploadList(this)),
32 pending_crash_list_loading_(false) {}
33
34 CrashIdsSource::~CrashIdsSource() {}
35
36 void CrashIdsSource::Fetch(const SysLogsSourceCallback& callback) {
37 // Unretained since we own these callbacks.
38 pending_requests_.emplace_back(base::Bind(
39 &CrashIdsSource::RespondWithCrashIds, base::Unretained(this), callback));
40
41 if (pending_crash_list_loading_)
42 return;
43
44 pending_crash_list_loading_ = true;
45 crash_upload_list_->LoadUploadListAsynchronously();
46 }
47
48 void CrashIdsSource::OnUploadListAvailable() {
49 pending_crash_list_loading_ = false;
50
51 // Only get the IDs of crashes that occurred within the last hour (if any).
52 std::vector<UploadList::UploadInfo> crashes;
53 crash_upload_list_->GetUploads(kMaxCrashesCountToRetrieve, &crashes);
54 const base::Time now = base::Time::Now();
55 crash_ids_list_.clear();
56 crash_ids_list_.reserve(kMaxCrashesCountToRetrieve *
57 (kCrashIdStringSize + 2));
58
59 // The feedback server expects the crash IDs to be a comma-separated list.
60 for (const auto& crash_info : crashes) {
61 if (now - crash_info.capture_time < kOneHourTimeDelta) {
62 const std::string& crash_id = crash_info.upload_id;
63 crash_ids_list_.append(crash_ids_list_.empty() ? crash_id
64 : ", " + crash_id);
65 }
66 }
67
68 for (const auto& request : pending_requests_)
69 request.Run();
70
71 pending_requests_.clear();
72 }
73
74 void CrashIdsSource::RespondWithCrashIds(
75 const SysLogsSourceCallback& callback) const {
76 std::unique_ptr<SystemLogsResponse> response(new SystemLogsResponse());
77 (*response)[feedback::FeedbackReport::kCrashReportIdsKey] = crash_ids_list_;
78
79 // We must respond anyways.
80 callback.Run(response.get());
81 }
82
83 } // namespace system_logs
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698