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