| 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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 189 |
| 190 if (device_conditions_->GetBatteryPercentage() < | 190 if (device_conditions_->GetBatteryPercentage() < |
| 191 policy_->BatteryPercentageRequired(request->user_requested())) { | 191 policy_->BatteryPercentageRequired(request->user_requested())) { |
| 192 return false; | 192 return false; |
| 193 } | 193 } |
| 194 | 194 |
| 195 // If the request is paused, do not consider it. | 195 // If the request is paused, do not consider it. |
| 196 if (request->request_state() == SavePageRequest::RequestState::PAUSED) | 196 if (request->request_state() == SavePageRequest::RequestState::PAUSED) |
| 197 return false; | 197 return false; |
| 198 | 198 |
| 199 // If this request is not active yet, return false. | |
| 200 // TODO(petewil): Remove the concept of activation time. crbug.com/705103. | |
| 201 if (request->activation_time() > base::Time::Now()) | |
| 202 return false; | |
| 203 | |
| 204 return true; | 199 return true; |
| 205 } | 200 } |
| 206 | 201 |
| 207 // Look at policies to decide which requests to prefer. | 202 // Look at policies to decide which requests to prefer. |
| 208 bool PickRequestTask::IsNewRequestBetter(const SavePageRequest* oldRequest, | 203 bool PickRequestTask::IsNewRequestBetter(const SavePageRequest* oldRequest, |
| 209 const SavePageRequest* newRequest, | 204 const SavePageRequest* newRequest, |
| 210 RequestCompareFunction comparator) { | 205 RequestCompareFunction comparator) { |
| 211 // If there is no old request, the new one is better. | 206 // If there is no old request, the new one is better. |
| 212 if (oldRequest == nullptr) | 207 if (oldRequest == nullptr) |
| 213 return true; | 208 return true; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 int result = signum(difference.InMilliseconds()); | 274 int result = signum(difference.InMilliseconds()); |
| 280 | 275 |
| 281 // Flip the direction of comparison if policy prefers fewer retries. | 276 // Flip the direction of comparison if policy prefers fewer retries. |
| 282 if (policy_->ShouldPreferEarlierRequests()) | 277 if (policy_->ShouldPreferEarlierRequests()) |
| 283 result *= -1; | 278 result *= -1; |
| 284 | 279 |
| 285 return result; | 280 return result; |
| 286 } | 281 } |
| 287 | 282 |
| 288 } // namespace offline_pages | 283 } // namespace offline_pages |
| OLD | NEW |