Index: components/offline_pages/offline_page_model_query.h |
diff --git a/components/offline_pages/offline_page_model_query.h b/components/offline_pages/offline_page_model_query.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5ce877ebcd24e3cc2f9b0ca67e95237cd9a0ed11 |
--- /dev/null |
+++ b/components/offline_pages/offline_page_model_query.h |
@@ -0,0 +1,134 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_QUERY_H_ |
+#define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_QUERY_H_ |
+ |
+#include <set> |
+#include <vector> |
+ |
+#include "base/memory/ptr_util.h" |
+#include "components/offline_pages/client_policy_controller.h" |
+#include "components/offline_pages/offline_page_item.h" |
+#include "components/offline_pages/offline_page_types.h" |
+ |
+namespace offline_pages { |
+ |
+// Can be used by OfflinePageModel instances to direct a query of the model. |
+class OfflinePageModelQuery { |
+ public: |
+ enum class Requirement { |
+ UNSET, |
+ MATCH, |
Dmitry Titov
2016/10/24 18:28:34
INCLUDE_MATCHING/EXCLUDE_MATCHING ?
dewittj
2016/10/24 22:20:12
Done.
|
+ EXCLUDE, |
+ }; |
+ |
+ OfflinePageModelQuery(); |
+ virtual ~OfflinePageModelQuery(); |
+ |
+ bool GetRestrictedToNamespaces(std::set<std::string>* namespaces_out); |
+ |
+ Requirement GetRestrictedToOfflineIds(std::set<int64_t>* ids_out); |
+ Requirement GetRestrictedToClientIds(std::set<ClientId>* ids_out); |
+ Requirement GetRestrictedToUrls(std::set<GURL>* ids_out); |
+ bool GetAllowExpired(); |
+ |
+ // This is the workhorse function that is used by the in-memory offline page |
+ // model, given a page it will find out whether that page matches the query. |
+ bool Matches(const OfflinePageItem& page); |
+ |
+ private: |
+ friend class OfflinePageModelQueryBuilder; |
+ |
+ bool allow_expired_ = false; |
+ |
+ std::unique_ptr<std::set<std::string>> restricted_to_namespaces_; |
+ |
+ std::pair<Requirement, std::set<int64_t>> offline_ids_; |
+ std::pair<Requirement, std::set<ClientId>> client_ids_; |
+ std::pair<Requirement, std::set<GURL>> urls_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(OfflinePageModelQuery); |
+}; |
+ |
+// 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.
|
+// namespaces. If the number of IDs or the number of namespaces are reduced to |
+// 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
|
+class OfflinePageModelQueryBuilder { |
+ public: |
+ using Requirement = OfflinePageModelQuery::Requirement; |
+ |
+ OfflinePageModelQueryBuilder(); |
+ ~OfflinePageModelQueryBuilder(); |
+ |
+ // Sets the offline page IDs that are valid for this request. If called |
+ // multiple times, overwrites previous offline page ID restrictions. |
+ OfflinePageModelQueryBuilder& SetOfflinePageIds( |
+ Requirement requirement, |
+ const std::vector<int64_t>& ids); |
+ |
+ // Sets the client IDs that are valid for this request. If called // multiple |
+ // times, overwrites previous client ID restrictions. |
+ OfflinePageModelQueryBuilder& SetClientIds(Requirement requirement, |
+ const std::vector<ClientId>& ids); |
+ |
+ // Sets the URLs that are valid for this request. If called multiple times, |
+ // overwrites previous URL restrictions. |
+ OfflinePageModelQueryBuilder& SetUrls(Requirement requirement, |
+ const std::vector<GURL>& urls); |
+ |
+ // Only include namespaces whose namespaces satisfy |
+ // ClientPolicyController::IsSupportedByDownload(|namespace|) == |
+ // |supported_by_download| |
+ // Multiple calls overwrite previous ones. |
+ OfflinePageModelQueryBuilder& RequireSupportedByDownload( |
+ Requirement supported_by_download); |
+ |
+ // Only include namespaces whose namespaces satisfy |
+ // ClientPolicyController::IsShownAsRecentlyVisitedSite(|namespace|) == |
+ // |recently_visited| |
+ // Multiple calls overwrite previous ones. |
+ OfflinePageModelQueryBuilder& RequireShownAsRecentlyVisitedSite( |
+ Requirement recently_visited); |
+ |
+ // Only include namespaces whose namespaces satisfy |
+ // ClientPolicyController::IsRestrictedToOriginalTab(|namespace|) == |
+ // |original_tab| |
+ // Multiple calls overwrite previous ones. |
+ OfflinePageModelQueryBuilder& RequireRestrictedToOriginalTab( |
+ Requirement original_tab); |
+ |
+ // Resets whether we return expired pages. If called multiple times the bit |
+ // is overwritten and |allow_expired| from the last call is saved. |
+ OfflinePageModelQueryBuilder& AllowExpiredPages(bool allow_expired); |
+ |
+ // Returns the built-up query based on the above APIs. This resets the |
+ // internal state. |
+ std::unique_ptr<OfflinePageModelQuery> Build( |
+ ClientPolicyController* controller); |
+ |
+ private: |
+ // Intersects the allowed namespaces in query_ with |namespaces|. If |
+ // |inverted| is true, intersects the allowed namespaces with all namespaces |
+ // except those provided in |namespaces|. |
+ void IntersectWithNamespaces(ClientPolicyController* controller, |
+ const std::vector<std::string>& namespaces, |
+ Requirement match_requirement); |
+ |
+ std::pair<Requirement, std::vector<int64_t>> offline_ids_; |
+ std::pair<Requirement, std::vector<ClientId>> client_ids_; |
+ std::pair<Requirement, std::vector<GURL>> urls_; |
+ |
+ Requirement supported_by_download_ = Requirement::UNSET; |
+ Requirement shown_as_recently_visited_site_ = Requirement::UNSET; |
+ Requirement restricted_to_original_tab_ = Requirement::UNSET; |
+ |
+ bool allow_expired_ = false; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(OfflinePageModelQueryBuilder); |
+}; |
+ |
+} // namespace offline_pages |
+ |
+#endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_QUERY_H_ |