| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 } | 402 } |
| 400 | 403 |
| 401 // KeyedService implementation: | 404 // KeyedService implementation: |
| 402 void Shutdown() override; | 405 void Shutdown() override; |
| 403 | 406 |
| 404 friend class RequestCoordinatorTest; | 407 friend class RequestCoordinatorTest; |
| 405 | 408 |
| 406 // Cached value of whether low end device. Overwritable for testing. | 409 // Cached value of whether low end device. Overwritable for testing. |
| 407 bool is_low_end_device_; | 410 bool is_low_end_device_; |
| 408 | 411 |
| 409 // The offliner can only handle one request at a time - if the offliner is | 412 // Current state of the request coordinator. |
| 410 // busy, prevent other requests. This flag marks whether the offliner is in | 413 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. | 414 // Identifies the type of current processing window or if processing stopped. |
| 417 ProcessingWindowState processing_state_; | 415 ProcessingWindowState processing_state_; |
| 418 // True if we should use the test device conditions instead of actual | 416 // True if we should use the test device conditions instead of actual |
| 419 // conditions. | 417 // conditions. |
| 420 bool use_test_device_conditions_; | 418 bool use_test_device_conditions_; |
| 421 // For use by tests, a fake network connection type | 419 // For use by tests, a fake network connection type |
| 422 net::NetworkChangeNotifier::ConnectionType test_connection_type_; | 420 net::NetworkChangeNotifier::ConnectionType test_connection_type_; |
| 423 // Owned pointer to the current offliner. | 421 // Owned pointer to the current offliner. |
| 424 std::unique_ptr<Offliner> offliner_; | 422 std::unique_ptr<Offliner> offliner_; |
| 425 base::Time operation_start_time_; | 423 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_; | 470 std::deque<int64_t> prioritized_requests_; |
| 473 // Allows us to pass a weak pointer to callbacks. | 471 // Allows us to pass a weak pointer to callbacks. |
| 474 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; | 472 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; |
| 475 | 473 |
| 476 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); | 474 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); |
| 477 }; | 475 }; |
| 478 | 476 |
| 479 } // namespace offline_pages | 477 } // namespace offline_pages |
| 480 | 478 |
| 481 #endif // COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_REQUEST_COORDINATOR_H_ | 479 #endif // COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_REQUEST_COORDINATOR_H_ |
| OLD | NEW |