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

Unified Diff: net/reporting/reporting_garbage_collector.cc

Issue 2740833004: Reporting: Implement garbage collector. (Closed)
Patch Set: rebase Created 3 years, 9 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
« no previous file with comments | « net/reporting/reporting_garbage_collector.h ('k') | net/reporting/reporting_garbage_collector_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/reporting/reporting_garbage_collector.cc
diff --git a/net/reporting/reporting_garbage_collector.cc b/net/reporting/reporting_garbage_collector.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b7e0365cf7a68020ed168e80d631390be19924f7
--- /dev/null
+++ b/net/reporting/reporting_garbage_collector.cc
@@ -0,0 +1,39 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/reporting/reporting_garbage_collector.h"
+
+#include <vector>
+
+#include "base/time/time.h"
+#include "net/reporting/reporting_cache.h"
+
+namespace net {
+
+using Report = ReportingCache::Report;
+
+// static
+void ReportingGarbageCollector::CollectGarbage(ReportingCache* cache,
+ const Policy& policy,
+ base::TimeTicks now,
+ bool network_changed) {
shivanisha 2017/03/16 00:22:45 DCHECK(cache)
Julia Tuttle 2017/03/21 19:26:57 Done.
+ std::vector<const Report*> all_reports;
+ cache->GetReports(&all_reports);
+
+ if (network_changed && !policy.report_persist_across_network_changes) {
+ cache->RemoveReports(all_reports);
shivanisha 2017/03/16 00:22:45 Since this policy is for all the reports, how abou
Julia Tuttle 2017/03/21 19:26:57 Done.
+ return;
+ }
+
+ std::vector<const Report*> reports_to_remove;
+ for (const Report* report : all_reports) {
+ if (now - report->queued >= policy.report_max_age ||
+ report->attempts >= policy.report_max_attempts) {
+ reports_to_remove.push_back(report);
+ }
+ }
+ cache->RemoveReports(reports_to_remove);
+}
+
+} // namespace net
« no previous file with comments | « net/reporting/reporting_garbage_collector.h ('k') | net/reporting/reporting_garbage_collector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698