| 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_CLIENT_POLICY_H_ | |
| 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_CLIENT_POLICY_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/time/time.h" | |
| 13 | |
| 14 namespace offline_pages { | |
| 15 | |
| 16 static const size_t kUnlimitedPages = 0; | |
| 17 | |
| 18 // The struct describing the lifetime policy of offline pages. | |
| 19 // The following behaviors are controlled by policy: | |
| 20 // a. Persistency of the offline page. | |
| 21 // b. Expiration time of an offline page | |
| 22 // c. Limit of number of pages offline. | |
| 23 struct LifetimePolicy { | |
| 24 // Type of the client, indicating where the archived page would be saved | |
| 25 // and whether it could be kept indefinitely. | |
| 26 enum class LifetimeType { | |
| 27 TEMPORARY, | |
| 28 PERSISTENT, | |
| 29 }; | |
| 30 | |
| 31 // Type of the page generated by the client. | |
| 32 LifetimeType lifetime_type; | |
| 33 | |
| 34 // The time after which the page expires. | |
| 35 // A TimeDelta of 0 means no expiration. | |
| 36 base::TimeDelta expiration_period; | |
| 37 | |
| 38 // The maximum number of pages allowed to be saved by the namespace. | |
| 39 // kUnlimitedPages (defined above) means no limit set. | |
| 40 size_t page_limit; | |
| 41 | |
| 42 LifetimePolicy(LifetimeType init_lifetime_type, size_t init_page_limit) | |
| 43 : lifetime_type(init_lifetime_type), | |
| 44 expiration_period(base::TimeDelta::FromDays(0)), | |
| 45 page_limit(init_page_limit){}; | |
| 46 }; | |
| 47 | |
| 48 // The struct describing feature set of the offline pages. | |
| 49 struct FeaturePolicy { | |
| 50 // Whether pages are shown in download ui. | |
| 51 bool is_supported_by_download; | |
| 52 // Whether pages are shown in recent tabs ui. | |
| 53 bool is_supported_by_recent_tabs; | |
| 54 // Whether pages should only be viewed in the tab they were generated in. | |
| 55 bool only_shown_in_original_tab; | |
| 56 // Whether pages are removed on user-initiated cache reset. Defaults to true. | |
| 57 bool is_removed_on_cache_reset; | |
| 58 | |
| 59 FeaturePolicy() | |
| 60 : is_supported_by_download(false), | |
| 61 is_supported_by_recent_tabs(false), | |
| 62 only_shown_in_original_tab(false), | |
| 63 is_removed_on_cache_reset(true){}; | |
| 64 }; | |
| 65 | |
| 66 // The struct describing policies for various namespaces (Bookmark, Last-N etc.) | |
| 67 // used by offline page model. The name_space is supposed to be key, so that | |
| 68 // it's sufficient to compare name_space only when doing comparisons. | |
| 69 struct OfflinePageClientPolicy { | |
| 70 // Namespace to which the policy applied. | |
| 71 std::string name_space; | |
| 72 | |
| 73 // Policy to control the lifetime of a page generated by this namespace. | |
| 74 LifetimePolicy lifetime_policy; | |
| 75 | |
| 76 // How many pages for the same online URL can be stored at any time. | |
| 77 // kUnlimitedPages means there's no limit. | |
| 78 size_t pages_allowed_per_url; | |
| 79 | |
| 80 FeaturePolicy feature_policy; | |
| 81 | |
| 82 OfflinePageClientPolicy(std::string namespace_val, | |
| 83 LifetimePolicy lifetime_policy_val, | |
| 84 size_t pages_allowed_per_url_val, | |
| 85 FeaturePolicy feature_policy_val) | |
| 86 : name_space(namespace_val), | |
| 87 lifetime_policy(lifetime_policy_val), | |
| 88 pages_allowed_per_url(pages_allowed_per_url_val), | |
| 89 feature_policy(feature_policy_val){}; | |
| 90 | |
| 91 OfflinePageClientPolicy(std::string namespace_val, | |
| 92 LifetimePolicy lifetime_policy_val, | |
| 93 size_t pages_allowed_per_url_val) | |
| 94 : OfflinePageClientPolicy(namespace_val, | |
| 95 lifetime_policy_val, | |
| 96 pages_allowed_per_url_val, | |
| 97 FeaturePolicy()){}; | |
| 98 }; | |
| 99 | |
| 100 class OfflinePageClientPolicyBuilder { | |
| 101 public: | |
| 102 OfflinePageClientPolicyBuilder(const std::string& name_space, | |
| 103 LifetimePolicy::LifetimeType lifetime_type, | |
| 104 size_t page_limit, | |
| 105 size_t pages_allowed_per_url) | |
| 106 : policy_( | |
| 107 OfflinePageClientPolicy(name_space, | |
| 108 LifetimePolicy(lifetime_type, page_limit), | |
| 109 pages_allowed_per_url)){}; | |
| 110 | |
| 111 ~OfflinePageClientPolicyBuilder() {} | |
| 112 | |
| 113 // Calling build does not reset the object inside. | |
| 114 const OfflinePageClientPolicy Build() const { return policy_; } | |
| 115 | |
| 116 OfflinePageClientPolicyBuilder& SetExpirePeriod( | |
| 117 const base::TimeDelta& expire_period) { | |
| 118 policy_.lifetime_policy.expiration_period = expire_period; | |
| 119 return *this; | |
| 120 } | |
| 121 | |
| 122 OfflinePageClientPolicyBuilder& SetIsSupportedByDownload( | |
| 123 const bool is_downloaded) { | |
| 124 policy_.feature_policy.is_supported_by_download = is_downloaded; | |
| 125 return *this; | |
| 126 } | |
| 127 | |
| 128 OfflinePageClientPolicyBuilder& SetIsSupportedByRecentTabs( | |
| 129 const bool is_recent_tabs) { | |
| 130 policy_.feature_policy.is_supported_by_recent_tabs = is_recent_tabs; | |
| 131 return *this; | |
| 132 } | |
| 133 | |
| 134 OfflinePageClientPolicyBuilder& SetIsRemovedOnCacheReset( | |
| 135 const bool removed_on_cache_reset) { | |
| 136 policy_.feature_policy.is_removed_on_cache_reset = removed_on_cache_reset; | |
| 137 return *this; | |
| 138 } | |
| 139 | |
| 140 OfflinePageClientPolicyBuilder& SetIsOnlyShownInOriginalTab( | |
| 141 const bool only_shown_in_original_tab) { | |
| 142 policy_.feature_policy.only_shown_in_original_tab = | |
| 143 only_shown_in_original_tab; | |
| 144 return *this; | |
| 145 } | |
| 146 | |
| 147 private: | |
| 148 OfflinePageClientPolicy policy_; | |
| 149 | |
| 150 DISALLOW_COPY_AND_ASSIGN(OfflinePageClientPolicyBuilder); | |
| 151 }; | |
| 152 | |
| 153 } // namespace offline_pages | |
| 154 | |
| 155 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_CLIENT_POLICY_H_ | |
| OLD | NEW |