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_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 | |
| 8 namespace { | 10 namespace { |
| 9 // The max number of started tries is to guard against pages that make the | 11 // 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 | 12 // prerenderer crash. It should be greater than or equal to the max number of |
| 11 // completed tries. | 13 // completed tries. |
| 12 const int kMaxStartedTries = 5; | 14 const int kMaxStartedTries = 5; |
| 13 // The number of max completed tries is based on Gin2G-poor testing showing that | 15 // 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 | 16 // 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. | 17 // minute window. Also, we count one try now for foreground/disabled requests. |
| 16 const int kMaxCompletedTries = 3; | 18 const int kMaxCompletedTries = 3; |
| 17 // By the time we get to a week, the user has forgotten asking for a page. | 19 // By the time we get to a week, the user has forgotten asking for a page. |
| 18 const int kRequestExpirationTimeInSeconds = 60 * 60 * 24 * 7; | 20 const int kRequestExpirationTimeInSeconds = 60 * 60 * 24 * 7; |
| 19 | 21 |
| 20 // Scheduled background processing time limits. | 22 // Scheduled background processing time limits for doze mode, which requires |
| 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. | |
| 21 const int kDozeModeBackgroundServiceWindowSeconds = 60 * 3; | 26 const int kDozeModeBackgroundServiceWindowSeconds = 60 * 3; |
| 22 const int kDefaultBackgroundProcessingTimeBudgetSeconds = | 27 const int kDefaultBackgroundProcessingTimeBudgetSeconds = |
| 23 kDozeModeBackgroundServiceWindowSeconds - 10; | 28 kDozeModeBackgroundServiceWindowSeconds - 10; |
| 24 const int kSinglePageTimeLimitWhenBackgroundScheduledSeconds = | 29 const int kSinglePageTimeLimitWhenBackgroundScheduledSeconds = |
| 25 kDozeModeBackgroundServiceWindowSeconds - 10; | 30 kDozeModeBackgroundServiceWindowSeconds - 10; |
| 26 | 31 |
| 32 const int kNonDozeModeBackgroundServiceWindowSeconds = 60 * 5; | |
| 33 const int kNonDozeDefaultBackgroundProcessingTimeBudgetSeconds = | |
| 34 kNonDozeModeBackgroundServiceWindowSeconds - 10; | |
| 35 const int kNonDozeSinglePageTimeLimitWhenBackgroundScheduledSeconds = | |
| 36 kNonDozeModeBackgroundServiceWindowSeconds - 10; | |
| 37 | |
| 27 // Immediate processing time limits. Note: experiments on GIN-2g-poor show many | 38 // Immediate processing time limits. Note: experiments on GIN-2g-poor show many |
| 28 // page requests took 3 or 4 attempts in background scheduled mode with timeout | 39 // page requests took 3 or 4 attempts in background scheduled mode with timeout |
| 29 // of 2 minutes. So for immediate processing mode, give page requests just under | 40 // of 2 minutes. So for immediate processing mode, give page requests just under |
| 30 // 5 minutes, which is the timeout limit for the prerender itself. Then budget | 41 // 5 minutes, which is the timeout limit for the prerender itself. Then budget |
| 31 // up to 3 of those requests in processing window. | 42 // up to 3 of those requests in processing window. |
| 32 const int kSinglePageTimeLimitForImmediateLoadSeconds = 60 * 4 + 50; | 43 const int kSinglePageTimeLimitForImmediateLoadSeconds = 60 * 4 + 50; |
| 33 const int kImmediateLoadProcessingTimeBudgetSeconds = | 44 const int kImmediateLoadProcessingTimeBudgetSeconds = |
| 34 kSinglePageTimeLimitForImmediateLoadSeconds * 5; | 45 kSinglePageTimeLimitForImmediateLoadSeconds * 5; |
| 35 } // namespace | 46 } // namespace |
| 36 | 47 |
| 37 namespace offline_pages { | 48 namespace offline_pages { |
| 38 | 49 |
| 39 // Policy for the Background Offlining system. Some policy will belong to the | 50 // Policy for the Background Offlining system. Some policy will belong to the |
| 40 // RequestCoordinator, some to the RequestQueue, and some to the Offliner. | 51 // RequestCoordinator, some to the RequestQueue, and some to the Offliner. |
| 41 class OfflinerPolicy { | 52 class OfflinerPolicy { |
| 42 public: | 53 public: |
| 43 OfflinerPolicy() | 54 OfflinerPolicy() |
| 44 : prefer_untried_requests_(true), | 55 : prefer_untried_requests_(true), |
| 45 prefer_earlier_requests_(true), | 56 prefer_earlier_requests_(true), |
| 46 retry_count_is_more_important_than_recency_(true), | 57 retry_count_is_more_important_than_recency_(true), |
| 47 max_started_tries_(kMaxStartedTries), | 58 max_started_tries_(kMaxStartedTries), |
| 48 max_completed_tries_(kMaxCompletedTries), | 59 max_completed_tries_(kMaxCompletedTries) { |
| 49 background_scheduled_processing_time_budget_( | 60 int32_t os_major_version = 0; |
| 50 kDefaultBackgroundProcessingTimeBudgetSeconds) {} | 61 int32_t os_minor_version = 0; |
| 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 background_scheduled_processing_time_budget_ = | |
| 67 kNonDozeDefaultBackgroundProcessingTimeBudgetSeconds; | |
| 68 has_doze_mode_ = false; | |
|
romax
2017/03/17 02:58:34
not sure if it's worth to have a member variable h
Pete Williamson
2017/03/17 21:05:55
I think I'd prefer checking this the first time th
romax
2017/03/23 21:56:37
Generally i wouldn't think this would fail. Even i
Pete Williamson
2017/03/23 22:52:53
OK, I took a look at the function, it doesn't seem
| |
| 69 } else { | |
| 70 background_scheduled_processing_time_budget_ = | |
| 71 kDefaultBackgroundProcessingTimeBudgetSeconds; | |
| 72 has_doze_mode_ = true; | |
| 73 } | |
| 74 } | |
| 51 | 75 |
| 52 // Constructor for unit tests. | 76 // Constructor for unit tests. |
| 53 OfflinerPolicy(bool prefer_untried, | 77 OfflinerPolicy(bool prefer_untried, |
| 54 bool prefer_earlier, | 78 bool prefer_earlier, |
| 55 bool prefer_retry_count, | 79 bool prefer_retry_count, |
| 56 int max_started_tries, | 80 int max_started_tries, |
| 57 int max_completed_tries, | 81 int max_completed_tries, |
| 58 int background_processing_time_budget) | 82 int background_processing_time_budget) |
| 59 : prefer_untried_requests_(prefer_untried), | 83 : prefer_untried_requests_(prefer_untried), |
| 60 prefer_earlier_requests_(prefer_earlier), | 84 prefer_earlier_requests_(prefer_earlier), |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 | 138 |
| 115 // How many seconds to keep trying new pages for, before we give up, when | 139 // How many seconds to keep trying new pages for, before we give up, when |
| 116 // processing started immediately (without scheduler). | 140 // processing started immediately (without scheduler). |
| 117 int GetProcessingTimeBudgetForImmediateLoadInSeconds() const { | 141 int GetProcessingTimeBudgetForImmediateLoadInSeconds() const { |
| 118 return kImmediateLoadProcessingTimeBudgetSeconds; | 142 return kImmediateLoadProcessingTimeBudgetSeconds; |
| 119 } | 143 } |
| 120 | 144 |
| 121 // How long do we allow a page to load before giving up on it when | 145 // How long do we allow a page to load before giving up on it when |
| 122 // background loading was scheduled. | 146 // background loading was scheduled. |
| 123 int GetSinglePageTimeLimitWhenBackgroundScheduledInSeconds() const { | 147 int GetSinglePageTimeLimitWhenBackgroundScheduledInSeconds() const { |
| 124 return kSinglePageTimeLimitWhenBackgroundScheduledSeconds; | 148 if (has_doze_mode_) |
| 149 return kSinglePageTimeLimitWhenBackgroundScheduledSeconds; | |
| 150 return kNonDozeSinglePageTimeLimitWhenBackgroundScheduledSeconds; | |
| 125 } | 151 } |
| 126 | 152 |
| 127 // How long do we allow a page to load before giving up on it when | 153 // How long do we allow a page to load before giving up on it when |
| 128 // immediately background loading. | 154 // immediately background loading. |
| 129 int GetSinglePageTimeLimitForImmediateLoadInSeconds() const { | 155 int GetSinglePageTimeLimitForImmediateLoadInSeconds() const { |
| 130 return kSinglePageTimeLimitForImmediateLoadSeconds; | 156 return kSinglePageTimeLimitForImmediateLoadSeconds; |
| 131 } | 157 } |
| 132 | 158 |
| 133 // How long we allow requests to remain in the system before giving up. | 159 // How long we allow requests to remain in the system before giving up. |
| 134 int GetRequestExpirationTimeInSeconds() const { | 160 int GetRequestExpirationTimeInSeconds() const { |
| 135 return kRequestExpirationTimeInSeconds; | 161 return kRequestExpirationTimeInSeconds; |
| 136 } | 162 } |
| 137 | 163 |
| 138 private: | 164 private: |
| 139 bool prefer_untried_requests_; | 165 bool prefer_untried_requests_; |
| 140 bool prefer_earlier_requests_; | 166 bool prefer_earlier_requests_; |
| 141 bool retry_count_is_more_important_than_recency_; | 167 bool retry_count_is_more_important_than_recency_; |
| 168 bool has_doze_mode_; | |
| 142 int max_started_tries_; | 169 int max_started_tries_; |
| 143 int max_completed_tries_; | 170 int max_completed_tries_; |
| 144 int background_scheduled_processing_time_budget_; | 171 int background_scheduled_processing_time_budget_; |
| 145 }; | 172 }; |
| 146 } // namespace offline_pages | 173 } // namespace offline_pages |
| 147 | 174 |
| 148 #endif // COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_OFFLINER_POLICY_H_ | 175 #endif // COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_OFFLINER_POLICY_H_ |
| OLD | NEW |