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

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

Issue 2373933003: [Offline pages] Updating RequestQueue::RemoveRequests to use a TaskQueue (Closed)
Patch Set: Addressing final feedback Created 4 years, 2 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 } 307 }
308 } 308 }
309 309
310 if (available_user_request) 310 if (available_user_request)
311 StartProcessingIfConnected(); 311 StartProcessingIfConnected();
312 } 312 }
313 313
314 void RequestCoordinator::HandleRemovedRequestsAndCallback( 314 void RequestCoordinator::HandleRemovedRequestsAndCallback(
315 const RemoveRequestsCallback& callback, 315 const RemoveRequestsCallback& callback,
316 BackgroundSavePageResult status, 316 BackgroundSavePageResult status,
317 const RequestQueue::UpdateMultipleRequestResults& results, 317 std::unique_ptr<UpdateRequestsResult> result) {
318 std::vector<std::unique_ptr<SavePageRequest>> requests) { 318 callback.Run(result->item_statuses);
319 callback.Run(results); 319 HandleRemovedRequests(status, std::move(result));
320 HandleRemovedRequests(status, results, std::move(requests));
321 } 320 }
322 321
323 void RequestCoordinator::HandleRemovedRequests( 322 void RequestCoordinator::HandleRemovedRequests(
324 BackgroundSavePageResult status, 323 BackgroundSavePageResult status,
325 const RequestQueue::UpdateMultipleRequestResults& results, 324 std::unique_ptr<UpdateRequestsResult> result) {
326 std::vector<std::unique_ptr<SavePageRequest>> requests) { 325 for (const auto& request : result->updated_items)
327 for (const auto& request : requests) 326 NotifyCompleted(request, status);
328 NotifyCompleted(*request, status);
329 } 327 }
330 328
331 void RequestCoordinator::ScheduleAsNeeded() { 329 void RequestCoordinator::ScheduleAsNeeded() {
332 // Get all requests from queue (there is no filtering mechanism). 330 // Get all requests from queue (there is no filtering mechanism).
333 queue_->GetRequests( 331 queue_->GetRequests(
334 base::Bind(&RequestCoordinator::GetRequestsForSchedulingCallback, 332 base::Bind(&RequestCoordinator::GetRequestsForSchedulingCallback,
335 weak_ptr_factory_.GetWeakPtr())); 333 weak_ptr_factory_.GetWeakPtr()));
336 } 334 }
337 335
338 void RequestCoordinator::StopProcessing( 336 void RequestCoordinator::StopProcessing(
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 is_busy_ = true; 461 is_busy_ = true;
464 462
465 // Update the request for this attempt to start it. 463 // Update the request for this attempt to start it.
466 SavePageRequest updated_request(request); 464 SavePageRequest updated_request(request);
467 updated_request.MarkAttemptStarted(base::Time::Now()); 465 updated_request.MarkAttemptStarted(base::Time::Now());
468 queue_->UpdateRequest( 466 queue_->UpdateRequest(
469 updated_request, 467 updated_request,
470 base::Bind(&RequestCoordinator::UpdateRequestCallback, 468 base::Bind(&RequestCoordinator::UpdateRequestCallback,
471 weak_ptr_factory_.GetWeakPtr(), updated_request.client_id())); 469 weak_ptr_factory_.GetWeakPtr(), updated_request.client_id()));
472 active_request_.reset(new SavePageRequest(updated_request)); 470 active_request_.reset(new SavePageRequest(updated_request));
473 queue_->UpdateRequest(
474 updated_request,
475 base::Bind(&RequestCoordinator::UpdateRequestCallback,
476 weak_ptr_factory_.GetWeakPtr(), updated_request.client_id()));
477 471
478 // Start the load and save process in the offliner (Async). 472 // Start the load and save process in the offliner (Async).
479 if (offliner_->LoadAndSave( 473 if (offliner_->LoadAndSave(
480 updated_request, base::Bind(&RequestCoordinator::OfflinerDoneCallback, 474 updated_request, base::Bind(&RequestCoordinator::OfflinerDoneCallback,
481 weak_ptr_factory_.GetWeakPtr()))) { 475 weak_ptr_factory_.GetWeakPtr()))) {
482 // Start a watchdog timer to catch pre-renders running too long 476 // Start a watchdog timer to catch pre-renders running too long
483 watchdog_timer_.Start(FROM_HERE, offliner_timeout_, this, 477 watchdog_timer_.Start(FROM_HERE, offliner_timeout_, this,
484 &RequestCoordinator::HandleWatchdogTimeout); 478 &RequestCoordinator::HandleWatchdogTimeout);
485 } else { 479 } else {
486 is_busy_ = false; 480 is_busy_ = false;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 if (!offliner_) { 591 if (!offliner_) {
598 offliner_ = factory_->GetOffliner(policy_.get()); 592 offliner_ = factory_->GetOffliner(policy_.get());
599 } 593 }
600 } 594 }
601 595
602 void RequestCoordinator::Shutdown() { 596 void RequestCoordinator::Shutdown() {
603 network_quality_estimator_ = nullptr; 597 network_quality_estimator_ = nullptr;
604 } 598 }
605 599
606 } // namespace offline_pages 600 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698