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

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

Issue 1932953002: [Offline pages] Empty RequestQueue and SavePageRequest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing nits from Pete Created 4 years, 8 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
« no previous file with comments | « components/offline_pages/background/BUILD.gn ('k') | components/offline_pages/background/request_queue.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
new file mode 100644
index 0000000000000000000000000000000000000000..afae725b64609daf5cb63fcbe3d9df06b66f6971
--- /dev/null
+++ b/components/offline_pages/background/request_queue.h
@@ -0,0 +1,85 @@
+// 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_QUEUE_H_
+#define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_
+
+#include <stdint.h>
+#include <vector>
+
+#include "base/callback.h"
+
+namespace offline_pages {
+
+class SavePageRequest;
+
+// Class responsible for managing save page requests.
+class RequestQueue {
+ public:
+ enum class GetRequestsResult {
+ kSuccess,
+ kStoreFailure,
+ };
+
+ enum class AddRequestResult {
+ kSuccess,
+ kStoreFailure,
+ kRequestQuotaHit, // Cannot add a request with this namespace, as it has
+ // reached a quota of active requests.
+ };
+
+ enum class UpdateRequestResult {
+ kSuccess,
+ kStoreFailure,
+ kRequestDoesNotExist, // Failed to delete the request because it does not
+ // exist.
+ };
+
+ // Callback used for |GetRequests|.
+ typedef base::Callback<void(GetRequestsResult,
+ const std::vector<SavePageRequest>&)>
+ GetRequestsCallback;
+
+ // Callback used for |AddRequest|.
+ typedef base::Callback<void(AddRequestResult, const SavePageRequest& request)>
+ AddRequestCallback;
+
+ // Callback used by |UdpateRequest| and |RemoveRequest|.
+ typedef base::Callback<void(UpdateRequestResult)> UpdateRequestCallback;
+
+ // Gets all of the active requests from the store. Calling this method may
+ // schedule purging of the request queue.
+ void GetRequests(const GetRequestsCallback& callback);
+
+ // Adds |request| to the request queue. Result is returned through |callback|.
+ // In case adding the request violates policy, the result will fail with
+ // appropriate result. Callback will also return a copy of a request with all
+ // fields set.
+ void AddRequest(const SavePageRequest& request,
+ const AddRequestCallback& callback);
+
+ // Updates a request in the request queue if a request with matching ID
+ // exists. Does nothing otherwise. Result is returned through |callback|.
+ void UpdateRequest(const SavePageRequest& request,
+ const UpdateRequestCallback& callback);
+
+ // Removes the request matching the |request_id|. Result is returned through
+ // |callback|.
+ void RemoveRequest(int64_t request_id, const UpdateRequestCallback& callback);
+
+ private:
+ // Callback used by |PurgeRequests|.
+ typedef base::Callback<void(UpdateRequestResult,
+ int /* removed requests count */)>
+ PurgeRequestsCallback;
+
+ // Purges the queue, removing the requests that are no longer relevant, e.g.
+ // expired request. Result is returned through |callback| carries the number
+ // of removed requests.
+ void PurgeRequests(const PurgeRequestsCallback& callback);
+};
+
+} // namespace offline_pages
+
+#endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_
« no previous file with comments | « components/offline_pages/background/BUILD.gn ('k') | components/offline_pages/background/request_queue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698