Chromium Code Reviews| 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 21 matching lines...) Expand all Loading... | |
| 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 base::TimeDelta expiration_period; | 35 base::TimeDelta expiration_period; |
| 36 | 36 |
| 37 // The maximum number of pages allowed to be saved by the namespace. | 37 // The maximum number of pages allowed to be saved by the namespace. |
| 38 // kUnlimitedPages (defined above) means no limit set. | 38 // kUnlimitedPages (defined above) means no limit set. |
| 39 size_t page_limit; | 39 size_t page_limit; |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 // The struct describing feature set of the offline pages. | |
| 43 struct FeaturePolicy { | |
| 44 // Whether pages are shown in download ui. | |
| 45 bool is_supported_by_download; | |
| 46 // Whether pages are removed on user-initiated cache reset. Defaults to true. | |
| 47 bool is_removed_on_cache_reset; | |
| 48 }; | |
| 49 | |
| 42 // The struct describing policies for various namespaces (Bookmark, Last-N etc.) | 50 // 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 | 51 // 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. | 52 // it's sufficient to compare name_space only when doing comparisons. |
| 45 struct OfflinePageClientPolicy { | 53 struct OfflinePageClientPolicy { |
| 46 // Namespace to which the policy applied. | 54 // Namespace to which the policy applied. |
| 47 std::string name_space; | 55 std::string name_space; |
| 48 | 56 |
| 49 // Policy to control the lifetime of a page generated by this namespace. | 57 // Policy to control the lifetime of a page generated by this namespace. |
| 50 LifetimePolicy lifetime_policy; | 58 LifetimePolicy lifetime_policy; |
| 51 | 59 |
| 52 // How many pages for the same online URL can be stored at any time. | 60 // How many pages for the same online URL can be stored at any time. |
| 53 // kUnlimitedPages means there's no limit. | 61 // kUnlimitedPages means there's no limit. |
| 54 size_t pages_allowed_per_url; | 62 size_t pages_allowed_per_url; |
| 63 | |
| 64 FeaturePolicy feature_policy; | |
| 65 }; | |
| 66 | |
| 67 class OfflinePageClientPolicyBuilder { | |
| 68 public: | |
| 69 OfflinePageClientPolicyBuilder(const std::string& name_space, | |
| 70 LifetimePolicy::LifetimeType lifetime_type, | |
| 71 size_t page_limit, | |
| 72 size_t pages_allowed_per_url) { | |
| 73 policy_ = OfflinePageClientPolicy( | |
| 74 {name_space, | |
| 75 {lifetime_type, base::TimeDelta::FromDays(0), page_limit}, | |
| 76 pages_allowed_per_url, | |
| 77 {false, true}}); | |
|
Dmitry Titov
2016/09/12 17:43:34
could you add in-line comments here to say what th
dewittj
2016/09/12 18:06:35
I'd propose adding default values when possible to
chili
2016/09/12 21:24:06
Done.
| |
| 78 } | |
| 79 | |
| 80 ~OfflinePageClientPolicyBuilder() {} | |
| 81 | |
| 82 // Calling build does not reset the object inside. | |
| 83 const OfflinePageClientPolicy Build() const { return policy_; } | |
| 84 | |
| 85 OfflinePageClientPolicyBuilder& SetExpirePeriod( | |
| 86 const base::TimeDelta& expire_period) { | |
| 87 policy_.lifetime_policy.expiration_period = expire_period; | |
| 88 return *this; | |
| 89 } | |
| 90 | |
| 91 OfflinePageClientPolicyBuilder& SetIsSupportedByDownload( | |
| 92 const bool is_downloaded) { | |
| 93 policy_.feature_policy.is_supported_by_download = is_downloaded; | |
| 94 return *this; | |
| 95 } | |
| 96 | |
| 97 OfflinePageClientPolicyBuilder& SetIsRemovedOnCacheReset( | |
| 98 const bool removed_on_cache_reset) { | |
| 99 policy_.feature_policy.is_removed_on_cache_reset = removed_on_cache_reset; | |
| 100 return *this; | |
| 101 } | |
| 102 | |
| 103 private: | |
| 104 OfflinePageClientPolicy policy_; | |
|
Dmitry Titov
2016/09/12 17:43:34
DISALLOW_COPY_AND_ASSIGN...
chili
2016/09/12 21:24:06
Done.
| |
| 55 }; | 105 }; |
| 56 | 106 |
| 57 } // namespace offline_pages | 107 } // namespace offline_pages |
| 58 | 108 |
| 59 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_CLIENT_POLICY_H_ | 109 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_CLIENT_POLICY_H_ |
| OLD | NEW |