Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Side by Side Diff: components/offline_pages/offline_page_model_query.h

Issue 2415473003: Query API: Introduces an OfflinePageModelQuery object. (Closed)
Patch Set: Address comments, add more tests, rename enum. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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
5 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_QUERY_H_
6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_QUERY_H_
7
8 #include <set>
9 #include <vector>
10
11 #include "base/memory/ptr_util.h"
12 #include "components/offline_pages/client_policy_controller.h"
13 #include "components/offline_pages/offline_page_item.h"
14 #include "components/offline_pages/offline_page_types.h"
15
16 namespace offline_pages {
17
18 // Can be used by OfflinePageModel instances to direct a query of the model.
19 class OfflinePageModelQuery {
20 public:
21 enum class Requirement {
fgorski 2016/10/26 18:05:42 this almost wants to be called constraint. What do
dewittj 2016/10/27 22:49:18 Could be, I like requirement but if you feel stron
22 UNSET,
23 INCLUDE_MATCHING,
24 EXCLUDE_MATCHING,
25 };
26
27 OfflinePageModelQuery();
28 virtual ~OfflinePageModelQuery();
29
30 bool GetRestrictedToNamespaces(std::set<std::string>* namespaces_out);
31
32 Requirement GetRestrictedToOfflineIds(std::set<int64_t>* ids_out);
fgorski 2016/10/26 18:05:42 This pattern would work for a status variable, but
dewittj 2016/10/27 22:49:18 Done.
33 Requirement GetRestrictedToClientIds(std::set<ClientId>* ids_out);
34 Requirement GetRestrictedToUrls(std::set<GURL>* ids_out);
35 bool GetAllowExpired();
36
37 // This is the workhorse function that is used by the in-memory offline page
38 // model, given a page it will find out whether that page matches the query.
39 bool Matches(const OfflinePageItem& page);
fgorski 2016/10/26 18:05:42 Now that I think about that. Everything between de
dewittj 2016/10/27 22:49:18 Match is not going to be usable when we move to a
40
41 private:
42 friend class OfflinePageModelQueryBuilder;
43
44 bool allow_expired_ = false;
fgorski 2016/10/26 18:05:42 constructor should take care of that I believe.
dewittj 2016/10/27 22:49:18 This is in the C++11 Allowed Features section of h
fgorski 2016/10/28 02:40:39 Acknowledged.
45
46 std::unique_ptr<std::set<std::string>> restricted_to_namespaces_;
fgorski 2016/10/26 18:05:42 I wonder if we can apply this to eliminate last_n
dewittj 2016/10/27 22:49:18 I'm not sure what you mean, can you elaborate?
fgorski 2016/10/28 02:40:39 Nerer mind, I realized that the policy is written
47
48 std::pair<Requirement, std::set<int64_t>> offline_ids_;
49 std::pair<Requirement, std::set<ClientId>> client_ids_;
50 std::pair<Requirement, std::set<GURL>> urls_;
51
52 DISALLOW_COPY_AND_ASSIGN(OfflinePageModelQuery);
53 };
54
55 // Used to create an offline page model query. QueryBuilders without
56 // modifications create queries that allow all pages that are not expired.
57 // Can restrict results by policies provided by |ClientPolicyController|, or by
58 // individual features of pages. Each restriction comes with a |Requirement|
59 // that can be used to specify whether the input restriction should match all
fgorski 2016/10/26 18:05:42 perhaps: should include or exclude matching pages?
dewittj 2016/10/27 22:49:18 Done.
60 // result pages or should match zero result pages.
61 class OfflinePageModelQueryBuilder {
62 public:
63 using Requirement = OfflinePageModelQuery::Requirement;
64
65 OfflinePageModelQueryBuilder();
66 ~OfflinePageModelQueryBuilder();
67
68 // Sets the offline page IDs that are valid for this request. If called
69 // multiple times, overwrites previous offline page ID restrictions.
70 OfflinePageModelQueryBuilder& SetOfflinePageIds(
71 Requirement requirement,
72 const std::vector<int64_t>& ids);
73
74 // Sets the client IDs that are valid for this request. If called // multiple
fgorski 2016/10/26 18:05:42 remove "// " before multiple.
dewittj 2016/10/27 22:49:18 Done.
75 // times, overwrites previous client ID restrictions.
76 OfflinePageModelQueryBuilder& SetClientIds(Requirement requirement,
77 const std::vector<ClientId>& ids);
78
79 // Sets the URLs that are valid for this request. If called multiple times,
80 // overwrites previous URL restrictions.
81 OfflinePageModelQueryBuilder& SetUrls(Requirement requirement,
82 const std::vector<GURL>& urls);
83
84 // Only include namespaces whose namespaces satisfy
fgorski 2016/10/26 18:05:42 If I am not mistaken you meant: Only include *page
dewittj 2016/10/27 22:49:18 Done.
85 // ClientPolicyController::IsSupportedByDownload(|namespace|) ==
86 // |supported_by_download|
87 // Multiple calls overwrite previous ones.
88 OfflinePageModelQueryBuilder& RequireSupportedByDownload(
89 Requirement supported_by_download);
90
91 // Only include namespaces whose namespaces satisfy
92 // ClientPolicyController::IsShownAsRecentlyVisitedSite(|namespace|) ==
93 // |recently_visited|
94 // Multiple calls overwrite previous ones.
95 OfflinePageModelQueryBuilder& RequireShownAsRecentlyVisitedSite(
96 Requirement recently_visited);
97
98 // Only include namespaces whose namespaces satisfy
99 // ClientPolicyController::IsRestrictedToOriginalTab(|namespace|) ==
100 // |original_tab|
101 // Multiple calls overwrite previous ones.
102 OfflinePageModelQueryBuilder& RequireRestrictedToOriginalTab(
103 Requirement original_tab);
104
105 // Resets whether we return expired pages. If called multiple times the bit
106 // is overwritten and |allow_expired| from the last call is saved.
107 OfflinePageModelQueryBuilder& AllowExpiredPages(bool allow_expired);
108
109 // Returns the built-up query based on the above APIs. This resets the
fgorski 2016/10/26 18:05:42 Builds the query using the provided policy |contro
dewittj 2016/10/27 22:49:18 Done.
110 // internal state.
111 std::unique_ptr<OfflinePageModelQuery> Build(
112 ClientPolicyController* controller);
113
114 private:
115 // Intersects the allowed namespaces in query_ with |namespaces|. If
116 // |inverted| is true, intersects the allowed namespaces with all namespaces
117 // except those provided in |namespaces|.
118 void IntersectWithNamespaces(ClientPolicyController* controller,
119 const std::vector<std::string>& namespaces,
120 Requirement match_requirement);
121
122 std::pair<Requirement, std::vector<int64_t>> offline_ids_;
123 std::pair<Requirement, std::vector<ClientId>> client_ids_;
124 std::pair<Requirement, std::vector<GURL>> urls_;
125
126 Requirement supported_by_download_ = Requirement::UNSET;
127 Requirement shown_as_recently_visited_site_ = Requirement::UNSET;
128 Requirement restricted_to_original_tab_ = Requirement::UNSET;
129
130 bool allow_expired_ = false;
131
132 DISALLOW_COPY_AND_ASSIGN(OfflinePageModelQueryBuilder);
133 };
134
135 } // namespace offline_pages
136
137 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_QUERY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698