| 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_COORDINATOR_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
| 6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ | 6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 void RemoveRequests(const std::vector<int64_t>& request_ids, | 82 void RemoveRequests(const std::vector<int64_t>& request_ids, |
| 83 const RemoveRequestsCallback& callback); | 83 const RemoveRequestsCallback& callback); |
| 84 | 84 |
| 85 // Pause a list of requests by |request_id|. This will change the state | 85 // Pause a list of requests by |request_id|. This will change the state |
| 86 // in the request queue so the request cannot be started. | 86 // in the request queue so the request cannot be started. |
| 87 void PauseRequests(const std::vector<int64_t>& request_ids); | 87 void PauseRequests(const std::vector<int64_t>& request_ids); |
| 88 | 88 |
| 89 // Resume a list of previously paused requests, making them available. | 89 // Resume a list of previously paused requests, making them available. |
| 90 void ResumeRequests(const std::vector<int64_t>& request_ids); | 90 void ResumeRequests(const std::vector<int64_t>& request_ids); |
| 91 | 91 |
| 92 // Callback that receives the response for GetAllRequests. Client must | 92 // Callback that receives the response for GetAllRequests. |
| 93 // copy the result right away, it goes out of scope at the end of the | 93 typedef base::Callback<void(std::vector<std::unique_ptr<SavePageRequest>>)> |
| 94 // callback. | |
| 95 typedef base::Callback<void(const std::vector<SavePageRequest>&)> | |
| 96 GetRequestsCallback; | 94 GetRequestsCallback; |
| 97 | 95 |
| 98 // Get all save page request items in the callback. | 96 // Get all save page request items in the callback. |
| 99 void GetAllRequests(const GetRequestsCallback& callback); | 97 void GetAllRequests(const GetRequestsCallback& callback); |
| 100 | 98 |
| 101 // Starts processing of one or more queued save page later requests. | 99 // Starts processing of one or more queued save page later requests. |
| 102 // Returns whether processing was started and that caller should expect | 100 // Returns whether processing was started and that caller should expect |
| 103 // a callback. If processing was already active, returns false. | 101 // a callback. If processing was already active, returns false. |
| 104 bool StartProcessing(const DeviceConditions& device_conditions, | 102 bool StartProcessing(const DeviceConditions& device_conditions, |
| 105 const base::Callback<void(bool)>& callback); | 103 const base::Callback<void(bool)>& callback); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 return is_stopped_; | 158 return is_stopped_; |
| 161 } | 159 } |
| 162 | 160 |
| 163 OfflineEventLogger* GetLogger() { | 161 OfflineEventLogger* GetLogger() { |
| 164 return &event_logger_; | 162 return &event_logger_; |
| 165 } | 163 } |
| 166 | 164 |
| 167 private: | 165 private: |
| 168 // Receives the results of a get from the request queue, and turns that into | 166 // Receives the results of a get from the request queue, and turns that into |
| 169 // SavePageRequest objects for the caller of GetQueuedRequests. | 167 // SavePageRequest objects for the caller of GetQueuedRequests. |
| 170 void GetQueuedRequestsCallback(const GetRequestsCallback& callback, | 168 void GetQueuedRequestsCallback( |
| 171 RequestQueue::GetRequestsResult result, | 169 const GetRequestsCallback& callback, |
| 172 const std::vector<SavePageRequest>& requests); | 170 RequestQueue::GetRequestsResult result, |
| 171 std::vector<std::unique_ptr<SavePageRequest>> requests); |
| 173 | 172 |
| 174 // Receives the results of a get from the request queue, and turns that into | 173 // Receives the results of a get from the request queue, and turns that into |
| 175 // SavePageRequest objects for the caller of GetQueuedRequests. | 174 // SavePageRequest objects for the caller of GetQueuedRequests. |
| 176 void GetRequestsForSchedulingCallback( | 175 void GetRequestsForSchedulingCallback( |
| 177 RequestQueue::GetRequestsResult result, | 176 RequestQueue::GetRequestsResult result, |
| 178 const std::vector<SavePageRequest>& requests); | 177 std::vector<std::unique_ptr<SavePageRequest>> requests); |
| 179 | 178 |
| 180 // Receives the result of add requests to the request queue. | 179 // Receives the result of add requests to the request queue. |
| 181 void AddRequestResultCallback(RequestQueue::AddRequestResult result, | 180 void AddRequestResultCallback(RequestQueue::AddRequestResult result, |
| 182 const SavePageRequest& request); | 181 const SavePageRequest& request); |
| 183 | 182 |
| 184 // Receives the result of update and delete requests to the request queue. | 183 // Receives the result of update and delete requests to the request queue. |
| 185 void UpdateRequestCallback(const ClientId& client_id, | 184 void UpdateRequestCallback(const ClientId& client_id, |
| 186 RequestQueue::UpdateRequestResult result); | 185 RequestQueue::UpdateRequestResult result); |
| 187 | 186 |
| 188 void UpdateMultipleRequestsCallback( | 187 void UpdateMultipleRequestsCallback( |
| 189 const RequestQueue::UpdateMultipleRequestResults& result, | 188 const RequestQueue::UpdateMultipleRequestResults& result, |
| 190 const std::vector<SavePageRequest>& requests); | 189 std::vector<std::unique_ptr<SavePageRequest>> requests); |
| 191 | 190 |
| 192 void HandleRemovedRequestsAndCallback( | 191 void HandleRemovedRequestsAndCallback( |
| 193 const RemoveRequestsCallback& callback, | 192 const RemoveRequestsCallback& callback, |
| 194 BackgroundSavePageResult status, | 193 BackgroundSavePageResult status, |
| 195 const RequestQueue::UpdateMultipleRequestResults& results, | 194 const RequestQueue::UpdateMultipleRequestResults& results, |
| 196 const std::vector<SavePageRequest>& requests); | 195 std::vector<std::unique_ptr<SavePageRequest>> requests); |
| 197 | 196 |
| 198 void HandleRemovedRequests( | 197 void HandleRemovedRequests( |
| 199 BackgroundSavePageResult status, | 198 BackgroundSavePageResult status, |
| 200 const RequestQueue::UpdateMultipleRequestResults& results, | 199 const RequestQueue::UpdateMultipleRequestResults& results, |
| 201 const std::vector<SavePageRequest>& requests); | 200 std::vector<std::unique_ptr<SavePageRequest>> requests); |
| 202 | 201 |
| 203 // Start processing now if connected (but with conservative assumption | 202 // Start processing now if connected (but with conservative assumption |
| 204 // as to other device conditions). | 203 // as to other device conditions). |
| 205 void StartProcessingIfConnected(); | 204 void StartProcessingIfConnected(); |
| 206 | 205 |
| 207 // Check the request queue, and schedule a task corresponding | 206 // Check the request queue, and schedule a task corresponding |
| 208 // to the least restrictive type of request in the queue. | 207 // to the least restrictive type of request in the queue. |
| 209 void ScheduleAsNeeded(); | 208 void ScheduleAsNeeded(); |
| 210 | 209 |
| 211 // Callback from the request picker when it has chosen our next request. | 210 // Callback from the request picker when it has chosen our next request. |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 base::TimeDelta offliner_timeout_; | 307 base::TimeDelta offliner_timeout_; |
| 309 // Allows us to pass a weak pointer to callbacks. | 308 // Allows us to pass a weak pointer to callbacks. |
| 310 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; | 309 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; |
| 311 | 310 |
| 312 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); | 311 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); |
| 313 }; | 312 }; |
| 314 | 313 |
| 315 } // namespace offline_pages | 314 } // namespace offline_pages |
| 316 | 315 |
| 317 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ | 316 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
| OLD | NEW |