| 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 const RemoveRequestsCallback& callback); | 82 const RemoveRequestsCallback& callback); |
| 83 | 83 |
| 84 // Pause a list of requests by |request_id|. This will change the state | 84 // Pause a list of requests by |request_id|. This will change the state |
| 85 // in the request queue so the request cannot be started. | 85 // in the request queue so the request cannot be started. |
| 86 // TODO(petewil): Add code to cancel an in-progress pre-render. | 86 // TODO(petewil): Add code to cancel an in-progress pre-render. |
| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 return is_stopped_; | 150 return is_stopped_; |
| 153 } | 151 } |
| 154 | 152 |
| 155 OfflineEventLogger* GetLogger() { | 153 OfflineEventLogger* GetLogger() { |
| 156 return &event_logger_; | 154 return &event_logger_; |
| 157 } | 155 } |
| 158 | 156 |
| 159 private: | 157 private: |
| 160 // Receives the results of a get from the request queue, and turns that into | 158 // Receives the results of a get from the request queue, and turns that into |
| 161 // SavePageRequest objects for the caller of GetQueuedRequests. | 159 // SavePageRequest objects for the caller of GetQueuedRequests. |
| 162 void GetQueuedRequestsCallback(const GetRequestsCallback& callback, | 160 void GetQueuedRequestsCallback( |
| 163 RequestQueue::GetRequestsResult result, | 161 const GetRequestsCallback& callback, |
| 164 const std::vector<SavePageRequest>& requests); | 162 RequestQueue::GetRequestsResult result, |
| 163 std::vector<std::unique_ptr<SavePageRequest>> requests); |
| 165 | 164 |
| 166 // Receives the result of add requests to the request queue. | 165 // Receives the result of add requests to the request queue. |
| 167 void AddRequestResultCallback(RequestQueue::AddRequestResult result, | 166 void AddRequestResultCallback(RequestQueue::AddRequestResult result, |
| 168 const SavePageRequest& request); | 167 const SavePageRequest& request); |
| 169 | 168 |
| 170 // Receives the result of update and delete requests to the request queue. | 169 // Receives the result of update and delete requests to the request queue. |
| 171 void UpdateRequestCallback(const ClientId& client_id, | 170 void UpdateRequestCallback(const ClientId& client_id, |
| 172 RequestQueue::UpdateRequestResult result); | 171 RequestQueue::UpdateRequestResult result); |
| 173 | 172 |
| 174 void UpdateMultipleRequestsCallback( | 173 void UpdateMultipleRequestsCallback( |
| 175 const RequestQueue::UpdateMultipleRequestResults& result, | 174 const RequestQueue::UpdateMultipleRequestResults& result, |
| 176 const std::vector<SavePageRequest>& requests); | 175 std::vector<std::unique_ptr<SavePageRequest>> requests); |
| 177 | 176 |
| 178 void HandleRemovedRequestsAndCallback( | 177 void HandleRemovedRequestsAndCallback( |
| 179 const RemoveRequestsCallback& callback, | 178 const RemoveRequestsCallback& callback, |
| 180 SavePageStatus status, | 179 SavePageStatus status, |
| 181 const RequestQueue::UpdateMultipleRequestResults& results, | 180 const RequestQueue::UpdateMultipleRequestResults& results, |
| 182 const std::vector<SavePageRequest>& requests); | 181 std::vector<std::unique_ptr<SavePageRequest>> requests); |
| 183 | 182 |
| 184 void HandleRemovedRequests( | 183 void HandleRemovedRequests( |
| 185 SavePageStatus status, | 184 SavePageStatus status, |
| 186 const RequestQueue::UpdateMultipleRequestResults& results, | 185 const RequestQueue::UpdateMultipleRequestResults& results, |
| 187 const std::vector<SavePageRequest>& requests); | 186 std::vector<std::unique_ptr<SavePageRequest>> requests); |
| 188 | 187 |
| 189 // Start processing now if connected (but with conservative assumption | 188 // Start processing now if connected (but with conservative assumption |
| 190 // as to other device conditions). | 189 // as to other device conditions). |
| 191 void StartProcessingIfConnected(); | 190 void StartProcessingIfConnected(); |
| 192 | 191 |
| 193 // Callback from the request picker when it has chosen our next request. | 192 // Callback from the request picker when it has chosen our next request. |
| 194 void RequestPicked(const SavePageRequest& request); | 193 void RequestPicked(const SavePageRequest& request); |
| 195 | 194 |
| 196 // Callback from the request picker when no more requests are in the queue. | 195 // Callback from the request picker when no more requests are in the queue. |
| 197 void RequestQueueEmpty(); | 196 void RequestQueueEmpty(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 base::TimeDelta offliner_timeout_; | 275 base::TimeDelta offliner_timeout_; |
| 277 // Allows us to pass a weak pointer to callbacks. | 276 // Allows us to pass a weak pointer to callbacks. |
| 278 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; | 277 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; |
| 279 | 278 |
| 280 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); | 279 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); |
| 281 }; | 280 }; |
| 282 | 281 |
| 283 } // namespace offline_pages | 282 } // namespace offline_pages |
| 284 | 283 |
| 285 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ | 284 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
| OLD | NEW |