page_criteria.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2019 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. #ifndef COMPONENTS_OFFLINE_PAGES_CORE_PAGE_CRITERIA_H_
  5. #define COMPONENTS_OFFLINE_PAGES_CORE_PAGE_CRITERIA_H_
  6. #include <cstdint>
  7. #include <string>
  8. #include <vector>
  9. #include "base/callback.h"
  10. #include "components/offline_pages/core/client_id.h"
  11. #include "components/offline_pages/core/offline_page_client_policy.h"
  12. #include "third_party/abseil-cpp/absl/types/optional.h"
  13. #include "url/gurl.h"
  14. namespace offline_pages {
  15. struct OfflinePageItem;
  16. // Criteria for matching an offline page. The default |PageCriteria| matches
  17. // all pages.
  18. struct PageCriteria {
  19. PageCriteria();
  20. ~PageCriteria();
  21. PageCriteria(const PageCriteria&);
  22. PageCriteria(PageCriteria&&);
  23. enum Order {
  24. kDescendingCreationTime,
  25. kAscendingAccessTime,
  26. kDescendingAccessTime,
  27. };
  28. // If non-empty, the page must match this URL. The provided URL
  29. // is matched both against the original and the actual URL fields (they
  30. // sometimes differ because of possible redirects).
  31. GURL url;
  32. // Whether to exclude pages that may only be opened in a specific tab.
  33. bool exclude_tab_bound_pages = false;
  34. // If specified, accepts pages that can be displayed in the specified tab.
  35. // That is, tab-bound pages are filtered out unless the tab ID matches this
  36. // field and non-tab-bound pages are always included.
  37. absl::optional<int> pages_for_tab_id;
  38. // Whether to restrict pages to those in namespaces supported by the
  39. // downloads UI.
  40. bool supported_by_downloads = false;
  41. // If set, the page's lifetime type must match this.
  42. absl::optional<LifetimeType> lifetime_type;
  43. // If set, the page's file_size must match.
  44. absl::optional<int64_t> file_size;
  45. // If non-empty, the page's digest must match.
  46. std::string digest;
  47. // If set, the page's namespace must match.
  48. absl::optional<std::vector<std::string>> client_namespaces;
  49. // If set, the page's client_id must match one of these.
  50. absl::optional<std::vector<ClientId>> client_ids;
  51. // If non-empty, the page's client_id.id must match this.
  52. std::string guid;
  53. // If non-empty, the page's request_origin must match.
  54. std::string request_origin;
  55. // If set, the page's offline_id must match.
  56. absl::optional<std::vector<int64_t>> offline_ids;
  57. // If non-null, this function is executed for each matching item. If it
  58. // returns false, the item will not be returned. This is evaluated last, and
  59. // only for pages that otherwise meet all other criteria.
  60. base::RepeatingCallback<bool(const OfflinePageItem&)> additional_criteria;
  61. // If > 0, returns at most this many pages.
  62. size_t maximum_matches = 0;
  63. // The order results are returned. Affects which results are dropped with
  64. // |maximum_matches|.
  65. Order result_order = kDescendingCreationTime;
  66. };
  67. // Returns true if an offline page with |client_id| could potentially match
  68. // |criteria|.
  69. bool MeetsCriteria(const PageCriteria& criteria, const ClientId& client_id);
  70. // Returns whether |item| matches |criteria|.
  71. bool MeetsCriteria(const PageCriteria& criteria, const OfflinePageItem& item);
  72. // Returns the list of offline page namespaces that could potentially match
  73. // Criteria. Returns an empty list if any namespace could match.
  74. std::vector<std::string> PotentiallyMatchingNamespaces(
  75. const PageCriteria& criteria);
  76. } // namespace offline_pages
  77. #endif // COMPONENTS_OFFLINE_PAGES_CORE_PAGE_CRITERIA_H_