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

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

Issue 2355163002: [Offline Pages] Breaks out new TIMED_OUT Offliner status for RequestCoordinator watchdog timeout in… (Closed)
Patch Set: Created 4 years, 3 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 weak_ptr_factory_.GetWeakPtr(), callback)); 130 weak_ptr_factory_.GetWeakPtr(), callback));
131 } 131 }
132 132
133 void RequestCoordinator::GetQueuedRequestsCallback( 133 void RequestCoordinator::GetQueuedRequestsCallback(
134 const GetRequestsCallback& callback, 134 const GetRequestsCallback& callback,
135 RequestQueue::GetRequestsResult result, 135 RequestQueue::GetRequestsResult result,
136 std::vector<std::unique_ptr<SavePageRequest>> requests) { 136 std::vector<std::unique_ptr<SavePageRequest>> requests) {
137 callback.Run(std::move(requests)); 137 callback.Run(std::move(requests));
138 } 138 }
139 139
140 void RequestCoordinator::StopPrerendering() { 140 void RequestCoordinator::StopPrerendering(Offliner::RequestStatus stop_status) {
141 if (offliner_ && is_busy_) { 141 if (offliner_ && is_busy_) {
142 DCHECK(active_request_.get()); 142 DCHECK(active_request_.get());
143 offliner_->Cancel(); 143 offliner_->Cancel();
144 AbortRequestAttempt(active_request_.get()); 144 AbortRequestAttempt(active_request_.get());
145 } 145 }
146 146
147 // Stopping offliner means it will not call callback. 147 // Stopping offliner means it will not call callback so set last status.
148 last_offlining_status_ = 148 last_offlining_status_ = stop_status;
149 Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED;
150 149
151 if (active_request_) { 150 if (active_request_) {
151 event_logger_.RecordOfflinerResult(active_request_->client_id().name_space,
152 last_offlining_status_,
153 active_request_->request_id());
152 RecordOfflinerResultUMA(active_request_->client_id(), 154 RecordOfflinerResultUMA(active_request_->client_id(),
153 last_offlining_status_); 155 last_offlining_status_);
154 is_busy_ = false; 156 is_busy_ = false;
155 active_request_.reset(); 157 active_request_.reset();
156 } 158 }
157 159
158 } 160 }
159 161
160 void RequestCoordinator::GetRequestsForSchedulingCallback( 162 void RequestCoordinator::GetRequestsForSchedulingCallback(
161 RequestQueue::GetRequestsResult result, 163 RequestQueue::GetRequestsResult result,
(...skipping 16 matching lines...) Expand all
178 } 180 }
179 181
180 bool RequestCoordinator::CancelActiveRequestIfItMatches( 182 bool RequestCoordinator::CancelActiveRequestIfItMatches(
181 const std::vector<int64_t>& request_ids) { 183 const std::vector<int64_t>& request_ids) {
182 // If we have a request in progress and need to cancel it, call the 184 // If we have a request in progress and need to cancel it, call the
183 // pre-renderer to cancel. TODO Make sure we remove any page created by the 185 // pre-renderer to cancel. TODO Make sure we remove any page created by the
184 // prerenderer if it doesn't get the cancel in time. 186 // prerenderer if it doesn't get the cancel in time.
185 if (active_request_ != nullptr) { 187 if (active_request_ != nullptr) {
186 if (request_ids.end() != std::find(request_ids.begin(), request_ids.end(), 188 if (request_ids.end() != std::find(request_ids.begin(), request_ids.end(),
187 active_request_->request_id())) { 189 active_request_->request_id())) {
188 StopPrerendering(); 190 StopPrerendering(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED);
Pete Williamson 2016/09/21 00:29:09 This is really the user deciding to cancel, not th
dougarnett 2016/09/21 15:58:56 We don't actually know at this point whether this
189 return true; 191 return true;
190 } 192 }
191 } 193 }
192 194
193 return false; 195 return false;
194 } 196 }
195 197
196 void RequestCoordinator::AbortRequestAttempt(SavePageRequest* request) { 198 void RequestCoordinator::AbortRequestAttempt(SavePageRequest* request) {
197 request->MarkAttemptAborted(); 199 request->MarkAttemptAborted();
198 if (request->started_attempt_count() >= policy_->GetMaxStartedTries()) { 200 if (request->started_attempt_count() >= policy_->GetMaxStartedTries()) {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 } 335 }
334 336
335 void RequestCoordinator::ScheduleAsNeeded() { 337 void RequestCoordinator::ScheduleAsNeeded() {
336 // Get all requests from queue (there is no filtering mechanism). 338 // Get all requests from queue (there is no filtering mechanism).
337 queue_->GetRequests( 339 queue_->GetRequests(
338 base::Bind(&RequestCoordinator::GetRequestsForSchedulingCallback, 340 base::Bind(&RequestCoordinator::GetRequestsForSchedulingCallback,
339 weak_ptr_factory_.GetWeakPtr())); 341 weak_ptr_factory_.GetWeakPtr()));
340 } 342 }
341 343
342 void RequestCoordinator::StopProcessing() { 344 void RequestCoordinator::StopProcessing() {
345 StopProcessingWithStatus(Offliner::REQUEST_COORDINATOR_CANCELED);
346 }
347
348 void RequestCoordinator::HandleWatchdogTimeout() {
349 StopProcessingWithStatus(Offliner::REQUEST_COORDINATOR_TIMED_OUT);
350 }
351
352 void RequestCoordinator::StopProcessingWithStatus(
353 Offliner::RequestStatus stop_status) {
343 is_stopped_ = true; 354 is_stopped_ = true;
344 StopPrerendering(); 355 StopPrerendering(stop_status);
345 356
346 // Let the scheduler know we are done processing. 357 // Let the scheduler know we are done processing.
347 scheduler_callback_.Run(true); 358 scheduler_callback_.Run(true);
348 } 359 }
349 360
350 // Returns true if the caller should expect a callback, false otherwise. For 361 // Returns true if the caller should expect a callback, false otherwise. For
351 // instance, this would return false if a request is already in progress. 362 // instance, this would return false if a request is already in progress.
352 bool RequestCoordinator::StartProcessing( 363 bool RequestCoordinator::StartProcessing(
353 const DeviceConditions& device_conditions, 364 const DeviceConditions& device_conditions,
354 const base::Callback<void(bool)>& callback) { 365 const base::Callback<void(bool)>& callback) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 updated_request, base::Bind(&RequestCoordinator::OfflinerDoneCallback, 474 updated_request, base::Bind(&RequestCoordinator::OfflinerDoneCallback,
464 weak_ptr_factory_.GetWeakPtr()))) { 475 weak_ptr_factory_.GetWeakPtr()))) {
465 // Offliner accepted request so update it in the queue. 476 // Offliner accepted request so update it in the queue.
466 queue_->UpdateRequest(updated_request, 477 queue_->UpdateRequest(updated_request,
467 base::Bind(&RequestCoordinator::UpdateRequestCallback, 478 base::Bind(&RequestCoordinator::UpdateRequestCallback,
468 weak_ptr_factory_.GetWeakPtr(), 479 weak_ptr_factory_.GetWeakPtr(),
469 updated_request.client_id())); 480 updated_request.client_id()));
470 481
471 // Start a watchdog timer to catch pre-renders running too long 482 // Start a watchdog timer to catch pre-renders running too long
472 watchdog_timer_.Start(FROM_HERE, offliner_timeout_, this, 483 watchdog_timer_.Start(FROM_HERE, offliner_timeout_, this,
473 &RequestCoordinator::StopProcessing); 484 &RequestCoordinator::HandleWatchdogTimeout);
474 } else { 485 } else {
475 is_busy_ = false; 486 is_busy_ = false;
476 DVLOG(0) << "Unable to start LoadAndSave"; 487 DVLOG(0) << "Unable to start LoadAndSave";
477 StopProcessing(); 488 StopProcessing();
478 } 489 }
479 } 490 }
480 491
481 void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request, 492 void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request,
482 Offliner::RequestStatus status) { 493 Offliner::RequestStatus status) {
483 DVLOG(2) << "offliner finished, saved: " 494 DVLOG(2) << "offliner finished, saved: "
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 FOR_EACH_OBSERVER(Observer, observers_, OnChanged(request)); 593 FOR_EACH_OBSERVER(Observer, observers_, OnChanged(request));
583 } 594 }
584 595
585 void RequestCoordinator::GetOffliner() { 596 void RequestCoordinator::GetOffliner() {
586 if (!offliner_) { 597 if (!offliner_) {
587 offliner_ = factory_->GetOffliner(policy_.get()); 598 offliner_ = factory_->GetOffliner(policy_.get());
588 } 599 }
589 } 600 }
590 601
591 } // namespace offline_pages 602 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698