| 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" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 14 #include "base/supports_user_data.h" | 14 #include "base/supports_user_data.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
| 17 #include "components/keyed_service/core/keyed_service.h" | 17 #include "components/keyed_service/core/keyed_service.h" |
| 18 #include "components/offline_pages/background/device_conditions.h" | 18 #include "components/offline_pages/background/device_conditions.h" |
| 19 #include "components/offline_pages/background/offliner.h" | 19 #include "components/offline_pages/background/offliner.h" |
| 20 #include "components/offline_pages/background/request_coordinator_event_logger.h
" | 20 #include "components/offline_pages/background/request_coordinator_event_logger.h
" |
| 21 #include "components/offline_pages/background/request_notifier.h" | 21 #include "components/offline_pages/background/request_notifier.h" |
| 22 #include "components/offline_pages/background/request_queue.h" | 22 #include "components/offline_pages/background/request_queue.h" |
| 23 #include "components/offline_pages/background/scheduler.h" | 23 #include "components/offline_pages/background/scheduler.h" |
| 24 #include "net/nqe/network_quality_estimator.h" |
| 24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 25 | 26 |
| 26 namespace offline_pages { | 27 namespace offline_pages { |
| 27 | 28 |
| 28 struct ClientId; | 29 struct ClientId; |
| 29 class OfflinerPolicy; | 30 class OfflinerPolicy; |
| 30 class OfflinerFactory; | 31 class OfflinerFactory; |
| 31 class Offliner; | 32 class Offliner; |
| 32 class RequestPicker; | 33 class RequestPicker; |
| 33 class SavePageRequest; | 34 class SavePageRequest; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 53 RequestNotifier::BackgroundSavePageResult status) = 0; | 54 RequestNotifier::BackgroundSavePageResult status) = 0; |
| 54 virtual void OnChanged(const SavePageRequest& request) = 0; | 55 virtual void OnChanged(const SavePageRequest& request) = 0; |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 // Callback to report when a request was available. | 58 // Callback to report when a request was available. |
| 58 typedef base::Callback<void(const SavePageRequest& request)> | 59 typedef base::Callback<void(const SavePageRequest& request)> |
| 59 RequestPickedCallback; | 60 RequestPickedCallback; |
| 60 // Callback to report when no request was available. | 61 // Callback to report when no request was available. |
| 61 typedef base::Callback<void(bool)> RequestNotPickedCallback; | 62 typedef base::Callback<void(bool)> RequestNotPickedCallback; |
| 62 | 63 |
| 63 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, | 64 RequestCoordinator( |
| 64 std::unique_ptr<OfflinerFactory> factory, | 65 std::unique_ptr<OfflinerPolicy> policy, |
| 65 std::unique_ptr<RequestQueue> queue, | 66 std::unique_ptr<OfflinerFactory> factory, |
| 66 std::unique_ptr<Scheduler> scheduler); | 67 std::unique_ptr<RequestQueue> queue, |
| 68 std::unique_ptr<Scheduler> scheduler, |
| 69 std::unique_ptr<net::NetworkQualityEstimator::NetworkQualityProvider> |
| 70 network_quality_provider); |
| 67 | 71 |
| 68 ~RequestCoordinator() override; | 72 ~RequestCoordinator() override; |
| 69 | 73 |
| 70 // Queues |request| to later load and save when system conditions allow. | 74 // Queues |request| to later load and save when system conditions allow. |
| 71 // Returns true if the page could be queued successfully. | 75 // Returns true if the page could be queued successfully. |
| 72 bool SavePageLater( | 76 bool SavePageLater( |
| 73 const GURL& url, const ClientId& client_id, bool user_reqeusted); | 77 const GURL& url, const ClientId& client_id, bool user_reqeusted); |
| 74 | 78 |
| 75 // Callback specifying which request IDs were actually removed. | 79 // Callback specifying which request IDs were actually removed. |
| 76 typedef base::Callback<void( | 80 typedef base::Callback<void( |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 // Last known conditions for network, battery | 288 // Last known conditions for network, battery |
| 285 std::unique_ptr<DeviceConditions> current_conditions_; | 289 std::unique_ptr<DeviceConditions> current_conditions_; |
| 286 // RequestCoordinator takes over ownership of the policy | 290 // RequestCoordinator takes over ownership of the policy |
| 287 std::unique_ptr<OfflinerPolicy> policy_; | 291 std::unique_ptr<OfflinerPolicy> policy_; |
| 288 // OfflinerFactory. Used to create offline pages. Owned. | 292 // OfflinerFactory. Used to create offline pages. Owned. |
| 289 std::unique_ptr<OfflinerFactory> factory_; | 293 std::unique_ptr<OfflinerFactory> factory_; |
| 290 // RequestQueue. Used to store incoming requests. Owned. | 294 // RequestQueue. Used to store incoming requests. Owned. |
| 291 std::unique_ptr<RequestQueue> queue_; | 295 std::unique_ptr<RequestQueue> queue_; |
| 292 // Scheduler. Used to request a callback when network is available. Owned. | 296 // Scheduler. Used to request a callback when network is available. Owned. |
| 293 std::unique_ptr<Scheduler> scheduler_; | 297 std::unique_ptr<Scheduler> scheduler_; |
| 298 // Network Quality Estimator. |
| 299 std::unique_ptr<net::NetworkQualityEstimator::NetworkQualityProvider> nqe_; |
| 294 // Holds copy of the active request, if any. | 300 // Holds copy of the active request, if any. |
| 295 std::unique_ptr<SavePageRequest> active_request_; | 301 std::unique_ptr<SavePageRequest> active_request_; |
| 296 // Status of the most recent offlining. | 302 // Status of the most recent offlining. |
| 297 Offliner::RequestStatus last_offlining_status_; | 303 Offliner::RequestStatus last_offlining_status_; |
| 298 // Class to choose which request to schedule next | 304 // Class to choose which request to schedule next |
| 299 std::unique_ptr<RequestPicker> picker_; | 305 std::unique_ptr<RequestPicker> picker_; |
| 300 // Calling this returns to the scheduler across the JNI bridge. | 306 // Calling this returns to the scheduler across the JNI bridge. |
| 301 base::Callback<void(bool)> scheduler_callback_; | 307 base::Callback<void(bool)> scheduler_callback_; |
| 302 // Logger to record events. | 308 // Logger to record events. |
| 303 RequestCoordinatorEventLogger event_logger_; | 309 RequestCoordinatorEventLogger event_logger_; |
| 304 // Timer to watch for pre-render attempts running too long. | 310 // Timer to watch for pre-render attempts running too long. |
| 305 base::OneShotTimer watchdog_timer_; | 311 base::OneShotTimer watchdog_timer_; |
| 306 // How long to wait for an offliner request before giving up. | 312 // How long to wait for an offliner request before giving up. |
| 307 base::TimeDelta offliner_timeout_; | 313 base::TimeDelta offliner_timeout_; |
| 308 // Allows us to pass a weak pointer to callbacks. | 314 // Allows us to pass a weak pointer to callbacks. |
| 309 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; | 315 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; |
| 310 | 316 |
| 311 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); | 317 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); |
| 312 }; | 318 }; |
| 313 | 319 |
| 314 } // namespace offline_pages | 320 } // namespace offline_pages |
| 315 | 321 |
| 316 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ | 322 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
| OLD | NEW |