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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 // If we have already tried this page the max number of times, it is not | 110 // If we have already tried this page the max number of times, it is not |
111 // eligible to try again. | 111 // eligible to try again. |
112 // TODO(petewil): Instead, we should have code to remove the page from the | 112 // TODO(petewil): Instead, we should have code to remove the page from the |
113 // queue after the last retry. | 113 // queue after the last retry. |
114 if (request.attempt_count() >= policy_->GetMaxRetries()) | 114 if (request.attempt_count() >= policy_->GetMaxRetries()) |
115 return false; | 115 return false; |
116 | 116 |
| 117 // If the request is expired, do not consider it. |
| 118 // TODO(petewil): We need to remove this from the queue. |
| 119 base::TimeDelta requestAge = base::Time::Now() - request.creation_time(); |
| 120 if (requestAge > |
| 121 base::TimeDelta::FromSeconds( |
| 122 policy_->GetRequestExpirationTimeInSeconds())) |
| 123 return false; |
| 124 |
117 // If this request is not active yet, return false. | 125 // If this request is not active yet, return false. |
118 // TODO(petewil): If the only reason we return nothing to do is that we have | 126 // TODO(petewil): If the only reason we return nothing to do is that we have |
119 // inactive requests, we still want to try again later after their activation | 127 // inactive requests, we still want to try again later after their activation |
120 // time elapses, we shouldn't take ourselves completely off the scheduler. | 128 // time elapses, we shouldn't take ourselves completely off the scheduler. |
121 if (request.activation_time() > base::Time::Now()) | 129 if (request.activation_time() > base::Time::Now()) |
122 return false; | 130 return false; |
123 | 131 |
124 return true; | 132 return true; |
125 } | 133 } |
126 | 134 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 int result = signum(difference.InMilliseconds()); | 205 int result = signum(difference.InMilliseconds()); |
198 | 206 |
199 // Flip the direction of comparison if policy prefers fewer retries. | 207 // Flip the direction of comparison if policy prefers fewer retries. |
200 if (earlier_requests_better_) | 208 if (earlier_requests_better_) |
201 result *= -1; | 209 result *= -1; |
202 | 210 |
203 return result; | 211 return result; |
204 } | 212 } |
205 | 213 |
206 } // namespace offline_pages | 214 } // namespace offline_pages |
OLD | NEW |