OLD | NEW |
---|---|
(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 OfflinePageModelQuery(); | |
22 virtual ~OfflinePageModelQuery(); | |
23 | |
24 bool GetRestrictedToOfflineIds(std::set<int64_t>* ids_out); | |
25 bool GetRestrictedToNamespaces(std::set<std::string>* namespaces_out); | |
26 bool GetRestrictedToClientIds(std::set<ClientId>* ids_out); | |
27 bool GetRestrictedToUrls(std::set<GURL>* ids_out); | |
28 bool GetAllowExpired(); | |
29 | |
30 // This is the workhorse function that is used by the in-memory offline page | |
31 // model, given a page it will find out whether that page matches the query. | |
32 bool Matches(const OfflinePageItem& page); | |
33 | |
34 private: | |
35 friend class OfflinePageModelQueryBuilder; | |
36 | |
37 bool allow_expired_ = false; | |
38 std::unique_ptr<std::set<int64_t>> offline_ids_; | |
39 std::unique_ptr<std::set<GURL>> urls_; | |
40 std::unique_ptr<std::set<std::string>> restricted_to_namespaces_; | |
41 std::unique_ptr<std::set<ClientId>> client_ids_; | |
42 | |
43 DISALLOW_COPY_AND_ASSIGN(OfflinePageModelQuery); | |
44 }; | |
45 | |
46 // Used to create an offline page model query. Set policy bits to limit by | |
47 // namespaces. If the number of IDs or the number of namespaces are reduced to | |
48 // zero, the builder will DCHECK. Call |Build| to generate an actual query. | |
49 class OfflinePageModelQueryBuilder { | |
50 public: | |
51 enum class Requirement { | |
52 Unset, | |
Dmitry Titov
2016/10/21 20:21:09
Enum values should be either CAPITALIZED or kNamed
dewittj
2016/10/24 18:19:33
Done.
| |
53 OnlyMatching, | |
54 OnlyNotMatching, | |
55 }; | |
56 | |
57 explicit OfflinePageModelQueryBuilder(); | |
Dmitry Titov
2016/10/21 20:21:09
doesn't have to be explicit
dewittj
2016/10/24 18:19:33
Done.
| |
58 ~OfflinePageModelQueryBuilder(); | |
59 | |
60 // Sets the offline page IDs that are valid for this request. If called | |
61 // multiple times, overwrites previous offline page ID restrictions. | |
62 OfflinePageModelQueryBuilder& SetOfflinePageIds( | |
Dmitry Titov
2016/10/21 20:21:09
I wonder if those "Set" methods can also take Requ
dewittj
2016/10/24 18:19:33
Done. What do you think? If you like the new sha
| |
63 const std::vector<int64_t>& ids); | |
64 | |
65 // Sets the client IDs that are valid for this request. If called | |
66 // multiple times, overwrites previous client ID restrictions. | |
67 OfflinePageModelQueryBuilder& SetClientIds(const std::vector<ClientId>& ids); | |
68 | |
69 // Sets the URLs that are valid for this request. If called multiple times, | |
70 // overwrites previous URL restrictions. | |
71 OfflinePageModelQueryBuilder& SetUrls(const std::vector<GURL>& urls); | |
72 | |
73 // Only include namespaces whose namespaces satisfy | |
74 // ClientPolicyController::IsSupportedByDownload(|namespace|) == | |
75 // |supported_by_download| | |
76 // Multiple calls overwrite previous ones. | |
77 OfflinePageModelQueryBuilder& RequireSupportedByDownload( | |
78 Requirement supported_by_download); | |
79 | |
80 // Only include namespaces whose namespaces satisfy | |
81 // ClientPolicyController::IsShownAsRecentlyVisitedSite(|namespace|) == | |
82 // |recently_visited| | |
83 // Multiple calls overwrite previous ones. | |
84 OfflinePageModelQueryBuilder& RequireShownAsRecentlyVisitedSite( | |
85 Requirement recently_visited); | |
86 | |
87 // Only include namespaces whose namespaces satisfy | |
88 // ClientPolicyController::IsRestrictedToOriginalTab(|namespace|) == | |
89 // |original_tab| | |
90 // Multiple calls overwrite previous ones. | |
91 OfflinePageModelQueryBuilder& RequireRestrictedToOriginalTab( | |
92 Requirement original_tab); | |
93 | |
94 // Resets whether we return expired pages. If called multiple times the bit | |
95 // is overwritten and |allow_expired| from the last call is saved. | |
96 OfflinePageModelQueryBuilder& AllowExpiredPages(bool allow_expired); | |
97 | |
98 // Returns the built-up query based on the above APIs. This resets the | |
99 // internal state. | |
100 std::unique_ptr<OfflinePageModelQuery> Build( | |
101 ClientPolicyController* controller); | |
102 | |
103 private: | |
104 // Intersects the allowed namespaces in query_ with |namespaces|. If | |
105 // |inverted| is true, intersects the allowed namespaces with all namespaces | |
106 // except those provided in |namespaces|. | |
107 void IntersectWithNamespaces(ClientPolicyController* controller, | |
Dmitry Titov
2016/10/21 20:21:09
If I understand correctly, "intersect with inversi
dewittj
2016/10/24 18:19:33
Moved to RemoveNamespaces & IntersectNamespaces.
| |
108 const std::vector<std::string>& namespaces, | |
109 bool invert); | |
110 | |
111 // The in-progress query object. | |
112 std::unique_ptr<OfflinePageModelQuery> query_; | |
113 | |
114 Requirement supported_by_download_ = Requirement::Unset; | |
115 Requirement shown_as_recently_visited_site_ = Requirement::Unset; | |
116 Requirement restricted_to_original_tab_ = Requirement::Unset; | |
117 | |
118 DISALLOW_COPY_AND_ASSIGN(OfflinePageModelQueryBuilder); | |
119 }; | |
120 | |
121 } // namespace offline_pages | |
122 | |
123 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_QUERY_H_ | |
OLD | NEW |