| 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 kMaxRetries = 2; | 9 const int kMaxRetries = 2; |
| 10 const int kBackgroundTimeBudgetSeconds = 170; | 10 const int kBackgroundTimeBudgetSeconds = 170; |
| 11 const int kSinglePageTimeBudgetSeconds = 120; | 11 const int kSinglePageTimeBudgetSeconds = 120; |
| 12 const int kMinimumBatteryPercentageForNonUserRequestOfflining = 50; | 12 const int kMinimumBatteryPercentageForNonUserRequestOfflining = 50; |
| 13 } // namespace | 13 } // namespace |
| 14 | 14 |
| 15 namespace offline_pages { | 15 namespace offline_pages { |
| 16 | 16 |
| 17 // Policy for the Background Offlining system. Some policy will belong to the | 17 // Policy for the Background Offlining system. Some policy will belong to the |
| 18 // RequestCoordinator, some to the RequestQueue, and some to the Offliner. | 18 // RequestCoordinator, some to the RequestQueue, and some to the Offliner. |
| 19 class OfflinerPolicy { | 19 class OfflinerPolicy { |
| 20 public: | 20 public: |
| 21 OfflinerPolicy(){}; | 21 OfflinerPolicy() |
| 22 : prefer_untried_requests_(false), |
| 23 prefer_earlier_requests_(true), |
| 24 retry_count_is_more_important_than_recency_(true) {} |
| 25 |
| 26 OfflinerPolicy(bool prefer_untried, |
| 27 bool prefer_earlier, |
| 28 bool prefer_retry_count) |
| 29 : prefer_untried_requests_(prefer_untried), |
| 30 prefer_earlier_requests_(prefer_earlier), |
| 31 retry_count_is_more_important_than_recency_(prefer_retry_count) {} |
| 22 | 32 |
| 23 // TODO(petewil): Numbers here are chosen arbitrarily, do the proper studies | 33 // TODO(petewil): Numbers here are chosen arbitrarily, do the proper studies |
| 24 // to get good policy numbers. | 34 // to get good policy numbers. |
| 25 | 35 |
| 26 // TODO(petewil): Eventually this should get data from a finch experiment. | 36 // TODO(petewil): Eventually this should get data from a finch experiment. |
| 27 | 37 |
| 28 // Returns true if we should prefer retrying lesser tried requests. | 38 // Returns true if we should prefer retrying lesser tried requests. |
| 29 bool ShouldPreferUntriedRequests() { return false; } | 39 bool ShouldPreferUntriedRequests() const { return prefer_untried_requests_; } |
| 30 | 40 |
| 31 // Returns true if we should prefer older requests of equal number of tries. | 41 // Returns true if we should prefer older requests of equal number of tries. |
| 32 bool ShouldPreferEarlierRequests() { return true; } | 42 bool ShouldPreferEarlierRequests() const { return prefer_earlier_requests_; } |
| 33 | 43 |
| 34 // Returns true if retry count is considered more important than recency in | 44 // Returns true if retry count is considered more important than recency in |
| 35 // picking which request to try next. | 45 // picking which request to try next. |
| 36 bool RetryCountIsMoreImportantThanRecency() { return true; } | 46 bool RetryCountIsMoreImportantThanRecency() const { |
| 47 return retry_count_is_more_important_than_recency_; |
| 48 } |
| 37 | 49 |
| 38 // The max number of times we will retry a request. | 50 // The max number of times we will retry a request. |
| 39 int GetMaxRetries() { return kMaxRetries; } | 51 int GetMaxRetries() { return kMaxRetries; } |
| 40 | 52 |
| 41 // How many seconds to keep trying new pages for, before we give up, and | 53 // How many seconds to keep trying new pages for, before we give up, and |
| 42 // return to the scheduler. | 54 // return to the scheduler. |
| 43 int GetBackgroundProcessingTimeBudgetSeconds() { | 55 int GetBackgroundProcessingTimeBudgetSeconds() { |
| 44 return kBackgroundTimeBudgetSeconds; | 56 return kBackgroundTimeBudgetSeconds; |
| 45 } | 57 } |
| 46 | 58 |
| 47 // How long do we allow a page to load before giving up on it | 59 // How long do we allow a page to load before giving up on it |
| 48 int GetSinglePageTimeBudgetInSeconds() { | 60 int GetSinglePageTimeBudgetInSeconds() { |
| 49 return kSinglePageTimeBudgetSeconds; | 61 return kSinglePageTimeBudgetSeconds; |
| 50 } | 62 } |
| 51 | 63 |
| 52 // How much battery must we have before fetching a page not explicitly | 64 // How much battery must we have before fetching a page not explicitly |
| 53 // requested by the user? | 65 // requested by the user? |
| 54 int GetMinimumBatteryPercentageForNonUserRequestOfflining() { | 66 int GetMinimumBatteryPercentageForNonUserRequestOfflining() { |
| 55 return kMinimumBatteryPercentageForNonUserRequestOfflining; | 67 return kMinimumBatteryPercentageForNonUserRequestOfflining; |
| 56 } | 68 } |
| 69 |
| 70 private: |
| 71 bool prefer_untried_requests_; |
| 72 bool prefer_earlier_requests_; |
| 73 bool retry_count_is_more_important_than_recency_; |
| 57 }; | 74 }; |
| 58 } | 75 } |
| 59 | 76 |
| 60 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_POLICY_H_ | 77 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_OFFLINER_POLICY_H_ |
| OLD | NEW |