| 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 #include "components/offline_pages/core/background/pick_request_task.h" | 5 #include "components/offline_pages/core/background/pick_request_task.h" |
| 6 | 6 |
| 7 #include <unordered_set> | 7 #include <unordered_set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 const SavePageRequest* picked_request = nullptr; | 77 const SavePageRequest* picked_request = nullptr; |
| 78 | 78 |
| 79 RequestCompareFunction comparator = nullptr; | 79 RequestCompareFunction comparator = nullptr; |
| 80 | 80 |
| 81 // Choose which comparison function to use based on policy. | 81 // Choose which comparison function to use based on policy. |
| 82 if (policy_->RetryCountIsMoreImportantThanRecency()) | 82 if (policy_->RetryCountIsMoreImportantThanRecency()) |
| 83 comparator = &PickRequestTask::RetryCountFirstCompareFunction; | 83 comparator = &PickRequestTask::RetryCountFirstCompareFunction; |
| 84 else | 84 else |
| 85 comparator = &PickRequestTask::RecencyFirstCompareFunction; | 85 comparator = &PickRequestTask::RecencyFirstCompareFunction; |
| 86 | 86 |
| 87 // TODO(petewil): Consider replacing this bool with a better named enum. | |
| 88 bool non_user_requested_tasks_remaining = false; | 87 bool non_user_requested_tasks_remaining = false; |
| 89 bool cleanup_needed = false; | 88 bool cleanup_needed = false; |
| 90 | 89 |
| 91 size_t available_request_count = 0; | 90 size_t available_request_count = 0; |
| 92 // Request ids which are available for picking. | 91 // Request ids which are available for picking. |
| 93 std::unordered_set<int64_t> available_request_ids; | 92 std::unordered_set<int64_t> available_request_ids; |
| 94 | 93 |
| 95 // Iterate through the requests, filter out unavailable requests and get other | 94 // Iterate through the requests, filter out unavailable requests and get other |
| 96 // information (if cleanup is needed and number of non-user-requested | 95 // information (if cleanup is needed and number of non-user-requested |
| 97 // requests). | 96 // requests). |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 if (device_conditions_->GetBatteryPercentage() < | 190 if (device_conditions_->GetBatteryPercentage() < |
| 192 policy_->BatteryPercentageRequired(request->user_requested())) { | 191 policy_->BatteryPercentageRequired(request->user_requested())) { |
| 193 return false; | 192 return false; |
| 194 } | 193 } |
| 195 | 194 |
| 196 // If the request is paused, do not consider it. | 195 // If the request is paused, do not consider it. |
| 197 if (request->request_state() == SavePageRequest::RequestState::PAUSED) | 196 if (request->request_state() == SavePageRequest::RequestState::PAUSED) |
| 198 return false; | 197 return false; |
| 199 | 198 |
| 200 // If this request is not active yet, return false. | 199 // If this request is not active yet, return false. |
| 201 // TODO(petewil): If the only reason we return nothing to do is that we have | 200 // TODO(petewil): Remove the concept of activation time. crbug.com/705103. |
| 202 // inactive requests, we still want to try again later after their activation | |
| 203 // time elapses, we shouldn't take ourselves completely off the scheduler. | |
| 204 if (request->activation_time() > base::Time::Now()) | 201 if (request->activation_time() > base::Time::Now()) |
| 205 return false; | 202 return false; |
| 206 | 203 |
| 207 return true; | 204 return true; |
| 208 } | 205 } |
| 209 | 206 |
| 210 // Look at policies to decide which requests to prefer. | 207 // Look at policies to decide which requests to prefer. |
| 211 bool PickRequestTask::IsNewRequestBetter(const SavePageRequest* oldRequest, | 208 bool PickRequestTask::IsNewRequestBetter(const SavePageRequest* oldRequest, |
| 212 const SavePageRequest* newRequest, | 209 const SavePageRequest* newRequest, |
| 213 RequestCompareFunction comparator) { | 210 RequestCompareFunction comparator) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 int result = signum(difference.InMilliseconds()); | 279 int result = signum(difference.InMilliseconds()); |
| 283 | 280 |
| 284 // Flip the direction of comparison if policy prefers fewer retries. | 281 // Flip the direction of comparison if policy prefers fewer retries. |
| 285 if (policy_->ShouldPreferEarlierRequests()) | 282 if (policy_->ShouldPreferEarlierRequests()) |
| 286 result *= -1; | 283 result *= -1; |
| 287 | 284 |
| 288 return result; | 285 return result; |
| 289 } | 286 } |
| 290 | 287 |
| 291 } // namespace offline_pages | 288 } // namespace offline_pages |
| OLD | NEW |