| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/reporting/reporting_browsing_data_remover.h" | 5 #include "net/reporting/reporting_browsing_data_remover.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" |
| 9 #include "net/reporting/reporting_cache.h" | 10 #include "net/reporting/reporting_cache.h" |
| 11 #include "net/reporting/reporting_client.h" |
| 10 #include "net/reporting/reporting_context.h" | 12 #include "net/reporting/reporting_context.h" |
| 11 #include "net/reporting/reporting_report.h" | 13 #include "net/reporting/reporting_report.h" |
| 12 | 14 |
| 13 namespace net { | 15 namespace net { |
| 14 | 16 |
| 15 // static | 17 namespace { |
| 16 void ReportingBrowsingDataRemover::RemoveBrowsingData( | |
| 17 ReportingContext* context, | |
| 18 int data_type_mask, | |
| 19 base::Callback<bool(const GURL&)> origin_filter) { | |
| 20 ReportingCache* cache = context->cache(); | |
| 21 bool remove_reports = (data_type_mask & DATA_TYPE_REPORTS) != 0; | |
| 22 bool remove_clients = (data_type_mask & DATA_TYPE_CLIENTS) != 0; | |
| 23 | 18 |
| 24 if (origin_filter.is_null()) { | 19 class ReportingBrowsingDataRemoverImpl : public ReportingBrowsingDataRemover { |
| 25 if (remove_reports) | 20 public: |
| 26 cache->RemoveAllReports(); | 21 ReportingBrowsingDataRemoverImpl(ReportingContext* context) |
| 27 if (remove_clients) | 22 : context_(context) {} |
| 28 cache->RemoveAllClients(); | 23 |
| 29 return; | 24 // ReportingBrowsingDataRemover implementation: |
| 25 |
| 26 ~ReportingBrowsingDataRemoverImpl() override {} |
| 27 |
| 28 void RemoveBrowsingData( |
| 29 int data_type_mask, |
| 30 base::Callback<bool(const GURL&)> origin_filter) override { |
| 31 ReportingCache* cache = context_->cache(); |
| 32 bool remove_reports = (data_type_mask & DATA_TYPE_REPORTS) != 0; |
| 33 bool remove_clients = (data_type_mask & DATA_TYPE_CLIENTS) != 0; |
| 34 |
| 35 if (origin_filter.is_null()) { |
| 36 if (remove_reports) |
| 37 cache->RemoveAllReports(); |
| 38 if (remove_clients) |
| 39 cache->RemoveAllClients(); |
| 40 return; |
| 41 } |
| 42 |
| 43 if (remove_reports) { |
| 44 std::vector<const ReportingReport*> all_reports; |
| 45 cache->GetReports(&all_reports); |
| 46 |
| 47 std::vector<const ReportingReport*> reports_to_remove; |
| 48 for (const ReportingReport* report : all_reports) { |
| 49 if (origin_filter.Run(report->url)) |
| 50 reports_to_remove.push_back(report); |
| 51 } |
| 52 |
| 53 cache->RemoveReports(reports_to_remove); |
| 54 } |
| 55 |
| 56 if (remove_clients) { |
| 57 std::vector<const ReportingClient*> all_clients; |
| 58 cache->GetClients(&all_clients); |
| 59 |
| 60 std::vector<const ReportingClient*> clients_to_remove; |
| 61 for (const ReportingClient* client : all_clients) { |
| 62 // TODO(juliatuttle): Examine client endpoint as well? |
| 63 if (origin_filter.Run(client->origin.GetURL())) |
| 64 clients_to_remove.push_back(client); |
| 65 } |
| 66 |
| 67 cache->RemoveClients(clients_to_remove); |
| 68 } |
| 30 } | 69 } |
| 31 | 70 |
| 32 if (remove_reports) { | 71 private: |
| 33 std::vector<const ReportingReport*> all_reports; | 72 ReportingContext* context_; |
| 34 cache->GetReports(&all_reports); | |
| 35 | 73 |
| 36 std::vector<const ReportingReport*> reports_to_remove; | 74 DISALLOW_COPY_AND_ASSIGN(ReportingBrowsingDataRemoverImpl); |
| 37 for (const ReportingReport* report : all_reports) { | 75 }; |
| 38 if (origin_filter.Run(report->url)) | |
| 39 reports_to_remove.push_back(report); | |
| 40 } | |
| 41 | 76 |
| 42 cache->RemoveReports(reports_to_remove); | 77 } // namespace |
| 43 } | |
| 44 | 78 |
| 45 if (remove_clients) { | 79 // static |
| 46 std::vector<const ReportingClient*> all_clients; | 80 std::unique_ptr<ReportingBrowsingDataRemover> |
| 47 cache->GetClients(&all_clients); | 81 ReportingBrowsingDataRemover::Create(ReportingContext* context) { |
| 48 | 82 return base::MakeUnique<ReportingBrowsingDataRemoverImpl>(context); |
| 49 std::vector<const ReportingClient*> clients_to_remove; | |
| 50 for (const ReportingClient* client : all_clients) { | |
| 51 if (origin_filter.Run(client->origin.GetURL())) | |
| 52 clients_to_remove.push_back(client); | |
| 53 } | |
| 54 | |
| 55 cache->RemoveClients(clients_to_remove); | |
| 56 } | |
| 57 } | 83 } |
| 58 | 84 |
| 85 ReportingBrowsingDataRemover::~ReportingBrowsingDataRemover() {} |
| 86 |
| 59 } // namespace net | 87 } // namespace net |
| OLD | NEW |