| 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 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 const SavePageRequest& request, | 56 const SavePageRequest& request, |
| 57 RequestNotifier::BackgroundSavePageResult status) = 0; | 57 RequestNotifier::BackgroundSavePageResult status) = 0; |
| 58 virtual void OnChanged(const SavePageRequest& request) = 0; | 58 virtual void OnChanged(const SavePageRequest& request) = 0; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 enum class RequestAvailability { | 61 enum class RequestAvailability { |
| 62 ENABLED_FOR_OFFLINER, | 62 ENABLED_FOR_OFFLINER, |
| 63 DISABLED_FOR_OFFLINER, | 63 DISABLED_FOR_OFFLINER, |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 // Callback to report when a request was available. | |
| 67 typedef base::Callback<void(const SavePageRequest& request)> | |
| 68 RequestPickedCallback; | |
| 69 | |
| 70 // Callback to report when no request was available. | |
| 71 typedef base::Callback<void(bool)> RequestNotPickedCallback; | |
| 72 | |
| 73 // Callback specifying which request IDs were actually removed. | 66 // Callback specifying which request IDs were actually removed. |
| 74 typedef base::Callback<void(const MultipleItemStatuses&)> | 67 typedef base::Callback<void(const MultipleItemStatuses&)> |
| 75 RemoveRequestsCallback; | 68 RemoveRequestsCallback; |
| 76 | 69 |
| 77 // Callback that receives the response for GetAllRequests. | 70 // Callback that receives the response for GetAllRequests. |
| 78 typedef base::Callback<void(std::vector<std::unique_ptr<SavePageRequest>>)> | 71 typedef base::Callback<void(std::vector<std::unique_ptr<SavePageRequest>>)> |
| 79 GetRequestsCallback; | 72 GetRequestsCallback; |
| 80 | 73 |
| 81 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, | 74 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, |
| 82 std::unique_ptr<OfflinerFactory> factory, | 75 std::unique_ptr<OfflinerFactory> factory, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 // Returns whether processing is starting (before it is decided to actually | 178 // Returns whether processing is starting (before it is decided to actually |
| 186 // process a request (is_busy()) at this time or not. | 179 // process a request (is_busy()) at this time or not. |
| 187 bool is_starting() { return is_starting_; } | 180 bool is_starting() { return is_starting_; } |
| 188 | 181 |
| 189 // Tracks whether the last offlining attempt got canceled. This is reset by | 182 // Tracks whether the last offlining attempt got canceled. This is reset by |
| 190 // the next StartProcessing() call. | 183 // the next StartProcessing() call. |
| 191 bool is_canceled() { | 184 bool is_canceled() { |
| 192 return processing_state_ == ProcessingWindowState::STOPPED; | 185 return processing_state_ == ProcessingWindowState::STOPPED; |
| 193 } | 186 } |
| 194 | 187 |
| 195 OfflineEventLogger* GetLogger() { | 188 RequestCoordinatorEventLogger* GetLogger() { return &event_logger_; } |
| 196 return &event_logger_; | |
| 197 } | |
| 198 | 189 |
| 199 private: | 190 private: |
| 200 // Immediate start attempt status code for UMA. | 191 // Immediate start attempt status code for UMA. |
| 201 // These values are written to logs. New enum values can be added, but | 192 // These values are written to logs. New enum values can be added, but |
| 202 // existing enums must never be renumbered or deleted and reused. | 193 // existing enums must never be renumbered or deleted and reused. |
| 203 // For any additions, also update corresponding histogram in histograms.xml. | 194 // For any additions, also update corresponding histogram in histograms.xml. |
| 204 enum OfflinerImmediateStartStatus { | 195 enum OfflinerImmediateStartStatus { |
| 205 // Did start processing request. | 196 // Did start processing request. |
| 206 STARTED = 0, | 197 STARTED = 0, |
| 207 // Already busy processing a request. | 198 // Already busy processing a request. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 222 enum class ProcessingWindowState { | 213 enum class ProcessingWindowState { |
| 223 STOPPED, | 214 STOPPED, |
| 224 SCHEDULED_WINDOW, | 215 SCHEDULED_WINDOW, |
| 225 IMMEDIATE_WINDOW, | 216 IMMEDIATE_WINDOW, |
| 226 }; | 217 }; |
| 227 | 218 |
| 228 // Receives the results of a get from the request queue, and turns that into | 219 // Receives the results of a get from the request queue, and turns that into |
| 229 // SavePageRequest objects for the caller of GetQueuedRequests. | 220 // SavePageRequest objects for the caller of GetQueuedRequests. |
| 230 void GetQueuedRequestsCallback( | 221 void GetQueuedRequestsCallback( |
| 231 const GetRequestsCallback& callback, | 222 const GetRequestsCallback& callback, |
| 232 RequestQueue::GetRequestsResult result, | 223 QueueResults::GetRequestsResult result, |
| 233 std::vector<std::unique_ptr<SavePageRequest>> requests); | 224 std::vector<std::unique_ptr<SavePageRequest>> requests); |
| 234 | 225 |
| 235 // Receives the results of a get from the request queue, and turns that into | 226 // Receives the results of a get from the request queue, and turns that into |
| 236 // SavePageRequest objects for the caller of GetQueuedRequests. | 227 // SavePageRequest objects for the caller of GetQueuedRequests. |
| 237 void GetRequestsForSchedulingCallback( | 228 void GetRequestsForSchedulingCallback( |
| 238 RequestQueue::GetRequestsResult result, | 229 QueueResults::GetRequestsResult result, |
| 239 std::vector<std::unique_ptr<SavePageRequest>> requests); | 230 std::vector<std::unique_ptr<SavePageRequest>> requests); |
| 240 | 231 |
| 241 // Receives the result of add requests to the request queue. | 232 // Receives the result of add requests to the request queue. |
| 242 void AddRequestResultCallback(RequestQueue::AddRequestResult result, | 233 void AddRequestResultCallback(QueueResults::AddRequestResult result, |
| 243 const SavePageRequest& request); | 234 const SavePageRequest& request); |
| 244 | 235 |
| 245 // Receives the result of mark attempt completed requests. | 236 // Receives the result of mark attempt completed requests. |
| 246 void MarkAttemptCompletedDoneCallback( | 237 void MarkAttemptCompletedDoneCallback( |
| 247 int64_t request_id, | 238 int64_t request_id, |
| 248 const ClientId& client_id, | 239 const ClientId& client_id, |
| 249 std::unique_ptr<UpdateRequestsResult> result); | 240 std::unique_ptr<QueueResults::UpdateRequestsResult> result); |
| 250 | 241 |
| 251 void UpdateMultipleRequestsCallback( | 242 void UpdateMultipleRequestsCallback( |
| 252 std::unique_ptr<UpdateRequestsResult> result); | 243 std::unique_ptr<QueueResults::UpdateRequestsResult> result); |
| 253 | 244 |
| 254 void CompletedRequestCallback(const MultipleItemStatuses& status); | 245 void CompletedRequestCallback(const MultipleItemStatuses& status); |
| 255 | 246 |
| 256 void HandleRemovedRequestsAndCallback( | 247 void HandleRemovedRequestsAndCallback( |
| 257 const RemoveRequestsCallback& callback, | 248 const RemoveRequestsCallback& callback, |
| 258 BackgroundSavePageResult status, | 249 RequestNotifier::BackgroundSavePageResult status, |
| 259 std::unique_ptr<UpdateRequestsResult> result); | 250 std::unique_ptr<QueueResults::UpdateRequestsResult> result); |
| 260 | 251 |
| 261 void HandleRemovedRequests(BackgroundSavePageResult status, | 252 void HandleRemovedRequests( |
| 262 std::unique_ptr<UpdateRequestsResult> result); | 253 RequestNotifier::BackgroundSavePageResult status, |
| 254 std::unique_ptr<QueueResults::UpdateRequestsResult> result); |
| 263 | 255 |
| 264 bool StartProcessingInternal(const ProcessingWindowState processing_state, | 256 bool StartProcessingInternal(const ProcessingWindowState processing_state, |
| 265 const DeviceConditions& device_conditions, | 257 const DeviceConditions& device_conditions, |
| 266 const base::Callback<void(bool)>& callback); | 258 const base::Callback<void(bool)>& callback); |
| 267 | 259 |
| 268 // Start processing now if connected (but with conservative assumption | 260 // Start processing now if connected (but with conservative assumption |
| 269 // as to other device conditions). | 261 // as to other device conditions). |
| 270 void StartImmediatelyIfConnected(); | 262 void StartImmediatelyIfConnected(); |
| 271 | 263 |
| 272 OfflinerImmediateStartStatus TryImmediateStart(); | 264 OfflinerImmediateStartStatus TryImmediateStart(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 286 void HandleWatchdogTimeout(); | 278 void HandleWatchdogTimeout(); |
| 287 | 279 |
| 288 // Cancels an in progress pre-rendering, and updates state appropriately. | 280 // Cancels an in progress pre-rendering, and updates state appropriately. |
| 289 void StopPrerendering(Offliner::RequestStatus stop_status); | 281 void StopPrerendering(Offliner::RequestStatus stop_status); |
| 290 | 282 |
| 291 // Marks attempt on the request and sends it to offliner in continuation. | 283 // Marks attempt on the request and sends it to offliner in continuation. |
| 292 void SendRequestToOffliner(const SavePageRequest& request); | 284 void SendRequestToOffliner(const SavePageRequest& request); |
| 293 | 285 |
| 294 // Continuation of |SendRequestToOffliner| after the request is marked as | 286 // Continuation of |SendRequestToOffliner| after the request is marked as |
| 295 // started. | 287 // started. |
| 296 void StartOffliner(int64_t request_id, | 288 void StartOffliner( |
| 297 const std::string& client_namespace, | 289 int64_t request_id, |
| 298 std::unique_ptr<UpdateRequestsResult> update_result); | 290 const std::string& client_namespace, |
| 291 std::unique_ptr<QueueResults::UpdateRequestsResult> update_result); |
| 299 | 292 |
| 300 // Called by the offliner when an offlining request is completed. (and by | 293 // Called by the offliner when an offlining request is completed. (and by |
| 301 // tests). | 294 // tests). |
| 302 void OfflinerDoneCallback(const SavePageRequest& request, | 295 void OfflinerDoneCallback(const SavePageRequest& request, |
| 303 Offliner::RequestStatus status); | 296 Offliner::RequestStatus status); |
| 304 | 297 |
| 305 void TryNextRequest(); | 298 void TryNextRequest(); |
| 306 | 299 |
| 307 // If there is an active request in the list, cancel that request. | 300 // If there is an active request in the list, cancel that request. |
| 308 bool CancelActiveRequestIfItMatches(const std::vector<int64_t>& request_ids); | 301 bool CancelActiveRequestIfItMatches(const std::vector<int64_t>& request_ids); |
| 309 | 302 |
| 310 // Records an aborted attempt for the request and update it in the queue | 303 // Records an aborted attempt for the request and update it in the queue |
| 311 // (possibly removing it). Returns the updated copy. | 304 // (possibly removing it). Returns the updated copy. |
| 312 void AbortRequestAttempt(SavePageRequest* request); | 305 void AbortRequestAttempt(SavePageRequest* request); |
| 313 | 306 |
| 314 // Remove the attempted request from the queue with status to pass through to | 307 // Remove the attempted request from the queue with status to pass through to |
| 315 // any observers and UMA histogram. | 308 // any observers and UMA histogram. |
| 316 void RemoveAttemptedRequest(const SavePageRequest& request, | 309 void RemoveAttemptedRequest(const SavePageRequest& request, |
| 317 BackgroundSavePageResult status); | 310 BackgroundSavePageResult status); |
| 318 | 311 |
| 319 // Completes aborting the request, reports an error if it fails. | 312 // Completes aborting the request, reports an error if it fails. |
| 320 void MarkAttemptAbortedDone(int64_t request_id, | 313 void MarkAttemptAbortedDone( |
| 321 const ClientId& client_id, | 314 int64_t request_id, |
| 322 std::unique_ptr<UpdateRequestsResult> result); | 315 const ClientId& client_id, |
| 316 std::unique_ptr<QueueResults::UpdateRequestsResult> result); |
| 323 | 317 |
| 324 // Returns the appropriate offliner to use, getting a new one from the factory | 318 // Returns the appropriate offliner to use, getting a new one from the factory |
| 325 // if needed. | 319 // if needed. |
| 326 void GetOffliner(); | 320 void GetOffliner(); |
| 327 | 321 |
| 328 // Method to wrap calls to getting the connection type so it can be | 322 // Method to wrap calls to getting the connection type so it can be |
| 329 // changed for tests. | 323 // changed for tests. |
| 330 net::NetworkChangeNotifier::ConnectionType GetConnectionType(); | 324 net::NetworkChangeNotifier::ConnectionType GetConnectionType(); |
| 331 | 325 |
| 332 void SetNetworkConditionsForTest( | 326 void SetNetworkConditionsForTest( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 std::unique_ptr<Scheduler> scheduler_; | 371 std::unique_ptr<Scheduler> scheduler_; |
| 378 // Controller of client policies. Owned. | 372 // Controller of client policies. Owned. |
| 379 std::unique_ptr<ClientPolicyController> policy_controller_; | 373 std::unique_ptr<ClientPolicyController> policy_controller_; |
| 380 // Unowned pointer to the Network Quality Estimator. | 374 // Unowned pointer to the Network Quality Estimator. |
| 381 net::NetworkQualityEstimator::NetworkQualityProvider* | 375 net::NetworkQualityEstimator::NetworkQualityProvider* |
| 382 network_quality_estimator_; | 376 network_quality_estimator_; |
| 383 // Holds copy of the active request, if any. | 377 // Holds copy of the active request, if any. |
| 384 std::unique_ptr<SavePageRequest> active_request_; | 378 std::unique_ptr<SavePageRequest> active_request_; |
| 385 // Status of the most recent offlining. | 379 // Status of the most recent offlining. |
| 386 Offliner::RequestStatus last_offlining_status_; | 380 Offliner::RequestStatus last_offlining_status_; |
| 387 // Class to choose which request to schedule next | |
| 388 std::unique_ptr<RequestPicker> picker_; | |
| 389 // A set of request_ids that we are holding off until the download manager is | 381 // A set of request_ids that we are holding off until the download manager is |
| 390 // done with them. | 382 // done with them. |
| 391 std::set<int64_t> disabled_requests_; | 383 std::set<int64_t> disabled_requests_; |
| 392 // Calling this returns to the scheduler across the JNI bridge. | 384 // Calling this returns to the scheduler across the JNI bridge. |
| 393 base::Callback<void(bool)> scheduler_callback_; | 385 base::Callback<void(bool)> scheduler_callback_; |
| 394 // Logger to record events. | 386 // Logger to record events. |
| 395 RequestCoordinatorEventLogger event_logger_; | 387 RequestCoordinatorEventLogger event_logger_; |
| 396 // Timer to watch for pre-render attempts running too long. | 388 // Timer to watch for pre-render attempts running too long. |
| 397 base::OneShotTimer watchdog_timer_; | 389 base::OneShotTimer watchdog_timer_; |
| 398 // Callback invoked when an immediate request is done (default empty). | 390 // Callback invoked when an immediate request is done (default empty). |
| 399 base::Callback<void(bool)> immediate_schedule_callback_; | 391 base::Callback<void(bool)> immediate_schedule_callback_; |
| 400 // Allows us to pass a weak pointer to callbacks. | 392 // Allows us to pass a weak pointer to callbacks. |
| 401 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; | 393 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; |
| 402 | 394 |
| 403 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); | 395 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); |
| 404 }; | 396 }; |
| 405 | 397 |
| 406 } // namespace offline_pages | 398 } // namespace offline_pages |
| 407 | 399 |
| 408 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ | 400 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
| OLD | NEW |