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

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

Issue 2395213002: Implement disabled list (Closed)
Patch Set: set pointer -> const ref 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 431
427 return; 432 return;
428 } 433 }
429 434
430 // Choose a request to process that meets the available conditions. 435 // Choose a request to process that meets the available conditions.
431 // This is an async call, and returns right away. 436 // This is an async call, and returns right away.
432 picker_->ChooseNextRequest(base::Bind(&RequestCoordinator::RequestPicked, 437 picker_->ChooseNextRequest(base::Bind(&RequestCoordinator::RequestPicked,
433 weak_ptr_factory_.GetWeakPtr()), 438 weak_ptr_factory_.GetWeakPtr()),
434 base::Bind(&RequestCoordinator::RequestNotPicked, 439 base::Bind(&RequestCoordinator::RequestNotPicked,
435 weak_ptr_factory_.GetWeakPtr()), 440 weak_ptr_factory_.GetWeakPtr()),
436 current_conditions_.get()); 441 current_conditions_.get(),
442 disabled_requests_);
437 } 443 }
438 444
439 // Called by the request picker when a request has been picked. 445 // Called by the request picker when a request has been picked.
440 void RequestCoordinator::RequestPicked(const SavePageRequest& request) { 446 void RequestCoordinator::RequestPicked(const SavePageRequest& request) {
441 is_starting_ = false; 447 is_starting_ = false;
442 448
443 // Make sure we were not stopped while picking. 449 // Make sure we were not stopped while picking.
444 if (!is_stopped_) { 450 if (!is_stopped_) {
445 // Send the request on to the offliner. 451 // Send the request on to the offliner.
446 SendRequestToOffliner(request); 452 SendRequestToOffliner(request);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 case Offliner::RequestStatus::PRERENDERING_FAILED: 574 case Offliner::RequestStatus::PRERENDERING_FAILED:
569 // No further processing in this service window. 575 // No further processing in this service window.
570 break; 576 break;
571 default: 577 default:
572 // Make explicit choice about new status codes that actually reach here. 578 // Make explicit choice about new status codes that actually reach here.
573 // Their default is no further processing in this service window. 579 // Their default is no further processing in this service window.
574 NOTREACHED(); 580 NOTREACHED();
575 } 581 }
576 } 582 }
577 583
578 void RequestCoordinator::EnableForOffliner(int64_t request_id) {} 584 void RequestCoordinator::EnableForOffliner(int64_t request_id) {
585 disabled_requests_.erase(request_id);
586 }
579 587
580 void RequestCoordinator::MarkRequestCompleted(int64_t request_id) {} 588 void RequestCoordinator::MarkRequestCompleted(int64_t request_id) {}
581 589
582 const Scheduler::TriggerConditions RequestCoordinator::GetTriggerConditions( 590 const Scheduler::TriggerConditions RequestCoordinator::GetTriggerConditions(
583 const bool user_requested) { 591 const bool user_requested) {
584 return Scheduler::TriggerConditions( 592 return Scheduler::TriggerConditions(
585 policy_->PowerRequired(user_requested), 593 policy_->PowerRequired(user_requested),
586 policy_->BatteryPercentageRequired(user_requested), 594 policy_->BatteryPercentageRequired(user_requested),
587 policy_->UnmeteredNetworkRequired(user_requested)); 595 policy_->UnmeteredNetworkRequired(user_requested));
588 } 596 }
(...skipping 28 matching lines...) Expand all
617 625
618 ClientPolicyController* RequestCoordinator::GetPolicyController() { 626 ClientPolicyController* RequestCoordinator::GetPolicyController() {
619 return policy_controller_.get(); 627 return policy_controller_.get();
620 } 628 }
621 629
622 void RequestCoordinator::Shutdown() { 630 void RequestCoordinator::Shutdown() {
623 network_quality_estimator_ = nullptr; 631 network_quality_estimator_ = nullptr;
624 } 632 }
625 633
626 } // namespace offline_pages 634 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/background/request_coordinator.h ('k') | components/offline_pages/background/request_picker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698