| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 // Callback used for |GetRequests|. | 46 // Callback used for |GetRequests|. |
| 47 typedef base::Callback<void(GetRequestsResult, | 47 typedef base::Callback<void(GetRequestsResult, |
| 48 const std::vector<SavePageRequest>&)> | 48 const std::vector<SavePageRequest>&)> |
| 49 GetRequestsCallback; | 49 GetRequestsCallback; |
| 50 | 50 |
| 51 // Callback used for |AddRequest|. | 51 // Callback used for |AddRequest|. |
| 52 typedef base::Callback<void(AddRequestResult, const SavePageRequest& request)> | 52 typedef base::Callback<void(AddRequestResult, const SavePageRequest& request)> |
| 53 AddRequestCallback; | 53 AddRequestCallback; |
| 54 | 54 |
| 55 // Callback used by |UdpateRequest| and |RemoveRequest|. | 55 // Callback used by |UdpateRequest|. |
| 56 typedef base::Callback<void(UpdateRequestResult)> UpdateRequestCallback; | 56 typedef base::Callback<void(UpdateRequestResult)> UpdateRequestCallback; |
| 57 | 57 |
| 58 // Callback used by |RemoveRequests|. |
| 59 typedef base::Callback<void( |
| 60 const std::vector<std::pair<int64_t, UpdateRequestResult>>& results)> |
| 61 RemoveRequestsCallback; |
| 62 |
| 58 explicit RequestQueue(std::unique_ptr<RequestQueueStore> store); | 63 explicit RequestQueue(std::unique_ptr<RequestQueueStore> store); |
| 59 ~RequestQueue(); | 64 ~RequestQueue(); |
| 60 | 65 |
| 61 // Gets all of the active requests from the store. Calling this method may | 66 // Gets all of the active requests from the store. Calling this method may |
| 62 // schedule purging of the request queue. | 67 // schedule purging of the request queue. |
| 63 void GetRequests(const GetRequestsCallback& callback); | 68 void GetRequests(const GetRequestsCallback& callback); |
| 64 | 69 |
| 65 // Adds |request| to the request queue. Result is returned through |callback|. | 70 // Adds |request| to the request queue. Result is returned through |callback|. |
| 66 // In case adding the request violates policy, the result will fail with | 71 // In case adding the request violates policy, the result will fail with |
| 67 // appropriate result. Callback will also return a copy of a request with all | 72 // appropriate result. Callback will also return a copy of a request with all |
| 68 // fields set. | 73 // fields set. |
| 69 void AddRequest(const SavePageRequest& request, | 74 void AddRequest(const SavePageRequest& request, |
| 70 const AddRequestCallback& callback); | 75 const AddRequestCallback& callback); |
| 71 | 76 |
| 72 // Updates a request in the request queue if a request with matching ID | 77 // Updates a request in the request queue if a request with matching ID |
| 73 // exists. Does nothing otherwise. Result is returned through |callback|. | 78 // exists. Does nothing otherwise. Result is returned through |callback|. |
| 74 void UpdateRequest(const SavePageRequest& request, | 79 void UpdateRequest(const SavePageRequest& request, |
| 75 const UpdateRequestCallback& callback); | 80 const UpdateRequestCallback& callback); |
| 76 | 81 |
| 77 // Removes the request matching the |request_id|. Result is returned through | 82 // Removes the requests matching the |request_ids|. Result is returned through |
| 78 // |callback|. | 83 // |callback|. If a request id cannot be removed, this will still remove the |
| 79 void RemoveRequest(int64_t request_id, const UpdateRequestCallback& callback); | 84 // others. |
| 80 | 85 void RemoveRequests(const std::vector<int64_t>& request_ids, |
| 81 // Removes the requests matching the |client_ids|. Results are returned | 86 const RemoveRequestsCallback& callback); |
| 82 // through |callback|. | |
| 83 void RemoveRequestsByClientId(const std::vector<ClientId>& client_id, | |
| 84 const UpdateRequestCallback& callback); | |
| 85 | 87 |
| 86 void GetForUpdateDone( | 88 void GetForUpdateDone( |
| 87 const RequestQueue::UpdateRequestCallback& update_callback, | 89 const RequestQueue::UpdateRequestCallback& update_callback, |
| 88 const SavePageRequest& update_request, | 90 const SavePageRequest& update_request, |
| 89 bool success, | 91 bool success, |
| 90 const std::vector<SavePageRequest>& requests); | 92 const std::vector<SavePageRequest>& requests); |
| 91 | 93 |
| 92 private: | 94 private: |
| 93 // Callback used by |PurgeRequests|. | 95 // Callback used by |PurgeRequests|. |
| 94 typedef base::Callback<void(UpdateRequestResult, | 96 typedef base::Callback<void(UpdateRequestResult, |
| 95 int /* removed requests count */)> | 97 int /* removed requests count */)> |
| 96 PurgeRequestsCallback; | 98 PurgeRequestsCallback; |
| 97 | 99 |
| 98 // Purges the queue, removing the requests that are no longer relevant, e.g. | 100 // Purges the queue, removing the requests that are no longer relevant, e.g. |
| 99 // expired request. Result is returned through |callback| carries the number | 101 // expired request. Result is returned through |callback| carries the number |
| 100 // of removed requests. | 102 // of removed requests. |
| 101 void PurgeRequests(const PurgeRequestsCallback& callback); | 103 void PurgeRequests(const PurgeRequestsCallback& callback); |
| 102 | 104 |
| 103 std::unique_ptr<RequestQueueStore> store_; | 105 std::unique_ptr<RequestQueueStore> store_; |
| 104 | 106 |
| 105 // Allows us to pass a weak pointer to callbacks. | 107 // Allows us to pass a weak pointer to callbacks. |
| 106 base::WeakPtrFactory<RequestQueue> weak_ptr_factory_; | 108 base::WeakPtrFactory<RequestQueue> weak_ptr_factory_; |
| 107 | 109 |
| 108 DISALLOW_COPY_AND_ASSIGN(RequestQueue); | 110 DISALLOW_COPY_AND_ASSIGN(RequestQueue); |
| 109 }; | 111 }; |
| 110 | 112 |
| 111 } // namespace offline_pages | 113 } // namespace offline_pages |
| 112 | 114 |
| 113 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ | 115 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ |
| OLD | NEW |