OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 "net/reporting/reporting_garbage_collector.h" | 5 #include "net/reporting/reporting_garbage_collector.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 } | 50 } |
51 | 51 |
52 private: | 52 private: |
53 void CollectGarbage() { | 53 void CollectGarbage() { |
54 base::TimeTicks now = context_->tick_clock()->NowTicks(); | 54 base::TimeTicks now = context_->tick_clock()->NowTicks(); |
55 const ReportingPolicy& policy = context_->policy(); | 55 const ReportingPolicy& policy = context_->policy(); |
56 | 56 |
57 std::vector<const ReportingReport*> all_reports; | 57 std::vector<const ReportingReport*> all_reports; |
58 context_->cache()->GetReports(&all_reports); | 58 context_->cache()->GetReports(&all_reports); |
59 | 59 |
60 std::vector<const ReportingReport*> reports_to_remove; | 60 std::vector<const ReportingReport*> failed_reports; |
| 61 std::vector<const ReportingReport*> expired_reports; |
61 for (const ReportingReport* report : all_reports) { | 62 for (const ReportingReport* report : all_reports) { |
62 if (now - report->queued >= policy.max_report_age || | 63 if (report->attempts >= policy.max_report_attempts) |
63 report->attempts >= policy.max_report_attempts) { | 64 failed_reports.push_back(report); |
64 reports_to_remove.push_back(report); | 65 else if (now - report->queued >= policy.max_report_age) |
65 } | 66 expired_reports.push_back(report); |
66 } | 67 } |
67 | 68 |
68 // Don't restart the timer on the garbage collector's own updates. | 69 // Don't restart the timer on the garbage collector's own updates. |
69 context_->RemoveObserver(this); | 70 context_->RemoveObserver(this); |
70 context_->cache()->RemoveReports(reports_to_remove); | 71 context_->cache()->RemoveReports(failed_reports, |
| 72 ReportingReport::Outcome::ERASED_FAILED); |
| 73 context_->cache()->RemoveReports(expired_reports, |
| 74 ReportingReport::Outcome::ERASED_EXPIRED); |
71 context_->AddObserver(this); | 75 context_->AddObserver(this); |
72 } | 76 } |
73 | 77 |
74 ReportingContext* context_; | 78 ReportingContext* context_; |
75 std::unique_ptr<base::Timer> timer_; | 79 std::unique_ptr<base::Timer> timer_; |
76 }; | 80 }; |
77 | 81 |
78 } // namespace | 82 } // namespace |
79 | 83 |
80 // static | 84 // static |
81 std::unique_ptr<ReportingGarbageCollector> ReportingGarbageCollector::Create( | 85 std::unique_ptr<ReportingGarbageCollector> ReportingGarbageCollector::Create( |
82 ReportingContext* context) { | 86 ReportingContext* context) { |
83 return base::MakeUnique<ReportingGarbageCollectorImpl>(context); | 87 return base::MakeUnique<ReportingGarbageCollectorImpl>(context); |
84 } | 88 } |
85 | 89 |
86 ReportingGarbageCollector::~ReportingGarbageCollector() {} | 90 ReportingGarbageCollector::~ReportingGarbageCollector() {} |
87 | 91 |
88 } // namespace net | 92 } // namespace net |
OLD | NEW |