Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_H_ |
| 6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_H_ | 6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "components/offline_pages/background/request_queue.h" | 12 #include "components/offline_pages/background/request_queue.h" |
| 13 #include "components/offline_pages/background/save_page_request.h" | 13 #include "components/offline_pages/background/save_page_request.h" |
| 14 #include "components/offline_pages/offline_store_types.h" | 14 #include "components/offline_pages/offline_store_types.h" |
| 15 | 15 |
| 16 namespace offline_pages { | 16 namespace offline_pages { |
| 17 | 17 |
| 18 typedef StoreUpdateResult<SavePageRequest> UpdateRequestsResult; | |
| 19 | |
| 20 // Interface for classes storing save page requests. | 18 // Interface for classes storing save page requests. |
| 21 class RequestQueueStore { | 19 class RequestQueueStore { |
| 22 public: | 20 public: |
| 23 enum class UpdateStatus { | 21 enum class UpdateStatus { |
| 24 ADDED, // Request was added successfully. | 22 ADDED, // Request was added successfully. |
| 25 UPDATED, // Request was updated successfully. | 23 UPDATED, // Request was updated successfully. |
| 26 FAILED, // Add or update attempt failed. | 24 FAILED, // Add or update attempt failed. |
| 27 }; | 25 }; |
| 28 | 26 |
| 27 using UpdateCallback = RequestQueue::UpdateCallback; | |
| 28 | |
| 29 typedef base::Callback<void( | 29 typedef base::Callback<void( |
| 30 bool /* success */, | 30 bool /* success */, |
| 31 std::vector<std::unique_ptr<SavePageRequest>> /* requests */)> | 31 std::vector<std::unique_ptr<SavePageRequest>> /* requests */)> |
| 32 GetRequestsCallback; | 32 GetRequestsCallback; |
| 33 typedef base::Callback<void(ItemActionStatus)> AddCallback; | 33 typedef base::Callback<void(ItemActionStatus)> AddCallback; |
| 34 typedef base::Callback<void(std::unique_ptr<UpdateRequestsResult>)> | |
| 35 UpdateCallback; | |
| 36 typedef base::Callback<void( | |
| 37 const RequestQueue::UpdateMultipleRequestResults& /* statuses*/, | |
| 38 std::vector<std::unique_ptr<SavePageRequest>> /* requests */)> | |
| 39 UpdateMultipleRequestsCallback; | |
| 40 typedef base::Callback<void( | 34 typedef base::Callback<void( |
| 41 const RequestQueue::UpdateMultipleRequestResults& /* statuses */, | 35 const RequestQueue::UpdateMultipleRequestResults& /* statuses */, |
| 42 std::vector<std::unique_ptr<SavePageRequest>> /* requests */)> | 36 std::vector<std::unique_ptr<SavePageRequest>> /* requests */)> |
| 43 RemoveCallback; | 37 RemoveCallback; |
| 44 typedef base::Callback<void(bool /* success */)> ResetCallback; | 38 typedef base::Callback<void(bool /* success */)> ResetCallback; |
| 45 | 39 |
| 46 virtual ~RequestQueueStore(){}; | 40 virtual ~RequestQueueStore(){}; |
| 47 | 41 |
| 48 // Gets all of the requests from the store. | 42 // Gets all of the requests from the store. |
| 49 virtual void GetRequests(const GetRequestsCallback& callback) = 0; | 43 virtual void GetRequests(const GetRequestsCallback& callback) = 0; |
| 50 | 44 |
| 51 // Asynchronously adds request in store. Fails if request with the same | 45 // Asynchronously adds request in store. Fails if request with the same |
| 52 // offline ID already exists. | 46 // offline ID already exists. |
| 53 virtual void AddRequest(const SavePageRequest& offline_page, | 47 virtual void AddRequest(const SavePageRequest& offline_page, |
| 54 const AddCallback& callback) = 0; | 48 const AddCallback& callback) = 0; |
| 55 | 49 |
| 56 // Asynchronously updates requests in store. | 50 // Asynchronously updates requests in store. |
| 57 virtual void UpdateRequests(const std::vector<SavePageRequest>& requests, | 51 virtual void UpdateRequests(const std::vector<SavePageRequest>& requests, |
| 58 const UpdateCallback& callback) = 0; | 52 const RequestQueue::UpdateCallback& callback) = 0; |
|
dougarnett
2016/09/29 21:02:49
Is this redundant with the "using" you added on li
fgorski
2016/09/30 23:14:35
Done. Good catch. Thanks.
| |
| 59 | 53 |
| 60 // Asynchronously removes requests from the store using their IDs. | 54 // Asynchronously removes requests from the store using their IDs. |
| 61 // Result of the update, and a number of removed pages is passed in the | 55 // Result of the update, and a number of removed pages is passed in the |
| 62 // callback. | 56 // callback. |
| 63 // Result of remove should be false, when one of the provided items couldn't | 57 // Result of remove should be false, when one of the provided items couldn't |
| 64 // be deleted, e.g. because it was missing. | 58 // be deleted, e.g. because it was missing. |
| 65 virtual void RemoveRequests(const std::vector<int64_t>& request_ids, | 59 virtual void RemoveRequests(const std::vector<int64_t>& request_ids, |
| 66 const RemoveCallback& callback) = 0; | 60 const RemoveCallback& callback) = 0; |
| 67 | 61 |
| 68 // Asynchronously changes the state of requests from the store using their | |
| 69 // request id. | |
| 70 virtual void ChangeRequestsState( | |
| 71 const std::vector<int64_t>& request_ids, | |
| 72 const SavePageRequest::RequestState new_state, | |
| 73 const UpdateMultipleRequestsCallback& callback) = 0; | |
| 74 | |
| 75 // Resets the store. | 62 // Resets the store. |
| 76 virtual void Reset(const ResetCallback& callback) = 0; | 63 virtual void Reset(const ResetCallback& callback) = 0; |
| 77 }; | 64 }; |
| 78 | 65 |
| 79 } // namespace offline_pages | 66 } // namespace offline_pages |
| 80 | 67 |
| 81 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_H_ | 68 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_H_ |
| OLD | NEW |