| 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_CORE_BACKGROUND_REQUEST_COORDINATOR_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_REQUEST_COORDINATOR_H_ |
| 6 #define COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_REQUEST_COORDINATOR_H_ | 6 #define COMPONENTS_OFFLINE_PAGES_CORE_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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 virtual void OnChanged(const SavePageRequest& request) = 0; | 55 virtual void OnChanged(const SavePageRequest& request) = 0; |
| 56 virtual void OnNetworkProgress(const SavePageRequest& request, | 56 virtual void OnNetworkProgress(const SavePageRequest& request, |
| 57 int64_t received_bytes) = 0; | 57 int64_t received_bytes) = 0; |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 enum class RequestAvailability { | 60 enum class RequestAvailability { |
| 61 ENABLED_FOR_OFFLINER, | 61 ENABLED_FOR_OFFLINER, |
| 62 DISABLED_FOR_OFFLINER, | 62 DISABLED_FOR_OFFLINER, |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 enum class RequestCoordinatorState { |
| 66 IDLE, |
| 67 PICKING, |
| 68 OFFLINING, |
| 69 }; |
| 70 |
| 65 // Describes the parameters to control how to save a page when system | 71 // Describes the parameters to control how to save a page when system |
| 66 // conditions allow. | 72 // conditions allow. |
| 67 struct SavePageLaterParams { | 73 struct SavePageLaterParams { |
| 68 SavePageLaterParams(); | 74 SavePageLaterParams(); |
| 69 SavePageLaterParams(const SavePageLaterParams& other); | 75 SavePageLaterParams(const SavePageLaterParams& other); |
| 70 | 76 |
| 71 // The last committed URL of the page to save. | 77 // The last committed URL of the page to save. |
| 72 GURL url; | 78 GURL url; |
| 73 | 79 |
| 74 // The identification used by the client. | 80 // The identification used by the client. |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 203 |
| 198 OfflinerPolicy* policy() { return policy_.get(); } | 204 OfflinerPolicy* policy() { return policy_.get(); } |
| 199 | 205 |
| 200 ClientPolicyController* GetPolicyController(); | 206 ClientPolicyController* GetPolicyController(); |
| 201 | 207 |
| 202 // Returns the status of the most recent offlining. | 208 // Returns the status of the most recent offlining. |
| 203 Offliner::RequestStatus last_offlining_status() { | 209 Offliner::RequestStatus last_offlining_status() { |
| 204 return last_offlining_status_; | 210 return last_offlining_status_; |
| 205 } | 211 } |
| 206 | 212 |
| 207 bool is_busy() { return is_busy_; } | 213 // Return the state of the request coordinator. |
| 208 | 214 RequestCoordinatorState state() { return state_; } |
| 209 // Returns whether processing is starting (before it is decided to actually | |
| 210 // process a request (is_busy()) at this time or not. | |
| 211 bool is_starting() { return is_starting_; } | |
| 212 | 215 |
| 213 // Tracks whether the last offlining attempt got canceled. This is reset by | 216 // Tracks whether the last offlining attempt got canceled. This is reset by |
| 214 // the next call to start processing. | 217 // the next call to start processing. |
| 215 bool is_canceled() { | 218 bool is_canceled() { |
| 216 return processing_state_ == ProcessingWindowState::STOPPED; | 219 return processing_state_ == ProcessingWindowState::STOPPED; |
| 217 } | 220 } |
| 218 | 221 |
| 219 RequestCoordinatorEventLogger* GetLogger() { return &event_logger_; } | 222 RequestCoordinatorEventLogger* GetLogger() { return &event_logger_; } |
| 220 | 223 |
| 221 private: | 224 private: |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 size_t total_requests, | 333 size_t total_requests, |
| 331 size_t available_requests); | 334 size_t available_requests); |
| 332 | 335 |
| 333 void HandleWatchdogTimeout(); | 336 void HandleWatchdogTimeout(); |
| 334 | 337 |
| 335 // Cancels an in progress pre-rendering, and updates state appropriately. | 338 // Cancels an in progress pre-rendering, and updates state appropriately. |
| 336 void StopPrerendering(const Offliner::CancelCallback& callback, | 339 void StopPrerendering(const Offliner::CancelCallback& callback, |
| 337 Offliner::RequestStatus stop_status); | 340 Offliner::RequestStatus stop_status); |
| 338 | 341 |
| 339 // Marks attempt on the request and sends it to offliner in continuation. | 342 // Marks attempt on the request and sends it to offliner in continuation. |
| 340 void SendRequestToOffliner(const SavePageRequest& request); | 343 // If it fails to send request to offliner, return false. |
| 344 bool SendRequestToOffliner(const SavePageRequest& request); |
| 341 | 345 |
| 342 // Continuation of |SendRequestToOffliner| after the request is marked as | 346 // Continuation of |SendRequestToOffliner| after the request is marked as |
| 343 // started. | 347 // started. |
| 344 void StartOffliner(int64_t request_id, | 348 void StartOffliner(int64_t request_id, |
| 345 const std::string& client_namespace, | 349 const std::string& client_namespace, |
| 346 std::unique_ptr<UpdateRequestsResult> update_result); | 350 std::unique_ptr<UpdateRequestsResult> update_result); |
| 347 | 351 |
| 348 // Called by the offliner when an offlining request is completed. (and by | 352 // Called by the offliner when an offlining request is completed. (and by |
| 349 // tests). | 353 // tests). |
| 350 void OfflinerDoneCallback(const SavePageRequest& request, | 354 void OfflinerDoneCallback(const SavePageRequest& request, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 } | 403 } |
| 400 | 404 |
| 401 // KeyedService implementation: | 405 // KeyedService implementation: |
| 402 void Shutdown() override; | 406 void Shutdown() override; |
| 403 | 407 |
| 404 friend class RequestCoordinatorTest; | 408 friend class RequestCoordinatorTest; |
| 405 | 409 |
| 406 // Cached value of whether low end device. Overwritable for testing. | 410 // Cached value of whether low end device. Overwritable for testing. |
| 407 bool is_low_end_device_; | 411 bool is_low_end_device_; |
| 408 | 412 |
| 409 // The offliner can only handle one request at a time - if the offliner is | 413 // Current state of the request coordinator. |
| 410 // busy, prevent other requests. This flag marks whether the offliner is in | 414 RequestCoordinatorState state_; |
| 411 // use. | |
| 412 bool is_busy_; | |
| 413 // There is more than one path to start processing so this flag is used | |
| 414 // to avoid race conditions before is_busy_ is established. | |
| 415 bool is_starting_; | |
| 416 // Identifies the type of current processing window or if processing stopped. | 415 // Identifies the type of current processing window or if processing stopped. |
| 417 ProcessingWindowState processing_state_; | 416 ProcessingWindowState processing_state_; |
| 418 // True if we should use the test device conditions instead of actual | 417 // True if we should use the test device conditions instead of actual |
| 419 // conditions. | 418 // conditions. |
| 420 bool use_test_device_conditions_; | 419 bool use_test_device_conditions_; |
| 421 // For use by tests, a fake network connection type | 420 // For use by tests, a fake network connection type |
| 422 net::NetworkChangeNotifier::ConnectionType test_connection_type_; | 421 net::NetworkChangeNotifier::ConnectionType test_connection_type_; |
| 423 // Owned pointer to the current offliner. | 422 // Owned pointer to the current offliner. |
| 424 std::unique_ptr<Offliner> offliner_; | 423 std::unique_ptr<Offliner> offliner_; |
| 425 base::Time operation_start_time_; | 424 base::Time operation_start_time_; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 std::deque<int64_t> prioritized_requests_; | 471 std::deque<int64_t> prioritized_requests_; |
| 473 // Allows us to pass a weak pointer to callbacks. | 472 // Allows us to pass a weak pointer to callbacks. |
| 474 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; | 473 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; |
| 475 | 474 |
| 476 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); | 475 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); |
| 477 }; | 476 }; |
| 478 | 477 |
| 479 } // namespace offline_pages | 478 } // namespace offline_pages |
| 480 | 479 |
| 481 #endif // COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_REQUEST_COORDINATOR_H_ | 480 #endif // COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_REQUEST_COORDINATOR_H_ |
| OLD | NEW |