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

Unified Diff: net/reporting/reporting_browsing_data_remover.cc

Issue 2752523005: Reporting: Implement browsing data remover. (Closed)
Patch Set: Make requested change. Created 3 years, 8 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..5041a47487c62a1425c26a1d776753cf6186dc82
--- /dev/null
+++ b/net/reporting/reporting_browsing_data_remover.cc
@@ -0,0 +1,59 @@
+// 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,
+ int data_type_mask,
+ base::Callback<bool(const GURL&)> origin_filter) {
+ ReportingCache* cache = context->cache();
+ bool remove_reports = (data_type_mask & DATA_TYPE_REPORTS) != 0;
+ bool remove_clients = (data_type_mask & DATA_TYPE_CLIENTS) != 0;
+
+ 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
« no previous file with comments | « net/reporting/reporting_browsing_data_remover.h ('k') | net/reporting/reporting_browsing_data_remover_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698