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

Unified Diff: components/offline_pages/core/background/pick_request_task.cc

Issue 2729763002: [Offline Pages] Pick correct request when resuming. (Closed)
Patch Set: comments from Pete. Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: components/offline_pages/core/background/pick_request_task.cc
diff --git a/components/offline_pages/core/background/pick_request_task.cc b/components/offline_pages/core/background/pick_request_task.cc
index 006d08b47aff2211d377e6869f8b95e49273185f..b7203d99eb8837712ebae8737cc38b59aa39df00 100644
--- a/components/offline_pages/core/background/pick_request_task.cc
+++ b/components/offline_pages/core/background/pick_request_task.cc
@@ -35,13 +35,15 @@ PickRequestTask::PickRequestTask(RequestQueueStore* store,
RequestNotPickedCallback not_picked_callback,
RequestCountCallback request_count_callback,
DeviceConditions& device_conditions,
- const std::set<int64_t>& disabled_requests)
+ const std::set<int64_t>& disabled_requests,
+ std::vector<int64_t>& prioritized_requests)
: store_(store),
policy_(policy),
picked_callback_(picked_callback),
not_picked_callback_(not_picked_callback),
request_count_callback_(request_count_callback),
disabled_requests_(disabled_requests),
+ prioritized_requests_(prioritized_requests),
weak_ptr_factory_(this) {
device_conditions_.reset(new DeviceConditions(device_conditions));
}
@@ -84,9 +86,14 @@ void PickRequestTask::Choose(
bool non_user_requested_tasks_remaining = false;
bool cleanup_needed = false;
+ size_t request_size = requests.size();
size_t available_request_count = 0;
- // Iterate once through the requests, keeping track of best candidate.
+ std::vector<std::unique_ptr<SavePageRequest>> available_requests;
+
+ // Iterate through the requests, filter out unavailable requests and get other
+ // information (if cleanup is needed and number of non-user-requested
+ // requests).
for (unsigned i = 0; i < requests.size(); ++i) {
// If the request is expired or has exceeded the retry count, skip it.
if (OfflinerPolicyUtils::CheckRequestExpirationStatus(requests[i].get(),
@@ -95,8 +102,7 @@ void PickRequestTask::Choose(
cleanup_needed = true;
continue;
}
-
- // If the request is on the disabled list, skip it.
+ // If the request is on the disabled list, skip it.
auto search = disabled_requests_.find(requests[i]->request_id());
if (search != disabled_requests_.end())
continue;
@@ -112,14 +118,40 @@ void PickRequestTask::Choose(
SavePageRequest::RequestState::AVAILABLE) {
available_request_count++;
}
- if (!RequestConditionsSatisfied(requests[i].get()))
- continue;
- if (IsNewRequestBetter(picked_request, requests[i].get(), comparator))
- picked_request = requests[i].get();
+ available_requests.push_back(std::move(requests[i]));
}
-
// Report the request queue counts.
- request_count_callback_.Run(requests.size(), available_request_count);
+ request_count_callback_.Run(request_size, available_requests.size());
+
+ // Search for and pick the prioritized request which is not disabled and in
+ // the request queue. An assumption is that requests later in the vector have
+ // higher priority than earlier ones in the vector. Also remove the picked
Pete Williamson 2017/03/07 20:57:02 Why do we remove the picked request here instead o
+ // request from the prioritized list.
+ int idx_to_delete = -1;
+ for (int i = prioritized_requests_.size() - 1; !picked_request && i >= 0;
+ --i) {
+ for (unsigned j = 0; j < available_requests.size(); ++j) {
+ if (available_requests[j]->request_id() == prioritized_requests_[i]) {
+ picked_request = available_requests[j].get();
+ idx_to_delete = i;
+ break;
+ }
+ }
+ }
+ prioritized_requests_.erase(prioritized_requests_.begin() + idx_to_delete);
+
+ // If no request was found from the priority list, find the best request
+ // according to current policies.
+ if (!picked_request) {
+ for (unsigned i = 0; i < available_requests.size(); ++i) {
+ if (!RequestConditionsSatisfied(available_requests[i].get()))
+ continue;
+ if (IsNewRequestBetter(picked_request, available_requests[i].get(),
+ comparator)) {
+ picked_request = available_requests[i].get();
+ }
+ }
+ }
// If we have a best request to try next, get the request coodinator to
// start it. Otherwise return that we have no candidates.

Powered by Google App Engine
This is Rietveld 408576698