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

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

Issue 2020833002: Add the request picker and a unit test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR feedback per Dimich and DougArnett Created 4 years, 6 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
(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
OLDNEW
« no previous file with comments | « components/offline_pages/background/request_picker.h ('k') | components/offline_pages/background/request_picker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698