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

Unified Diff: components/offline_pages/background/request_picker.h

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.h
diff --git a/components/offline_pages/background/request_picker.h b/components/offline_pages/background/request_picker.h
new file mode 100644
index 0000000000000000000000000000000000000000..7e8f318eb009393c57e1baf7044461088659737b
--- /dev/null
+++ b/components/offline_pages/background/request_picker.h
@@ -0,0 +1,43 @@
+// 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.
+
+#ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_PICKER_H_
+#define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_PICKER_H_
+
+#include "base/memory/weak_ptr.h"
+#include "components/offline_pages/background/request_coordinator.h"
+#include "components/offline_pages/background/request_queue.h"
+
+namespace offline_pages {
+
+class RequestPicker {
+ public:
+ RequestPicker(RequestQueue* requestQueue);
+
+ ~RequestPicker();
+
+ // Choose which request we should process next based on the current
+ // conditions, and call back to the RequestCoordinator when we have one.
+ void ChooseNextRequest(
+ RequestCoordinator::RequestPickedCallback picked_callback,
+ RequestCoordinator::RequestQueueEmptyCallback empty_callback);
+
+ private:
+ // Callback for the GetRequest results to be delivered.
+ void GetRequestResultCallback(RequestQueue::GetRequestsResult result,
+ const std::vector<SavePageRequest>& results);
+
+ // unowned pointer to the request queue.
+ RequestQueue* queue_;
+ // Callback for when we are done picking a request to do next.
+ RequestCoordinator::RequestPickedCallback picked_callback_;
+ // Callback for when there are no more reqeusts to pick.
+ RequestCoordinator::RequestQueueEmptyCallback empty_callback_;
+ // Allows us to pass a weak pointer to callbacks.
+ base::WeakPtrFactory<RequestPicker> weak_ptr_factory_;
+};
+
+} // namespace offline_pages
+
+#endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_PICKER_H_

Powered by Google App Engine
This is Rietveld 408576698