OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 "net/reporting/reporting_garbage_collector.h" |
| 6 |
| 7 #include <vector> |
| 8 |
| 9 #include "base/macros.h" |
| 10 #include "base/time/time.h" |
| 11 #include "net/reporting/reporting_cache.h" |
| 12 #include "net/reporting/reporting_report.h" |
| 13 |
| 14 namespace net { |
| 15 |
| 16 // static |
| 17 void ReportingGarbageCollector::CollectGarbage(ReportingCache* cache, |
| 18 const Policy& policy, |
| 19 base::TimeTicks now, |
| 20 bool network_changed) { |
| 21 DCHECK(cache); |
| 22 |
| 23 if (network_changed && !policy.report_persist_across_network_changes) { |
| 24 cache->RemoveAllReports(); |
| 25 return; |
| 26 } |
| 27 |
| 28 std::vector<const ReportingReport*> all_reports; |
| 29 cache->GetReports(&all_reports); |
| 30 |
| 31 std::vector<const ReportingReport*> reports_to_remove; |
| 32 for (const ReportingReport* report : all_reports) { |
| 33 if (now - report->queued >= policy.report_max_age || |
| 34 report->attempts >= policy.report_max_attempts) { |
| 35 reports_to_remove.push_back(report); |
| 36 } |
| 37 } |
| 38 cache->RemoveReports(reports_to_remove); |
| 39 } |
| 40 |
| 41 } // namespace net |
OLD | NEW |