Chromium Code Reviews| 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 enum class Requirement { | |
| 22 UNSET, | |
| 23 MATCH, | |
|
Dmitry Titov
2016/10/24 18:28:34
INCLUDE_MATCHING/EXCLUDE_MATCHING ?
dewittj
2016/10/24 22:20:12
Done.
| |
| 24 EXCLUDE, | |
| 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); | |
| 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); | |
| 40 | |
| 41 private: | |
| 42 friend class OfflinePageModelQueryBuilder; | |
| 43 | |
| 44 bool allow_expired_ = false; | |
| 45 | |
| 46 std::unique_ptr<std::set<std::string>> restricted_to_namespaces_; | |
| 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. Set policy bits to limit by | |
|
Dmitry Titov
2016/10/24 18:28:34
"Set policy bits to limit by namespaces" is unclea
dewittj
2016/10/24 22:20:12
Done.
| |
| 56 // namespaces. If the number of IDs or the number of namespaces are reduced to | |
| 57 // zero, the builder will DCHECK. Call |Build| to generate an actual query. | |
|
Dmitry Titov
2016/10/24 18:28:34
Not sure why would Builder DCHECK... This seems li
dewittj
2016/10/24 22:20:12
This was outdated anyway. The whole comment is no
| |
| 58 class OfflinePageModelQueryBuilder { | |
| 59 public: | |
| 60 using Requirement = OfflinePageModelQuery::Requirement; | |
| 61 | |
| 62 OfflinePageModelQueryBuilder(); | |
| 63 ~OfflinePageModelQueryBuilder(); | |
| 64 | |
| 65 // Sets the offline page IDs that are valid for this request. If called | |
| 66 // multiple times, overwrites previous offline page ID restrictions. | |
| 67 OfflinePageModelQueryBuilder& SetOfflinePageIds( | |
| 68 Requirement requirement, | |
| 69 const std::vector<int64_t>& ids); | |
| 70 | |
| 71 // Sets the client IDs that are valid for this request. If called // multiple | |
| 72 // times, overwrites previous client ID restrictions. | |
| 73 OfflinePageModelQueryBuilder& SetClientIds(Requirement requirement, | |
| 74 const std::vector<ClientId>& ids); | |
| 75 | |
| 76 // Sets the URLs that are valid for this request. If called multiple times, | |
| 77 // overwrites previous URL restrictions. | |
| 78 OfflinePageModelQueryBuilder& SetUrls(Requirement requirement, | |
| 79 const std::vector<GURL>& urls); | |
| 80 | |
| 81 // Only include namespaces whose namespaces satisfy | |
| 82 // ClientPolicyController::IsSupportedByDownload(|namespace|) == | |
| 83 // |supported_by_download| | |
| 84 // Multiple calls overwrite previous ones. | |
| 85 OfflinePageModelQueryBuilder& RequireSupportedByDownload( | |
| 86 Requirement supported_by_download); | |
| 87 | |
| 88 // Only include namespaces whose namespaces satisfy | |
| 89 // ClientPolicyController::IsShownAsRecentlyVisitedSite(|namespace|) == | |
| 90 // |recently_visited| | |
| 91 // Multiple calls overwrite previous ones. | |
| 92 OfflinePageModelQueryBuilder& RequireShownAsRecentlyVisitedSite( | |
| 93 Requirement recently_visited); | |
| 94 | |
| 95 // Only include namespaces whose namespaces satisfy | |
| 96 // ClientPolicyController::IsRestrictedToOriginalTab(|namespace|) == | |
| 97 // |original_tab| | |
| 98 // Multiple calls overwrite previous ones. | |
| 99 OfflinePageModelQueryBuilder& RequireRestrictedToOriginalTab( | |
| 100 Requirement original_tab); | |
| 101 | |
| 102 // Resets whether we return expired pages. If called multiple times the bit | |
| 103 // is overwritten and |allow_expired| from the last call is saved. | |
| 104 OfflinePageModelQueryBuilder& AllowExpiredPages(bool allow_expired); | |
| 105 | |
| 106 // Returns the built-up query based on the above APIs. This resets the | |
| 107 // internal state. | |
| 108 std::unique_ptr<OfflinePageModelQuery> Build( | |
| 109 ClientPolicyController* controller); | |
| 110 | |
| 111 private: | |
| 112 // Intersects the allowed namespaces in query_ with |namespaces|. If | |
| 113 // |inverted| is true, intersects the allowed namespaces with all namespaces | |
| 114 // except those provided in |namespaces|. | |
| 115 void IntersectWithNamespaces(ClientPolicyController* controller, | |
| 116 const std::vector<std::string>& namespaces, | |
| 117 Requirement match_requirement); | |
| 118 | |
| 119 std::pair<Requirement, std::vector<int64_t>> offline_ids_; | |
| 120 std::pair<Requirement, std::vector<ClientId>> client_ids_; | |
| 121 std::pair<Requirement, std::vector<GURL>> urls_; | |
| 122 | |
| 123 Requirement supported_by_download_ = Requirement::UNSET; | |
| 124 Requirement shown_as_recently_visited_site_ = Requirement::UNSET; | |
| 125 Requirement restricted_to_original_tab_ = Requirement::UNSET; | |
| 126 | |
| 127 bool allow_expired_ = false; | |
| 128 | |
| 129 DISALLOW_COPY_AND_ASSIGN(OfflinePageModelQueryBuilder); | |
| 130 }; | |
| 131 | |
| 132 } // namespace offline_pages | |
| 133 | |
| 134 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_QUERY_H_ | |
| OLD | NEW |