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_BACKGROUND_OFFLINER_POLICY_H_ | |
6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_POLICY_H_ | |
7 | |
8 namespace { | |
9 // The max number of started tries is to guard against pages that make the | |
10 // prerenderer crash. It should be greater than or equal to the max number of | |
11 // completed tries. | |
12 const int kMaxStartedTries = 5; | |
13 // The number of max completed tries is based on Gin2G-poor testing showing that | |
14 // we often need about 4 tries with a 2 minute window, or 3 retries with a 3 | |
15 // minute window. Also, we count one try now for foreground/disabled requests. | |
16 const int kMaxCompletedTries = 3; | |
17 // By the time we get to a week, the user has forgotten asking for a page. | |
18 const int kRequestExpirationTimeInSeconds = 60 * 60 * 24 * 7; | |
19 | |
20 // Scheduled background processing time limits. | |
21 const int kDozeModeBackgroundServiceWindowSeconds = 60 * 3; | |
22 const int kDefaultBackgroundProcessingTimeBudgetSeconds = | |
23 kDozeModeBackgroundServiceWindowSeconds - 10; | |
24 const int kSinglePageTimeLimitWhenBackgroundScheduledSeconds = | |
25 kDozeModeBackgroundServiceWindowSeconds - 10; | |
26 | |
27 // Immediate processing time limits. | |
28 // Note: experiments on GIN-2g-poor show many page requests took 3 or 4 | |
29 // attempts in background scheduled mode with timeout of 2 minutes. So for | |
30 // immediate processing mode, give page requests 4 times that limit (8 min). | |
31 // Then budget up to 5 of those requests in processing window. | |
32 const int kSinglePageTimeLimitForImmediateLoadSeconds = 60 * 8; | |
33 const int kImmediateLoadProcessingTimeBudgetSeconds = | |
34 kSinglePageTimeLimitForImmediateLoadSeconds * 5; | |
35 } // namespace | |
36 | |
37 namespace offline_pages { | |
38 | |
39 // Policy for the Background Offlining system. Some policy will belong to the | |
40 // RequestCoordinator, some to the RequestQueue, and some to the Offliner. | |
41 class OfflinerPolicy { | |
42 public: | |
43 OfflinerPolicy() | |
44 : prefer_untried_requests_(true), | |
45 prefer_earlier_requests_(true), | |
46 retry_count_is_more_important_than_recency_(true), | |
47 max_started_tries_(kMaxStartedTries), | |
48 max_completed_tries_(kMaxCompletedTries), | |
49 background_scheduled_processing_time_budget_( | |
50 kDefaultBackgroundProcessingTimeBudgetSeconds) {} | |
51 | |
52 // Constructor for unit tests. | |
53 OfflinerPolicy(bool prefer_untried, | |
54 bool prefer_earlier, | |
55 bool prefer_retry_count, | |
56 int max_started_tries, | |
57 int max_completed_tries, | |
58 int background_processing_time_budget) | |
59 : prefer_untried_requests_(prefer_untried), | |
60 prefer_earlier_requests_(prefer_earlier), | |
61 retry_count_is_more_important_than_recency_(prefer_retry_count), | |
62 max_started_tries_(max_started_tries), | |
63 max_completed_tries_(max_completed_tries), | |
64 background_scheduled_processing_time_budget_( | |
65 background_processing_time_budget) {} | |
66 | |
67 // TODO(petewil): Numbers here are chosen arbitrarily, do the proper studies | |
68 // to get good policy numbers. Eventually this should get data from a finch | |
69 // experiment. | |
70 | |
71 // Returns true if we should prefer retrying lesser tried requests. | |
72 bool ShouldPreferUntriedRequests() const { return prefer_untried_requests_; } | |
73 | |
74 // Returns true if we should prefer older requests of equal number of tries. | |
75 bool ShouldPreferEarlierRequests() const { return prefer_earlier_requests_; } | |
76 | |
77 // Returns true if retry count is considered more important than recency in | |
78 // picking which request to try next. | |
79 bool RetryCountIsMoreImportantThanRecency() const { | |
80 return retry_count_is_more_important_than_recency_; | |
81 } | |
82 | |
83 // The max number of times we will start a request. Not all started attempts | |
84 // will complete. This may be caused by prerenderer issues or chromium being | |
85 // swapped out of memory. | |
86 int GetMaxStartedTries() const { return max_started_tries_; } | |
87 | |
88 // The max number of times we will retry a request when the attempt | |
89 // completed, but failed. | |
90 int GetMaxCompletedTries() const { return max_completed_tries_; } | |
91 | |
92 bool PowerRequired(bool user_requested) const { | |
93 return (!user_requested); | |
94 } | |
95 | |
96 bool UnmeteredNetworkRequired(bool user_requested) const { | |
97 return !(user_requested); | |
98 } | |
99 | |
100 int BatteryPercentageRequired(bool user_requested) const { | |
101 if (user_requested) | |
102 return 0; | |
103 // This is so low because we require the device to be plugged in and | |
104 // charging. If we decide to allow non-user requested pages when not | |
105 // plugged in, we should raise this somewhat higher. | |
106 return 25; | |
107 } | |
108 | |
109 // How many seconds to keep trying new pages for, before we give up, and | |
110 // return to the scheduler. | |
111 // TODO(dougarnett): Consider parameterizing these time limit/budget | |
112 // calls with processing mode. | |
113 int GetProcessingTimeBudgetWhenBackgroundScheduledInSeconds() const { | |
114 return background_scheduled_processing_time_budget_; | |
115 } | |
116 | |
117 // How many seconds to keep trying new pages for, before we give up, when | |
118 // processing started immediately (without scheduler). | |
119 int GetProcessingTimeBudgetForImmediateLoadInSeconds() const { | |
120 return kImmediateLoadProcessingTimeBudgetSeconds; | |
121 } | |
122 | |
123 // How long do we allow a page to load before giving up on it when | |
124 // background loading was scheduled. | |
125 int GetSinglePageTimeLimitWhenBackgroundScheduledInSeconds() const { | |
126 return kSinglePageTimeLimitWhenBackgroundScheduledSeconds; | |
127 } | |
128 | |
129 // How long do we allow a page to load before giving up on it when | |
130 // immediately background loading. | |
131 int GetSinglePageTimeLimitForImmediateLoadInSeconds() const { | |
132 return kSinglePageTimeLimitForImmediateLoadSeconds; | |
133 } | |
134 | |
135 // How long we allow requests to remain in the system before giving up. | |
136 int GetRequestExpirationTimeInSeconds() const { | |
137 return kRequestExpirationTimeInSeconds; | |
138 } | |
139 | |
140 private: | |
141 bool prefer_untried_requests_; | |
142 bool prefer_earlier_requests_; | |
143 bool retry_count_is_more_important_than_recency_; | |
144 int max_started_tries_; | |
145 int max_completed_tries_; | |
146 int background_scheduled_processing_time_budget_; | |
147 }; | |
148 } // namespace offline_pages | |
149 | |
150 | |
151 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_POLICY_H_ | |
OLD | NEW |