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

Side by Side 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: 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 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_coordinator.h" 5 #include "components/offline_pages/background/request_coordinator.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 RequestQueue::AddRequestResult result, 88 RequestQueue::AddRequestResult result,
89 const SavePageRequest& request) { 89 const SavePageRequest& request) {
90 90
91 // Inform the scheduler that we have an outstanding task. 91 // Inform the scheduler that we have an outstanding task.
92 // TODO(petewil): Determine trigger conditions from policy. 92 // TODO(petewil): Determine trigger conditions from policy.
93 scheduler_->Schedule(GetTriggerConditionsForUserRequest()); 93 scheduler_->Schedule(GetTriggerConditionsForUserRequest());
94 } 94 }
95 95
96 // Called in response to updating a request in the request queue. 96 // Called in response to updating a request in the request queue.
97 void RequestCoordinator::UpdateRequestCallback( 97 void RequestCoordinator::UpdateRequestCallback(
98 RequestQueue::UpdateRequestResult result) {} 98 RequestQueue::UpdateRequestResult result) {
99 // If the request succeeded, nothing to do. If it failed, we can't really do
100 // much, so just log it.
101 if (result != RequestQueue::UpdateRequestResult::SUCCESS) {
102 LOG(WARNING) << "Failed to update a request retry count. "
fgorski 2016/07/22 16:14:58 why not DVLOG? Also, do we have a UMA for this ca
Pete Williamson 2016/07/22 18:27:00 TODO added, Changed to DLOG (DVLOG doesn't work wi
103 << static_cast<int>(result);
104 }
105 }
99 106
100 void RequestCoordinator::StopProcessing() { 107 void RequestCoordinator::StopProcessing() {
101 is_canceled_ = true; 108 is_canceled_ = true;
102 if (offliner_ && is_busy_) 109 if (offliner_ && is_busy_)
103 offliner_->Cancel(); 110 offliner_->Cancel();
104 111
105 // Stopping offliner means it will not call callback. 112 // Stopping offliner means it will not call callback.
106 last_offlining_status_ = 113 last_offlining_status_ =
107 Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED; 114 Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED;
108 RecordOfflinerResultUMA(last_offlining_status_); 115 RecordOfflinerResultUMA(last_offlining_status_);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 event_logger_.RecordSavePageRequestUpdated( 194 event_logger_.RecordSavePageRequestUpdated(
188 request.client_id().name_space, 195 request.client_id().name_space,
189 "Saved", 196 "Saved",
190 request.request_id()); 197 request.request_id());
191 last_offlining_status_ = status; 198 last_offlining_status_ = status;
192 RecordOfflinerResultUMA(last_offlining_status_); 199 RecordOfflinerResultUMA(last_offlining_status_);
193 watchdog_timer_.Stop(); 200 watchdog_timer_.Stop();
194 201
195 is_busy_ = false; 202 is_busy_ = false;
196 203
197 // If the request succeeded, remove it from the Queue and maybe schedule 204 int64_t new_attempt_count = request.attempt_count() + 1;
198 // another one. 205
199 if (status == Offliner::RequestStatus::SAVED) { 206 // Remove the request from the queue if it either succeeded or exceeded the
207 // max number of retries.
208 if (status == Offliner::RequestStatus::SAVED
209 /* || new_attempt_count > policy_->GetMaxRetries()*/) {
Pete Williamson 2016/07/22 01:12:43 This commented out code will be commented back in
200 queue_->RemoveRequest(request.request_id(), 210 queue_->RemoveRequest(request.request_id(),
201 base::Bind(&RequestCoordinator::UpdateRequestCallback, 211 base::Bind(&RequestCoordinator::UpdateRequestCallback,
202 weak_ptr_factory_.GetWeakPtr())); 212 weak_ptr_factory_.GetWeakPtr()));
213 } else {
214 // If we failed, but are not over the limit, update the request in the
215 // queue.
216 SavePageRequest updated_request(request);
217 updated_request.set_attempt_count(new_attempt_count);
218 updated_request.set_last_attempt_time(base::Time::Now());
219 RequestQueue::UpdateRequestCallback update_callback =
220 base::Bind(&RequestCoordinator::UpdateRequestCallback,
221 weak_ptr_factory_.GetWeakPtr());
222 queue_->UpdateRequest(updated_request,
fgorski 2016/07/22 16:14:58 nit: is this how git cl format worked on this call
Pete Williamson 2016/07/22 18:27:00 Nope, that was me. Changed to be a bit more unifo
223 base::Bind(&RequestCoordinator::UpdateRequestCallback,
224 weak_ptr_factory_.GetWeakPtr()));
225 }
203 226
204 // TODO(petewil): Check time budget. Return to the scheduler if we are out. 227 // TODO(petewil): Check time budget. Return to the scheduler if we are out.
205 228 // Start another request if we have time.
206 // Start another request if we have time. 229 TryNextRequest();
207 TryNextRequest();
208 }
209 } 230 }
210 231
211 const Scheduler::TriggerConditions& 232 const Scheduler::TriggerConditions&
212 RequestCoordinator::GetTriggerConditionsForUserRequest() { 233 RequestCoordinator::GetTriggerConditionsForUserRequest() {
213 return kUserRequestTriggerConditions; 234 return kUserRequestTriggerConditions;
214 } 235 }
215 236
216 void RequestCoordinator::GetOffliner() { 237 void RequestCoordinator::GetOffliner() {
217 if (!offliner_) { 238 if (!offliner_) {
218 offliner_ = factory_->GetOffliner(policy_.get()); 239 offliner_ = factory_->GetOffliner(policy_.get());
219 } 240 }
220 } 241 }
221 242
222 } // namespace offline_pages 243 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698