| 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_page_item.h" | 14 #include "components/offline_pages/offline_page_types.h" |
| 15 | 15 |
| 16 namespace offline_pages { | 16 namespace offline_pages { |
| 17 | 17 |
| 18 // Interface for classes storing save page requests. | 18 // Interface for classes storing save page requests. |
| 19 class RequestQueueStore { | 19 class RequestQueueStore { |
| 20 public: | 20 public: |
| 21 enum class UpdateStatus { | 21 enum class UpdateStatus { |
| 22 ADDED, // Request was added successfully. | 22 ADDED, // Request was added successfully. |
| 23 UPDATED, // Request was updated successfully. | 23 UPDATED, // Request was updated successfully. |
| 24 FAILED, // Add or update attempt failed. | 24 FAILED, // Add or update attempt failed. |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 typedef base::Callback<void( | 27 typedef base::Callback<void( |
| 28 bool /* success */, | 28 bool /* success */, |
| 29 std::vector<std::unique_ptr<SavePageRequest>> /* requests */)> | 29 std::vector<std::unique_ptr<SavePageRequest>> /* requests */)> |
| 30 GetRequestsCallback; | 30 GetRequestsCallback; |
| 31 typedef base::Callback<void(ItemActionStatus)> AddCallback; |
| 31 typedef base::Callback<void(UpdateStatus)> UpdateCallback; | 32 typedef base::Callback<void(UpdateStatus)> UpdateCallback; |
| 32 typedef base::Callback<void( | 33 typedef base::Callback<void( |
| 33 const RequestQueue::UpdateMultipleRequestResults& /* statuses*/, | 34 const RequestQueue::UpdateMultipleRequestResults& /* statuses*/, |
| 34 std::vector<std::unique_ptr<SavePageRequest>> /* requests */)> | 35 std::vector<std::unique_ptr<SavePageRequest>> /* requests */)> |
| 35 UpdateMultipleRequestsCallback; | 36 UpdateMultipleRequestsCallback; |
| 36 typedef base::Callback<void( | 37 typedef base::Callback<void( |
| 37 const RequestQueue::UpdateMultipleRequestResults& /* statuses */, | 38 const RequestQueue::UpdateMultipleRequestResults& /* statuses */, |
| 38 std::vector<std::unique_ptr<SavePageRequest>> /* requests */)> | 39 std::vector<std::unique_ptr<SavePageRequest>> /* requests */)> |
| 39 RemoveCallback; | 40 RemoveCallback; |
| 40 typedef base::Callback<void(bool /* success */)> ResetCallback; | 41 typedef base::Callback<void(bool /* success */)> ResetCallback; |
| 41 | 42 |
| 42 virtual ~RequestQueueStore(){}; | 43 virtual ~RequestQueueStore(){}; |
| 43 | 44 |
| 44 // Gets all of the requests from the store. | 45 // Gets all of the requests from the store. |
| 45 virtual void GetRequests(const GetRequestsCallback& callback) = 0; | 46 virtual void GetRequests(const GetRequestsCallback& callback) = 0; |
| 46 | 47 |
| 48 // Asynchronously adds request in store. Fails if request with the same |
| 49 // offline ID already exists. |
| 50 virtual void AddRequest(const SavePageRequest& offline_page, |
| 51 const AddCallback& callback) = 0; |
| 52 |
| 47 // Asynchronously adds or updates request in store. | 53 // Asynchronously adds or updates request in store. |
| 48 // Result of the update is passed in the callback. | 54 // Result of the update is passed in the callback. |
| 49 virtual void AddOrUpdateRequest(const SavePageRequest& request, | 55 virtual void AddOrUpdateRequest(const SavePageRequest& request, |
| 50 const UpdateCallback& callback) = 0; | 56 const UpdateCallback& callback) = 0; |
| 51 | 57 |
| 52 // Asynchronously removes requests from the store using their IDs. | 58 // Asynchronously removes requests from the store using their IDs. |
| 53 // Result of the update, and a number of removed pages is passed in the | 59 // Result of the update, and a number of removed pages is passed in the |
| 54 // callback. | 60 // callback. |
| 55 // Result of remove should be false, when one of the provided items couldn't | 61 // Result of remove should be false, when one of the provided items couldn't |
| 56 // be deleted, e.g. because it was missing. | 62 // be deleted, e.g. because it was missing. |
| 57 virtual void RemoveRequests(const std::vector<int64_t>& request_ids, | 63 virtual void RemoveRequests(const std::vector<int64_t>& request_ids, |
| 58 const RemoveCallback& callback) = 0; | 64 const RemoveCallback& callback) = 0; |
| 59 | 65 |
| 60 // Asynchronously changes the state of requests from the store using their | 66 // Asynchronously changes the state of requests from the store using their |
| 61 // request id. | 67 // request id. |
| 62 virtual void ChangeRequestsState( | 68 virtual void ChangeRequestsState( |
| 63 const std::vector<int64_t>& request_ids, | 69 const std::vector<int64_t>& request_ids, |
| 64 const SavePageRequest::RequestState new_state, | 70 const SavePageRequest::RequestState new_state, |
| 65 const UpdateMultipleRequestsCallback& callback) = 0; | 71 const UpdateMultipleRequestsCallback& callback) = 0; |
| 66 | 72 |
| 67 // Resets the store. | 73 // Resets the store. |
| 68 virtual void Reset(const ResetCallback& callback) = 0; | 74 virtual void Reset(const ResetCallback& callback) = 0; |
| 69 }; | 75 }; |
| 70 | 76 |
| 71 } // namespace offline_pages | 77 } // namespace offline_pages |
| 72 | 78 |
| 73 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_H_ | 79 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_H_ |
| OLD | NEW |