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_BACKGROUND_OFFLINER_POLICY_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_POLICY_H_ |
6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_POLICY_H_ | 6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_POLICY_H_ |
7 | 7 |
8 namespace { | 8 namespace { |
9 const int kMaxStartedTries = 4; | 9 const int kMaxStartedTries = 4; |
10 const int kMaxCompletedTries = 1; | 10 const int kMaxCompletedTries = 1; |
11 const int kDefaultBackgroundProcessingTimeBudgetSeconds = 170; | |
12 const int kSinglePageTimeLimitWhenBackgroundScheduledSeconds = 120; | |
13 const int kSinglePageTimeLimitForImmediateLoadSeconds = 300; | |
14 const int kRequestExpirationTimeInSeconds = 60 * 60 * 24 * 7; | 11 const int kRequestExpirationTimeInSeconds = 60 * 60 * 24 * 7; |
| 12 |
| 13 // Scheduled background processing time limits. |
| 14 const int kDozeModeBackgroundServiceWindowSeconds = 60 * 3; |
| 15 const int kDefaultBackgroundProcessingTimeBudgetSeconds = |
| 16 kDozeModeBackgroundServiceWindowSeconds - 10; |
| 17 const int kSinglePageTimeLimitWhenBackgroundScheduledSeconds = |
| 18 kDozeModeBackgroundServiceWindowSeconds - 10; |
| 19 |
| 20 // Immediate processing time limits. |
| 21 // Note: experiments on GIN-2g-poor show many page requests took 3 or 4 |
| 22 // attempts in background scheduled mode with timeout of 2 minutes. So for |
| 23 // immediate processing mode, give page requests 4 times that limit (8 min). |
| 24 // Then budget up to 5 of those requests in processing window. |
| 25 const int kSinglePageTimeLimitForImmediateLoadSeconds = 60 * 8; |
| 26 const int kImmediateLoadProcessingTimeBudgetSeconds = |
| 27 kSinglePageTimeLimitForImmediateLoadSeconds * 5; |
15 } // namespace | 28 } // namespace |
16 | 29 |
17 namespace offline_pages { | 30 namespace offline_pages { |
18 | 31 |
19 // Policy for the Background Offlining system. Some policy will belong to the | 32 // Policy for the Background Offlining system. Some policy will belong to the |
20 // RequestCoordinator, some to the RequestQueue, and some to the Offliner. | 33 // RequestCoordinator, some to the RequestQueue, and some to the Offliner. |
21 class OfflinerPolicy { | 34 class OfflinerPolicy { |
22 public: | 35 public: |
23 OfflinerPolicy() | 36 OfflinerPolicy() |
24 : prefer_untried_requests_(false), | 37 : prefer_untried_requests_(false), |
25 prefer_earlier_requests_(true), | 38 prefer_earlier_requests_(true), |
26 retry_count_is_more_important_than_recency_(false), | 39 retry_count_is_more_important_than_recency_(false), |
27 max_started_tries_(kMaxStartedTries), | 40 max_started_tries_(kMaxStartedTries), |
28 max_completed_tries_(kMaxCompletedTries), | 41 max_completed_tries_(kMaxCompletedTries), |
29 background_processing_time_budget_( | 42 background_scheduled_processing_time_budget_( |
30 kDefaultBackgroundProcessingTimeBudgetSeconds) {} | 43 kDefaultBackgroundProcessingTimeBudgetSeconds) {} |
31 | 44 |
32 // Constructor for unit tests. | 45 // Constructor for unit tests. |
33 OfflinerPolicy(bool prefer_untried, | 46 OfflinerPolicy(bool prefer_untried, |
34 bool prefer_earlier, | 47 bool prefer_earlier, |
35 bool prefer_retry_count, | 48 bool prefer_retry_count, |
36 int max_started_tries, | 49 int max_started_tries, |
37 int max_completed_tries, | 50 int max_completed_tries, |
38 int background_processing_time_budget) | 51 int background_processing_time_budget) |
39 : prefer_untried_requests_(prefer_untried), | 52 : prefer_untried_requests_(prefer_untried), |
40 prefer_earlier_requests_(prefer_earlier), | 53 prefer_earlier_requests_(prefer_earlier), |
41 retry_count_is_more_important_than_recency_(prefer_retry_count), | 54 retry_count_is_more_important_than_recency_(prefer_retry_count), |
42 max_started_tries_(max_started_tries), | 55 max_started_tries_(max_started_tries), |
43 max_completed_tries_(max_completed_tries), | 56 max_completed_tries_(max_completed_tries), |
44 background_processing_time_budget_(background_processing_time_budget) {} | 57 background_scheduled_processing_time_budget_( |
| 58 background_processing_time_budget) {} |
45 | 59 |
46 // TODO(petewil): Numbers here are chosen arbitrarily, do the proper studies | 60 // TODO(petewil): Numbers here are chosen arbitrarily, do the proper studies |
47 // to get good policy numbers. Eventually this should get data from a finch | 61 // to get good policy numbers. Eventually this should get data from a finch |
48 // experiment. | 62 // experiment. |
49 | 63 |
50 // Returns true if we should prefer retrying lesser tried requests. | 64 // Returns true if we should prefer retrying lesser tried requests. |
51 bool ShouldPreferUntriedRequests() const { return prefer_untried_requests_; } | 65 bool ShouldPreferUntriedRequests() const { return prefer_untried_requests_; } |
52 | 66 |
53 // Returns true if we should prefer older requests of equal number of tries. | 67 // Returns true if we should prefer older requests of equal number of tries. |
54 bool ShouldPreferEarlierRequests() const { return prefer_earlier_requests_; } | 68 bool ShouldPreferEarlierRequests() const { return prefer_earlier_requests_; } |
(...skipping 23 matching lines...) Expand all Loading... |
78 | 92 |
79 int BatteryPercentageRequired(bool user_requested) const { | 93 int BatteryPercentageRequired(bool user_requested) const { |
80 if (user_requested) | 94 if (user_requested) |
81 return 0; | 95 return 0; |
82 // This is so low because we require the device to be plugged in and | 96 // This is so low because we require the device to be plugged in and |
83 // charging. If we decide to allow non-user requested pages when not | 97 // charging. If we decide to allow non-user requested pages when not |
84 // plugged in, we should raise this somewhat higher. | 98 // plugged in, we should raise this somewhat higher. |
85 return 25; | 99 return 25; |
86 } | 100 } |
87 | 101 |
88 // How many seconds to keep trying new pages for, before we give up, and | 102 // How many seconds to keep trying new pages for, before we give up, and |
89 // return to the scheduler. | 103 // return to the scheduler. |
90 int GetBackgroundProcessingTimeBudgetSeconds() const { | 104 // TODO(dougarnett): Consider parameterizing these time limit/budget |
91 return background_processing_time_budget_; | 105 // calls with processing mode. |
| 106 int GetProcessingTimeBudgetWhenBackgroundScheduledInSeconds() const { |
| 107 return background_scheduled_processing_time_budget_; |
| 108 } |
| 109 |
| 110 // How many seconds to keep trying new pages for, before we give up, when |
| 111 // processing started immediately (without scheduler). |
| 112 int GetProcessingTimeBudgetForImmediateLoadInSeconds() const { |
| 113 return kImmediateLoadProcessingTimeBudgetSeconds; |
92 } | 114 } |
93 | 115 |
94 // How long do we allow a page to load before giving up on it when | 116 // How long do we allow a page to load before giving up on it when |
95 // background loading was scheduled. | 117 // background loading was scheduled. |
96 int GetSinglePageTimeLimitWhenBackgroundScheduledInSeconds() const { | 118 int GetSinglePageTimeLimitWhenBackgroundScheduledInSeconds() const { |
97 return kSinglePageTimeLimitWhenBackgroundScheduledSeconds; | 119 return kSinglePageTimeLimitWhenBackgroundScheduledSeconds; |
98 } | 120 } |
99 | 121 |
100 // How long do we allow a page to load before giving up on it when | 122 // How long do we allow a page to load before giving up on it when |
101 // immediately background loading. | 123 // immediately background loading. |
102 int GetSinglePageTimeLimitForImmediateLoadInSeconds() const { | 124 int GetSinglePageTimeLimitForImmediateLoadInSeconds() const { |
103 return kSinglePageTimeLimitForImmediateLoadSeconds; | 125 return kSinglePageTimeLimitForImmediateLoadSeconds; |
104 } | 126 } |
105 | 127 |
106 // How long we allow requests to remain in the system before giving up. | 128 // How long we allow requests to remain in the system before giving up. |
107 int GetRequestExpirationTimeInSeconds() const { | 129 int GetRequestExpirationTimeInSeconds() const { |
108 return kRequestExpirationTimeInSeconds; | 130 return kRequestExpirationTimeInSeconds; |
109 } | 131 } |
110 | 132 |
111 private: | 133 private: |
112 bool prefer_untried_requests_; | 134 bool prefer_untried_requests_; |
113 bool prefer_earlier_requests_; | 135 bool prefer_earlier_requests_; |
114 bool retry_count_is_more_important_than_recency_; | 136 bool retry_count_is_more_important_than_recency_; |
115 int max_started_tries_; | 137 int max_started_tries_; |
116 int max_completed_tries_; | 138 int max_completed_tries_; |
117 int background_processing_time_budget_; | 139 int background_scheduled_processing_time_budget_; |
118 }; | 140 }; |
119 } // namespace offline_pages | 141 } // namespace offline_pages |
120 | 142 |
121 | 143 |
122 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_POLICY_H_ | 144 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_POLICY_H_ |
OLD | NEW |