Chromium Code Reviews| 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..22dd1779192cd979ef6b4e2165450489f0b50dd9 |
| --- /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 { |
| + |
| +struct 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 |
|
dougarnett
2016/04/29 15:39:14
I see the QuotaHit result defined above - could yo
fgorski
2016/04/30 18:56:14
I think we should document that only once we have
|
| + // 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|. |
|
dougarnett
2016/04/29 15:39:14
Is this a simple overwrite?
fgorski
2016/04/30 18:56:14
Yes.
|
| + 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_ |