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

Side by Side Diff: components/offline_pages/offline_page_client_policy.h

Issue 2289143005: [Offline pages] Add a builder and feature struct to policy (Closed)
Patch Set: make constructor more readable 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 unified diff | Download patch
« no previous file with comments | « components/offline_pages/client_policy_controller_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 11 matching lines...) Expand all
22 // c. Limit of number of pages offline. 22 // c. Limit of number of pages offline.
23 struct LifetimePolicy { 23 struct LifetimePolicy {
24 // Type of the client, indicating where the archived page would be saved 24 // Type of the client, indicating where the archived page would be saved
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;
dewittj 2016/09/12 21:40:53 I might also assign defaults here and in page_limi
chili 2016/09/13 00:36:10 Done.
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 = base::TimeDelta::FromDays(0);
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 = false;
46 // Whether pages are removed on user-initiated cache reset. Defaults to true.
47 bool is_removed_on_cache_reset = true;
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();
dewittj 2016/09/12 21:40:53 Is this line strictly necessary? I think it shoul
chili 2016/09/13 00:36:10 Done.
74 policy_.name_space = name_space;
75 policy_.lifetime_policy.lifetime_type = lifetime_type;
76 policy_.lifetime_policy.page_limit = page_limit;
77 policy_.pages_allowed_per_url = pages_allowed_per_url;
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_;
105
106 DISALLOW_COPY_AND_ASSIGN(OfflinePageClientPolicyBuilder);
55 }; 107 };
56 108
57 } // namespace offline_pages 109 } // namespace offline_pages
58 110
59 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_CLIENT_POLICY_H_ 111 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_CLIENT_POLICY_H_
OLDNEW
« 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