| 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_CLIENT_POLICY_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_CLIENT_POLICY_H_ |
| 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_CLIENT_POLICY_H_ | 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_CLIENT_POLICY_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // and whether it could be kept indefinitely. | 25 // and whether it could be kept indefinitely. |
| 26 enum class LifetimeType { | 26 enum class LifetimeType { |
| 27 TEMPORARY, | 27 TEMPORARY, |
| 28 PERSISTENT, | 28 PERSISTENT, |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 // Type of the page generated by the client. | 31 // Type of the page generated by the client. |
| 32 LifetimeType lifetime_type; | 32 LifetimeType lifetime_type; |
| 33 | 33 |
| 34 // The time after which the page expires. | 34 // The time after which the page expires. |
| 35 // A TimeDelta of 0 means no expiration. |
| 35 base::TimeDelta expiration_period; | 36 base::TimeDelta expiration_period; |
| 36 | 37 |
| 37 // The maximum number of pages allowed to be saved by the namespace. | 38 // The maximum number of pages allowed to be saved by the namespace. |
| 38 // kUnlimitedPages (defined above) means no limit set. | 39 // kUnlimitedPages (defined above) means no limit set. |
| 39 size_t page_limit; | 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 removed on user-initiated cache reset. Defaults to true. |
| 53 bool is_removed_on_cache_reset; |
| 54 |
| 55 FeaturePolicy() |
| 56 : is_supported_by_download(false), is_removed_on_cache_reset(true){}; |
| 40 }; | 57 }; |
| 41 | 58 |
| 42 // The struct describing policies for various namespaces (Bookmark, Last-N etc.) | 59 // The struct describing policies for various namespaces (Bookmark, Last-N etc.) |
| 43 // used by offline page model. The name_space is supposed to be key, so that | 60 // used by offline page model. The name_space is supposed to be key, so that |
| 44 // it's sufficient to compare name_space only when doing comparisons. | 61 // it's sufficient to compare name_space only when doing comparisons. |
| 45 struct OfflinePageClientPolicy { | 62 struct OfflinePageClientPolicy { |
| 46 // Namespace to which the policy applied. | 63 // Namespace to which the policy applied. |
| 47 std::string name_space; | 64 std::string name_space; |
| 48 | 65 |
| 49 // Policy to control the lifetime of a page generated by this namespace. | 66 // Policy to control the lifetime of a page generated by this namespace. |
| 50 LifetimePolicy lifetime_policy; | 67 LifetimePolicy lifetime_policy; |
| 51 | 68 |
| 52 // How many pages for the same online URL can be stored at any time. | 69 // How many pages for the same online URL can be stored at any time. |
| 53 // kUnlimitedPages means there's no limit. | 70 // kUnlimitedPages means there's no limit. |
| 54 size_t pages_allowed_per_url; | 71 size_t pages_allowed_per_url; |
| 72 |
| 73 FeaturePolicy feature_policy; |
| 74 |
| 75 OfflinePageClientPolicy(std::string namespace_val, |
| 76 LifetimePolicy lifetime_policy_val, |
| 77 size_t pages_allowed_per_url_val, |
| 78 FeaturePolicy feature_policy_val) |
| 79 : name_space(namespace_val), |
| 80 lifetime_policy(lifetime_policy_val), |
| 81 pages_allowed_per_url(pages_allowed_per_url_val), |
| 82 feature_policy(feature_policy_val){}; |
| 83 |
| 84 OfflinePageClientPolicy(std::string namespace_val, |
| 85 LifetimePolicy lifetime_policy_val, |
| 86 size_t pages_allowed_per_url_val) |
| 87 : OfflinePageClientPolicy(namespace_val, |
| 88 lifetime_policy_val, |
| 89 pages_allowed_per_url_val, |
| 90 FeaturePolicy()){}; |
| 91 }; |
| 92 |
| 93 class OfflinePageClientPolicyBuilder { |
| 94 public: |
| 95 OfflinePageClientPolicyBuilder(const std::string& name_space, |
| 96 LifetimePolicy::LifetimeType lifetime_type, |
| 97 size_t page_limit, |
| 98 size_t pages_allowed_per_url) |
| 99 : policy_( |
| 100 OfflinePageClientPolicy(name_space, |
| 101 LifetimePolicy(lifetime_type, page_limit), |
| 102 pages_allowed_per_url)){}; |
| 103 |
| 104 ~OfflinePageClientPolicyBuilder() {} |
| 105 |
| 106 // Calling build does not reset the object inside. |
| 107 const OfflinePageClientPolicy Build() const { return policy_; } |
| 108 |
| 109 OfflinePageClientPolicyBuilder& SetExpirePeriod( |
| 110 const base::TimeDelta& expire_period) { |
| 111 policy_.lifetime_policy.expiration_period = expire_period; |
| 112 return *this; |
| 113 } |
| 114 |
| 115 OfflinePageClientPolicyBuilder& SetIsSupportedByDownload( |
| 116 const bool is_downloaded) { |
| 117 policy_.feature_policy.is_supported_by_download = is_downloaded; |
| 118 return *this; |
| 119 } |
| 120 |
| 121 OfflinePageClientPolicyBuilder& SetIsRemovedOnCacheReset( |
| 122 const bool removed_on_cache_reset) { |
| 123 policy_.feature_policy.is_removed_on_cache_reset = removed_on_cache_reset; |
| 124 return *this; |
| 125 } |
| 126 |
| 127 private: |
| 128 OfflinePageClientPolicy policy_; |
| 129 |
| 130 DISALLOW_COPY_AND_ASSIGN(OfflinePageClientPolicyBuilder); |
| 55 }; | 131 }; |
| 56 | 132 |
| 57 } // namespace offline_pages | 133 } // namespace offline_pages |
| 58 | 134 |
| 59 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_CLIENT_POLICY_H_ | 135 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_CLIENT_POLICY_H_ |
| OLD | NEW |