Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Unified Diff: components/offline_pages/offline_page_model_query.h

Issue 2415473003: Query API: Introduces an OfflinePageModelQuery object. (Closed)
Patch Set: Stop making a new client policy controller, have a dangling pointer. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..cf79424a9e51c5583eb48ad90986074970c69bef
--- /dev/null
+++ b/components/offline_pages/offline_page_model_query.h
@@ -0,0 +1,104 @@
+// 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 "base/optional.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:
+ OfflinePageModelQuery();
+ virtual ~OfflinePageModelQuery();
+
+ bool GetRestrictedToOfflineIds(std::set<int64_t>* ids_out);
+ bool GetRestrictedToNamespaces(std::set<std::string>* namespaces_out);
+ bool GetRestrictedToClientIds(std::set<ClientId>* 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<int64_t>> offline_ids_;
+ std::unique_ptr<std::set<GURL>> urls_;
+ std::unique_ptr<std::set<std::string>> restricted_to_namespaces_;
+ std::unique_ptr<std::set<ClientId>> client_ids_;
+
+ DISALLOW_COPY_AND_ASSIGN(OfflinePageModelQuery);
+};
+
+// Used to create an offline page model query. Set policy bits to limit by
+// 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.
+class OfflinePageModelQueryBuilder {
+ public:
+ // The lifetime of policy_controller is not managed; so Build should be called
+ // before policy_controller is destroyed. Typically this is not an issue
+ // because a Builder is turned into a Query right away.
+ explicit OfflinePageModelQueryBuilder(
+ ClientPolicyController* policy_controller);
+ ~OfflinePageModelQueryBuilder();
+
+ // Sets the offline page IDs that are valid for this request. If called
+ // 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
+ OfflinePageModelQueryBuilder& SetOfflinePageIds(
+ const std::vector<int64_t>& ids);
+
+ // Sets the client IDs that are valid for this request. If called
+ // multiple times, takes the intersection of the IDs in all the requests.
+ 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.
+
+ OfflinePageModelQueryBuilder& SetUrls(const std::vector<GURL>& urls);
+
+ // Intersects the currently allowed namespaces with those supported by
+ // download.
+ OfflinePageModelQueryBuilder& RequireSupportedByDownload(
+ bool supported_by_download);
+ // Intersects the currently allowed namespaces with those shown in the NTP as
+ // 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.
+ OfflinePageModelQueryBuilder& RequireShownAsRecentlyVisitedSite(
+ bool recently_visited);
+ // Intersects the currently allowed namespaces with those restricted to
+ // the original tab.
+ OfflinePageModelQueryBuilder& RequireRestrictedToOriginalTab(
+ bool 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();
+
+ private:
+ void IntersectWithNamespaces(const std::vector<std::string>& namespaces);
+
+ // The in-progress query object.
+ std::unique_ptr<OfflinePageModelQuery> query_;
+
+ // Used to turn policy bits into namespace lists.
+ ClientPolicyController* policy_controller_;
+
+ DISALLOW_COPY_AND_ASSIGN(OfflinePageModelQueryBuilder);
+};
+
+} // namespace offline_pages
+
+#endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_QUERY_H_

Powered by Google App Engine
This is Rietveld 408576698