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 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 17 #include "base/supports_user_data.h" | 17 #include "base/supports_user_data.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "base/timer/timer.h" | 19 #include "base/timer/timer.h" |
| 20 #include "components/keyed_service/core/keyed_service.h" | 20 #include "components/keyed_service/core/keyed_service.h" |
| 21 #include "components/offline_pages/background/connection_notifier.h" | |
| 21 #include "components/offline_pages/background/device_conditions.h" | 22 #include "components/offline_pages/background/device_conditions.h" |
| 22 #include "components/offline_pages/background/offliner.h" | 23 #include "components/offline_pages/background/offliner.h" |
| 23 #include "components/offline_pages/background/request_coordinator_event_logger.h " | 24 #include "components/offline_pages/background/request_coordinator_event_logger.h " |
| 24 #include "components/offline_pages/background/request_notifier.h" | 25 #include "components/offline_pages/background/request_notifier.h" |
| 25 #include "components/offline_pages/background/request_queue.h" | 26 #include "components/offline_pages/background/request_queue.h" |
| 26 #include "components/offline_pages/background/scheduler.h" | 27 #include "components/offline_pages/background/scheduler.h" |
| 27 #include "net/nqe/network_quality_estimator.h" | 28 #include "net/nqe/network_quality_estimator.h" |
| 28 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 29 | 30 |
| 30 namespace offline_pages { | 31 namespace offline_pages { |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 bool StartProcessingInternal(const ProcessingWindowState processing_state, | 249 bool StartProcessingInternal(const ProcessingWindowState processing_state, |
| 249 const DeviceConditions& device_conditions, | 250 const DeviceConditions& device_conditions, |
| 250 const base::Callback<void(bool)>& callback); | 251 const base::Callback<void(bool)>& callback); |
| 251 | 252 |
| 252 // Start processing now if connected (but with conservative assumption | 253 // Start processing now if connected (but with conservative assumption |
| 253 // as to other device conditions). | 254 // as to other device conditions). |
| 254 void StartImmediatelyIfConnected(); | 255 void StartImmediatelyIfConnected(); |
| 255 | 256 |
| 256 OfflinerImmediateStartStatus TryImmediateStart(); | 257 OfflinerImmediateStartStatus TryImmediateStart(); |
| 257 | 258 |
| 259 // Requests a callback upon the next network connection to start processing. | |
| 260 void RequestConnectedEventForStarting(); | |
| 261 | |
| 262 // Clears the request for connected event if it was set. | |
| 263 void ClearConnectedEventRequest(); | |
| 264 | |
| 265 // Handles receiving a connection event. Will start immediate processing. | |
| 266 void HandleConnectedEventForStarting(); | |
| 267 | |
| 258 // Check the request queue, and schedule a task corresponding | 268 // Check the request queue, and schedule a task corresponding |
| 259 // to the least restrictive type of request in the queue. | 269 // to the least restrictive type of request in the queue. |
| 260 void ScheduleAsNeeded(); | 270 void ScheduleAsNeeded(); |
| 261 | 271 |
| 262 // Callback from the request picker when it has chosen our next request. | 272 // Callback from the request picker when it has chosen our next request. |
| 263 void RequestPicked(const SavePageRequest& request); | 273 void RequestPicked(const SavePageRequest& request); |
| 264 | 274 |
| 265 // Callback from the request picker when no more requests are in the queue. | 275 // Callback from the request picker when no more requests are in the queue. |
| 266 // The parameter is a signal for what (if any) conditions to schedule future | 276 // The parameter is a signal for what (if any) conditions to schedule future |
| 267 // processing for. | 277 // processing for. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 void GetOffliner(); | 345 void GetOffliner(); |
| 336 | 346 |
| 337 // Method to wrap calls to getting the connection type so it can be | 347 // Method to wrap calls to getting the connection type so it can be |
| 338 // changed for tests. | 348 // changed for tests. |
| 339 net::NetworkChangeNotifier::ConnectionType GetConnectionType(); | 349 net::NetworkChangeNotifier::ConnectionType GetConnectionType(); |
| 340 | 350 |
| 341 void SetNetworkConditionsForTest( | 351 void SetNetworkConditionsForTest( |
| 342 net::NetworkChangeNotifier::ConnectionType connection) { | 352 net::NetworkChangeNotifier::ConnectionType connection) { |
| 343 use_test_connection_type_ = true; | 353 use_test_connection_type_ = true; |
| 344 test_connection_type_ = connection; | 354 test_connection_type_ = connection; |
| 355 if (connection_notifier_) | |
|
Pete Williamson
2016/12/02 01:42:57
Why add this? It will fire an event, right? In t
dougarnett
2016/12/02 02:24:54
Yes, I want to be able to fire an event if there i
dougarnett
2016/12/02 19:08:46
Added separate method in test class
| |
| 356 connection_notifier_->OnConnectionTypeChanged(connection); | |
| 345 } | 357 } |
| 346 | 358 |
| 347 void SetDeviceConditionsForTest(const DeviceConditions& current_conditions) { | 359 void SetDeviceConditionsForTest(const DeviceConditions& current_conditions) { |
| 348 current_conditions_.reset(new DeviceConditions(current_conditions)); | 360 current_conditions_.reset(new DeviceConditions(current_conditions)); |
| 349 } | 361 } |
| 350 | 362 |
| 351 // KeyedService implementation: | 363 // KeyedService implementation: |
| 352 void Shutdown() override; | 364 void Shutdown() override; |
| 353 | 365 |
| 354 friend class RequestCoordinatorTest; | 366 friend class RequestCoordinatorTest; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 397 // done with them. | 409 // done with them. |
| 398 std::set<int64_t> disabled_requests_; | 410 std::set<int64_t> disabled_requests_; |
| 399 // Calling this returns to the scheduler across the JNI bridge. | 411 // Calling this returns to the scheduler across the JNI bridge. |
| 400 base::Callback<void(bool)> scheduler_callback_; | 412 base::Callback<void(bool)> scheduler_callback_; |
| 401 // Logger to record events. | 413 // Logger to record events. |
| 402 RequestCoordinatorEventLogger event_logger_; | 414 RequestCoordinatorEventLogger event_logger_; |
| 403 // Timer to watch for pre-render attempts running too long. | 415 // Timer to watch for pre-render attempts running too long. |
| 404 base::OneShotTimer watchdog_timer_; | 416 base::OneShotTimer watchdog_timer_; |
| 405 // Callback invoked when an immediate request is done (default empty). | 417 // Callback invoked when an immediate request is done (default empty). |
| 406 base::Callback<void(bool)> immediate_schedule_callback_; | 418 base::Callback<void(bool)> immediate_schedule_callback_; |
| 419 // Used for potential immediate processing when we get network connection. | |
| 420 std::unique_ptr<ConnectionNotifier> connection_notifier_; | |
| 407 // Allows us to pass a weak pointer to callbacks. | 421 // Allows us to pass a weak pointer to callbacks. |
| 408 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; | 422 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; |
| 409 | 423 |
| 410 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); | 424 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); |
| 411 }; | 425 }; |
| 412 | 426 |
| 413 } // namespace offline_pages | 427 } // namespace offline_pages |
| 414 | 428 |
| 415 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ | 429 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
| OLD | NEW |