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_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ |
6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ | 6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 const std::vector<SavePageRequest>&)> | 52 const std::vector<SavePageRequest>&)> |
53 GetRequestsCallback; | 53 GetRequestsCallback; |
54 | 54 |
55 // Callback used for |AddRequest|. | 55 // Callback used for |AddRequest|. |
56 typedef base::Callback<void(AddRequestResult, const SavePageRequest& request)> | 56 typedef base::Callback<void(AddRequestResult, const SavePageRequest& request)> |
57 AddRequestCallback; | 57 AddRequestCallback; |
58 | 58 |
59 // Callback used by |UdpateRequest|. | 59 // Callback used by |UdpateRequest|. |
60 typedef base::Callback<void(UpdateRequestResult)> UpdateRequestCallback; | 60 typedef base::Callback<void(UpdateRequestResult)> UpdateRequestCallback; |
61 | 61 |
| 62 // Callback used by |ChangeState| for more than one update at a time. |
| 63 typedef base::Callback<void(const UpdateMultipleRequestResults& results, |
| 64 const std::vector<SavePageRequest>& requests)> |
| 65 UpdateMultipleRequestsCallback; |
| 66 |
62 // Callback used by |RemoveRequests|. | 67 // Callback used by |RemoveRequests|. |
63 typedef base::Callback<void(const UpdateMultipleRequestResults& results)> | 68 typedef base::Callback<void(const UpdateMultipleRequestResults& results, |
| 69 const std::vector<SavePageRequest>& requests)> |
64 RemoveRequestsCallback; | 70 RemoveRequestsCallback; |
65 | 71 |
66 explicit RequestQueue(std::unique_ptr<RequestQueueStore> store); | 72 explicit RequestQueue(std::unique_ptr<RequestQueueStore> store); |
67 ~RequestQueue(); | 73 ~RequestQueue(); |
68 | 74 |
69 // Gets all of the active requests from the store. Calling this method may | 75 // Gets all of the active requests from the store. Calling this method may |
70 // schedule purging of the request queue. | 76 // schedule purging of the request queue. |
71 void GetRequests(const GetRequestsCallback& callback); | 77 void GetRequests(const GetRequestsCallback& callback); |
72 | 78 |
73 // Adds |request| to the request queue. Result is returned through |callback|. | 79 // Adds |request| to the request queue. Result is returned through |callback|. |
(...skipping 14 matching lines...) Expand all Loading... |
88 void RemoveRequests(const std::vector<int64_t>& request_ids, | 94 void RemoveRequests(const std::vector<int64_t>& request_ids, |
89 const RemoveRequestsCallback& callback); | 95 const RemoveRequestsCallback& callback); |
90 | 96 |
91 // Changes the state to |new_state_ for requests matching the | 97 // Changes the state to |new_state_ for requests matching the |
92 // |request_ids|. Results are returned through |callback|. | 98 // |request_ids|. Results are returned through |callback|. |
93 // TODO(petewil): Instead of having one function per property, | 99 // TODO(petewil): Instead of having one function per property, |
94 // modify this to have a single update function that updates an entire | 100 // modify this to have a single update function that updates an entire |
95 // request, and doesn't need to care what updates. | 101 // request, and doesn't need to care what updates. |
96 void ChangeRequestsState(const std::vector<int64_t>& request_ids, | 102 void ChangeRequestsState(const std::vector<int64_t>& request_ids, |
97 const SavePageRequest::RequestState new_state, | 103 const SavePageRequest::RequestState new_state, |
98 const UpdateRequestCallback& callback); | 104 const UpdateMultipleRequestsCallback& callback); |
99 | 105 |
100 void GetForUpdateDone( | 106 void GetForUpdateDone( |
101 const RequestQueue::UpdateRequestCallback& update_callback, | 107 const RequestQueue::UpdateRequestCallback& update_callback, |
102 const SavePageRequest& update_request, | 108 const SavePageRequest& update_request, |
103 bool success, | 109 bool success, |
104 const std::vector<SavePageRequest>& requests); | 110 const std::vector<SavePageRequest>& requests); |
105 | 111 |
106 private: | 112 private: |
107 // Callback used by |PurgeRequests|. | 113 // Callback used by |PurgeRequests|. |
108 typedef base::Callback<void(UpdateRequestResult, | 114 typedef base::Callback<void(UpdateRequestResult, |
109 int /* removed requests count */)> | 115 int /* removed requests count */)> |
110 PurgeRequestsCallback; | 116 PurgeRequestsCallback; |
111 | 117 |
112 // Purges the queue, removing the requests that are no longer relevant, e.g. | 118 // Purges the queue, removing the requests that are no longer relevant, e.g. |
113 // expired request. Result is returned through |callback| carries the number | 119 // expired request. Result is returned through |callback| carries the number |
114 // of removed requests. | 120 // of removed requests. |
115 void PurgeRequests(const PurgeRequestsCallback& callback); | 121 void PurgeRequests(const PurgeRequestsCallback& callback); |
116 | 122 |
117 std::unique_ptr<RequestQueueStore> store_; | 123 std::unique_ptr<RequestQueueStore> store_; |
118 | 124 |
119 // Allows us to pass a weak pointer to callbacks. | 125 // Allows us to pass a weak pointer to callbacks. |
120 base::WeakPtrFactory<RequestQueue> weak_ptr_factory_; | 126 base::WeakPtrFactory<RequestQueue> weak_ptr_factory_; |
121 | 127 |
122 DISALLOW_COPY_AND_ASSIGN(RequestQueue); | 128 DISALLOW_COPY_AND_ASSIGN(RequestQueue); |
123 }; | 129 }; |
124 | 130 |
125 } // namespace offline_pages | 131 } // namespace offline_pages |
126 | 132 |
127 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ | 133 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ |
OLD | NEW |