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

Unified Diff: components/offline_pages/offline_page_client_policy.h

Issue 2289143005: [Offline pages] Add a builder and feature struct to policy (Closed)
Patch Set: fix compile issues in test Created 4 years, 3 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
« no previous file with comments | « components/offline_pages/client_policy_controller_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/offline_pages/offline_page_client_policy.h
diff --git a/components/offline_pages/offline_page_client_policy.h b/components/offline_pages/offline_page_client_policy.h
index de7ae526b0038685b403773c3a2ec1bcd3c14aa0..20fd564ecb99c22f42f66bac909581b67e3d3e4e 100644
--- a/components/offline_pages/offline_page_client_policy.h
+++ b/components/offline_pages/offline_page_client_policy.h
@@ -32,11 +32,28 @@ struct LifetimePolicy {
LifetimeType lifetime_type;
// The time after which the page expires.
+ // A TimeDelta of 0 means no expiration.
base::TimeDelta expiration_period;
// The maximum number of pages allowed to be saved by the namespace.
// kUnlimitedPages (defined above) means no limit set.
size_t page_limit;
+
+ LifetimePolicy(LifetimeType init_lifetime_type, size_t init_page_limit)
+ : lifetime_type(init_lifetime_type),
+ expiration_period(base::TimeDelta::FromDays(0)),
+ page_limit(init_page_limit){};
+};
+
+// The struct describing feature set of the offline pages.
+struct FeaturePolicy {
+ // Whether pages are shown in download ui.
+ bool is_supported_by_download;
+ // Whether pages are removed on user-initiated cache reset. Defaults to true.
+ bool is_removed_on_cache_reset;
+
+ FeaturePolicy()
+ : is_supported_by_download(false), is_removed_on_cache_reset(true){};
};
// The struct describing policies for various namespaces (Bookmark, Last-N etc.)
@@ -52,6 +69,65 @@ struct OfflinePageClientPolicy {
// How many pages for the same online URL can be stored at any time.
// kUnlimitedPages means there's no limit.
size_t pages_allowed_per_url;
+
+ FeaturePolicy feature_policy;
+
+ OfflinePageClientPolicy(std::string namespace_val,
+ LifetimePolicy lifetime_policy_val,
+ size_t pages_allowed_per_url_val,
+ FeaturePolicy feature_policy_val)
+ : name_space(namespace_val),
+ lifetime_policy(lifetime_policy_val),
+ pages_allowed_per_url(pages_allowed_per_url_val),
+ feature_policy(feature_policy_val){};
+
+ OfflinePageClientPolicy(std::string namespace_val,
+ LifetimePolicy lifetime_policy_val,
+ size_t pages_allowed_per_url_val)
+ : OfflinePageClientPolicy(namespace_val,
+ lifetime_policy_val,
+ pages_allowed_per_url_val,
+ FeaturePolicy()){};
+};
+
+class OfflinePageClientPolicyBuilder {
+ public:
+ OfflinePageClientPolicyBuilder(const std::string& name_space,
+ LifetimePolicy::LifetimeType lifetime_type,
+ size_t page_limit,
+ size_t pages_allowed_per_url)
+ : policy_(
+ OfflinePageClientPolicy(name_space,
+ LifetimePolicy(lifetime_type, page_limit),
+ pages_allowed_per_url)){};
+
+ ~OfflinePageClientPolicyBuilder() {}
+
+ // Calling build does not reset the object inside.
+ const OfflinePageClientPolicy Build() const { return policy_; }
+
+ OfflinePageClientPolicyBuilder& SetExpirePeriod(
+ const base::TimeDelta& expire_period) {
+ policy_.lifetime_policy.expiration_period = expire_period;
+ return *this;
+ }
+
+ OfflinePageClientPolicyBuilder& SetIsSupportedByDownload(
+ const bool is_downloaded) {
+ policy_.feature_policy.is_supported_by_download = is_downloaded;
+ return *this;
+ }
+
+ OfflinePageClientPolicyBuilder& SetIsRemovedOnCacheReset(
+ const bool removed_on_cache_reset) {
+ policy_.feature_policy.is_removed_on_cache_reset = removed_on_cache_reset;
+ return *this;
+ }
+
+ private:
+ OfflinePageClientPolicy policy_;
+
+ DISALLOW_COPY_AND_ASSIGN(OfflinePageClientPolicyBuilder);
};
} // namespace offline_pages
« no previous file with comments | « components/offline_pages/client_policy_controller_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698