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

Unified Diff: net/reporting/reporting_cache.cc

Issue 2900553004: Reporting: Add histograms. (Closed)
Patch Set: oops, forgot about dependency Created 3 years, 7 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: net/reporting/reporting_cache.cc
diff --git a/net/reporting/reporting_cache.cc b/net/reporting/reporting_cache.cc
index 7920a20ca4f43552512d6693240954e61e3c969a..21a06efcaf5cf1787b2916c1a4777a68fbf257ca 100644
--- a/net/reporting/reporting_cache.cc
+++ b/net/reporting/reporting_cache.cc
@@ -48,7 +48,20 @@ ReportingCache::ReportingCache(ReportingContext* context) : context_(context) {
DCHECK(context_);
}
-ReportingCache::~ReportingCache() {}
+ReportingCache::~ReportingCache() {
+ base::TimeTicks now = tick_clock()->NowTicks();
+
+ // Mark all undoomed reports as erased at shutdown, and record outcomes of
+ // all remaining reports (doomed or not).
+ for (auto it = reports_.begin(); it != reports_.end(); ++it) {
+ ReportingReport* report = it->second.get();
+ if (!base::ContainsKey(doomed_reports_, report))
+ report->outcome = ReportingReport::Outcome::ERASED_REPORTING_SHUT_DOWN;
+ report->RecordOutcome(now);
+ }
+
+ reports_.clear();
+}
void ReportingCache::AddReport(const GURL& url,
const std::string& group,
@@ -71,8 +84,8 @@ void ReportingCache::AddReport(const GURL& url,
// The newly-added report isn't pending, so even if all other reports are
// pending, the cache should have a report to evict.
DCHECK(!base::ContainsKey(pending_reports_, to_evict));
- size_t erased = reports_.erase(to_evict);
- DCHECK_EQ(1u, erased);
+ reports_[to_evict]->outcome = ReportingReport::Outcome::ERASED_EVICTED;
+ RemoveReportInternal(to_evict);
}
context_->NotifyCacheUpdated();
@@ -108,7 +121,8 @@ void ReportingCache::ClearReportsPending(
}
}
- RemoveReports(reports_to_remove);
+ for (const ReportingReport* report : reports_to_remove)
+ RemoveReportInternal(report);
}
void ReportingCache::IncrementReportsAttempts(
@@ -122,34 +136,34 @@ void ReportingCache::IncrementReportsAttempts(
}
void ReportingCache::RemoveReports(
- const std::vector<const ReportingReport*>& reports) {
+ const std::vector<const ReportingReport*>& reports,
+ ReportingReport::Outcome outcome) {
for (const ReportingReport* report : reports) {
+ reports_[report]->outcome = outcome;
if (base::ContainsKey(pending_reports_, report)) {
doomed_reports_.insert(report);
} else {
DCHECK(!base::ContainsKey(doomed_reports_, report));
- size_t erased = reports_.erase(report);
- DCHECK_EQ(1u, erased);
+ RemoveReportInternal(report);
}
}
context_->NotifyCacheUpdated();
}
-void ReportingCache::RemoveAllReports() {
- std::vector<std::unordered_map<const ReportingReport*,
- std::unique_ptr<ReportingReport>>::iterator>
- reports_to_remove;
+void ReportingCache::RemoveAllReports(ReportingReport::Outcome outcome) {
+ std::vector<const ReportingReport*> reports_to_remove;
for (auto it = reports_.begin(); it != reports_.end(); ++it) {
ReportingReport* report = it->second.get();
+ report->outcome = outcome;
if (!base::ContainsKey(pending_reports_, report))
- reports_to_remove.push_back(it);
+ reports_to_remove.push_back(report);
else
doomed_reports_.insert(report);
}
- for (auto& it : reports_to_remove)
- reports_.erase(it);
+ for (const ReportingReport* report : reports_to_remove)
+ RemoveReportInternal(report);
context_->NotifyCacheUpdated();
}
@@ -268,6 +282,12 @@ void ReportingCache::RemoveAllClients() {
context_->NotifyCacheUpdated();
}
+void ReportingCache::RemoveReportInternal(const ReportingReport* report) {
+ reports_[report]->RecordOutcome(tick_clock()->NowTicks());
+ size_t erased = reports_.erase(report);
+ DCHECK_EQ(1u, erased);
+}
+
const ReportingReport* ReportingCache::FindReportToEvict() const {
const ReportingReport* earliest_queued = nullptr;

Powered by Google App Engine
This is Rietveld 408576698