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

Unified Diff: components/offline_pages/background/request_coordinator.cc

Issue 2176453002: Update the request count when a request fails. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test Created 4 years, 5 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
« no previous file with comments | « no previous file | components/offline_pages/background/request_coordinator_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/offline_pages/background/request_coordinator.cc
diff --git a/components/offline_pages/background/request_coordinator.cc b/components/offline_pages/background/request_coordinator.cc
index 85d6356f3d54d8d66526295f6acc4eefdb3b9c21..a78d58cbdcfe24663f5e444c1777d3ab4155c104 100644
--- a/components/offline_pages/background/request_coordinator.cc
+++ b/components/offline_pages/background/request_coordinator.cc
@@ -96,7 +96,15 @@ void RequestCoordinator::AddRequestResultCallback(
// Called in response to updating a request in the request queue.
void RequestCoordinator::UpdateRequestCallback(
- RequestQueue::UpdateRequestResult result) {}
+ RequestQueue::UpdateRequestResult result) {
+ // If the request succeeded, nothing to do. If it failed, we can't really do
+ // much, so just log it.
+ if (result != RequestQueue::UpdateRequestResult::SUCCESS) {
+ // TODO(petewil): Consider adding UMA or showing on offline-internals page.
+ DLOG(WARNING) << "Failed to update a request retry count. "
+ << static_cast<int>(result);
+ }
+}
void RequestCoordinator::StopProcessing() {
is_canceled_ = true;
@@ -197,18 +205,33 @@ void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request,
is_busy_ = false;
- // If the request succeeded, remove it from the Queue and maybe schedule
- // another one.
- if (status == Offliner::RequestStatus::SAVED) {
+ int64_t new_attempt_count = request.attempt_count() + 1;
+
+ // Remove the request from the queue if it either succeeded or exceeded the
+ // max number of retries.
+ if (status == Offliner::RequestStatus::SAVED
+ || new_attempt_count > policy_->GetMaxRetries()) {
queue_->RemoveRequest(request.request_id(),
base::Bind(&RequestCoordinator::UpdateRequestCallback,
weak_ptr_factory_.GetWeakPtr()));
-
- // TODO(petewil): Check time budget. Return to the scheduler if we are out.
-
- // Start another request if we have time.
- TryNextRequest();
+ } else {
+ // If we failed, but are not over the limit, update the request in the
+ // queue.
+ SavePageRequest updated_request(request);
+ updated_request.set_attempt_count(new_attempt_count);
+ updated_request.set_last_attempt_time(base::Time::Now());
+ RequestQueue::UpdateRequestCallback update_callback =
+ base::Bind(&RequestCoordinator::UpdateRequestCallback,
+ weak_ptr_factory_.GetWeakPtr());
+ queue_->UpdateRequest(
+ updated_request,
+ base::Bind(&RequestCoordinator::UpdateRequestCallback,
+ weak_ptr_factory_.GetWeakPtr()));
}
+
+ // TODO(petewil): Check time budget. Return to the scheduler if we are out.
+ // Start another request if we have time.
+ TryNextRequest();
}
const Scheduler::TriggerConditions&
« no previous file with comments | « no previous file | components/offline_pages/background/request_coordinator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698