| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 // schedule purging of the request queue. | 71 // schedule purging of the request queue. |
| 72 void GetRequests(const GetRequestsCallback& callback); | 72 void GetRequests(const GetRequestsCallback& callback); |
| 73 | 73 |
| 74 // Adds |request| to the request queue. Result is returned through |callback|. | 74 // Adds |request| to the request queue. Result is returned through |callback|. |
| 75 // In case adding the request violates policy, the result will fail with | 75 // In case adding the request violates policy, the result will fail with |
| 76 // appropriate result. Callback will also return a copy of a request with all | 76 // appropriate result. Callback will also return a copy of a request with all |
| 77 // fields set. | 77 // fields set. |
| 78 void AddRequest(const SavePageRequest& request, | 78 void AddRequest(const SavePageRequest& request, |
| 79 const AddRequestCallback& callback); | 79 const AddRequestCallback& callback); |
| 80 | 80 |
| 81 // Updates a request in the request queue if a request with matching ID | |
| 82 // exists. Does nothing otherwise. Result is returned through |callback|. | |
| 83 void UpdateRequest(const SavePageRequest& request, | |
| 84 const UpdateRequestCallback& callback); | |
| 85 | |
| 86 // Removes the requests matching the |request_ids|. Result is returned through | 81 // Removes the requests matching the |request_ids|. Result is returned through |
| 87 // |callback|. If a request id cannot be removed, this will still remove the | 82 // |callback|. If a request id cannot be removed, this will still remove the |
| 88 // others. | 83 // others. |
| 89 void RemoveRequests(const std::vector<int64_t>& request_ids, | 84 void RemoveRequests(const std::vector<int64_t>& request_ids, |
| 90 const UpdateCallback& callback); | 85 const UpdateCallback& callback); |
| 91 | 86 |
| 92 // Changes the state to |new_state| for requests matching the | 87 // Changes the state to |new_state| for requests matching the |
| 93 // |request_ids|. Results are returned through |callback|. | 88 // |request_ids|. Results are returned through |callback|. |
| 94 void ChangeRequestsState(const std::vector<int64_t>& request_ids, | 89 void ChangeRequestsState(const std::vector<int64_t>& request_ids, |
| 95 const SavePageRequest::RequestState new_state, | 90 const SavePageRequest::RequestState new_state, |
| 96 const UpdateCallback& callback); | 91 const UpdateCallback& callback); |
| 97 | 92 |
| 98 // Marks attempt with |request_id| as started. Results are returned through | 93 // Marks attempt with |request_id| as started. Results are returned through |
| 99 // |callback|. | 94 // |callback|. |
| 100 void MarkAttemptStarted(int64_t request_id, const UpdateCallback& callback); | 95 void MarkAttemptStarted(int64_t request_id, const UpdateCallback& callback); |
| 101 | 96 |
| 102 // Marks attempt with |request_id| as aborted. Results are returned through | 97 // Marks attempt with |request_id| as aborted. Results are returned through |
| 103 // |callback|. | 98 // |callback|. |
| 104 void MarkAttemptAborted(int64_t request_id, const UpdateCallback& callback); | 99 void MarkAttemptAborted(int64_t request_id, const UpdateCallback& callback); |
| 105 | 100 |
| 106 void GetForUpdateDone( | 101 // Marks attempt with |request_id| as completed. The attempt may have |
| 107 const RequestQueue::UpdateRequestCallback& update_callback, | 102 // completed with either success or failure (not denoted here). Results |
| 108 const SavePageRequest& update_request, | 103 // are returned through |callback|. |
| 109 bool success, | 104 void MarkAttemptCompleted(int64_t request_id, const UpdateCallback& callback); |
| 110 std::vector<std::unique_ptr<SavePageRequest>> requests); | |
| 111 | 105 |
| 112 private: | 106 private: |
| 113 // Callback used by |PurgeRequests|. | 107 // Callback used by |PurgeRequests|. |
| 114 typedef base::Callback<void(UpdateRequestResult, | 108 typedef base::Callback<void(UpdateRequestResult, |
| 115 int /* removed requests count */)> | 109 int /* removed requests count */)> |
| 116 PurgeRequestsCallback; | 110 PurgeRequestsCallback; |
| 117 | 111 |
| 118 // Purges the queue, removing the requests that are no longer relevant, e.g. | 112 // Purges the queue, removing the requests that are no longer relevant, e.g. |
| 119 // expired request. Result is returned through |callback| carries the number | 113 // expired request. Result is returned through |callback| carries the number |
| 120 // of removed requests. | 114 // of removed requests. |
| 121 void PurgeRequests(const PurgeRequestsCallback& callback); | 115 void PurgeRequests(const PurgeRequestsCallback& callback); |
| 122 | 116 |
| 123 std::unique_ptr<RequestQueueStore> store_; | 117 std::unique_ptr<RequestQueueStore> store_; |
| 124 | 118 |
| 125 // Task queue to serialize store access. | 119 // Task queue to serialize store access. |
| 126 TaskQueue task_queue_; | 120 TaskQueue task_queue_; |
| 127 | 121 |
| 128 // Allows us to pass a weak pointer to callbacks. | 122 // Allows us to pass a weak pointer to callbacks. |
| 129 base::WeakPtrFactory<RequestQueue> weak_ptr_factory_; | 123 base::WeakPtrFactory<RequestQueue> weak_ptr_factory_; |
| 130 | 124 |
| 131 DISALLOW_COPY_AND_ASSIGN(RequestQueue); | 125 DISALLOW_COPY_AND_ASSIGN(RequestQueue); |
| 132 }; | 126 }; |
| 133 | 127 |
| 134 } // namespace offline_pages | 128 } // namespace offline_pages |
| 135 | 129 |
| 136 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ | 130 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ |
| OLD | NEW |