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 RequestCoordinator::RequestPickedCallback picked_callback, | |
16 RequestCoordinator::RequestQueueEmptyCallback empty_callback) | |
17 : queue_(requestQueue), | |
18 picked_callback_(picked_callback), | |
19 empty_callback_(empty_callback), | |
20 weak_ptr_factory_(this) {} | |
21 | |
22 RequestPicker::~RequestPicker() {} | |
23 | |
24 void RequestPicker::ChooseNextRequest() { | |
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]; | |
chili
2016/05/27 23:54:13
Should we have a TODO here to actually check all t
Pete Williamson
2016/05/28 00:08:52
The whole purpose of this class is to make a more
| |
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 |