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

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

Issue 2221323003: Add an API to Pause and Resume background offlining requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit test break introduced by merge 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 if (request.started_attempt_count() >= policy_->GetMaxStartedTries()) 114 if (request.started_attempt_count() >= policy_->GetMaxStartedTries())
115 return false; 115 return false;
116 116
117 // If we have already completed trying this page the max number of times, it 117 // If we have already completed trying this page the max number of times, it
118 // is not eligible to try again. 118 // is not eligible to try again.
119 // TODO(petewil): We should have code to remove the page from the 119 // TODO(petewil): We should have code to remove the page from the
120 // queue after the last retry. 120 // queue after the last retry.
121 if (request.completed_attempt_count() >= policy_->GetMaxCompletedTries()) 121 if (request.completed_attempt_count() >= policy_->GetMaxCompletedTries())
122 return false; 122 return false;
123 123
124 // If the request is paused, do not consider it.
125 if (request.request_state() == SavePageRequest::RequestState::PAUSED)
126 return false;
127
124 // If the request is expired, do not consider it. 128 // If the request is expired, do not consider it.
125 // TODO(petewil): We need to remove this from the queue. 129 // TODO(petewil): We need to remove this from the queue.
126 base::TimeDelta requestAge = base::Time::Now() - request.creation_time(); 130 base::TimeDelta requestAge = base::Time::Now() - request.creation_time();
127 if (requestAge > 131 if (requestAge >
128 base::TimeDelta::FromSeconds( 132 base::TimeDelta::FromSeconds(
129 policy_->GetRequestExpirationTimeInSeconds())) 133 policy_->GetRequestExpirationTimeInSeconds()))
130 return false; 134 return false;
131 135
132 // If this request is not active yet, return false. 136 // If this request is not active yet, return false.
133 // TODO(petewil): If the only reason we return nothing to do is that we have 137 // TODO(petewil): If the only reason we return nothing to do is that we have
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 int result = signum(difference.InMilliseconds()); 217 int result = signum(difference.InMilliseconds());
214 218
215 // Flip the direction of comparison if policy prefers fewer retries. 219 // Flip the direction of comparison if policy prefers fewer retries.
216 if (earlier_requests_better_) 220 if (earlier_requests_better_)
217 result *= -1; 221 result *= -1;
218 222
219 return result; 223 return result;
220 } 224 }
221 225
222 } // namespace offline_pages 226 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/background/request_coordinator.cc ('k') | components/offline_pages/background/request_queue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698