File: page_criteria.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (89 lines) | stat: -rw-r--r-- 3,457 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_OFFLINE_PAGES_CORE_PAGE_CRITERIA_H_
#define COMPONENTS_OFFLINE_PAGES_CORE_PAGE_CRITERIA_H_

#include <cstdint>
#include <optional>
#include <string>
#include <vector>

#include "base/functional/callback.h"
#include "components/offline_pages/core/client_id.h"
#include "components/offline_pages/core/offline_page_client_policy.h"
#include "url/gurl.h"

namespace offline_pages {
struct OfflinePageItem;

// Criteria for matching an offline page. The default |PageCriteria| matches
// all pages.
struct PageCriteria {
  PageCriteria();
  ~PageCriteria();
  PageCriteria(const PageCriteria&);
  PageCriteria(PageCriteria&&);

  enum Order {
    kDescendingCreationTime,
    kAscendingAccessTime,
    kDescendingAccessTime,
  };

  // If non-empty, the page must match this URL. The provided URL
  // is matched both against the original and the actual URL fields (they
  // sometimes differ because of possible redirects).
  GURL url;
  // Whether to exclude pages that may only be opened in a specific tab.
  bool exclude_tab_bound_pages = false;
  // If specified, accepts pages that can be displayed in the specified tab.
  // That is, tab-bound pages are filtered out unless the tab ID matches this
  // field and non-tab-bound pages are always included.
  std::optional<int> pages_for_tab_id;
  // Whether to restrict pages to those in namespaces supported by the
  // downloads UI.
  bool supported_by_downloads = false;
  // If set, the page's lifetime type must match this.
  std::optional<LifetimeType> lifetime_type;
  // If set, the page's file_size must match.
  std::optional<int64_t> file_size;
  // If non-empty, the page's digest must match.
  std::string digest;
  // If set, the page's namespace must match.
  std::optional<std::vector<std::string>> client_namespaces;
  // If set, the page's client_id must match one of these.
  std::optional<std::vector<ClientId>> client_ids;
  // If non-empty, the page's client_id.id must match this.
  std::string guid;
  // If non-empty, the page's request_origin must match.
  std::string request_origin;
  // If set, the page's offline_id must match.
  std::optional<std::vector<int64_t>> offline_ids;
  // If non-null, this function is executed for each matching item. If it
  // returns false, the item will not be returned. This is evaluated last, and
  // only for pages that otherwise meet all other criteria.
  base::RepeatingCallback<bool(const OfflinePageItem&)> additional_criteria;
  // If > 0, returns at most this many pages.
  size_t maximum_matches = 0;
  // The order results are returned. Affects which results are dropped with
  // |maximum_matches|.
  Order result_order = kDescendingCreationTime;
};

// Returns true if an offline page with |client_id| could potentially match
// |criteria|.
bool MeetsCriteria(const PageCriteria& criteria, const ClientId& client_id);

// Returns whether |item| matches |criteria|.
bool MeetsCriteria(const PageCriteria& criteria, const OfflinePageItem& item);

// Returns the list of offline page namespaces that could potentially match
// Criteria. Returns an empty list if any namespace could match.
std::vector<std::string> PotentiallyMatchingNamespaces(
    const PageCriteria& criteria);

}  // namespace offline_pages

#endif  // COMPONENTS_OFFLINE_PAGES_CORE_PAGE_CRITERIA_H_