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 "base/optional.h" | |
13 #include "components/offline_pages/client_policy_controller.h" | |
14 #include "components/offline_pages/offline_page_item.h" | |
15 #include "components/offline_pages/offline_page_types.h" | |
16 | |
17 namespace offline_pages { | |
18 | |
19 // Can be used by OfflinePageModel instances to direct a query of the model. | |
20 class OfflinePageModelQuery { | |
21 public: | |
22 OfflinePageModelQuery(); | |
23 virtual ~OfflinePageModelQuery(); | |
24 | |
25 bool GetRestrictedToOfflineIds(std::set<int64_t>* ids_out); | |
26 bool GetRestrictedToNamespaces(std::set<std::string>* namespaces_out); | |
27 bool GetRestrictedToClientIds(std::set<ClientId>* 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 // The lifetime of policy_controller is not managed; so Build should be called | |
52 // before policy_controller is destroyed. Typically this is not an issue | |
53 // because a Builder is turned into a Query right away. | |
54 explicit OfflinePageModelQueryBuilder( | |
55 ClientPolicyController* policy_controller); | |
56 ~OfflinePageModelQueryBuilder(); | |
57 | |
58 // Sets the offline page IDs that are valid for this request. If called | |
59 // multiple times, takes the intersection of the IDs in all the requests. | |
Dmitry Titov
2016/10/20 19:40:54
Intersection is probably the least intuitive resul
dewittj
2016/10/21 17:49:47
Intersection seemed useful if you wanted different
| |
60 OfflinePageModelQueryBuilder& SetOfflinePageIds( | |
61 const std::vector<int64_t>& ids); | |
62 | |
63 // Sets the client IDs that are valid for this request. If called | |
64 // multiple times, takes the intersection of the IDs in all the requests. | |
65 OfflinePageModelQueryBuilder& SetClientIds(const std::vector<ClientId>& ids); | |
Dmitry Titov
2016/10/20 19:40:54
Same here. I think SetClientIds should simply repl
dewittj
2016/10/21 17:49:46
Done.
| |
66 | |
67 OfflinePageModelQueryBuilder& SetUrls(const std::vector<GURL>& urls); | |
68 | |
69 // Intersects the currently allowed namespaces with those supported by | |
70 // download. | |
71 OfflinePageModelQueryBuilder& RequireSupportedByDownload( | |
72 bool supported_by_download); | |
73 // Intersects the currently allowed namespaces with those shown in the NTP as | |
74 // a recently visited site. | |
Dmitry Titov
2016/10/20 19:40:54
I think for policy bits they (policy bits) should
dewittj
2016/10/21 17:49:46
Done.
| |
75 OfflinePageModelQueryBuilder& RequireShownAsRecentlyVisitedSite( | |
76 bool recently_visited); | |
77 // Intersects the currently allowed namespaces with those restricted to | |
78 // the original tab. | |
79 OfflinePageModelQueryBuilder& RequireRestrictedToOriginalTab( | |
80 bool original_tab); | |
81 | |
82 // Resets whether we return expired pages. If called multiple times the bit | |
83 // is overwritten and |allow_expired| from the last call is saved. | |
84 OfflinePageModelQueryBuilder& AllowExpiredPages(bool allow_expired); | |
85 | |
86 // Returns the built-up query based on the above APIs. This resets the | |
87 // internal state. | |
88 std::unique_ptr<OfflinePageModelQuery> Build(); | |
89 | |
90 private: | |
91 void IntersectWithNamespaces(const std::vector<std::string>& namespaces); | |
92 | |
93 // The in-progress query object. | |
94 std::unique_ptr<OfflinePageModelQuery> query_; | |
95 | |
96 // Used to turn policy bits into namespace lists. | |
97 ClientPolicyController* policy_controller_; | |
98 | |
99 DISALLOW_COPY_AND_ASSIGN(OfflinePageModelQueryBuilder); | |
100 }; | |
101 | |
102 } // namespace offline_pages | |
103 | |
104 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_QUERY_H_ | |
OLD | NEW |