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