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

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: Updated with documentation and formatting 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
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..bc974fa66613a89bd1ab06199d82fd4e7b975b05
--- /dev/null
+++ b/components/offline_pages/background/request_queue.h
@@ -0,0 +1,86 @@
+// 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 "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,
+ kActiveRequestQuotaHit, // Cannot add a request with this namespace, as
+ // it has reached a quota of active requests.
Pete Williamson 2016/04/28 23:16:07 Why do we need two quotas? Would one suffice? I s
fgorski 2016/04/29 05:19:15 Done.
+ kTotalRequestQuotaHit, // Cannot add a request with this namespace, as
+ // it has reached a quota of total requests.
+ };
+
+ enum class UpdateRequestResult {
+ kSuccess,
+ kStoreFailure,
+ kRequestDoesNotExist, // Failed to delete the request because it does not
+ // exist.
+ };
+
+ // Callback used for |GetRequests|.
Pete Williamson 2016/04/28 23:16:07 Why make these async? I'm not averse to async per
fgorski 2016/04/29 05:19:15 The capability to store and read it from a file.
+ 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.
Pete Williamson 2016/04/28 23:16:07 Why not have all the methods schedule a queue purg
fgorski 2016/04/29 05:19:15 Because other methods don't know if there is anyth
+ void GetRequests(const GetRequestsResult& 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_

Powered by Google App Engine
This is Rietveld 408576698