Chromium Code Reviews| Index: net/reporting/reporting_cache.cc |
| diff --git a/net/reporting/reporting_cache.cc b/net/reporting/reporting_cache.cc |
| index b3b60101eb864652a7436de2338d1198786d2b7f..7e147b38008a390266e047ab20ce457c2a012697 100644 |
| --- a/net/reporting/reporting_cache.cc |
| +++ b/net/reporting/reporting_cache.cc |
| @@ -61,6 +61,18 @@ void ReportingCache::AddReport(const GURL& url, |
| reports_.insert(std::make_pair(report.get(), std::move(report))); |
| DCHECK(inserted.second); |
| + if (reports_.size() > context_->policy().max_report_count) { |
| + // There should be at most one extra report (the one added above). |
| + DCHECK_EQ(context_->policy().max_report_count + 1, reports_.size()); |
| + const ReportingReport* to_evict = FindReportToEvict(); |
| + // The newly-added report isn't pending, so even if all other reports are |
| + // pending, the cache should have a report to evict. |
|
shivanisha
2017/05/09 13:58:27
dcheck that to_evict is not pending?
Julia Tuttle
2017/05/09 14:37:22
I do that, two lines below. I'll move the comment
|
| + DCHECK_NE(nullptr, to_evict); |
| + DCHECK(!base::ContainsKey(pending_reports_, to_evict)); |
| + size_t erased = reports_.erase(to_evict); |
| + DCHECK_EQ(1u, erased); |
|
shivanisha
2017/05/09 13:58:27
May be call RemoveReports instead of lines 71 to 7
Julia Tuttle
2017/05/09 14:37:22
Don't wanna check pending_reports_ and call OnCach
|
| + } |
| + |
| context_->NotifyCacheUpdated(); |
| } |
| @@ -233,6 +245,21 @@ void ReportingCache::RemoveAllClients() { |
| context_->NotifyCacheUpdated(); |
| } |
| +const ReportingReport* ReportingCache::FindReportToEvict() const { |
| + const ReportingReport* earliest_queued = nullptr; |
| + |
| + for (const auto& it : reports_) { |
| + const ReportingReport* report = it.first; |
| + if (base::ContainsKey(pending_reports_, report)) |
| + continue; |
| + if (!earliest_queued || report->queued < earliest_queued->queued) { |
| + earliest_queued = report; |
| + } |
| + } |
| + |
| + return earliest_queued; |
| +} |
| + |
| void ReportingCache::MaybeAddWildcardClient(const ReportingClient* client) { |
| if (client->subdomains != ReportingClient::Subdomains::INCLUDE) |
| return; |