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/background/request_picker.h" | 5 #include "components/offline_pages/background/request_picker.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "components/offline_pages/background/save_page_request.h" | 9 #include "components/offline_pages/background/save_page_request.h" |
10 | 10 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 return false; | 120 return false; |
121 } | 121 } |
122 | 122 |
123 if (current_conditions_->GetBatteryPercentage() < | 123 if (current_conditions_->GetBatteryPercentage() < |
124 policy_->BatteryPercentageRequired(request.user_requested())) { | 124 policy_->BatteryPercentageRequired(request.user_requested())) { |
125 return false; | 125 return false; |
126 } | 126 } |
127 | 127 |
128 // If we have already started this page the max number of times, it is not | 128 // If we have already started this page the max number of times, it is not |
129 // eligible to try again. | 129 // eligible to try again. |
130 // TODO(petewil): We should have code to remove the page from the | |
131 // queue after the last retry. | |
132 if (request.started_attempt_count() >= policy_->GetMaxStartedTries()) | 130 if (request.started_attempt_count() >= policy_->GetMaxStartedTries()) |
133 return false; | 131 return false; |
134 | 132 |
135 // If we have already completed trying this page the max number of times, it | 133 // If we have already completed trying this page the max number of times, it |
136 // is not eligible to try again. | 134 // is not eligible to try again. |
137 // TODO(petewil): We should have code to remove the page from the | |
138 // queue after the last retry. | |
139 if (request.completed_attempt_count() >= policy_->GetMaxCompletedTries()) | 135 if (request.completed_attempt_count() >= policy_->GetMaxCompletedTries()) |
140 return false; | 136 return false; |
141 | 137 |
142 // If the request is paused, do not consider it. | 138 // If the request is paused, do not consider it. |
143 if (request.request_state() == SavePageRequest::RequestState::PAUSED) | 139 if (request.request_state() == SavePageRequest::RequestState::PAUSED) |
144 return false; | 140 return false; |
145 | 141 |
146 // If the request is expired, do not consider it. | 142 // If the request is expired, do not consider it. |
147 // TODO(petewil): We need to remove this from the queue. | |
148 base::TimeDelta requestAge = base::Time::Now() - request.creation_time(); | 143 base::TimeDelta requestAge = base::Time::Now() - request.creation_time(); |
149 if (requestAge > | 144 if (requestAge > |
150 base::TimeDelta::FromSeconds( | 145 base::TimeDelta::FromSeconds( |
151 policy_->GetRequestExpirationTimeInSeconds())) | 146 policy_->GetRequestExpirationTimeInSeconds())) |
152 return false; | 147 return false; |
153 | 148 |
154 // If this request is not active yet, return false. | 149 // If this request is not active yet, return false. |
155 // TODO(petewil): If the only reason we return nothing to do is that we have | 150 // TODO(petewil): If the only reason we return nothing to do is that we have |
156 // inactive requests, we still want to try again later after their activation | 151 // inactive requests, we still want to try again later after their activation |
157 // time elapses, we shouldn't take ourselves completely off the scheduler. | 152 // time elapses, we shouldn't take ourselves completely off the scheduler. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 // the coordinator. | 255 // the coordinator. |
261 void RequestPicker::OnRequestExpired( | 256 void RequestPicker::OnRequestExpired( |
262 const RequestQueue::UpdateMultipleRequestResults& results, | 257 const RequestQueue::UpdateMultipleRequestResults& results, |
263 const std::vector<SavePageRequest>& requests) { | 258 const std::vector<SavePageRequest>& requests) { |
264 for (auto request : requests) | 259 for (auto request : requests) |
265 notifier_->NotifyCompleted( | 260 notifier_->NotifyCompleted( |
266 request, RequestCoordinator::BackgroundSavePageResult::EXPIRED); | 261 request, RequestCoordinator::BackgroundSavePageResult::EXPIRED); |
267 } | 262 } |
268 | 263 |
269 } // namespace offline_pages | 264 } // namespace offline_pages |
OLD | NEW |