| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_QUERY_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_QUERY_H_ |
| 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_QUERY_H_ | 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_QUERY_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 OfflinePageModelQuery(); | 35 OfflinePageModelQuery(); |
| 36 virtual ~OfflinePageModelQuery(); | 36 virtual ~OfflinePageModelQuery(); |
| 37 | 37 |
| 38 std::pair<bool, std::set<std::string>> GetRestrictedToNamespaces() const; | 38 std::pair<bool, std::set<std::string>> GetRestrictedToNamespaces() const; |
| 39 std::pair<Requirement, std::set<int64_t>> GetRestrictedToOfflineIds() const; | 39 std::pair<Requirement, std::set<int64_t>> GetRestrictedToOfflineIds() const; |
| 40 std::pair<Requirement, std::set<ClientId>> GetRestrictedToClientIds() const; | 40 std::pair<Requirement, std::set<ClientId>> GetRestrictedToClientIds() const; |
| 41 std::pair<Requirement, std::set<GURL>> GetRestrictedToUrls() const; | 41 std::pair<Requirement, std::set<GURL>> GetRestrictedToUrls() const; |
| 42 | 42 |
| 43 bool GetAllowExpired() const; | |
| 44 | |
| 45 // This is the workhorse function that is used by the in-memory offline page | 43 // This is the workhorse function that is used by the in-memory offline page |
| 46 // model, given a page it will find out whether that page matches the query. | 44 // model, given a page it will find out whether that page matches the query. |
| 47 bool Matches(const OfflinePageItem& page) const; | 45 bool Matches(const OfflinePageItem& page) const; |
| 48 | 46 |
| 49 private: | 47 private: |
| 50 friend class OfflinePageModelQueryBuilder; | 48 friend class OfflinePageModelQueryBuilder; |
| 51 | 49 |
| 52 bool allow_expired_ = false; | |
| 53 | |
| 54 std::unique_ptr<std::set<std::string>> restricted_to_namespaces_; | 50 std::unique_ptr<std::set<std::string>> restricted_to_namespaces_; |
| 55 | 51 |
| 56 std::pair<Requirement, std::set<int64_t>> offline_ids_; | 52 std::pair<Requirement, std::set<int64_t>> offline_ids_; |
| 57 std::pair<Requirement, std::set<ClientId>> client_ids_; | 53 std::pair<Requirement, std::set<ClientId>> client_ids_; |
| 58 std::pair<Requirement, std::set<GURL>> urls_; | 54 std::pair<Requirement, std::set<GURL>> urls_; |
| 59 | 55 |
| 60 DISALLOW_COPY_AND_ASSIGN(OfflinePageModelQuery); | 56 DISALLOW_COPY_AND_ASSIGN(OfflinePageModelQuery); |
| 61 }; | 57 }; |
| 62 | 58 |
| 63 // Used to create an offline page model query. QueryBuilders without | 59 // Used to create an offline page model query. QueryBuilders without |
| 64 // modifications create queries that allow all pages that are not expired. | 60 // modifications create queries that allow all pages. |
| 65 // Can restrict results by policies provided by |ClientPolicyController|, or by | 61 // Can restrict results by policies provided by |ClientPolicyController|, or by |
| 66 // individual features of pages. Each restriction comes with a |Requirement| | 62 // individual features of pages. Each restriction comes with a |Requirement| |
| 67 // that can be used to specify whether the input restriction should include or | 63 // that can be used to specify whether the input restriction should include or |
| 68 // exclude matching pages. | 64 // exclude matching pages. |
| 69 class OfflinePageModelQueryBuilder { | 65 class OfflinePageModelQueryBuilder { |
| 70 public: | 66 public: |
| 71 using Requirement = OfflinePageModelQuery::Requirement; | 67 using Requirement = OfflinePageModelQuery::Requirement; |
| 72 | 68 |
| 73 OfflinePageModelQueryBuilder(); | 69 OfflinePageModelQueryBuilder(); |
| 74 ~OfflinePageModelQueryBuilder(); | 70 ~OfflinePageModelQueryBuilder(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 103 OfflinePageModelQueryBuilder& RequireShownAsRecentlyVisitedSite( | 99 OfflinePageModelQueryBuilder& RequireShownAsRecentlyVisitedSite( |
| 104 Requirement recently_visited); | 100 Requirement recently_visited); |
| 105 | 101 |
| 106 // Only include pages whose namespaces satisfy | 102 // Only include pages whose namespaces satisfy |
| 107 // ClientPolicyController::IsRestrictedToOriginalTab(|namespace|) == | 103 // ClientPolicyController::IsRestrictedToOriginalTab(|namespace|) == |
| 108 // |original_tab| | 104 // |original_tab| |
| 109 // Multiple calls overwrite previous ones. | 105 // Multiple calls overwrite previous ones. |
| 110 OfflinePageModelQueryBuilder& RequireRestrictedToOriginalTab( | 106 OfflinePageModelQueryBuilder& RequireRestrictedToOriginalTab( |
| 111 Requirement original_tab); | 107 Requirement original_tab); |
| 112 | 108 |
| 113 // Resets whether we return expired pages. If called multiple times the bit | |
| 114 // is overwritten and |allow_expired| from the last call is saved. | |
| 115 OfflinePageModelQueryBuilder& AllowExpiredPages(bool allow_expired); | |
| 116 | |
| 117 // Builds the query using the namespace policies provided by |controller| | 109 // Builds the query using the namespace policies provided by |controller| |
| 118 // This resets the internal state. |controller| should not be |nullptr|. | 110 // This resets the internal state. |controller| should not be |nullptr|. |
| 119 std::unique_ptr<OfflinePageModelQuery> Build( | 111 std::unique_ptr<OfflinePageModelQuery> Build( |
| 120 ClientPolicyController* controller); | 112 ClientPolicyController* controller); |
| 121 | 113 |
| 122 private: | 114 private: |
| 123 // Intersects the allowed namespaces in query_ with |namespaces|. If | 115 // Intersects the allowed namespaces in query_ with |namespaces|. If |
| 124 // |inverted| is true, intersects the allowed namespaces with all namespaces | 116 // |inverted| is true, intersects the allowed namespaces with all namespaces |
| 125 // except those provided in |namespaces|. | 117 // except those provided in |namespaces|. |
| 126 void IntersectWithNamespaces(ClientPolicyController* controller, | 118 void IntersectWithNamespaces(ClientPolicyController* controller, |
| 127 const std::vector<std::string>& namespaces, | 119 const std::vector<std::string>& namespaces, |
| 128 Requirement match_requirement); | 120 Requirement match_requirement); |
| 129 | 121 |
| 130 std::pair<Requirement, std::vector<int64_t>> offline_ids_; | 122 std::pair<Requirement, std::vector<int64_t>> offline_ids_; |
| 131 std::pair<Requirement, std::vector<ClientId>> client_ids_; | 123 std::pair<Requirement, std::vector<ClientId>> client_ids_; |
| 132 std::pair<Requirement, std::vector<GURL>> urls_; | 124 std::pair<Requirement, std::vector<GURL>> urls_; |
| 133 | 125 |
| 134 Requirement supported_by_download_ = Requirement::UNSET; | 126 Requirement supported_by_download_ = Requirement::UNSET; |
| 135 Requirement shown_as_recently_visited_site_ = Requirement::UNSET; | 127 Requirement shown_as_recently_visited_site_ = Requirement::UNSET; |
| 136 Requirement restricted_to_original_tab_ = Requirement::UNSET; | 128 Requirement restricted_to_original_tab_ = Requirement::UNSET; |
| 137 | 129 |
| 138 bool allow_expired_ = false; | |
| 139 | |
| 140 DISALLOW_COPY_AND_ASSIGN(OfflinePageModelQueryBuilder); | 130 DISALLOW_COPY_AND_ASSIGN(OfflinePageModelQueryBuilder); |
| 141 }; | 131 }; |
| 142 | 132 |
| 143 } // namespace offline_pages | 133 } // namespace offline_pages |
| 144 | 134 |
| 145 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_QUERY_H_ | 135 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_QUERY_H_ |
| OLD | NEW |