OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/offline_pages/background/request_picker.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/logging.h" |
| 9 #include "components/offline_pages/background/save_page_request.h" |
| 10 |
| 11 namespace offline_pages { |
| 12 |
| 13 RequestPicker::RequestPicker( |
| 14 RequestQueue* requestQueue) |
| 15 : queue_(requestQueue), |
| 16 weak_ptr_factory_(this) {} |
| 17 |
| 18 RequestPicker::~RequestPicker() {} |
| 19 |
| 20 void RequestPicker::ChooseNextRequest( |
| 21 RequestCoordinator::RequestPickedCallback picked_callback, |
| 22 RequestCoordinator::RequestQueueEmptyCallback empty_callback) { |
| 23 picked_callback_ = picked_callback; |
| 24 empty_callback_ = empty_callback; |
| 25 // Get all requests from queue (there is no filtering mechanism). |
| 26 queue_->GetRequests(base::Bind(&RequestPicker::GetRequestResultCallback, |
| 27 weak_ptr_factory_.GetWeakPtr())); |
| 28 } |
| 29 |
| 30 void RequestPicker::GetRequestResultCallback( |
| 31 RequestQueue::GetRequestsResult, |
| 32 const std::vector<SavePageRequest>& requests) { |
| 33 // If there is nothing to do, return right away. |
| 34 if (requests.size() == 0) { |
| 35 empty_callback_.Run(); |
| 36 return; |
| 37 } |
| 38 |
| 39 // Pick the most deserving request for our conditions. |
| 40 const SavePageRequest& picked_request = requests[0]; |
| 41 |
| 42 // When we have a best request to try next, get the request coodinator to |
| 43 // start it. |
| 44 picked_callback_.Run(picked_request); |
| 45 } |
| 46 |
| 47 } // namespace offline_pages |
OLD | NEW |