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

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: Rahul's comments 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 // We are only interested in crashes that took place within the last hour.
22 constexpr base::TimeDelta kOneHourTimeDelta = base::TimeDelta::FromHours(1);
23
24 } // namespace
25
26 CrashIdsSource::CrashIdsSource()
27 : SystemLogsSource("CrashId"),
28 crash_upload_list_(CreateCrashUploadList(this)),
29 pending_crash_list_loading_(false) {}
30
31 CrashIdsSource::~CrashIdsSource() {}
32
33 void CrashIdsSource::Fetch(const SysLogsSourceCallback& callback) {
34 // Unretained since we own these callbacks.
35 pending_requests_.emplace_back(base::Bind(
36 &CrashIdsSource::RespondWithCrashIds, base::Unretained(this), callback));
37
38 if (pending_crash_list_loading_)
39 return;
40
41 pending_crash_list_loading_ = true;
42 crash_upload_list_->LoadUploadListAsynchronously();
43 }
44
45 void CrashIdsSource::OnUploadListAvailable() {
46 pending_crash_list_loading_ = false;
47
48 // Only get the IDs of crashes that occurred within the last hour (if any).
49 std::vector<UploadList::UploadInfo> crashes;
50 crash_upload_list_->GetUploads(kMaxCrashesCountToRetrieve, &crashes);
51 const base::Time now = base::Time::Now();
52 crash_ids_list_.clear();
53 crash_ids_list_.reserve(kMaxCrashesCountToRetrieve);
Rahul Chaturvedi 2016/09/12 22:31:21 kMaxCrashesCountToRetrieve * (kCrashIdStringSize +
afakhry 2016/09/13 16:59:46 Wow, thanks for catching that! I think I confused
54
55 // The feedback server expects the crash IDs to be a comma-separated list.
56 for (const auto& crash_info : crashes) {
57 if (now - crash_info.capture_time < kOneHourTimeDelta) {
58 const std::string& crash_id = crash_info.upload_id;
59 crash_ids_list_.append(crash_ids_list_.empty() ? crash_id
60 : ", " + crash_id);
61 }
62 }
63
64 for (const auto& request : pending_requests_)
65 request.Run();
66
67 pending_requests_.clear();
68 }
69
70 void CrashIdsSource::RespondWithCrashIds(
71 const SysLogsSourceCallback& callback) const {
72 std::unique_ptr<SystemLogsResponse> response(new SystemLogsResponse());
73 (*response)[feedback::FeedbackReport::kCrashReportIdsKey] = crash_ids_list_;
74
75 // We must respond anyways.
76 callback.Run(response.get());
77 }
78
79 } // namespace system_logs
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698