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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
Index: components/offline_pages/background/request_picker.cc
diff --git a/components/offline_pages/background/request_picker.cc b/components/offline_pages/background/request_picker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..665b39fee53977fd875c138db8e3e7bbe4729b4f
--- /dev/null
+++ b/components/offline_pages/background/request_picker.cc
@@ -0,0 +1,47 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/offline_pages/background/request_picker.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "components/offline_pages/background/save_page_request.h"
+
+namespace offline_pages {
+
+RequestPicker::RequestPicker(
+ RequestQueue* requestQueue)
+ : queue_(requestQueue),
+ weak_ptr_factory_(this) {}
+
+RequestPicker::~RequestPicker() {}
+
+void RequestPicker::ChooseNextRequest(
+ RequestCoordinator::RequestPickedCallback picked_callback,
+ RequestCoordinator::RequestQueueEmptyCallback empty_callback) {
+ picked_callback_ = picked_callback;
+ empty_callback_ = empty_callback;
+ // Get all requests from queue (there is no filtering mechanism).
+ queue_->GetRequests(base::Bind(&RequestPicker::GetRequestResultCallback,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void RequestPicker::GetRequestResultCallback(
+ RequestQueue::GetRequestsResult,
+ const std::vector<SavePageRequest>& requests) {
+ // If there is nothing to do, return right away.
+ if (requests.size() == 0) {
+ empty_callback_.Run();
+ return;
+ }
+
+ // Pick the most deserving request for our conditions.
+ const SavePageRequest& picked_request = requests[0];
+
+ // When we have a best request to try next, get the request coodinator to
+ // start it.
+ picked_callback_.Run(picked_request);
+}
+
+} // namespace offline_pages
« 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