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

Unified Diff: net/reporting/reporting_browsing_data_remover.cc

Issue 2752523005: Reporting: Implement browsing data remover. (Closed)
Patch Set: Move after Context CL. 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
Index: net/reporting/reporting_browsing_data_remover.cc
diff --git a/net/reporting/reporting_browsing_data_remover.cc b/net/reporting/reporting_browsing_data_remover.cc
new file mode 100644
index 0000000000000000000000000000000000000000..19b7100728811b2814d014a16268f7fb13c1d48c
--- /dev/null
+++ b/net/reporting/reporting_browsing_data_remover.cc
@@ -0,0 +1,58 @@
+// 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_browsing_data_remover.h"
+
+#include <vector>
+
+#include "net/reporting/reporting_cache.h"
+#include "net/reporting/reporting_context.h"
+#include "net/reporting/reporting_report.h"
+
+namespace net {
+
+// static
+void ReportingBrowsingDataRemover::RemoveBrowsingData(
+ ReportingContext* context,
+ bool remove_reports,
+ bool remove_clients,
shivanisha 2017/04/07 15:10:30 nit: Enum in place of two boolean arguments.
Julia Tuttle 2017/04/07 16:25:10 Done.
+ base::Callback<bool(const GURL&)> origin_filter) {
+ ReportingCache* cache = context->cache();
+
+ if (origin_filter.is_null()) {
+ if (remove_reports)
+ cache->RemoveAllReports();
+ if (remove_clients)
+ cache->RemoveAllClients();
+ return;
+ }
+
+ if (remove_reports) {
+ std::vector<const ReportingReport*> all_reports;
+ cache->GetReports(&all_reports);
+
+ std::vector<const ReportingReport*> reports_to_remove;
+ for (const ReportingReport* report : all_reports) {
+ if (origin_filter.Run(report->url))
+ reports_to_remove.push_back(report);
+ }
+
+ cache->RemoveReports(reports_to_remove);
+ }
+
+ if (remove_clients) {
+ std::vector<const ReportingClient*> all_clients;
+ cache->GetClients(&all_clients);
+
+ std::vector<const ReportingClient*> clients_to_remove;
+ for (const ReportingClient* client : all_clients) {
+ if (origin_filter.Run(client->origin.GetURL()))
+ clients_to_remove.push_back(client);
+ }
+
+ cache->RemoveClients(clients_to_remove);
+ }
+}
+
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698