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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/feedback/system_logs/log_sources/crash_ids_source.cc
diff --git a/chrome/browser/feedback/system_logs/log_sources/crash_ids_source.cc b/chrome/browser/feedback/system_logs/log_sources/crash_ids_source.cc
new file mode 100644
index 0000000000000000000000000000000000000000..69adc339b6a18c96afc2f03f77efa533ddf3cb48
--- /dev/null
+++ b/chrome/browser/feedback/system_logs/log_sources/crash_ids_source.cc
@@ -0,0 +1,83 @@
+// Copyright 2016 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/feedback/system_logs/log_sources/crash_ids_source.h"
+
+#include <string>
+
+#include "base/bind.h"
+#include "base/time/time.h"
+#include "chrome/browser/crash_upload_list/crash_upload_list.h"
+#include "components/feedback/feedback_report.h"
+
+namespace system_logs {
+
+namespace {
+
+// The maximum number of crashes we retrieve from the crash list.
+constexpr size_t kMaxCrashesCountToRetrieve = 10;
+
+// The length of the crash ID string.
+constexpr size_t kCrashIdStringSize = 16;
+
+// We are only interested in crashes that took place within the last hour.
+constexpr base::TimeDelta kOneHourTimeDelta = base::TimeDelta::FromHours(1);
+
+} // namespace
+
+CrashIdsSource::CrashIdsSource()
+ : SystemLogsSource("CrashId"),
+ crash_upload_list_(CreateCrashUploadList(this)),
+ pending_crash_list_loading_(false) {}
+
+CrashIdsSource::~CrashIdsSource() {}
+
+void CrashIdsSource::Fetch(const SysLogsSourceCallback& callback) {
+ // Unretained since we own these callbacks.
+ pending_requests_.emplace_back(base::Bind(
+ &CrashIdsSource::RespondWithCrashIds, base::Unretained(this), callback));
+
+ if (pending_crash_list_loading_)
+ return;
+
+ pending_crash_list_loading_ = true;
+ crash_upload_list_->LoadUploadListAsynchronously();
+}
+
+void CrashIdsSource::OnUploadListAvailable() {
+ pending_crash_list_loading_ = false;
+
+ // Only get the IDs of crashes that occurred within the last hour (if any).
+ std::vector<UploadList::UploadInfo> crashes;
+ crash_upload_list_->GetUploads(kMaxCrashesCountToRetrieve, &crashes);
+ const base::Time now = base::Time::Now();
+ crash_ids_list_.clear();
+ crash_ids_list_.reserve(kMaxCrashesCountToRetrieve *
+ (kCrashIdStringSize + 2));
+
+ // The feedback server expects the crash IDs to be a comma-separated list.
+ for (const auto& crash_info : crashes) {
+ if (now - crash_info.capture_time < kOneHourTimeDelta) {
+ const std::string& crash_id = crash_info.upload_id;
+ crash_ids_list_.append(crash_ids_list_.empty() ? crash_id
+ : ", " + crash_id);
+ }
+ }
+
+ for (const auto& request : pending_requests_)
+ request.Run();
+
+ pending_requests_.clear();
+}
+
+void CrashIdsSource::RespondWithCrashIds(
+ const SysLogsSourceCallback& callback) const {
+ std::unique_ptr<SystemLogsResponse> response(new SystemLogsResponse());
+ (*response)[feedback::FeedbackReport::kCrashReportIdsKey] = crash_ids_list_;
+
+ // We must respond anyways.
+ callback.Run(response.get());
+}
+
+} // namespace system_logs

Powered by Google App Engine
This is Rietveld 408576698