reporting_browsing_data_remover.cc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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
  3. // found in the LICENSE file.
  4. #include "net/reporting/reporting_browsing_data_remover.h"
  5. #include <vector>
  6. #include "net/reporting/reporting_cache.h"
  7. #include "net/reporting/reporting_context.h"
  8. #include "net/reporting/reporting_report.h"
  9. namespace net {
  10. // static
  11. void ReportingBrowsingDataRemover::RemoveBrowsingData(
  12. ReportingCache* cache,
  13. uint64_t data_type_mask,
  14. const base::RepeatingCallback<bool(const url::Origin&)>& origin_filter) {
  15. if ((data_type_mask & DATA_TYPE_REPORTS) != 0) {
  16. std::vector<const ReportingReport*> all_reports;
  17. cache->GetReports(&all_reports);
  18. std::vector<const ReportingReport*> reports_to_remove;
  19. for (const ReportingReport* report : all_reports) {
  20. if (origin_filter.Run(url::Origin::Create(report->url)))
  21. reports_to_remove.push_back(report);
  22. }
  23. cache->RemoveReports(reports_to_remove);
  24. }
  25. if ((data_type_mask & DATA_TYPE_CLIENTS) != 0) {
  26. for (const url::Origin& origin : cache->GetAllOrigins()) {
  27. if (origin_filter.Run(origin))
  28. cache->RemoveClientsForOrigin(origin);
  29. }
  30. }
  31. cache->Flush();
  32. }
  33. // static
  34. void ReportingBrowsingDataRemover::RemoveAllBrowsingData(
  35. ReportingCache* cache,
  36. uint64_t data_type_mask) {
  37. if ((data_type_mask & DATA_TYPE_REPORTS) != 0) {
  38. cache->RemoveAllReports();
  39. }
  40. if ((data_type_mask & DATA_TYPE_CLIENTS) != 0) {
  41. cache->RemoveAllClients();
  42. }
  43. cache->Flush();
  44. }
  45. } // namespace net