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; | 11 const int kDefaultBackgroundProcessingTimeBudgetSeconds = 60 * 3 - 10; |
Dmitry Titov
2016/10/19 21:41:26
Would be good to have some comments reflecting why
Pete Williamson
2016/10/19 23:18:18
This is based on the Marshmallow Doze mode 3 minut
dougarnett
2016/10/21 20:01:19
Did some doc and naming here to try to communicate
| |
12 const int kSinglePageTimeLimitWhenBackgroundScheduledSeconds = 120; | 12 const int kImmediateLoadProcessingTimeBudgetSeconds = 60 * 10; |
13 const int kSinglePageTimeLimitForImmediateLoadSeconds = 300; | 13 const int kSinglePageTimeLimitWhenBackgroundScheduledSeconds = 60 * 2; |
Pete Williamson
2016/10/19 23:18:18
Based on our recent Gin2G-poor testing, we might a
dougarnett
2016/10/21 20:01:19
Done.
| |
14 const int kSinglePageTimeLimitForImmediateLoadSeconds = 60 * 5; | |
14 const int kRequestExpirationTimeInSeconds = 60 * 60 * 24 * 7; | 15 const int kRequestExpirationTimeInSeconds = 60 * 60 * 24 * 7; |
15 } // namespace | 16 } // namespace |
16 | 17 |
17 namespace offline_pages { | 18 namespace offline_pages { |
18 | 19 |
19 // Policy for the Background Offlining system. Some policy will belong to the | 20 // Policy for the Background Offlining system. Some policy will belong to the |
20 // RequestCoordinator, some to the RequestQueue, and some to the Offliner. | 21 // RequestCoordinator, some to the RequestQueue, and some to the Offliner. |
21 class OfflinerPolicy { | 22 class OfflinerPolicy { |
22 public: | 23 public: |
23 OfflinerPolicy() | 24 OfflinerPolicy() |
24 : prefer_untried_requests_(false), | 25 : prefer_untried_requests_(false), |
25 prefer_earlier_requests_(true), | 26 prefer_earlier_requests_(true), |
26 retry_count_is_more_important_than_recency_(false), | 27 retry_count_is_more_important_than_recency_(false), |
27 max_started_tries_(kMaxStartedTries), | 28 max_started_tries_(kMaxStartedTries), |
28 max_completed_tries_(kMaxCompletedTries), | 29 max_completed_tries_(kMaxCompletedTries), |
29 background_processing_time_budget_( | 30 background_scheduled_processing_time_budget_( |
30 kDefaultBackgroundProcessingTimeBudgetSeconds) {} | 31 kDefaultBackgroundProcessingTimeBudgetSeconds) {} |
31 | 32 |
32 // Constructor for unit tests. | 33 // Constructor for unit tests. |
33 OfflinerPolicy(bool prefer_untried, | 34 OfflinerPolicy(bool prefer_untried, |
34 bool prefer_earlier, | 35 bool prefer_earlier, |
35 bool prefer_retry_count, | 36 bool prefer_retry_count, |
36 int max_started_tries, | 37 int max_started_tries, |
37 int max_completed_tries, | 38 int max_completed_tries, |
38 int background_processing_time_budget) | 39 int background_processing_time_budget) |
39 : prefer_untried_requests_(prefer_untried), | 40 : prefer_untried_requests_(prefer_untried), |
40 prefer_earlier_requests_(prefer_earlier), | 41 prefer_earlier_requests_(prefer_earlier), |
41 retry_count_is_more_important_than_recency_(prefer_retry_count), | 42 retry_count_is_more_important_than_recency_(prefer_retry_count), |
42 max_started_tries_(max_started_tries), | 43 max_started_tries_(max_started_tries), |
43 max_completed_tries_(max_completed_tries), | 44 max_completed_tries_(max_completed_tries), |
44 background_processing_time_budget_(background_processing_time_budget) {} | 45 background_scheduled_processing_time_budget_( |
46 background_processing_time_budget) {} | |
45 | 47 |
46 // TODO(petewil): Numbers here are chosen arbitrarily, do the proper studies | 48 // 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 | 49 // to get good policy numbers. Eventually this should get data from a finch |
48 // experiment. | 50 // experiment. |
49 | 51 |
50 // Returns true if we should prefer retrying lesser tried requests. | 52 // Returns true if we should prefer retrying lesser tried requests. |
51 bool ShouldPreferUntriedRequests() const { return prefer_untried_requests_; } | 53 bool ShouldPreferUntriedRequests() const { return prefer_untried_requests_; } |
52 | 54 |
53 // Returns true if we should prefer older requests of equal number of tries. | 55 // Returns true if we should prefer older requests of equal number of tries. |
54 bool ShouldPreferEarlierRequests() const { return prefer_earlier_requests_; } | 56 bool ShouldPreferEarlierRequests() const { return prefer_earlier_requests_; } |
(...skipping 23 matching lines...) Expand all Loading... | |
78 | 80 |
79 int BatteryPercentageRequired(bool user_requested) const { | 81 int BatteryPercentageRequired(bool user_requested) const { |
80 if (user_requested) | 82 if (user_requested) |
81 return 0; | 83 return 0; |
82 // This is so low because we require the device to be plugged in and | 84 // 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 | 85 // charging. If we decide to allow non-user requested pages when not |
84 // plugged in, we should raise this somewhat higher. | 86 // plugged in, we should raise this somewhat higher. |
85 return 25; | 87 return 25; |
86 } | 88 } |
87 | 89 |
88 // How many seconds to keep trying new pages for, before we give up, and | 90 // How many seconds to keep trying new pages for, before we give up, and |
89 // return to the scheduler. | 91 // return to the scheduler. |
90 int GetBackgroundProcessingTimeBudgetSeconds() const { | 92 int GetProcessingTimeBudgetWhenBackgroundScheduledInSeconds() const { |
Pete Williamson
2016/10/19 23:18:18
Maybe better to have one method that takes an enum
dougarnett
2016/10/21 20:01:19
Adding TODO for now. Currently this enum is privat
| |
91 return background_processing_time_budget_; | 93 return background_scheduled_processing_time_budget_; |
94 } | |
95 | |
96 // How many seconds to keep trying new pages for, before we give up, when | |
97 // processing started immediately (without scheduler). | |
98 int GetProcessingTimeBudgetForImmediateLoadInSeconds() const { | |
99 return kImmediateLoadProcessingTimeBudgetSeconds; | |
92 } | 100 } |
93 | 101 |
94 // How long do we allow a page to load before giving up on it when | 102 // How long do we allow a page to load before giving up on it when |
95 // background loading was scheduled. | 103 // background loading was scheduled. |
96 int GetSinglePageTimeLimitWhenBackgroundScheduledInSeconds() const { | 104 int GetSinglePageTimeLimitWhenBackgroundScheduledInSeconds() const { |
97 return kSinglePageTimeLimitWhenBackgroundScheduledSeconds; | 105 return kSinglePageTimeLimitWhenBackgroundScheduledSeconds; |
98 } | 106 } |
99 | 107 |
100 // How long do we allow a page to load before giving up on it when | 108 // How long do we allow a page to load before giving up on it when |
101 // immediately background loading. | 109 // immediately background loading. |
102 int GetSinglePageTimeLimitForImmediateLoadInSeconds() const { | 110 int GetSinglePageTimeLimitForImmediateLoadInSeconds() const { |
103 return kSinglePageTimeLimitForImmediateLoadSeconds; | 111 return kSinglePageTimeLimitForImmediateLoadSeconds; |
104 } | 112 } |
105 | 113 |
106 // How long we allow requests to remain in the system before giving up. | 114 // How long we allow requests to remain in the system before giving up. |
107 int GetRequestExpirationTimeInSeconds() const { | 115 int GetRequestExpirationTimeInSeconds() const { |
108 return kRequestExpirationTimeInSeconds; | 116 return kRequestExpirationTimeInSeconds; |
109 } | 117 } |
110 | 118 |
111 private: | 119 private: |
112 bool prefer_untried_requests_; | 120 bool prefer_untried_requests_; |
113 bool prefer_earlier_requests_; | 121 bool prefer_earlier_requests_; |
114 bool retry_count_is_more_important_than_recency_; | 122 bool retry_count_is_more_important_than_recency_; |
115 int max_started_tries_; | 123 int max_started_tries_; |
116 int max_completed_tries_; | 124 int max_completed_tries_; |
117 int background_processing_time_budget_; | 125 int background_scheduled_processing_time_budget_; |
118 }; | 126 }; |
119 } // namespace offline_pages | 127 } // namespace offline_pages |
120 | 128 |
121 | 129 |
122 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_POLICY_H_ | 130 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_POLICY_H_ |
OLD | NEW |