| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 return is_stopped_; | 156 return is_stopped_; |
| 159 } | 157 } |
| 160 | 158 |
| 161 OfflineEventLogger* GetLogger() { | 159 OfflineEventLogger* GetLogger() { |
| 162 return &event_logger_; | 160 return &event_logger_; |
| 163 } | 161 } |
| 164 | 162 |
| 165 private: | 163 private: |
| 166 // Receives the results of a get from the request queue, and turns that into | 164 // Receives the results of a get from the request queue, and turns that into |
| 167 // SavePageRequest objects for the caller of GetQueuedRequests. | 165 // SavePageRequest objects for the caller of GetQueuedRequests. |
| 168 void GetQueuedRequestsCallback(const GetRequestsCallback& callback, | 166 void GetQueuedRequestsCallback( |
| 169 RequestQueue::GetRequestsResult result, | 167 const GetRequestsCallback& callback, |
| 170 const std::vector<SavePageRequest>& requests); | 168 RequestQueue::GetRequestsResult result, |
| 169 std::vector<std::unique_ptr<SavePageRequest>> requests); |
| 171 | 170 |
| 172 // Receives the results of a get from the request queue, and turns that into | 171 // Receives the results of a get from the request queue, and turns that into |
| 173 // SavePageRequest objects for the caller of GetQueuedRequests. | 172 // SavePageRequest objects for the caller of GetQueuedRequests. |
| 174 void GetRequestsForSchedulingCallback( | 173 void GetRequestsForSchedulingCallback( |
| 175 RequestQueue::GetRequestsResult result, | 174 RequestQueue::GetRequestsResult result, |
| 176 const std::vector<SavePageRequest>& requests); | 175 std::vector<std::unique_ptr<SavePageRequest>> requests); |
| 177 | 176 |
| 178 // Receives the result of add requests to the request queue. | 177 // Receives the result of add requests to the request queue. |
| 179 void AddRequestResultCallback(RequestQueue::AddRequestResult result, | 178 void AddRequestResultCallback(RequestQueue::AddRequestResult result, |
| 180 const SavePageRequest& request); | 179 const SavePageRequest& request); |
| 181 | 180 |
| 182 // Receives the result of update and delete requests to the request queue. | 181 // Receives the result of update and delete requests to the request queue. |
| 183 void UpdateRequestCallback(const ClientId& client_id, | 182 void UpdateRequestCallback(const ClientId& client_id, |
| 184 RequestQueue::UpdateRequestResult result); | 183 RequestQueue::UpdateRequestResult result); |
| 185 | 184 |
| 186 void UpdateMultipleRequestsCallback( | 185 void UpdateMultipleRequestsCallback( |
| 187 const RequestQueue::UpdateMultipleRequestResults& result, | 186 const RequestQueue::UpdateMultipleRequestResults& result, |
| 188 const std::vector<SavePageRequest>& requests); | 187 std::vector<std::unique_ptr<SavePageRequest>> requests); |
| 189 | 188 |
| 190 void HandleRemovedRequestsAndCallback( | 189 void HandleRemovedRequestsAndCallback( |
| 191 const RemoveRequestsCallback& callback, | 190 const RemoveRequestsCallback& callback, |
| 192 BackgroundSavePageResult status, | 191 BackgroundSavePageResult status, |
| 193 const RequestQueue::UpdateMultipleRequestResults& results, | 192 const RequestQueue::UpdateMultipleRequestResults& results, |
| 194 const std::vector<SavePageRequest>& requests); | 193 std::vector<std::unique_ptr<SavePageRequest>> requests); |
| 195 | 194 |
| 196 void HandleRemovedRequests( | 195 void HandleRemovedRequests( |
| 197 BackgroundSavePageResult status, | 196 BackgroundSavePageResult status, |
| 198 const RequestQueue::UpdateMultipleRequestResults& results, | 197 const RequestQueue::UpdateMultipleRequestResults& results, |
| 199 const std::vector<SavePageRequest>& requests); | 198 std::vector<std::unique_ptr<SavePageRequest>> requests); |
| 200 | 199 |
| 201 // Start processing now if connected (but with conservative assumption | 200 // Start processing now if connected (but with conservative assumption |
| 202 // as to other device conditions). | 201 // as to other device conditions). |
| 203 void StartProcessingIfConnected(); | 202 void StartProcessingIfConnected(); |
| 204 | 203 |
| 205 // Check the request queue, and schedule a task corresponding | 204 // Check the request queue, and schedule a task corresponding |
| 206 // to the least restrictive type of request in the queue. | 205 // to the least restrictive type of request in the queue. |
| 207 void ScheduleAsNeeded(); | 206 void ScheduleAsNeeded(); |
| 208 | 207 |
| 209 // Callback from the request picker when it has chosen our next request. | 208 // Callback from the request picker when it has chosen our next request. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 base::TimeDelta offliner_timeout_; | 302 base::TimeDelta offliner_timeout_; |
| 304 // Allows us to pass a weak pointer to callbacks. | 303 // Allows us to pass a weak pointer to callbacks. |
| 305 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; | 304 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; |
| 306 | 305 |
| 307 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); | 306 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); |
| 308 }; | 307 }; |
| 309 | 308 |
| 310 } // namespace offline_pages | 309 } // namespace offline_pages |
| 311 | 310 |
| 312 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ | 311 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
| OLD | NEW |