| 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 30 matching lines...) Expand all Loading... |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 // GENERATED_JAVA_ENUM_PACKAGE:org.chromium.components.offlinepages.background | 43 // GENERATED_JAVA_ENUM_PACKAGE:org.chromium.components.offlinepages.background |
| 44 enum class UpdateRequestResult { | 44 enum class UpdateRequestResult { |
| 45 SUCCESS, | 45 SUCCESS, |
| 46 STORE_FAILURE, | 46 STORE_FAILURE, |
| 47 REQUEST_DOES_NOT_EXIST, // Failed to delete the request because it does not | 47 REQUEST_DOES_NOT_EXIST, // Failed to delete the request because it does not |
| 48 // exist. | 48 // exist. |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 // Type for a pair of request_id and result. | |
| 52 typedef std::vector<std::pair<int64_t, UpdateRequestResult>> | |
| 53 UpdateMultipleRequestResults; | |
| 54 | |
| 55 // Callback used for |GetRequests|. | 51 // Callback used for |GetRequests|. |
| 56 typedef base::Callback<void(GetRequestsResult, | 52 typedef base::Callback<void(GetRequestsResult, |
| 57 std::vector<std::unique_ptr<SavePageRequest>>)> | 53 std::vector<std::unique_ptr<SavePageRequest>>)> |
| 58 GetRequestsCallback; | 54 GetRequestsCallback; |
| 59 | 55 |
| 60 // Callback used for |AddRequest|. | 56 // Callback used for |AddRequest|. |
| 61 typedef base::Callback<void(AddRequestResult, const SavePageRequest& request)> | 57 typedef base::Callback<void(AddRequestResult, const SavePageRequest& request)> |
| 62 AddRequestCallback; | 58 AddRequestCallback; |
| 63 | 59 |
| 64 // Callback used by |ChangeRequestsState|. | 60 // Callback used by |ChangeRequestsState|. |
| 65 typedef base::Callback<void(std::unique_ptr<UpdateRequestsResult>)> | 61 typedef base::Callback<void(std::unique_ptr<UpdateRequestsResult>)> |
| 66 UpdateCallback; | 62 UpdateCallback; |
| 67 | 63 |
| 68 // Callback used by |UdpateRequest|. | 64 // Callback used by |UdpateRequest|. |
| 69 typedef base::Callback<void(UpdateRequestResult)> UpdateRequestCallback; | 65 typedef base::Callback<void(UpdateRequestResult)> UpdateRequestCallback; |
| 70 | 66 |
| 71 // Callback used by |ChangeState| for more than one update at a time. | |
| 72 typedef base::Callback<void( | |
| 73 const UpdateMultipleRequestResults& results, | |
| 74 std::vector<std::unique_ptr<SavePageRequest>> requests)> | |
| 75 UpdateMultipleRequestsCallback; | |
| 76 | |
| 77 // Callback used by |RemoveRequests|. | |
| 78 typedef base::Callback<void( | |
| 79 const UpdateMultipleRequestResults& results, | |
| 80 std::vector<std::unique_ptr<SavePageRequest>> requests)> | |
| 81 RemoveRequestsCallback; | |
| 82 | |
| 83 explicit RequestQueue(std::unique_ptr<RequestQueueStore> store); | 67 explicit RequestQueue(std::unique_ptr<RequestQueueStore> store); |
| 84 ~RequestQueue(); | 68 ~RequestQueue(); |
| 85 | 69 |
| 86 // Gets all of the active requests from the store. Calling this method may | 70 // Gets all of the active requests from the store. Calling this method may |
| 87 // schedule purging of the request queue. | 71 // schedule purging of the request queue. |
| 88 void GetRequests(const GetRequestsCallback& callback); | 72 void GetRequests(const GetRequestsCallback& callback); |
| 89 | 73 |
| 90 // Adds |request| to the request queue. Result is returned through |callback|. | 74 // Adds |request| to the request queue. Result is returned through |callback|. |
| 91 // 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 |
| 92 // 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 |
| 93 // fields set. | 77 // fields set. |
| 94 void AddRequest(const SavePageRequest& request, | 78 void AddRequest(const SavePageRequest& request, |
| 95 const AddRequestCallback& callback); | 79 const AddRequestCallback& callback); |
| 96 | 80 |
| 97 // Updates a request in the request queue if a request with matching ID | 81 // Updates a request in the request queue if a request with matching ID |
| 98 // exists. Does nothing otherwise. Result is returned through |callback|. | 82 // exists. Does nothing otherwise. Result is returned through |callback|. |
| 99 void UpdateRequest(const SavePageRequest& request, | 83 void UpdateRequest(const SavePageRequest& request, |
| 100 const UpdateRequestCallback& callback); | 84 const UpdateRequestCallback& callback); |
| 101 | 85 |
| 102 // Removes the requests matching the |request_ids|. Result is returned through | 86 // Removes the requests matching the |request_ids|. Result is returned through |
| 103 // |callback|. If a request id cannot be removed, this will still remove the | 87 // |callback|. If a request id cannot be removed, this will still remove the |
| 104 // others. | 88 // others. |
| 105 void RemoveRequests(const std::vector<int64_t>& request_ids, | 89 void RemoveRequests(const std::vector<int64_t>& request_ids, |
| 106 const RemoveRequestsCallback& callback); | 90 const UpdateCallback& callback); |
| 107 | 91 |
| 108 // Changes the state to |new_state| for requests matching the | 92 // Changes the state to |new_state| for requests matching the |
| 109 // |request_ids|. Results are returned through |callback|. | 93 // |request_ids|. Results are returned through |callback|. |
| 110 void ChangeRequestsState(const std::vector<int64_t>& request_ids, | 94 void ChangeRequestsState(const std::vector<int64_t>& request_ids, |
| 111 const SavePageRequest::RequestState new_state, | 95 const SavePageRequest::RequestState new_state, |
| 112 const UpdateCallback& callback); | 96 const UpdateCallback& callback); |
| 113 | 97 |
| 114 void GetForUpdateDone( | 98 void GetForUpdateDone( |
| 115 const RequestQueue::UpdateRequestCallback& update_callback, | 99 const RequestQueue::UpdateRequestCallback& update_callback, |
| 116 const SavePageRequest& update_request, | 100 const SavePageRequest& update_request, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 135 | 119 |
| 136 // Allows us to pass a weak pointer to callbacks. | 120 // Allows us to pass a weak pointer to callbacks. |
| 137 base::WeakPtrFactory<RequestQueue> weak_ptr_factory_; | 121 base::WeakPtrFactory<RequestQueue> weak_ptr_factory_; |
| 138 | 122 |
| 139 DISALLOW_COPY_AND_ASSIGN(RequestQueue); | 123 DISALLOW_COPY_AND_ASSIGN(RequestQueue); |
| 140 }; | 124 }; |
| 141 | 125 |
| 142 } // namespace offline_pages | 126 } // namespace offline_pages |
| 143 | 127 |
| 144 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ | 128 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ |
| OLD | NEW |