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

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: 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
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 21 matching lines...) Expand all
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 bool is_enabled_for_downloads;
45 bool is_user_requested;
46 };
47
42 // The struct describing policies for various namespaces (Bookmark, Last-N etc.) 48 // 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 49 // 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. 50 // it's sufficient to compare name_space only when doing comparisons.
45 struct OfflinePageClientPolicy { 51 struct OfflinePageClientPolicy {
46 // Namespace to which the policy applied. 52 // Namespace to which the policy applied.
47 std::string name_space; 53 std::string name_space;
48 54
49 // Policy to control the lifetime of a page generated by this namespace. 55 // Policy to control the lifetime of a page generated by this namespace.
50 LifetimePolicy lifetime_policy; 56 LifetimePolicy lifetime_policy;
51 57
52 // How many pages for the same online URL can be stored at any time. 58 // How many pages for the same online URL can be stored at any time.
53 // kUnlimitedPages means there's no limit. 59 // kUnlimitedPages means there's no limit.
54 size_t pages_allowed_per_url; 60 size_t pages_allowed_per_url;
fgorski 2016/08/31 21:31:00 wouldn't this qualify as feature policy?
chili 2016/09/06 20:55:20 I see feature policies (perhaps I should change na
61
62 FeaturePolicy feature_policy;
63 };
64
65 class OfflinePageClientPolicyBuilder {
66 public:
67 OfflinePageClientPolicyBuilder(const std::string& name_space,
68 LifetimePolicy::LifetimeType lifetime_type,
69 size_t page_limit,
70 size_t pages_allowed_per_url) {
71 policy_ = OfflinePageClientPolicy({name_space,
72 {lifetime_type, base::TimeDelta::FromDays(0), page_limit},
73 pages_allowed_per_url,
74 {false, false}});
75 }
76
77 ~OfflinePageClientPolicyBuilder() {}
78
79 const OfflinePageClientPolicy Build() { return policy_; }
80
81 OfflinePageClientPolicyBuilder& SetExpirePeriod(
82 const base::TimeDelta& expire_period) {
83 policy_.lifetime_policy.expiration_period = expire_period;
84 return *this;
85 }
86
87 OfflinePageClientPolicyBuilder& SetIsDownloaded(
88 const bool is_downloaded) {
89 policy_.feature_policy.is_enabled_for_downloads = is_downloaded;
90 return *this;
91 }
92
93 OfflinePageClientPolicyBuilder& SetUserRequested(
94 const bool user_requested) {
95 policy_.feature_policy.is_user_requested = user_requested;
96 return *this;
97 }
98
99 private:
100 OfflinePageClientPolicy policy_;
55 }; 101 };
56 102
57 } // namespace offline_pages 103 } // namespace offline_pages
58 104
59 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_CLIENT_POLICY_H_ 105 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_CLIENT_POLICY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698