Chromium Code Reviews| 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 bool remove_reports = (data_type_mask & DATA_TYPE_REPORTS) != 0; | |
| 32 bool remove_clients = (data_type_mask & DATA_TYPE_CLIENTS) != 0; | |
| 33 | |
|
shivanisha
2017/04/20 18:21:52
ReportingCache* cache = context_->cache(); instead
Julia Tuttle
2017/04/21 13:34:53
Done.
| |
| 34 if (origin_filter.is_null()) { | |
| 35 if (remove_reports) | |
| 36 cache()->RemoveAllReports(); | |
| 37 if (remove_clients) | |
| 38 cache()->RemoveAllClients(); | |
| 39 return; | |
| 40 } | |
| 41 | |
| 42 if (remove_reports) { | |
| 43 std::vector<const ReportingReport*> all_reports; | |
| 44 cache()->GetReports(&all_reports); | |
| 45 | |
| 46 std::vector<const ReportingReport*> reports_to_remove; | |
| 47 for (const ReportingReport* report : all_reports) { | |
| 48 if (origin_filter.Run(report->url)) | |
| 49 reports_to_remove.push_back(report); | |
| 50 } | |
| 51 | |
| 52 cache()->RemoveReports(reports_to_remove); | |
| 53 } | |
| 54 | |
| 55 if (remove_clients) { | |
| 56 std::vector<const ReportingClient*> all_clients; | |
| 57 cache()->GetClients(&all_clients); | |
| 58 | |
| 59 std::vector<const ReportingClient*> clients_to_remove; | |
| 60 for (const ReportingClient* client : all_clients) { | |
| 61 // TODO(juliatuttle): Examine client endpoint as well? | |
| 62 if (origin_filter.Run(client->origin.GetURL())) | |
| 63 clients_to_remove.push_back(client); | |
| 64 } | |
| 65 | |
| 66 cache()->RemoveClients(clients_to_remove); | |
| 67 } | |
| 30 } | 68 } |
| 31 | 69 |
| 32 if (remove_reports) { | 70 private: |
| 33 std::vector<const ReportingReport*> all_reports; | 71 ReportingCache* cache() { return context_->cache(); } |
| 34 cache->GetReports(&all_reports); | |
| 35 | 72 |
| 36 std::vector<const ReportingReport*> reports_to_remove; | 73 ReportingContext* context_; |
| 37 for (const ReportingReport* report : all_reports) { | |
| 38 if (origin_filter.Run(report->url)) | |
| 39 reports_to_remove.push_back(report); | |
| 40 } | |
| 41 | 74 |
| 42 cache->RemoveReports(reports_to_remove); | 75 DISALLOW_COPY_AND_ASSIGN(ReportingBrowsingDataRemoverImpl); |
| 43 } | 76 }; |
| 44 | 77 |
| 45 if (remove_clients) { | 78 } // namespace |
| 46 std::vector<const ReportingClient*> all_clients; | |
| 47 cache->GetClients(&all_clients); | |
| 48 | 79 |
| 49 std::vector<const ReportingClient*> clients_to_remove; | 80 // static |
| 50 for (const ReportingClient* client : all_clients) { | 81 std::unique_ptr<ReportingBrowsingDataRemover> |
| 51 if (origin_filter.Run(client->origin.GetURL())) | 82 ReportingBrowsingDataRemover::Create(ReportingContext* context) { |
| 52 clients_to_remove.push_back(client); | 83 return base::MakeUnique<ReportingBrowsingDataRemoverImpl>(context); |
| 53 } | |
| 54 | |
| 55 cache->RemoveClients(clients_to_remove); | |
| 56 } | |
| 57 } | 84 } |
| 58 | 85 |
| 86 ReportingBrowsingDataRemover::~ReportingBrowsingDataRemover() {} | |
| 87 | |
| 59 } // namespace net | 88 } // namespace net |
| OLD | NEW |