| 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 #include "components/offline_pages/background/request_coordinator.h" | 5 #include "components/offline_pages/background/request_coordinator.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 115 |
| 116 } // namespace | 116 } // namespace |
| 117 | 117 |
| 118 RequestCoordinator::RequestCoordinator( | 118 RequestCoordinator::RequestCoordinator( |
| 119 std::unique_ptr<OfflinerPolicy> policy, | 119 std::unique_ptr<OfflinerPolicy> policy, |
| 120 std::unique_ptr<OfflinerFactory> factory, | 120 std::unique_ptr<OfflinerFactory> factory, |
| 121 std::unique_ptr<RequestQueue> queue, | 121 std::unique_ptr<RequestQueue> queue, |
| 122 std::unique_ptr<Scheduler> scheduler, | 122 std::unique_ptr<Scheduler> scheduler, |
| 123 net::NetworkQualityEstimator::NetworkQualityProvider* | 123 net::NetworkQualityEstimator::NetworkQualityProvider* |
| 124 network_quality_estimator) | 124 network_quality_estimator) |
| 125 : is_busy_(false), | 125 : is_low_end_device_(base::SysInfo::IsLowEndDevice()), |
| 126 is_busy_(false), |
| 126 is_starting_(false), | 127 is_starting_(false), |
| 127 processing_state_(ProcessingWindowState::STOPPED), | 128 processing_state_(ProcessingWindowState::STOPPED), |
| 128 use_test_connection_type_(false), | 129 use_test_connection_type_(false), |
| 129 test_connection_type_(), | 130 test_connection_type_(), |
| 130 offliner_(nullptr), | 131 offliner_(nullptr), |
| 131 policy_(std::move(policy)), | 132 policy_(std::move(policy)), |
| 132 factory_(std::move(factory)), | 133 factory_(std::move(factory)), |
| 133 queue_(std::move(queue)), | 134 queue_(std::move(queue)), |
| 134 scheduler_(std::move(scheduler)), | 135 scheduler_(std::move(scheduler)), |
| 135 policy_controller_(new ClientPolicyController()), | 136 policy_controller_(new ClientPolicyController()), |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 RequestCoordinator::OfflinerImmediateStartStatus::STATUS_COUNT); | 441 RequestCoordinator::OfflinerImmediateStartStatus::STATUS_COUNT); |
| 441 } | 442 } |
| 442 | 443 |
| 443 RequestCoordinator::OfflinerImmediateStartStatus | 444 RequestCoordinator::OfflinerImmediateStartStatus |
| 444 RequestCoordinator::TryImmediateStart() { | 445 RequestCoordinator::TryImmediateStart() { |
| 445 // Make sure not already busy processing. | 446 // Make sure not already busy processing. |
| 446 if (is_busy_) | 447 if (is_busy_) |
| 447 return OfflinerImmediateStartStatus::BUSY; | 448 return OfflinerImmediateStartStatus::BUSY; |
| 448 | 449 |
| 449 // Make sure we are not on svelte device to start immediately. | 450 // Make sure we are not on svelte device to start immediately. |
| 450 if (base::SysInfo::IsLowEndDevice()) | 451 if (is_low_end_device_) |
| 451 return OfflinerImmediateStartStatus::NOT_STARTED_ON_SVELTE; | 452 return OfflinerImmediateStartStatus::NOT_STARTED_ON_SVELTE; |
| 452 | 453 |
| 453 // Make sure we have reasonable network quality (or at least a connection). | 454 // Make sure we have reasonable network quality (or at least a connection). |
| 454 if (network_quality_estimator_) { | 455 if (network_quality_estimator_) { |
| 455 // TODO(dougarnett): Add UMA for quality type experienced. | 456 // TODO(dougarnett): Add UMA for quality type experienced. |
| 456 net::EffectiveConnectionType quality = | 457 net::EffectiveConnectionType quality = |
| 457 network_quality_estimator_->GetEffectiveConnectionType(); | 458 network_quality_estimator_->GetEffectiveConnectionType(); |
| 458 if (quality < net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_2G) | 459 if (quality < net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_2G) |
| 459 return OfflinerImmediateStartStatus::WEAK_CONNECTION; | 460 return OfflinerImmediateStartStatus::WEAK_CONNECTION; |
| 460 } else if (GetConnectionType() == | 461 } else if (GetConnectionType() == |
| 461 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) { | 462 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) { |
| 462 return OfflinerImmediateStartStatus::NO_CONNECTION; | 463 return OfflinerImmediateStartStatus::NO_CONNECTION; |
| 463 } | 464 } |
| 464 | 465 |
| 465 // Start processing with manufactured conservative battery conditions | 466 // Start processing with manufactured conservative battery conditions |
| 466 // (i.e., assume no battery). | 467 // (i.e., assume no battery). |
| 467 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java). | 468 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java). |
| 468 | 469 |
| 469 DeviceConditions device_conditions(false, 0, GetConnectionType()); | 470 DeviceConditions device_conditions(false, 0, GetConnectionType()); |
| 470 if (StartProcessingInternal(ProcessingWindowState::IMMEDIATE_WINDOW, | 471 if (StartProcessingInternal(ProcessingWindowState::IMMEDIATE_WINDOW, |
| 471 device_conditions, immediate_schedule_callback_)) | 472 device_conditions, immediate_schedule_callback_)) |
| 472 return OfflinerImmediateStartStatus::STARTED; | 473 return OfflinerImmediateStartStatus::STARTED; |
| 473 else | 474 else |
| 474 return OfflinerImmediateStartStatus::NOT_ACCEPTED; | 475 return OfflinerImmediateStartStatus::NOT_ACCEPTED; |
| 475 } | 476 } |
| 476 | 477 |
| 477 void RequestCoordinator::TryNextRequest() { | 478 void RequestCoordinator::TryNextRequest() { |
| 479 base::TimeDelta processing_time_budget; |
| 480 if (processing_state_ == ProcessingWindowState::SCHEDULED_WINDOW) { |
| 481 processing_time_budget = base::TimeDelta::FromSeconds( |
| 482 policy_->GetProcessingTimeBudgetWhenBackgroundScheduledInSeconds()); |
| 483 } else { |
| 484 DCHECK(processing_state_ == ProcessingWindowState::IMMEDIATE_WINDOW); |
| 485 processing_time_budget = base::TimeDelta::FromSeconds( |
| 486 policy_->GetProcessingTimeBudgetForImmediateLoadInSeconds()); |
| 487 } |
| 488 |
| 478 // If there is no time left in the budget, return to the scheduler. | 489 // If there is no time left in the budget, return to the scheduler. |
| 479 // We do not remove the pending task that was set up earlier in case | 490 // We do not remove the pending task that was set up earlier in case |
| 480 // we run out of time, so the background scheduler will return to us | 491 // we run out of time, so the background scheduler will return to us |
| 481 // at the next opportunity to run background tasks. | 492 // at the next opportunity to run background tasks. |
| 482 if (base::Time::Now() - operation_start_time_ > | 493 if ((base::Time::Now() - operation_start_time_) > processing_time_budget) { |
| 483 base::TimeDelta::FromSeconds( | |
| 484 policy_->GetBackgroundProcessingTimeBudgetSeconds())) { | |
| 485 is_starting_ = false; | 494 is_starting_ = false; |
| 486 | 495 |
| 487 // Let the scheduler know we are done processing. | 496 // Let the scheduler know we are done processing. |
| 488 scheduler_callback_.Run(true); | 497 scheduler_callback_.Run(true); |
| 489 | 498 |
| 490 return; | 499 return; |
| 491 } | 500 } |
| 492 | 501 |
| 493 // Choose a request to process that meets the available conditions. | 502 // Choose a request to process that meets the available conditions. |
| 494 // This is an async call, and returns right away. | 503 // This is an async call, and returns right away. |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 | 732 |
| 724 ClientPolicyController* RequestCoordinator::GetPolicyController() { | 733 ClientPolicyController* RequestCoordinator::GetPolicyController() { |
| 725 return policy_controller_.get(); | 734 return policy_controller_.get(); |
| 726 } | 735 } |
| 727 | 736 |
| 728 void RequestCoordinator::Shutdown() { | 737 void RequestCoordinator::Shutdown() { |
| 729 network_quality_estimator_ = nullptr; | 738 network_quality_estimator_ = nullptr; |
| 730 } | 739 } |
| 731 | 740 |
| 732 } // namespace offline_pages | 741 } // namespace offline_pages |
| OLD | NEW |