Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(711)

Side by Side Diff: components/offline_pages/background/request_picker.cc

Issue 2176393004: Add expiration policy, code to check it, and a test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 base::TimeDelta requestAge = base::Time::Now() - request.creation_time();
119 if (requestAge >
120 base::TimeDelta::FromSeconds(policy_->GetPageExpirationTimeInSeconds()))
121 return false;
dougarnett 2016/07/27 15:40:41 Maybe add TODO wrt need to remove this from the qu
Pete Williamson 2016/07/27 17:20:06 Done.
122
117 // If this request is not active yet, return false. 123 // 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 124 // 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 125 // inactive requests, we still want to try again later after their activation
120 // time elapses, we shouldn't take ourselves completely off the scheduler. 126 // time elapses, we shouldn't take ourselves completely off the scheduler.
121 if (request.activation_time() > base::Time::Now()) 127 if (request.activation_time() > base::Time::Now())
122 return false; 128 return false;
123 129
124 return true; 130 return true;
125 } 131 }
126 132
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 int result = signum(difference.InMilliseconds()); 203 int result = signum(difference.InMilliseconds());
198 204
199 // Flip the direction of comparison if policy prefers fewer retries. 205 // Flip the direction of comparison if policy prefers fewer retries.
200 if (earlier_requests_better_) 206 if (earlier_requests_better_)
201 result *= -1; 207 result *= -1;
202 208
203 return result; 209 return result;
204 } 210 }
205 211
206 } // namespace offline_pages 212 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698