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

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

Issue 2256373002: Adds request queue removal capability to OfflinePageBridge. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@query-queue
Patch Set: Rebase. 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 active_request_->request_id())) { 145 active_request_->request_id())) {
146 StopPrerendering(); 146 StopPrerendering();
147 return true; 147 return true;
148 } 148 }
149 } 149 }
150 150
151 return false; 151 return false;
152 } 152 }
153 153
154 void RequestCoordinator::RemoveRequests( 154 void RequestCoordinator::RemoveRequests(
155 const std::vector<int64_t>& request_ids) { 155 const std::vector<int64_t>& request_ids,
156 const RemoveRequestsCallback& callback) {
156 bool canceled = CancelActiveRequestIfItMatches(request_ids); 157 bool canceled = CancelActiveRequestIfItMatches(request_ids);
157 queue_->RemoveRequests(request_ids, 158 queue_->RemoveRequests(
158 base::Bind(&RequestCoordinator::RemoveRequestsCallback, 159 request_ids,
159 weak_ptr_factory_.GetWeakPtr())); 160 base::Bind(&RequestCoordinator::HandleRemovedRequestsAndCallback,
161 weak_ptr_factory_.GetWeakPtr(), callback));
160 if (canceled) 162 if (canceled)
161 TryNextRequest(); 163 TryNextRequest();
162 } 164 }
163 165
164 void RequestCoordinator::PauseRequests( 166 void RequestCoordinator::PauseRequests(
165 const std::vector<int64_t>& request_ids) { 167 const std::vector<int64_t>& request_ids) {
166 bool canceled = CancelActiveRequestIfItMatches(request_ids); 168 bool canceled = CancelActiveRequestIfItMatches(request_ids);
167 queue_->ChangeRequestsState( 169 queue_->ChangeRequestsState(
168 request_ids, SavePageRequest::RequestState::PAUSED, 170 request_ids, SavePageRequest::RequestState::PAUSED,
169 base::Bind(&RequestCoordinator::UpdateMultipleRequestsCallback, 171 base::Bind(&RequestCoordinator::UpdateMultipleRequestsCallback,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 } 205 }
204 206
205 // Called in response to updating multiple requests in the request queue. 207 // Called in response to updating multiple requests in the request queue.
206 void RequestCoordinator::UpdateMultipleRequestsCallback( 208 void RequestCoordinator::UpdateMultipleRequestsCallback(
207 const RequestQueue::UpdateMultipleRequestResults& results, 209 const RequestQueue::UpdateMultipleRequestResults& results,
208 const std::vector<SavePageRequest>& requests) { 210 const std::vector<SavePageRequest>& requests) {
209 for (SavePageRequest request : requests) 211 for (SavePageRequest request : requests)
210 NotifyChanged(request); 212 NotifyChanged(request);
211 } 213 }
212 214
213 void RequestCoordinator::RemoveRequestsCallback( 215 void RequestCoordinator::HandleRemovedRequestsAndCallback(
216 const RemoveRequestsCallback& callback,
217 const RequestQueue::UpdateMultipleRequestResults& results,
218 const std::vector<SavePageRequest>& requests) {
219 callback.Run(results);
220 HandleRemovedRequests(results, requests);
221 }
222
223 void RequestCoordinator::HandleRemovedRequests(
214 const RequestQueue::UpdateMultipleRequestResults& results, 224 const RequestQueue::UpdateMultipleRequestResults& results,
215 const std::vector<SavePageRequest>& requests) { 225 const std::vector<SavePageRequest>& requests) {
216 for (SavePageRequest request : requests) 226 for (SavePageRequest request : requests)
217 NotifyCompleted(request, SavePageStatus::REMOVED); 227 NotifyCompleted(request, SavePageStatus::REMOVED);
218 } 228 }
219 229
220 void RequestCoordinator::StopProcessing() { 230 void RequestCoordinator::StopProcessing() {
221 is_stopped_ = true; 231 is_stopped_ = true;
222 StopPrerendering(); 232 StopPrerendering();
223 233
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 base::Bind(&RequestCoordinator::UpdateRequestCallback, 359 base::Bind(&RequestCoordinator::UpdateRequestCallback,
350 weak_ptr_factory_.GetWeakPtr(), 360 weak_ptr_factory_.GetWeakPtr(),
351 updated_request.client_id())); 361 updated_request.client_id()));
352 NotifyCompleted(updated_request, SavePageStatus::FOREGROUND_CANCELED); 362 NotifyCompleted(updated_request, SavePageStatus::FOREGROUND_CANCELED);
353 363
354 } else if (status == Offliner::RequestStatus::SAVED) { 364 } else if (status == Offliner::RequestStatus::SAVED) {
355 // Remove the request from the queue if it succeeded. 365 // Remove the request from the queue if it succeeded.
356 std::vector<int64_t> remove_requests; 366 std::vector<int64_t> remove_requests;
357 remove_requests.push_back(request.request_id()); 367 remove_requests.push_back(request.request_id());
358 queue_->RemoveRequests( 368 queue_->RemoveRequests(
359 remove_requests, base::Bind(&RequestCoordinator::RemoveRequestsCallback, 369 remove_requests, base::Bind(&RequestCoordinator::HandleRemovedRequests,
360 weak_ptr_factory_.GetWeakPtr())); 370 weak_ptr_factory_.GetWeakPtr()));
361 NotifyCompleted(request, SavePageStatus::SUCCESS); 371 NotifyCompleted(request, SavePageStatus::SUCCESS);
362 } else if (request.completed_attempt_count() + 1 >= 372 } else if (request.completed_attempt_count() + 1 >=
363 policy_->GetMaxCompletedTries()) { 373 policy_->GetMaxCompletedTries()) {
364 // Remove from the request queue if we exceeeded max retries. The +1 374 // Remove from the request queue if we exceeeded max retries. The +1
365 // represents the request that just completed. Since we call 375 // represents the request that just completed. Since we call
366 // MarkAttemptCompleted within the if branches, the completed_attempt_count 376 // MarkAttemptCompleted within the if branches, the completed_attempt_count
367 // has not yet been updated when we are checking the if condition. 377 // has not yet been updated when we are checking the if condition.
368 std::vector<int64_t> remove_requests; 378 std::vector<int64_t> remove_requests;
369 remove_requests.push_back(request.request_id()); 379 remove_requests.push_back(request.request_id());
370 queue_->RemoveRequests( 380 queue_->RemoveRequests(
371 remove_requests, base::Bind(&RequestCoordinator::RemoveRequestsCallback, 381 remove_requests, base::Bind(&RequestCoordinator::HandleRemovedRequests,
372 weak_ptr_factory_.GetWeakPtr())); 382 weak_ptr_factory_.GetWeakPtr()));
373 NotifyCompleted(request, SavePageStatus::RETRY_COUNT_EXCEEDED); 383 NotifyCompleted(request, SavePageStatus::RETRY_COUNT_EXCEEDED);
374 } else { 384 } else {
375 // If we failed, but are not over the limit, update the request in the 385 // If we failed, but are not over the limit, update the request in the
376 // queue. 386 // queue.
377 SavePageRequest updated_request(request); 387 SavePageRequest updated_request(request);
378 updated_request.MarkAttemptCompleted(); 388 updated_request.MarkAttemptCompleted();
379 queue_->UpdateRequest(updated_request, 389 queue_->UpdateRequest(updated_request,
380 base::Bind(&RequestCoordinator::UpdateRequestCallback, 390 base::Bind(&RequestCoordinator::UpdateRequestCallback,
381 weak_ptr_factory_.GetWeakPtr(), 391 weak_ptr_factory_.GetWeakPtr(),
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 FOR_EACH_OBSERVER(Observer, observers_, OnChanged(request)); 448 FOR_EACH_OBSERVER(Observer, observers_, OnChanged(request));
439 } 449 }
440 450
441 void RequestCoordinator::GetOffliner() { 451 void RequestCoordinator::GetOffliner() {
442 if (!offliner_) { 452 if (!offliner_) {
443 offliner_ = factory_->GetOffliner(policy_.get()); 453 offliner_ = factory_->GetOffliner(policy_.get());
444 } 454 }
445 } 455 }
446 456
447 } // namespace offline_pages 457 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698