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_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 kMaxTries = 1; | 9 const int kMaxStartedTries = 5; |
| 10 const int kMaxCompletedTries = 1; | |
| 10 const int kBackgroundProcessingTimeBudgetSeconds = 170; | 11 const int kBackgroundProcessingTimeBudgetSeconds = 170; |
| 11 const int kSinglePageTimeLimitSeconds = 120; | 12 const int kSinglePageTimeLimitSeconds = 120; |
| 12 const int kMinimumBatteryPercentageForNonUserRequestOfflining = 50; | 13 const int kMinimumBatteryPercentageForNonUserRequestOfflining = 50; |
| 13 const int kRequestExpirationTimeInSeconds = 60 * 60 * 24 * 7; | 14 const int kRequestExpirationTimeInSeconds = 60 * 60 * 24 * 7; |
| 14 } // namespace | 15 } // namespace |
| 15 | 16 |
| 16 namespace offline_pages { | 17 namespace offline_pages { |
| 17 | 18 |
| 18 // Policy for the Background Offlining system. Some policy will belong to the | 19 // Policy for the Background Offlining system. Some policy will belong to the |
| 19 // RequestCoordinator, some to the RequestQueue, and some to the Offliner. | 20 // RequestCoordinator, some to the RequestQueue, and some to the Offliner. |
| 20 class OfflinerPolicy { | 21 class OfflinerPolicy { |
| 21 public: | 22 public: |
| 22 OfflinerPolicy() | 23 OfflinerPolicy() |
| 23 : prefer_untried_requests_(false), | 24 : prefer_untried_requests_(false), |
| 24 prefer_earlier_requests_(true), | 25 prefer_earlier_requests_(true), |
| 25 retry_count_is_more_important_than_recency_(false) {} | 26 retry_count_is_more_important_than_recency_(false), |
| 27 max_started_tries_(kMaxStartedTries), | |
| 28 max_completed_tries_(kMaxCompletedTries) {} | |
| 26 | 29 |
| 30 // Constructor for unit tests. | |
| 27 OfflinerPolicy(bool prefer_untried, | 31 OfflinerPolicy(bool prefer_untried, |
| 28 bool prefer_earlier, | 32 bool prefer_earlier, |
| 29 bool prefer_retry_count) | 33 bool prefer_retry_count, |
| 34 int max_started_tries, | |
| 35 int max_completed_tries) | |
| 30 : prefer_untried_requests_(prefer_untried), | 36 : prefer_untried_requests_(prefer_untried), |
| 31 prefer_earlier_requests_(prefer_earlier), | 37 prefer_earlier_requests_(prefer_earlier), |
| 32 retry_count_is_more_important_than_recency_(prefer_retry_count) {} | 38 retry_count_is_more_important_than_recency_(prefer_retry_count), |
| 39 max_started_tries_(max_started_tries), | |
| 40 max_completed_tries_(max_completed_tries) {} | |
| 33 | 41 |
| 34 // TODO(petewil): Numbers here are chosen arbitrarily, do the proper studies | 42 // TODO(petewil): Numbers here are chosen arbitrarily, do the proper studies |
| 35 // to get good policy numbers. | 43 // to get good policy numbers. |
| 36 | 44 |
| 37 // TODO(petewil): Eventually this should get data from a finch experiment. | 45 // TODO(petewil): Eventually this should get data from a finch experiment. |
| 38 | 46 |
| 39 // Returns true if we should prefer retrying lesser tried requests. | 47 // Returns true if we should prefer retrying lesser tried requests. |
| 40 bool ShouldPreferUntriedRequests() const { return prefer_untried_requests_; } | 48 bool ShouldPreferUntriedRequests() const { return prefer_untried_requests_; } |
| 41 | 49 |
| 42 // Returns true if we should prefer older requests of equal number of tries. | 50 // Returns true if we should prefer older requests of equal number of tries. |
| 43 bool ShouldPreferEarlierRequests() const { return prefer_earlier_requests_; } | 51 bool ShouldPreferEarlierRequests() const { return prefer_earlier_requests_; } |
| 44 | 52 |
| 45 // Returns true if retry count is considered more important than recency in | 53 // Returns true if retry count is considered more important than recency in |
| 46 // picking which request to try next. | 54 // picking which request to try next. |
| 47 bool RetryCountIsMoreImportantThanRecency() const { | 55 bool RetryCountIsMoreImportantThanRecency() const { |
| 48 return retry_count_is_more_important_than_recency_; | 56 return retry_count_is_more_important_than_recency_; |
| 49 } | 57 } |
| 50 | 58 |
| 51 // The max number of times we will retry a request. | 59 // The max number of times we will *start* a request. |
|
fgorski
2016/08/08 17:48:05
Drop the **.
I think you could add something like
Pete Williamson
2016/08/08 18:44:28
Done.
| |
| 52 int GetMaxTries() const { return kMaxTries; } | 60 int GetMaxStartedTries() const { return max_started_tries_; } |
| 61 | |
| 62 // The max number of times we will retry a request when the attempt | |
| 63 // completed, but failed. | |
| 64 int GetMaxCompletedTries() const { return max_completed_tries_; } | |
| 53 | 65 |
| 54 bool PowerRequiredForUserRequestedPage() const { return false; } | 66 bool PowerRequiredForUserRequestedPage() const { return false; } |
| 55 | 67 |
| 56 bool PowerRequiredForNonUserRequestedPage() const { return true; } | 68 bool PowerRequiredForNonUserRequestedPage() const { return true; } |
| 57 | 69 |
| 58 bool UnmeteredNetworkRequiredForUserRequestedPage() const { return false; } | 70 bool UnmeteredNetworkRequiredForUserRequestedPage() const { return false; } |
| 59 | 71 |
| 60 bool UnmeteredNetworkRequiredForNonUserRequestedPage() const { return true; } | 72 bool UnmeteredNetworkRequiredForNonUserRequestedPage() const { return true; } |
| 61 | 73 |
| 62 int BatteryPercentageRequiredForUserRequestedPage() const { return 0; } | 74 int BatteryPercentageRequiredForUserRequestedPage() const { return 0; } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 85 // How much battery must we have before fetching a page not explicitly | 97 // How much battery must we have before fetching a page not explicitly |
| 86 // requested by the user? | 98 // requested by the user? |
| 87 int GetMinimumBatteryPercentageForNonUserRequestOfflining() const { | 99 int GetMinimumBatteryPercentageForNonUserRequestOfflining() const { |
| 88 return kMinimumBatteryPercentageForNonUserRequestOfflining; | 100 return kMinimumBatteryPercentageForNonUserRequestOfflining; |
| 89 } | 101 } |
| 90 | 102 |
| 91 private: | 103 private: |
| 92 bool prefer_untried_requests_; | 104 bool prefer_untried_requests_; |
| 93 bool prefer_earlier_requests_; | 105 bool prefer_earlier_requests_; |
| 94 bool retry_count_is_more_important_than_recency_; | 106 bool retry_count_is_more_important_than_recency_; |
| 107 int max_started_tries_; | |
| 108 int max_completed_tries_; | |
| 95 }; | 109 }; |
| 96 } | 110 } |
| 97 | 111 |
| 98 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_POLICY_H_ | 112 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_POLICY_H_ |
| OLD | NEW |