Chromium Code Reviews| 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 88ebb6092d655506a1fd9a701bb813f1639ce229..17490135e29e1890d1410feba9c7a056ae79a339 100644 |
| --- a/components/offline_pages/background/request_coordinator.cc |
| +++ b/components/offline_pages/background/request_coordinator.cc |
| @@ -112,19 +112,60 @@ void RequestCoordinator::GetQueuedRequestsCallback( |
| callback.Run(requests); |
| } |
| +void RequestCoordinator::StopPrerendering() { |
| + if (offliner_ && is_busy_) { |
| + // TODO(dougarnett): Find current request and mark attempt aborted. |
|
dougarnett
2016/08/23 20:59:45
maybe actually DO MarkAttemptAborted now on active
|
| + offliner_->Cancel(); |
| + } |
| + |
| + // Stopping offliner means it will not call callback. |
| + last_offlining_status_ = |
| + Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED; |
| + |
| + if (active_request_) { |
| + RecordOfflinerResultUMA(active_request_->client_id(), |
| + last_offlining_status_); |
| + active_request_.reset(); |
| + } |
| + |
| +} |
| + |
| +bool RequestCoordinator::CancelActiveRequestIfItMatches( |
| + const std::vector<int64_t>& request_ids) { |
| + // If we have a request in progress and need to cancel it, call the |
| + // pre-renderer to cancel. TODO Make sure we remove any page created by the |
| + // prerenderer if it doesn't get the cancel in time. |
| + if (active_request_ != nullptr) { |
| + if (request_ids.end() != std::find(request_ids.begin(), request_ids.end(), |
| + active_request_->request_id())) { |
| + StopPrerendering(); |
| + return true; |
| + } |
| + } |
| + |
| + return false; |
| +} |
| + |
| void RequestCoordinator::RemoveRequests( |
| const std::vector<int64_t>& request_ids) { |
| + bool canceled = CancelActiveRequestIfItMatches(request_ids); |
| queue_->RemoveRequests(request_ids, |
| base::Bind(&RequestCoordinator::RemoveRequestsCallback, |
| weak_ptr_factory_.GetWeakPtr())); |
| + if (canceled) |
| + TryNextRequest(); |
| } |
| void RequestCoordinator::PauseRequests( |
| const std::vector<int64_t>& request_ids) { |
| + bool canceled = CancelActiveRequestIfItMatches(request_ids); |
| queue_->ChangeRequestsState( |
| request_ids, SavePageRequest::RequestState::PAUSED, |
| base::Bind(&RequestCoordinator::UpdateMultipleRequestsCallback, |
| weak_ptr_factory_.GetWeakPtr())); |
| + |
| + if (canceled) |
| + TryNextRequest(); |
| } |
| void RequestCoordinator::ResumeRequests( |
| @@ -173,20 +214,7 @@ void RequestCoordinator::RemoveRequestsCallback( |
| void RequestCoordinator::StopProcessing() { |
| is_canceled_ = true; |
|
dougarnett
2016/08/23 20:59:45
if this flag only applies to StopProcessing (and n
Pete Williamson
2016/08/23 21:57:00
Done.
|
| - if (offliner_ && is_busy_) { |
| - // TODO(dougarnett): Find current request and mark attempt aborted. |
| - offliner_->Cancel(); |
| - } |
| - |
| - // Stopping offliner means it will not call callback. |
| - last_offlining_status_ = |
| - Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED; |
| - |
| - if (active_request_) { |
| - RecordOfflinerResultUMA(active_request_->client_id(), |
| - last_offlining_status_); |
| - active_request_.reset(); |
| - } |
| + StopPrerendering(); |
| // Let the scheduler know we are done processing. |
| scheduler_callback_.Run(true); |
| @@ -264,11 +292,11 @@ void RequestCoordinator::SendRequestToOffliner(const SavePageRequest& request) { |
| DCHECK(!is_busy_); |
| is_busy_ = true; |
| - active_request_.reset(new SavePageRequest(request)); |
| // Prepare an updated request to attempt. |
| SavePageRequest updated_request(request); |
| updated_request.MarkAttemptStarted(base::Time::Now()); |
| + active_request_.reset(new SavePageRequest(updated_request)); |
| // Start the load and save process in the offliner (Async). |
| if (offliner_->LoadAndSave( |