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_item.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 // TODO(petewil): What if no items were updated? Maybe this should work more | |
27 // like DeleteCallback, passing pairs of request_id and status. | |
28 | 26 |
29 typedef base::Callback<void( | 27 typedef base::Callback<void( |
30 bool /* success */, | 28 bool /* success */, |
31 const std::vector<SavePageRequest>& /* requests */)> | 29 const std::vector<SavePageRequest>& /* requests */)> |
32 GetRequestsCallback; | 30 GetRequestsCallback; |
33 typedef base::Callback<void(UpdateStatus)> UpdateCallback; | 31 typedef base::Callback<void(UpdateStatus)> UpdateCallback; |
| 32 // TODO(petewil) - UpdateMultiple looks exactly like Remove, consider |
| 33 // merging them into a single callback. |
34 typedef base::Callback<void( | 34 typedef base::Callback<void( |
35 const RequestQueue::UpdateMultipleRequestResults&)> | 35 const RequestQueue::UpdateMultipleRequestResults& /* statuses*/, |
| 36 const std::vector<SavePageRequest>& /* requests */)> |
| 37 UpdateMultipleRequestsCallback; |
| 38 typedef base::Callback<void( |
| 39 const RequestQueue::UpdateMultipleRequestResults& /* statuses */, |
| 40 const std::vector<SavePageRequest>& /* requests */)> |
36 RemoveCallback; | 41 RemoveCallback; |
37 typedef base::Callback<void(bool /* success */)> ResetCallback; | 42 typedef base::Callback<void(bool /* success */)> ResetCallback; |
38 | 43 |
39 virtual ~RequestQueueStore(){}; | 44 virtual ~RequestQueueStore(){}; |
40 | 45 |
41 // Gets all of the requests from the store. | 46 // Gets all of the requests from the store. |
42 virtual void GetRequests(const GetRequestsCallback& callback) = 0; | 47 virtual void GetRequests(const GetRequestsCallback& callback) = 0; |
43 | 48 |
44 // Asynchronously adds or updates request in store. | 49 // Asynchronously adds or updates request in store. |
45 // Result of the update is passed in the callback. | 50 // Result of the update is passed in the callback. |
46 virtual void AddOrUpdateRequest(const SavePageRequest& request, | 51 virtual void AddOrUpdateRequest(const SavePageRequest& request, |
47 const UpdateCallback& callback) = 0; | 52 const UpdateCallback& callback) = 0; |
48 | 53 |
49 // Asynchronously removes requests from the store using their IDs. | 54 // Asynchronously removes requests from the store using their IDs. |
50 // 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 |
51 // callback. | 56 // callback. |
52 // 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 |
53 // be deleted, e.g. because it was missing. | 58 // be deleted, e.g. because it was missing. |
54 virtual void RemoveRequests(const std::vector<int64_t>& request_ids, | 59 virtual void RemoveRequests(const std::vector<int64_t>& request_ids, |
55 const RemoveCallback& callback) = 0; | 60 const RemoveCallback& callback) = 0; |
56 | 61 |
57 // Asynchronously changes the state of requests from the store using their | 62 // Asynchronously changes the state of requests from the store using their |
58 // request id. | 63 // request id. |
59 virtual void ChangeRequestsState( | 64 virtual void ChangeRequestsState( |
60 const std::vector<int64_t>& request_ids, | 65 const std::vector<int64_t>& request_ids, |
61 const SavePageRequest::RequestState new_state, | 66 const SavePageRequest::RequestState new_state, |
62 const UpdateCallback& callback) = 0; | 67 const UpdateMultipleRequestsCallback& callback) = 0; |
63 | 68 |
64 // Resets the store. | 69 // Resets the store. |
65 virtual void Reset(const ResetCallback& callback) = 0; | 70 virtual void Reset(const ResetCallback& callback) = 0; |
66 }; | 71 }; |
67 | 72 |
68 } // namespace offline_pages | 73 } // namespace offline_pages |
69 | 74 |
70 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_H_ | 75 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_H_ |
OLD | NEW |