| OLD | NEW |
| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 DVLOG(1) << "Not able to save page for requested url: " << url; | 152 DVLOG(1) << "Not able to save page for requested url: " << url; |
| 153 return 0L; | 153 return 0L; |
| 154 } | 154 } |
| 155 | 155 |
| 156 int64_t id = GenerateOfflineId(); | 156 int64_t id = GenerateOfflineId(); |
| 157 | 157 |
| 158 // Build a SavePageRequest. | 158 // Build a SavePageRequest. |
| 159 offline_pages::SavePageRequest request(id, url, client_id, base::Time::Now(), | 159 offline_pages::SavePageRequest request(id, url, client_id, base::Time::Now(), |
| 160 user_requested); | 160 user_requested); |
| 161 | 161 |
| 162 // If the download manager is not done with the request, put it on the |
| 163 // disabled list. |
| 164 if (availability == RequestAvailability::DISABLED_FOR_OFFLINER) |
| 165 disabled_requests_.insert(id); |
| 166 |
| 162 // Put the request on the request queue. | 167 // Put the request on the request queue. |
| 163 queue_->AddRequest(request, | 168 queue_->AddRequest(request, |
| 164 base::Bind(&RequestCoordinator::AddRequestResultCallback, | 169 base::Bind(&RequestCoordinator::AddRequestResultCallback, |
| 165 weak_ptr_factory_.GetWeakPtr())); | 170 weak_ptr_factory_.GetWeakPtr())); |
| 166 return id; | 171 return id; |
| 167 } | 172 } |
| 168 void RequestCoordinator::GetAllRequests(const GetRequestsCallback& callback) { | 173 void RequestCoordinator::GetAllRequests(const GetRequestsCallback& callback) { |
| 169 // Get all matching requests from the request queue, send them to our | 174 // Get all matching requests from the request queue, send them to our |
| 170 // callback. We bind the namespace and callback to the front of the callback | 175 // callback. We bind the namespace and callback to the front of the callback |
| 171 // param set. | 176 // param set. |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 | 471 |
| 467 return; | 472 return; |
| 468 } | 473 } |
| 469 | 474 |
| 470 // Choose a request to process that meets the available conditions. | 475 // Choose a request to process that meets the available conditions. |
| 471 // This is an async call, and returns right away. | 476 // This is an async call, and returns right away. |
| 472 picker_->ChooseNextRequest(base::Bind(&RequestCoordinator::RequestPicked, | 477 picker_->ChooseNextRequest(base::Bind(&RequestCoordinator::RequestPicked, |
| 473 weak_ptr_factory_.GetWeakPtr()), | 478 weak_ptr_factory_.GetWeakPtr()), |
| 474 base::Bind(&RequestCoordinator::RequestNotPicked, | 479 base::Bind(&RequestCoordinator::RequestNotPicked, |
| 475 weak_ptr_factory_.GetWeakPtr()), | 480 weak_ptr_factory_.GetWeakPtr()), |
| 476 current_conditions_.get()); | 481 current_conditions_.get(), |
| 482 disabled_requests_); |
| 477 } | 483 } |
| 478 | 484 |
| 479 // Called by the request picker when a request has been picked. | 485 // Called by the request picker when a request has been picked. |
| 480 void RequestCoordinator::RequestPicked(const SavePageRequest& request) { | 486 void RequestCoordinator::RequestPicked(const SavePageRequest& request) { |
| 481 is_starting_ = false; | 487 is_starting_ = false; |
| 482 | 488 |
| 483 // Make sure we were not stopped while picking. | 489 // Make sure we were not stopped while picking. |
| 484 if (!is_stopped_) { | 490 if (!is_stopped_) { |
| 485 // Send the request on to the offliner. | 491 // Send the request on to the offliner. |
| 486 SendRequestToOffliner(request); | 492 SendRequestToOffliner(request); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 case Offliner::RequestStatus::PRERENDERING_FAILED: | 615 case Offliner::RequestStatus::PRERENDERING_FAILED: |
| 610 // No further processing in this service window. | 616 // No further processing in this service window. |
| 611 break; | 617 break; |
| 612 default: | 618 default: |
| 613 // Make explicit choice about new status codes that actually reach here. | 619 // Make explicit choice about new status codes that actually reach here. |
| 614 // Their default is no further processing in this service window. | 620 // Their default is no further processing in this service window. |
| 615 NOTREACHED(); | 621 NOTREACHED(); |
| 616 } | 622 } |
| 617 } | 623 } |
| 618 | 624 |
| 619 void RequestCoordinator::EnableForOffliner(int64_t request_id) {} | 625 void RequestCoordinator::EnableForOffliner(int64_t request_id) { |
| 626 disabled_requests_.erase(request_id); |
| 627 } |
| 620 | 628 |
| 621 void RequestCoordinator::MarkRequestCompleted(int64_t request_id) {} | 629 void RequestCoordinator::MarkRequestCompleted(int64_t request_id) {} |
| 622 | 630 |
| 623 const Scheduler::TriggerConditions RequestCoordinator::GetTriggerConditions( | 631 const Scheduler::TriggerConditions RequestCoordinator::GetTriggerConditions( |
| 624 const bool user_requested) { | 632 const bool user_requested) { |
| 625 return Scheduler::TriggerConditions( | 633 return Scheduler::TriggerConditions( |
| 626 policy_->PowerRequired(user_requested), | 634 policy_->PowerRequired(user_requested), |
| 627 policy_->BatteryPercentageRequired(user_requested), | 635 policy_->BatteryPercentageRequired(user_requested), |
| 628 policy_->UnmeteredNetworkRequired(user_requested)); | 636 policy_->UnmeteredNetworkRequired(user_requested)); |
| 629 } | 637 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 658 | 666 |
| 659 ClientPolicyController* RequestCoordinator::GetPolicyController() { | 667 ClientPolicyController* RequestCoordinator::GetPolicyController() { |
| 660 return policy_controller_.get(); | 668 return policy_controller_.get(); |
| 661 } | 669 } |
| 662 | 670 |
| 663 void RequestCoordinator::Shutdown() { | 671 void RequestCoordinator::Shutdown() { |
| 664 network_quality_estimator_ = nullptr; | 672 network_quality_estimator_ = nullptr; |
| 665 } | 673 } |
| 666 | 674 |
| 667 } // namespace offline_pages | 675 } // namespace offline_pages |
| OLD | NEW |