Chromium Code Reviews| 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..3b09a36eb4e103240e0407d53f0932f013ffb3ab |
| --- /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); |
|
shivanisha
2017/04/07 16:42:48
Why the 2 negate signs?
|
| + bool remove_clients = !!(data_type_mask & DATA_TYPE_CLIENTS); |
| + |
| + 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 |