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_CORE_BACKGROUND_OFFLINER_POLICY_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_OFFLINER_POLICY_H_ |
6 #define COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_OFFLINER_POLICY_H_ | 6 #define COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_OFFLINER_POLICY_H_ |
7 | 7 |
8 #include "base/sys_info.h" | |
9 | |
10 namespace { | 8 namespace { |
11 // The max number of started tries is to guard against pages that make the | 9 // The max number of started tries is to guard against pages that make the |
12 // prerenderer crash. It should be greater than or equal to the max number of | 10 // prerenderer crash. It should be greater than or equal to the max number of |
13 // completed tries. | 11 // completed tries. |
14 const int kMaxStartedTries = 5; | 12 const int kMaxStartedTries = 5; |
15 // The number of max completed tries is based on Gin2G-poor testing showing that | 13 // The number of max completed tries is based on Gin2G-poor testing showing that |
16 // we often need about 4 tries with a 2 minute window, or 3 retries with a 3 | 14 // we often need about 4 tries with a 2 minute window, or 3 retries with a 3 |
17 // minute window. Also, we count one try now for foreground/disabled requests. | 15 // minute window. Also, we count one try now for foreground/disabled requests. |
18 const int kMaxCompletedTries = 3; | 16 const int kMaxCompletedTries = 3; |
19 // By the time we get to a week, the user has forgotten asking for a page. | 17 // By the time we get to a week, the user has forgotten asking for a page. |
20 const int kRequestExpirationTimeInSeconds = 60 * 60 * 24 * 7; | 18 const int kRequestExpirationTimeInSeconds = 60 * 60 * 24 * 7; |
21 | 19 |
22 // Scheduled background processing time limits for doze mode, which requires | 20 // Scheduled background processing time limits. |
23 // Android version >= 6.0 (API level >= 23). Otherwise the scheduled background | |
24 // processing time should be the same as immediate loading (4 min 50 secs), it's | |
25 // capped by the Prerenderer's 5 minute timeout. | |
26 const int kDozeModeBackgroundServiceWindowSeconds = 60 * 3; | 21 const int kDozeModeBackgroundServiceWindowSeconds = 60 * 3; |
27 const int kDefaultBackgroundProcessingTimeBudgetSeconds = | 22 const int kDefaultBackgroundProcessingTimeBudgetSeconds = |
28 kDozeModeBackgroundServiceWindowSeconds - 10; | 23 kDozeModeBackgroundServiceWindowSeconds - 10; |
29 const int kSinglePageTimeLimitWhenBackgroundScheduledSeconds = | 24 const int kSinglePageTimeLimitWhenBackgroundScheduledSeconds = |
30 kDozeModeBackgroundServiceWindowSeconds - 10; | 25 kDozeModeBackgroundServiceWindowSeconds - 10; |
31 | 26 |
32 const int kNonDozeModeBackgroundServiceWindowSeconds = 60 * 5; | |
33 const int kNonDozeDefaultBackgroundProcessingTimeBudgetSeconds = | |
34 kNonDozeModeBackgroundServiceWindowSeconds - 10; | |
35 const int kNonDozeSinglePageTimeLimitWhenBackgroundScheduledSeconds = | |
36 kNonDozeModeBackgroundServiceWindowSeconds - 10; | |
37 | |
38 // Immediate processing time limits. Note: experiments on GIN-2g-poor show many | 27 // Immediate processing time limits. Note: experiments on GIN-2g-poor show many |
39 // page requests took 3 or 4 attempts in background scheduled mode with timeout | 28 // page requests took 3 or 4 attempts in background scheduled mode with timeout |
40 // of 2 minutes. So for immediate processing mode, give page requests just under | 29 // of 2 minutes. So for immediate processing mode, give page requests just under |
41 // 5 minutes, which is the timeout limit for the prerender itself. Then budget | 30 // 5 minutes, which is the timeout limit for the prerender itself. Then budget |
42 // up to 3 of those requests in processing window. | 31 // up to 3 of those requests in processing window. |
43 const int kSinglePageTimeLimitForImmediateLoadSeconds = 60 * 4 + 50; | 32 const int kSinglePageTimeLimitForImmediateLoadSeconds = 60 * 4 + 50; |
44 const int kImmediateLoadProcessingTimeBudgetSeconds = | 33 const int kImmediateLoadProcessingTimeBudgetSeconds = |
45 kSinglePageTimeLimitForImmediateLoadSeconds * 5; | 34 kSinglePageTimeLimitForImmediateLoadSeconds * 5; |
46 } // namespace | 35 } // namespace |
47 | 36 |
48 namespace offline_pages { | 37 namespace offline_pages { |
49 | 38 |
50 // Policy for the Background Offlining system. Some policy will belong to the | 39 // Policy for the Background Offlining system. Some policy will belong to the |
51 // RequestCoordinator, some to the RequestQueue, and some to the Offliner. | 40 // RequestCoordinator, some to the RequestQueue, and some to the Offliner. |
52 class OfflinerPolicy { | 41 class OfflinerPolicy { |
53 public: | 42 public: |
54 OfflinerPolicy() | 43 OfflinerPolicy() |
55 : prefer_untried_requests_(true), | 44 : prefer_untried_requests_(true), |
56 prefer_earlier_requests_(true), | 45 prefer_earlier_requests_(true), |
57 retry_count_is_more_important_than_recency_(true), | 46 retry_count_is_more_important_than_recency_(true), |
58 max_started_tries_(kMaxStartedTries), | 47 max_started_tries_(kMaxStartedTries), |
59 max_completed_tries_(kMaxCompletedTries) { | 48 max_completed_tries_(kMaxCompletedTries), |
60 int32_t os_major_version = 0; | 49 background_scheduled_processing_time_budget_( |
61 int32_t os_minor_version = 0; | 50 kDefaultBackgroundProcessingTimeBudgetSeconds) {} |
62 int32_t os_bugfix_version = 0; | |
63 base::SysInfo::OperatingSystemVersionNumbers( | |
64 &os_major_version, &os_minor_version, &os_bugfix_version); | |
65 if (os_major_version < 6) | |
66 has_doze_mode_ = false; | |
67 else | |
68 has_doze_mode_ = true; | |
69 } | |
70 | 51 |
71 // Constructor for unit tests. | 52 // Constructor for unit tests. |
72 OfflinerPolicy(bool prefer_untried, | 53 OfflinerPolicy(bool prefer_untried, |
73 bool prefer_earlier, | 54 bool prefer_earlier, |
74 bool prefer_retry_count, | 55 bool prefer_retry_count, |
75 int max_started_tries, | 56 int max_started_tries, |
76 int max_completed_tries) | 57 int max_completed_tries, |
| 58 int background_processing_time_budget) |
77 : prefer_untried_requests_(prefer_untried), | 59 : prefer_untried_requests_(prefer_untried), |
78 prefer_earlier_requests_(prefer_earlier), | 60 prefer_earlier_requests_(prefer_earlier), |
79 retry_count_is_more_important_than_recency_(prefer_retry_count), | 61 retry_count_is_more_important_than_recency_(prefer_retry_count), |
80 max_started_tries_(max_started_tries), | 62 max_started_tries_(max_started_tries), |
81 max_completed_tries_(max_completed_tries) {} | 63 max_completed_tries_(max_completed_tries), |
| 64 background_scheduled_processing_time_budget_( |
| 65 background_processing_time_budget) {} |
82 | 66 |
83 // TODO(petewil): Numbers here are chosen arbitrarily, do the proper studies | 67 // TODO(petewil): Numbers here are chosen arbitrarily, do the proper studies |
84 // to get good policy numbers. Eventually this should get data from a finch | 68 // to get good policy numbers. Eventually this should get data from a finch |
85 // experiment. | 69 // experiment. |
86 | 70 |
87 // Returns true if we should prefer retrying lesser tried requests. | 71 // Returns true if we should prefer retrying lesser tried requests. |
88 bool ShouldPreferUntriedRequests() const { return prefer_untried_requests_; } | 72 bool ShouldPreferUntriedRequests() const { return prefer_untried_requests_; } |
89 | 73 |
90 // Returns true if we should prefer older requests of equal number of tries. | 74 // Returns true if we should prefer older requests of equal number of tries. |
91 bool ShouldPreferEarlierRequests() const { return prefer_earlier_requests_; } | 75 bool ShouldPreferEarlierRequests() const { return prefer_earlier_requests_; } |
(...skipping 26 matching lines...) Expand all Loading... |
118 // charging. If we decide to allow non-user requested pages when not | 102 // charging. If we decide to allow non-user requested pages when not |
119 // plugged in, we should raise this somewhat higher. | 103 // plugged in, we should raise this somewhat higher. |
120 return 25; | 104 return 25; |
121 } | 105 } |
122 | 106 |
123 // How many seconds to keep trying new pages for, before we give up, and | 107 // How many seconds to keep trying new pages for, before we give up, and |
124 // return to the scheduler. | 108 // return to the scheduler. |
125 // TODO(dougarnett): Consider parameterizing these time limit/budget | 109 // TODO(dougarnett): Consider parameterizing these time limit/budget |
126 // calls with processing mode. | 110 // calls with processing mode. |
127 int GetProcessingTimeBudgetWhenBackgroundScheduledInSeconds() const { | 111 int GetProcessingTimeBudgetWhenBackgroundScheduledInSeconds() const { |
128 if (has_doze_mode_) | 112 return background_scheduled_processing_time_budget_; |
129 return kDefaultBackgroundProcessingTimeBudgetSeconds; | |
130 return kNonDozeDefaultBackgroundProcessingTimeBudgetSeconds; | |
131 } | 113 } |
132 | 114 |
133 // How many seconds to keep trying new pages for, before we give up, when | 115 // How many seconds to keep trying new pages for, before we give up, when |
134 // processing started immediately (without scheduler). | 116 // processing started immediately (without scheduler). |
135 int GetProcessingTimeBudgetForImmediateLoadInSeconds() const { | 117 int GetProcessingTimeBudgetForImmediateLoadInSeconds() const { |
136 return kImmediateLoadProcessingTimeBudgetSeconds; | 118 return kImmediateLoadProcessingTimeBudgetSeconds; |
137 } | 119 } |
138 | 120 |
139 // How long do we allow a page to load before giving up on it when | 121 // How long do we allow a page to load before giving up on it when |
140 // background loading was scheduled. | 122 // background loading was scheduled. |
141 int GetSinglePageTimeLimitWhenBackgroundScheduledInSeconds() const { | 123 int GetSinglePageTimeLimitWhenBackgroundScheduledInSeconds() const { |
142 if (has_doze_mode_) | 124 return kSinglePageTimeLimitWhenBackgroundScheduledSeconds; |
143 return kSinglePageTimeLimitWhenBackgroundScheduledSeconds; | |
144 return kNonDozeSinglePageTimeLimitWhenBackgroundScheduledSeconds; | |
145 } | 125 } |
146 | 126 |
147 // How long do we allow a page to load before giving up on it when | 127 // How long do we allow a page to load before giving up on it when |
148 // immediately background loading. | 128 // immediately background loading. |
149 int GetSinglePageTimeLimitForImmediateLoadInSeconds() const { | 129 int GetSinglePageTimeLimitForImmediateLoadInSeconds() const { |
150 return kSinglePageTimeLimitForImmediateLoadSeconds; | 130 return kSinglePageTimeLimitForImmediateLoadSeconds; |
151 } | 131 } |
152 | 132 |
153 // How long we allow requests to remain in the system before giving up. | 133 // How long we allow requests to remain in the system before giving up. |
154 int GetRequestExpirationTimeInSeconds() const { | 134 int GetRequestExpirationTimeInSeconds() const { |
155 return kRequestExpirationTimeInSeconds; | 135 return kRequestExpirationTimeInSeconds; |
156 } | 136 } |
157 | 137 |
158 private: | 138 private: |
159 bool prefer_untried_requests_; | 139 bool prefer_untried_requests_; |
160 bool prefer_earlier_requests_; | 140 bool prefer_earlier_requests_; |
161 bool retry_count_is_more_important_than_recency_; | 141 bool retry_count_is_more_important_than_recency_; |
162 bool has_doze_mode_; | |
163 int max_started_tries_; | 142 int max_started_tries_; |
164 int max_completed_tries_; | 143 int max_completed_tries_; |
| 144 int background_scheduled_processing_time_budget_; |
165 }; | 145 }; |
166 } // namespace offline_pages | 146 } // namespace offline_pages |
167 | 147 |
168 #endif // COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_OFFLINER_POLICY_H_ | 148 #endif // COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_OFFLINER_POLICY_H_ |
OLD | NEW |