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

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

Issue 2209813002: [Offline Pages] Moves Coordinator to using MarkAttemptStarted/MarkAttemptCompleted API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes status string send to event logger (was hardwired to "Saved" without checking actual status) 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_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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 scheduler_->Schedule(GetTriggerConditionsForUserRequest()); 78 scheduler_->Schedule(GetTriggerConditionsForUserRequest());
79 } 79 }
80 80
81 // Called in response to updating a request in the request queue. 81 // Called in response to updating a request in the request queue.
82 void RequestCoordinator::UpdateRequestCallback( 82 void RequestCoordinator::UpdateRequestCallback(
83 RequestQueue::UpdateRequestResult result) { 83 RequestQueue::UpdateRequestResult result) {
84 // If the request succeeded, nothing to do. If it failed, we can't really do 84 // If the request succeeded, nothing to do. If it failed, we can't really do
85 // much, so just log it. 85 // much, so just log it.
86 if (result != RequestQueue::UpdateRequestResult::SUCCESS) { 86 if (result != RequestQueue::UpdateRequestResult::SUCCESS) {
87 // TODO(petewil): Consider adding UMA or showing on offline-internals page. 87 // TODO(petewil): Consider adding UMA or showing on offline-internals page.
88 DLOG(WARNING) << "Failed to update a request retry count. " 88 DLOG(WARNING) << "Failed to update request attempt details. "
Pete Williamson 2016/08/03 20:44:55 Now that more is hanging off the update request, w
dougarnett 2016/08/03 21:40:01 What can we do if persisting fails? Diagnostic thi
dougarnett 2016/08/03 23:33:51 Added event logger event
89 << static_cast<int>(result); 89 << static_cast<int>(result);
90 } 90 }
91 } 91 }
92 92
93 void RequestCoordinator::StopProcessing() { 93 void RequestCoordinator::StopProcessing() {
94 is_canceled_ = true; 94 is_canceled_ = true;
95 if (offliner_ && is_busy_) 95 if (offliner_ && is_busy_)
96 offliner_->Cancel(); 96 offliner_->Cancel();
97 97
98 // Stopping offliner means it will not call callback. 98 // Stopping offliner means it will not call callback.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 GetOffliner(); 170 GetOffliner();
171 if (!offliner_) { 171 if (!offliner_) {
172 DVLOG(0) << "Unable to create Offliner. " 172 DVLOG(0) << "Unable to create Offliner. "
173 << "Cannot background offline page."; 173 << "Cannot background offline page.";
174 return; 174 return;
175 } 175 }
176 176
177 DCHECK(!is_busy_); 177 DCHECK(!is_busy_);
178 is_busy_ = true; 178 is_busy_ = true;
179 179
180 // Prepare an updated request to attempt.
181 SavePageRequest updated_request(request);
182 updated_request.MarkAttemptStarted(base::Time::Now());
183
180 // Start the load and save process in the offliner (Async). 184 // Start the load and save process in the offliner (Async).
181 offliner_->LoadAndSave(request, 185 if (offliner_->LoadAndSave(updated_request,
182 base::Bind(&RequestCoordinator::OfflinerDoneCallback, 186 base::Bind(&RequestCoordinator::OfflinerDoneCallback,
183 weak_ptr_factory_.GetWeakPtr())); 187 weak_ptr_factory_.GetWeakPtr()))) {
188 // Offliner accepted request so update it in the queue.
189 RequestQueue::UpdateRequestCallback update_callback =
190 base::Bind(&RequestCoordinator::UpdateRequestCallback,
191 weak_ptr_factory_.GetWeakPtr());
Pete Williamson 2016/08/04 00:17:14 Good catch to delete this, looks like leftover cod
dougarnett 2016/08/04 00:23:35 I am curious as well.
192 queue_->UpdateRequest(
193 updated_request,
194 base::Bind(&RequestCoordinator::UpdateRequestCallback,
195 weak_ptr_factory_.GetWeakPtr()));
184 196
185 // Start a watchdog timer to catch pre-renders running too long 197 // Start a watchdog timer to catch pre-renders running too long
186 watchdog_timer_.Start(FROM_HERE, offliner_timeout_, this, 198 watchdog_timer_.Start(FROM_HERE, offliner_timeout_, this,
187 &RequestCoordinator::StopProcessing); 199 &RequestCoordinator::StopProcessing);
200 } else {
201 is_busy_ = false;
202 DVLOG(0) << "Unable to start LoadAndSave";
203 StopProcessing();
Pete Williamson 2016/08/03 20:44:55 So do we always need to call StopProcessing if the
dougarnett 2016/08/03 21:40:01 This was a hole before - LoadAndSave will never ca
Pete Williamson 2016/08/03 22:29:12 Case 1 - Should never happen (I'm happy to add a D
dougarnett 2016/08/03 23:33:51 Added CanSaveURL check in SavePageLater API to not
204 }
188 } 205 }
189 206
190 void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request, 207 void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request,
191 Offliner::RequestStatus status) { 208 Offliner::RequestStatus status) {
192 DVLOG(2) << "offliner finished, saved: " 209 DVLOG(2) << "offliner finished, saved: "
193 << (status == Offliner::RequestStatus::SAVED) 210 << (status == Offliner::RequestStatus::SAVED)
194 << ", status: " << static_cast<int>(status) << ", " << __func__; 211 << ", status: " << static_cast<int>(status) << ", " << __func__;
195 DCHECK_NE(status, Offliner::RequestStatus::UNKNOWN); 212 DCHECK_NE(status, Offliner::RequestStatus::UNKNOWN);
196 DCHECK_NE(status, Offliner::RequestStatus::LOADED); 213 DCHECK_NE(status, Offliner::RequestStatus::LOADED);
197 event_logger_.RecordSavePageRequestUpdated( 214 event_logger_.RecordSavePageRequestUpdated(
198 request.client_id().name_space, 215 request.client_id().name_space,
199 "Saved", 216 Offliner::RequestStatusToString(status),
200 request.request_id()); 217 request.request_id());
201 last_offlining_status_ = status; 218 last_offlining_status_ = status;
202 RecordOfflinerResultUMA(last_offlining_status_); 219 RecordOfflinerResultUMA(last_offlining_status_);
203 watchdog_timer_.Stop(); 220 watchdog_timer_.Stop();
204 221
205 is_busy_ = false; 222 is_busy_ = false;
206 223
207 int64_t new_attempt_count = request.attempt_count() + 1; 224 if (status == Offliner::RequestStatus::FOREGROUND_CANCELED) {
225 // Update the request for the canceled attempt.
Pete Williamson 2016/08/03 20:44:55 Aborted cases include: * StopProcessing called by
dougarnett 2016/08/03 21:40:01 Yeah, we need to add these - none of them in Offli
Pete Williamson 2016/08/03 22:29:12 Acknowledged.
dougarnett 2016/08/03 23:33:51 Added a TODO in StopProcessing for is_busy_ case t
226 // TODO(dougarnett): See if we can conclusively identify other
227 // attempt aborted cases to treat this way.
228 SavePageRequest updated_request(request);
229 updated_request.MarkAttemptAborted();
230 RequestQueue::UpdateRequestCallback update_callback =
231 base::Bind(&RequestCoordinator::UpdateRequestCallback,
232 weak_ptr_factory_.GetWeakPtr());
233 queue_->UpdateRequest(
234 updated_request,
235 base::Bind(&RequestCoordinator::UpdateRequestCallback,
236 weak_ptr_factory_.GetWeakPtr()));
208 237
209 // Remove the request from the queue if it either succeeded or exceeded the 238 } else if (status == Offliner::RequestStatus::SAVED
210 // max number of retries. 239 || request.attempt_count() >= policy_->GetMaxTries()) {
211 if (status == Offliner::RequestStatus::SAVED 240 // Remove the request from the queue if it either succeeded or exceeded the
212 || new_attempt_count > policy_->GetMaxTries()) { 241 // max number of retries.
213 queue_->RemoveRequest(request.request_id(), 242 queue_->RemoveRequest(request.request_id(),
214 base::Bind(&RequestCoordinator::UpdateRequestCallback, 243 base::Bind(&RequestCoordinator::UpdateRequestCallback,
215 weak_ptr_factory_.GetWeakPtr())); 244 weak_ptr_factory_.GetWeakPtr()));
216 } else { 245 } else {
217 // If we failed, but are not over the limit, update the request in the 246 // If we failed, but are not over the limit, update the request in the
218 // queue. 247 // queue.
219 SavePageRequest updated_request(request); 248 SavePageRequest updated_request(request);
220 updated_request.set_attempt_count(new_attempt_count); 249 updated_request.MarkAttemptCompleted();
221 updated_request.set_last_attempt_time(base::Time::Now());
222 RequestQueue::UpdateRequestCallback update_callback = 250 RequestQueue::UpdateRequestCallback update_callback =
223 base::Bind(&RequestCoordinator::UpdateRequestCallback, 251 base::Bind(&RequestCoordinator::UpdateRequestCallback,
224 weak_ptr_factory_.GetWeakPtr()); 252 weak_ptr_factory_.GetWeakPtr());
225 queue_->UpdateRequest( 253 queue_->UpdateRequest(
226 updated_request, 254 updated_request,
227 base::Bind(&RequestCoordinator::UpdateRequestCallback, 255 base::Bind(&RequestCoordinator::UpdateRequestCallback,
228 weak_ptr_factory_.GetWeakPtr())); 256 weak_ptr_factory_.GetWeakPtr()));
229 } 257 }
230 258
231 // Determine whether we might try another request in this 259 // Determine whether we might try another request in this
(...skipping 29 matching lines...) Expand all
261 return trigger_conditions; 289 return trigger_conditions;
262 } 290 }
263 291
264 void RequestCoordinator::GetOffliner() { 292 void RequestCoordinator::GetOffliner() {
265 if (!offliner_) { 293 if (!offliner_) {
266 offliner_ = factory_->GetOffliner(policy_.get()); 294 offliner_ = factory_->GetOffliner(policy_.get());
267 } 295 }
268 } 296 }
269 297
270 } // namespace offline_pages 298 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698