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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 if (!available_user_request && request.user_requested() && | 350 if (!available_user_request && request.user_requested() && |
351 request.request_state() == SavePageRequest::RequestState::AVAILABLE) { | 351 request.request_state() == SavePageRequest::RequestState::AVAILABLE) { |
352 available_user_request = true; | 352 available_user_request = true; |
353 } | 353 } |
354 } | 354 } |
355 | 355 |
356 if (available_user_request) | 356 if (available_user_request) |
357 StartProcessingIfConnected(); | 357 StartProcessingIfConnected(); |
358 } | 358 } |
359 | 359 |
| 360 // When we successfully remove a request that completed successfully, move on to |
| 361 // the next request. |
| 362 void RequestCoordinator::CompletedRequestCallback( |
| 363 const MultipleItemStatuses& status) { |
| 364 TryNextRequest(); |
| 365 } |
| 366 |
360 void RequestCoordinator::HandleRemovedRequestsAndCallback( | 367 void RequestCoordinator::HandleRemovedRequestsAndCallback( |
361 const RemoveRequestsCallback& callback, | 368 const RemoveRequestsCallback& callback, |
362 BackgroundSavePageResult status, | 369 BackgroundSavePageResult status, |
363 std::unique_ptr<UpdateRequestsResult> result) { | 370 std::unique_ptr<UpdateRequestsResult> result) { |
364 // TODO(dougarnett): Define status code for user/api cancel and use here | 371 // TODO(dougarnett): Define status code for user/api cancel and use here |
365 // to determine whether to record cancel time UMA. | 372 // to determine whether to record cancel time UMA. |
366 for (const auto& request : result->updated_items) | 373 for (const auto& request : result->updated_items) |
367 RecordCancelTimeUMA(request); | 374 RecordCancelTimeUMA(request); |
368 callback.Run(result->item_statuses); | 375 callback.Run(result->item_statuses); |
369 HandleRemovedRequests(status, std::move(result)); | 376 HandleRemovedRequests(status, std::move(result)); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 } | 637 } |
631 } | 638 } |
632 | 639 |
633 void RequestCoordinator::EnableForOffliner(int64_t request_id) { | 640 void RequestCoordinator::EnableForOffliner(int64_t request_id) { |
634 disabled_requests_.erase(request_id); | 641 disabled_requests_.erase(request_id); |
635 // If we are not busy, start processing right away. | 642 // If we are not busy, start processing right away. |
636 StartProcessingIfConnected(); | 643 StartProcessingIfConnected(); |
637 } | 644 } |
638 | 645 |
639 void RequestCoordinator::MarkRequestCompleted(int64_t request_id) { | 646 void RequestCoordinator::MarkRequestCompleted(int64_t request_id) { |
640 // TODO: Remove the request, but send out SUCCEEDED instead of removed. | 647 // Remove the request, but send out SUCCEEDED instead of removed. |
| 648 std::vector<int64_t> request_ids { request_id }; |
| 649 queue_->RemoveRequests( |
| 650 request_ids, |
| 651 base::Bind(&RequestCoordinator::HandleRemovedRequestsAndCallback, |
| 652 weak_ptr_factory_.GetWeakPtr(), |
| 653 base::Bind(&RequestCoordinator::CompletedRequestCallback, |
| 654 weak_ptr_factory_.GetWeakPtr()), |
| 655 BackgroundSavePageResult::SUCCESS)); |
641 } | 656 } |
642 | 657 |
643 const Scheduler::TriggerConditions RequestCoordinator::GetTriggerConditions( | 658 const Scheduler::TriggerConditions RequestCoordinator::GetTriggerConditions( |
644 const bool user_requested) { | 659 const bool user_requested) { |
645 return Scheduler::TriggerConditions( | 660 return Scheduler::TriggerConditions( |
646 policy_->PowerRequired(user_requested), | 661 policy_->PowerRequired(user_requested), |
647 policy_->BatteryPercentageRequired(user_requested), | 662 policy_->BatteryPercentageRequired(user_requested), |
648 policy_->UnmeteredNetworkRequired(user_requested)); | 663 policy_->UnmeteredNetworkRequired(user_requested)); |
649 } | 664 } |
650 | 665 |
(...skipping 27 matching lines...) Expand all Loading... |
678 | 693 |
679 ClientPolicyController* RequestCoordinator::GetPolicyController() { | 694 ClientPolicyController* RequestCoordinator::GetPolicyController() { |
680 return policy_controller_.get(); | 695 return policy_controller_.get(); |
681 } | 696 } |
682 | 697 |
683 void RequestCoordinator::Shutdown() { | 698 void RequestCoordinator::Shutdown() { |
684 network_quality_estimator_ = nullptr; | 699 network_quality_estimator_ = nullptr; |
685 } | 700 } |
686 | 701 |
687 } // namespace offline_pages | 702 } // namespace offline_pages |
OLD | NEW |