| 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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 RequestCoordinator::OfflinerImmediateStartStatus::STATUS_COUNT); | 460 RequestCoordinator::OfflinerImmediateStartStatus::STATUS_COUNT); |
| 460 } | 461 } |
| 461 | 462 |
| 462 RequestCoordinator::OfflinerImmediateStartStatus | 463 RequestCoordinator::OfflinerImmediateStartStatus |
| 463 RequestCoordinator::TryImmediateStart() { | 464 RequestCoordinator::TryImmediateStart() { |
| 464 // Make sure not already busy processing. | 465 // Make sure not already busy processing. |
| 465 if (is_busy_) | 466 if (is_busy_) |
| 466 return OfflinerImmediateStartStatus::BUSY; | 467 return OfflinerImmediateStartStatus::BUSY; |
| 467 | 468 |
| 468 // Make sure we are not on svelte device to start immediately. | 469 // Make sure we are not on svelte device to start immediately. |
| 469 // Let the scheduler know we are done processing and failed due to svelte. | 470 if (is_low_end_device_) { |
| 470 if (base::SysInfo::IsLowEndDevice()) { | 471 // Let the scheduler know we are done processing and failed due to svelte. |
| 471 immediate_schedule_callback_.Run(false); | 472 immediate_schedule_callback_.Run(false); |
| 472 return OfflinerImmediateStartStatus::NOT_STARTED_ON_SVELTE; | 473 return OfflinerImmediateStartStatus::NOT_STARTED_ON_SVELTE; |
| 473 } | 474 } |
| 474 | 475 |
| 475 // Make sure we have reasonable network quality (or at least a connection). | 476 // Make sure we have reasonable network quality (or at least a connection). |
| 476 if (network_quality_estimator_) { | 477 if (network_quality_estimator_) { |
| 477 // TODO(dougarnett): Add UMA for quality type experienced. | 478 // TODO(dougarnett): Add UMA for quality type experienced. |
| 478 net::EffectiveConnectionType quality = | 479 net::EffectiveConnectionType quality = |
| 479 network_quality_estimator_->GetEffectiveConnectionType(); | 480 network_quality_estimator_->GetEffectiveConnectionType(); |
| 480 if (quality < net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_2G) | 481 if (quality < net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_2G) |
| 481 return OfflinerImmediateStartStatus::WEAK_CONNECTION; | 482 return OfflinerImmediateStartStatus::WEAK_CONNECTION; |
| 482 } else if (GetConnectionType() == | 483 } else if (GetConnectionType() == |
| 483 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) { | 484 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) { |
| 484 return OfflinerImmediateStartStatus::NO_CONNECTION; | 485 return OfflinerImmediateStartStatus::NO_CONNECTION; |
| 485 } | 486 } |
| 486 | 487 |
| 487 // Start processing with manufactured conservative battery conditions | 488 // Start processing with manufactured conservative battery conditions |
| 488 // (i.e., assume no battery). | 489 // (i.e., assume no battery). |
| 489 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java). | 490 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java). |
| 490 | 491 |
| 491 DeviceConditions device_conditions(false, 0, GetConnectionType()); | 492 DeviceConditions device_conditions(false, 0, GetConnectionType()); |
| 492 if (StartProcessingInternal(ProcessingWindowState::IMMEDIATE_WINDOW, | 493 if (StartProcessingInternal(ProcessingWindowState::IMMEDIATE_WINDOW, |
| 493 device_conditions, immediate_schedule_callback_)) | 494 device_conditions, immediate_schedule_callback_)) |
| 494 return OfflinerImmediateStartStatus::STARTED; | 495 return OfflinerImmediateStartStatus::STARTED; |
| 495 else | 496 else |
| 496 return OfflinerImmediateStartStatus::NOT_ACCEPTED; | 497 return OfflinerImmediateStartStatus::NOT_ACCEPTED; |
| 497 } | 498 } |
| 498 | 499 |
| 499 void RequestCoordinator::TryNextRequest() { | 500 void RequestCoordinator::TryNextRequest() { |
| 501 base::TimeDelta processing_time_budget; |
| 502 if (processing_state_ == ProcessingWindowState::SCHEDULED_WINDOW) { |
| 503 processing_time_budget = base::TimeDelta::FromSeconds( |
| 504 policy_->GetProcessingTimeBudgetWhenBackgroundScheduledInSeconds()); |
| 505 } else { |
| 506 DCHECK(processing_state_ == ProcessingWindowState::IMMEDIATE_WINDOW); |
| 507 processing_time_budget = base::TimeDelta::FromSeconds( |
| 508 policy_->GetProcessingTimeBudgetForImmediateLoadInSeconds()); |
| 509 } |
| 510 |
| 500 // If there is no time left in the budget, return to the scheduler. | 511 // If there is no time left in the budget, return to the scheduler. |
| 501 // We do not remove the pending task that was set up earlier in case | 512 // We do not remove the pending task that was set up earlier in case |
| 502 // we run out of time, so the background scheduler will return to us | 513 // we run out of time, so the background scheduler will return to us |
| 503 // at the next opportunity to run background tasks. | 514 // at the next opportunity to run background tasks. |
| 504 if (base::Time::Now() - operation_start_time_ > | 515 if ((base::Time::Now() - operation_start_time_) > processing_time_budget) { |
| 505 base::TimeDelta::FromSeconds( | |
| 506 policy_->GetBackgroundProcessingTimeBudgetSeconds())) { | |
| 507 is_starting_ = false; | 516 is_starting_ = false; |
| 508 | 517 |
| 509 // Let the scheduler know we are done processing. | 518 // Let the scheduler know we are done processing. |
| 510 scheduler_callback_.Run(true); | 519 scheduler_callback_.Run(true); |
| 511 | 520 |
| 512 return; | 521 return; |
| 513 } | 522 } |
| 514 | 523 |
| 515 // Choose a request to process that meets the available conditions. | 524 // Choose a request to process that meets the available conditions. |
| 516 // This is an async call, and returns right away. | 525 // This is an async call, and returns right away. |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 | 781 |
| 773 ClientPolicyController* RequestCoordinator::GetPolicyController() { | 782 ClientPolicyController* RequestCoordinator::GetPolicyController() { |
| 774 return policy_controller_.get(); | 783 return policy_controller_.get(); |
| 775 } | 784 } |
| 776 | 785 |
| 777 void RequestCoordinator::Shutdown() { | 786 void RequestCoordinator::Shutdown() { |
| 778 network_quality_estimator_ = nullptr; | 787 network_quality_estimator_ = nullptr; |
| 779 } | 788 } |
| 780 | 789 |
| 781 } // namespace offline_pages | 790 } // namespace offline_pages |
| OLD | NEW |