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

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

Issue 2473553004: Request Picker task (Closed)
Patch Set: merge with latest Created 4 years, 1 month 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_queue.h
diff --git a/components/offline_pages/background/request_queue.h b/components/offline_pages/background/request_queue.h
index 3168ea1d90539654e40e83f4ca3f6a44adade9bf..bed7ca26b07bf6e1de2aa9f59a17c6b650a22c51 100644
--- a/components/offline_pages/background/request_queue.h
+++ b/components/offline_pages/background/request_queue.h
@@ -8,12 +8,17 @@
#include <stdint.h>
#include <memory>
+#include <set>
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
+#include "components/offline_pages/background/device_conditions.h"
+#include "components/offline_pages/background/pick_request_task.h"
+#include "components/offline_pages/background/pick_request_task_factory.h"
+#include "components/offline_pages/background/request_queue_results.h"
#include "components/offline_pages/background/save_page_request.h"
#include "components/offline_pages/core/task_queue.h"
#include "components/offline_pages/offline_page_item.h"
@@ -22,31 +27,11 @@
namespace offline_pages {
class RequestQueueStore;
-typedef StoreUpdateResult<SavePageRequest> UpdateRequestsResult;
+class PickRequestTaskFactory;
// Class responsible for managing save page requests.
class RequestQueue {
public:
- enum class GetRequestsResult {
- SUCCESS,
- STORE_FAILURE,
- };
-
- enum class AddRequestResult {
- SUCCESS,
- STORE_FAILURE,
- ALREADY_EXISTS,
- REQUEST_QUOTA_HIT, // Cannot add a request with this namespace, as it has
- // reached a quota of active requests.
- };
-
- // GENERATED_JAVA_ENUM_PACKAGE:org.chromium.components.offlinepages.background
- enum class UpdateRequestResult {
- SUCCESS,
- STORE_FAILURE,
- REQUEST_DOES_NOT_EXIST, // Failed to delete the request because it does not
- // exist.
- };
// Callback used for |GetRequests|.
typedef base::Callback<void(GetRequestsResult,
@@ -103,6 +88,22 @@ class RequestQueue {
// are returned through |callback|.
void MarkAttemptCompleted(int64_t request_id, const UpdateCallback& callback);
+ // Make a task to pick the next request, and report our choice to the
+ // callbacks.
+ void PickNextRequest(
+ PickRequestTask::RequestPickedCallback picked_callback,
+ PickRequestTask::RequestNotPickedCallback not_picked_callback,
+ DeviceConditions& conditions,
+ std::set<int64_t>& disabled_requests);
+
+ // Takes ownership of the factory. We use a setter to allow users of the
+ // request queue to not need a PickerFactory to create it, since we have lots
+ // of code using the request queue. The request coordinator will set a
+ // factory before calling PickNextRequest.
+ void SetPickerFactory(std::unique_ptr<PickRequestTaskFactory> factory) {
+ picker_factory_ = std::move(factory);
+ }
+
private:
// Callback used by |PurgeRequests|.
typedef base::Callback<void(UpdateRequestResult,
@@ -119,6 +120,9 @@ class RequestQueue {
// Task queue to serialize store access.
TaskQueue task_queue_;
+ // Builds PickRequestTask objects.
+ std::unique_ptr<PickRequestTaskFactory> picker_factory_;
+
// Allows us to pass a weak pointer to callbacks.
base::WeakPtrFactory<RequestQueue> weak_ptr_factory_;
« no previous file with comments | « components/offline_pages/background/request_picker_unittest.cc ('k') | components/offline_pages/background/request_queue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698