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

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

Issue 2395213002: Implement disabled list (Closed)
Patch Set: Pass the disabled list when looking for a new request. 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 DVLOG(1) << "Not able to save page for requested url: " << url; 117 DVLOG(1) << "Not able to save page for requested url: " << url;
118 return 0L; 118 return 0L;
119 } 119 }
120 120
121 int64_t id = GenerateOfflineId(); 121 int64_t id = GenerateOfflineId();
122 122
123 // Build a SavePageRequest. 123 // Build a SavePageRequest.
124 offline_pages::SavePageRequest request(id, url, client_id, base::Time::Now(), 124 offline_pages::SavePageRequest request(id, url, client_id, base::Time::Now(),
125 user_requested); 125 user_requested);
126 126
127 // If the download manager is not done with the request, put it on the
128 // disabled list.
129 if (availability == RequestAvailability::DISABLED_FOR_OFFLINER)
130 disabled_requests_.insert(id);
131
127 // Put the request on the request queue. 132 // Put the request on the request queue.
128 queue_->AddRequest(request, 133 queue_->AddRequest(request,
129 base::Bind(&RequestCoordinator::AddRequestResultCallback, 134 base::Bind(&RequestCoordinator::AddRequestResultCallback,
130 weak_ptr_factory_.GetWeakPtr())); 135 weak_ptr_factory_.GetWeakPtr()));
131 return id; 136 return id;
132 } 137 }
133 void RequestCoordinator::GetAllRequests(const GetRequestsCallback& callback) { 138 void RequestCoordinator::GetAllRequests(const GetRequestsCallback& callback) {
134 // Get all matching requests from the request queue, send them to our 139 // Get all matching requests from the request queue, send them to our
135 // callback. We bind the namespace and callback to the front of the callback 140 // callback. We bind the namespace and callback to the front of the callback
136 // param set. 141 // param set.
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 419
415 return; 420 return;
416 } 421 }
417 422
418 // Choose a request to process that meets the available conditions. 423 // Choose a request to process that meets the available conditions.
419 // This is an async call, and returns right away. 424 // This is an async call, and returns right away.
420 picker_->ChooseNextRequest(base::Bind(&RequestCoordinator::RequestPicked, 425 picker_->ChooseNextRequest(base::Bind(&RequestCoordinator::RequestPicked,
421 weak_ptr_factory_.GetWeakPtr()), 426 weak_ptr_factory_.GetWeakPtr()),
422 base::Bind(&RequestCoordinator::RequestNotPicked, 427 base::Bind(&RequestCoordinator::RequestNotPicked,
423 weak_ptr_factory_.GetWeakPtr()), 428 weak_ptr_factory_.GetWeakPtr()),
424 current_conditions_.get()); 429 current_conditions_.get(),
430 &disabled_requests_);
425 } 431 }
426 432
427 // Called by the request picker when a request has been picked. 433 // Called by the request picker when a request has been picked.
428 void RequestCoordinator::RequestPicked(const SavePageRequest& request) { 434 void RequestCoordinator::RequestPicked(const SavePageRequest& request) {
429 is_starting_ = false; 435 is_starting_ = false;
430 436
431 // Make sure we were not stopped while picking. 437 // Make sure we were not stopped while picking.
432 if (!is_stopped_) { 438 if (!is_stopped_) {
433 // Send the request on to the offliner. 439 // Send the request on to the offliner.
434 SendRequestToOffliner(request); 440 SendRequestToOffliner(request);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 case Offliner::RequestStatus::PRERENDERING_FAILED: 562 case Offliner::RequestStatus::PRERENDERING_FAILED:
557 // No further processing in this service window. 563 // No further processing in this service window.
558 break; 564 break;
559 default: 565 default:
560 // Make explicit choice about new status codes that actually reach here. 566 // Make explicit choice about new status codes that actually reach here.
561 // Their default is no further processing in this service window. 567 // Their default is no further processing in this service window.
562 NOTREACHED(); 568 NOTREACHED();
563 } 569 }
564 } 570 }
565 571
566 void RequestCoordinator::EnableForOffliner(int64_t request_id) {} 572 void RequestCoordinator::EnableForOffliner(int64_t request_id) {
573 disabled_requests_.erase(request_id);
574 }
567 575
568 void RequestCoordinator::MarkRequestCompleted(int64_t request_id) {} 576 void RequestCoordinator::MarkRequestCompleted(int64_t request_id) {}
569 577
570 const Scheduler::TriggerConditions RequestCoordinator::GetTriggerConditions( 578 const Scheduler::TriggerConditions RequestCoordinator::GetTriggerConditions(
571 const bool user_requested) { 579 const bool user_requested) {
572 return Scheduler::TriggerConditions( 580 return Scheduler::TriggerConditions(
573 policy_->PowerRequired(user_requested), 581 policy_->PowerRequired(user_requested),
574 policy_->BatteryPercentageRequired(user_requested), 582 policy_->BatteryPercentageRequired(user_requested),
575 policy_->UnmeteredNetworkRequired(user_requested)); 583 policy_->UnmeteredNetworkRequired(user_requested));
576 } 584 }
(...skipping 28 matching lines...) Expand all
605 613
606 ClientPolicyController* RequestCoordinator::GetPolicyController() { 614 ClientPolicyController* RequestCoordinator::GetPolicyController() {
607 return policy_controller_.get(); 615 return policy_controller_.get();
608 } 616 }
609 617
610 void RequestCoordinator::Shutdown() { 618 void RequestCoordinator::Shutdown() {
611 network_quality_estimator_ = nullptr; 619 network_quality_estimator_ = nullptr;
612 } 620 }
613 621
614 } // namespace offline_pages 622 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698