• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "net/reporting/reporting_browsing_data_remover.h"
6 
7 #include <vector>
8 
9 #include "net/reporting/reporting_cache.h"
10 #include "net/reporting/reporting_context.h"
11 #include "net/reporting/reporting_report.h"
12 
13 namespace net {
14 
15 // static
RemoveBrowsingData(ReportingCache * cache,uint64_t data_type_mask,const base::RepeatingCallback<bool (const url::Origin &)> & origin_filter)16 void ReportingBrowsingDataRemover::RemoveBrowsingData(
17     ReportingCache* cache,
18     uint64_t data_type_mask,
19     const base::RepeatingCallback<bool(const url::Origin&)>& origin_filter) {
20   if ((data_type_mask & DATA_TYPE_REPORTS) != 0) {
21     std::vector<const ReportingReport*> all_reports;
22     cache->GetReports(&all_reports);
23 
24     std::vector<const ReportingReport*> reports_to_remove;
25     for (const ReportingReport* report : all_reports) {
26       if (origin_filter.Run(url::Origin::Create(report->url)))
27         reports_to_remove.push_back(report);
28     }
29 
30     cache->RemoveReports(reports_to_remove);
31   }
32 
33   if ((data_type_mask & DATA_TYPE_CLIENTS) != 0) {
34     for (const url::Origin& origin : cache->GetAllOrigins()) {
35       if (origin_filter.Run(origin))
36         cache->RemoveClientsForOrigin(origin);
37     }
38   }
39   cache->Flush();
40 }
41 
42 // static
RemoveAllBrowsingData(ReportingCache * cache,uint64_t data_type_mask)43 void ReportingBrowsingDataRemover::RemoveAllBrowsingData(
44     ReportingCache* cache,
45     uint64_t data_type_mask) {
46   if ((data_type_mask & DATA_TYPE_REPORTS) != 0) {
47     cache->RemoveAllReports();
48   }
49   if ((data_type_mask & DATA_TYPE_CLIENTS) != 0) {
50     cache->RemoveAllClients();
51   }
52   cache->Flush();
53 }
54 
55 }  // namespace net
56