Chromium Code Reviews| 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 22 matching lines...) Expand all Loading... | |
| 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(std::unique_ptr<OfflinerPolicy> policy, |
| 64 std::unique_ptr<OfflinerFactory> factory, | 65 std::unique_ptr<OfflinerFactory> factory, |
| 65 std::unique_ptr<RequestQueue> queue, | 66 std::unique_ptr<RequestQueue> queue, |
| 66 std::unique_ptr<Scheduler> scheduler); | 67 std::unique_ptr<Scheduler> scheduler, |
| 68 net::NetworkQualityEstimator::NetworkQualityProvider* nqe); | |
|
Pete Williamson
2016/09/16 22:26:01
nqe -> network_quality_estimator or network_qualit
dougarnett
2016/09/19 19:34:32
Done.
| |
| 67 | 69 |
| 68 ~RequestCoordinator() override; | 70 ~RequestCoordinator() override; |
| 69 | 71 |
| 70 // Queues |request| to later load and save when system conditions allow. | 72 // Queues |request| to later load and save when system conditions allow. |
| 71 // Returns true if the page could be queued successfully. | 73 // Returns true if the page could be queued successfully. |
| 72 bool SavePageLater( | 74 bool SavePageLater( |
| 73 const GURL& url, const ClientId& client_id, bool user_reqeusted); | 75 const GURL& url, const ClientId& client_id, bool user_reqeusted); |
| 74 | 76 |
| 75 // Callback specifying which request IDs were actually removed. | 77 // Callback specifying which request IDs were actually removed. |
| 76 typedef base::Callback<void( | 78 typedef base::Callback<void( |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 } | 256 } |
| 255 | 257 |
| 256 void SetOfflinerTimeoutForTest(const base::TimeDelta& timeout) { | 258 void SetOfflinerTimeoutForTest(const base::TimeDelta& timeout) { |
| 257 offliner_timeout_ = timeout; | 259 offliner_timeout_ = timeout; |
| 258 } | 260 } |
| 259 | 261 |
| 260 void SetDeviceConditionsForTest(DeviceConditions& current_conditions) { | 262 void SetDeviceConditionsForTest(DeviceConditions& current_conditions) { |
| 261 current_conditions_.reset(new DeviceConditions(current_conditions)); | 263 current_conditions_.reset(new DeviceConditions(current_conditions)); |
| 262 } | 264 } |
| 263 | 265 |
| 266 // KeyedService implementation: | |
| 267 void Shutdown() override; | |
| 268 | |
| 264 friend class RequestCoordinatorTest; | 269 friend class RequestCoordinatorTest; |
| 265 | 270 |
| 266 // The offliner can only handle one request at a time - if the offliner is | 271 // The offliner can only handle one request at a time - if the offliner is |
| 267 // busy, prevent other requests. This flag marks whether the offliner is in | 272 // busy, prevent other requests. This flag marks whether the offliner is in |
| 268 // use. | 273 // use. |
| 269 bool is_busy_; | 274 bool is_busy_; |
| 270 // There is more than one path to start processing so this flag is used | 275 // There is more than one path to start processing so this flag is used |
| 271 // to avoid race conditions before is_busy_ is established. | 276 // to avoid race conditions before is_busy_ is established. |
| 272 bool is_starting_; | 277 bool is_starting_; |
| 273 // True if the current processing window has been canceled. | 278 // True if the current processing window has been canceled. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 284 // Last known conditions for network, battery | 289 // Last known conditions for network, battery |
| 285 std::unique_ptr<DeviceConditions> current_conditions_; | 290 std::unique_ptr<DeviceConditions> current_conditions_; |
| 286 // RequestCoordinator takes over ownership of the policy | 291 // RequestCoordinator takes over ownership of the policy |
| 287 std::unique_ptr<OfflinerPolicy> policy_; | 292 std::unique_ptr<OfflinerPolicy> policy_; |
| 288 // OfflinerFactory. Used to create offline pages. Owned. | 293 // OfflinerFactory. Used to create offline pages. Owned. |
| 289 std::unique_ptr<OfflinerFactory> factory_; | 294 std::unique_ptr<OfflinerFactory> factory_; |
| 290 // RequestQueue. Used to store incoming requests. Owned. | 295 // RequestQueue. Used to store incoming requests. Owned. |
| 291 std::unique_ptr<RequestQueue> queue_; | 296 std::unique_ptr<RequestQueue> queue_; |
| 292 // Scheduler. Used to request a callback when network is available. Owned. | 297 // Scheduler. Used to request a callback when network is available. Owned. |
| 293 std::unique_ptr<Scheduler> scheduler_; | 298 std::unique_ptr<Scheduler> scheduler_; |
| 299 // Unowned pointer to the Network Quality Estimator. | |
| 300 net::NetworkQualityEstimator::NetworkQualityProvider* nqe_; | |
| 294 // Holds copy of the active request, if any. | 301 // Holds copy of the active request, if any. |
| 295 std::unique_ptr<SavePageRequest> active_request_; | 302 std::unique_ptr<SavePageRequest> active_request_; |
| 296 // Status of the most recent offlining. | 303 // Status of the most recent offlining. |
| 297 Offliner::RequestStatus last_offlining_status_; | 304 Offliner::RequestStatus last_offlining_status_; |
| 298 // Class to choose which request to schedule next | 305 // Class to choose which request to schedule next |
| 299 std::unique_ptr<RequestPicker> picker_; | 306 std::unique_ptr<RequestPicker> picker_; |
| 300 // Calling this returns to the scheduler across the JNI bridge. | 307 // Calling this returns to the scheduler across the JNI bridge. |
| 301 base::Callback<void(bool)> scheduler_callback_; | 308 base::Callback<void(bool)> scheduler_callback_; |
| 302 // Logger to record events. | 309 // Logger to record events. |
| 303 RequestCoordinatorEventLogger event_logger_; | 310 RequestCoordinatorEventLogger event_logger_; |
| 304 // Timer to watch for pre-render attempts running too long. | 311 // Timer to watch for pre-render attempts running too long. |
| 305 base::OneShotTimer watchdog_timer_; | 312 base::OneShotTimer watchdog_timer_; |
| 306 // How long to wait for an offliner request before giving up. | 313 // How long to wait for an offliner request before giving up. |
| 307 base::TimeDelta offliner_timeout_; | 314 base::TimeDelta offliner_timeout_; |
| 308 // Allows us to pass a weak pointer to callbacks. | 315 // Allows us to pass a weak pointer to callbacks. |
| 309 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; | 316 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; |
| 310 | 317 |
| 311 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); | 318 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); |
| 312 }; | 319 }; |
| 313 | 320 |
| 314 } // namespace offline_pages | 321 } // namespace offline_pages |
| 315 | 322 |
| 316 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ | 323 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
| OLD | NEW |