| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/feedback/system_logs/log_sources/crash_ids_source.h" | 5 #include "chrome/browser/feedback/system_logs/log_sources/crash_ids_source.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 // Only get the IDs of crashes that occurred within the last hour (if any). | 51 // Only get the IDs of crashes that occurred within the last hour (if any). |
| 52 std::vector<UploadList::UploadInfo> crashes; | 52 std::vector<UploadList::UploadInfo> crashes; |
| 53 crash_upload_list_->GetUploads(kMaxCrashesCountToRetrieve, &crashes); | 53 crash_upload_list_->GetUploads(kMaxCrashesCountToRetrieve, &crashes); |
| 54 const base::Time now = base::Time::Now(); | 54 const base::Time now = base::Time::Now(); |
| 55 crash_ids_list_.clear(); | 55 crash_ids_list_.clear(); |
| 56 crash_ids_list_.reserve(kMaxCrashesCountToRetrieve * | 56 crash_ids_list_.reserve(kMaxCrashesCountToRetrieve * |
| 57 (kCrashIdStringSize + 2)); | 57 (kCrashIdStringSize + 2)); |
| 58 | 58 |
| 59 // The feedback server expects the crash IDs to be a comma-separated list. | 59 // The feedback server expects the crash IDs to be a comma-separated list. |
| 60 for (const auto& crash_info : crashes) { | 60 for (const auto& crash_info : crashes) { |
| 61 if (now - crash_info.capture_time < kOneHourTimeDelta) { | 61 const base::Time& report_time = |
| 62 crash_info.state == UploadList::UploadInfo::State::Uploaded |
| 63 ? crash_info.upload_time |
| 64 : crash_info.capture_time; |
| 65 if (now - report_time < kOneHourTimeDelta) { |
| 62 const std::string& crash_id = crash_info.upload_id; | 66 const std::string& crash_id = crash_info.upload_id; |
| 63 crash_ids_list_.append(crash_ids_list_.empty() ? crash_id | 67 crash_ids_list_.append(crash_ids_list_.empty() ? crash_id |
| 64 : ", " + crash_id); | 68 : ", " + crash_id); |
| 65 } | 69 } |
| 66 } | 70 } |
| 67 | 71 |
| 68 for (const auto& request : pending_requests_) | 72 for (const auto& request : pending_requests_) |
| 69 request.Run(); | 73 request.Run(); |
| 70 | 74 |
| 71 pending_requests_.clear(); | 75 pending_requests_.clear(); |
| 72 } | 76 } |
| 73 | 77 |
| 74 void CrashIdsSource::RespondWithCrashIds( | 78 void CrashIdsSource::RespondWithCrashIds( |
| 75 const SysLogsSourceCallback& callback) const { | 79 const SysLogsSourceCallback& callback) const { |
| 76 std::unique_ptr<SystemLogsResponse> response(new SystemLogsResponse()); | 80 std::unique_ptr<SystemLogsResponse> response(new SystemLogsResponse()); |
| 77 (*response)[feedback::FeedbackReport::kCrashReportIdsKey] = crash_ids_list_; | 81 (*response)[feedback::FeedbackReport::kCrashReportIdsKey] = crash_ids_list_; |
| 78 | 82 |
| 79 // We must respond anyways. | 83 // We must respond anyways. |
| 80 callback.Run(response.get()); | 84 callback.Run(response.get()); |
| 81 } | 85 } |
| 82 | 86 |
| 83 } // namespace system_logs | 87 } // namespace system_logs |
| OLD | NEW |