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 #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 <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 // Make sure we are not on svelte device to start immediately. | 552 // Make sure we are not on svelte device to start immediately. |
| 553 if (is_low_end_device_ && | 553 if (is_low_end_device_ && |
| 554 !offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled()) { | 554 !offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled()) { |
| 555 DVLOG(2) << "low end device, returning"; | 555 DVLOG(2) << "low end device, returning"; |
| 556 // Let the scheduler know we are done processing and failed due to svelte. | 556 // Let the scheduler know we are done processing and failed due to svelte. |
| 557 immediate_schedule_callback_.Run(false); | 557 immediate_schedule_callback_.Run(false); |
| 558 return OfflinerImmediateStartStatus::NOT_STARTED_ON_SVELTE; | 558 return OfflinerImmediateStartStatus::NOT_STARTED_ON_SVELTE; |
| 559 } | 559 } |
| 560 | 560 |
| 561 if (GetConnectionType() == | 561 if (GetConnectionType() == |
| 562 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) | 562 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) { |
| 563 RequestConnectedEventForStarting(); | |
|
Pete Williamson
2016/12/01 01:34:08
Should we remove ourselves from the notifier when
dougarnett
2016/12/01 19:25:22
Yeah, I'll add as an else here - in case another p
| |
| 563 return OfflinerImmediateStartStatus::NO_CONNECTION; | 564 return OfflinerImmediateStartStatus::NO_CONNECTION; |
| 565 } | |
| 564 | 566 |
| 565 // Start processing with manufactured conservative battery conditions | 567 // Start processing with manufactured conservative battery conditions |
| 566 // (i.e., assume no battery). | 568 // (i.e., assume no battery). |
| 567 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java). | 569 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java). |
| 568 | 570 |
| 569 DeviceConditions device_conditions(false, 0, GetConnectionType()); | 571 DeviceConditions device_conditions(false, 0, GetConnectionType()); |
| 570 if (StartProcessingInternal(ProcessingWindowState::IMMEDIATE_WINDOW, | 572 if (StartProcessingInternal(ProcessingWindowState::IMMEDIATE_WINDOW, |
| 571 device_conditions, immediate_schedule_callback_)) | 573 device_conditions, immediate_schedule_callback_)) |
| 572 return OfflinerImmediateStartStatus::STARTED; | 574 return OfflinerImmediateStartStatus::STARTED; |
| 573 else | 575 else |
| 574 return OfflinerImmediateStartStatus::NOT_ACCEPTED; | 576 return OfflinerImmediateStartStatus::NOT_ACCEPTED; |
| 575 } | 577 } |
| 576 | 578 |
| 579 void RequestCoordinator::RequestConnectedEventForStarting() { | |
| 580 connection_notifier_.reset(new ConnectionNotifier( | |
| 581 base::Bind(&RequestCoordinator::HandleConnectedEventForStarting, | |
| 582 weak_ptr_factory_.GetWeakPtr()))); | |
| 583 } | |
| 584 | |
| 585 void RequestCoordinator::HandleConnectedEventForStarting() { | |
| 586 connection_notifier_.reset(nullptr); | |
| 587 StartImmediatelyIfConnected(); | |
| 588 } | |
| 589 | |
| 577 void RequestCoordinator::TryNextRequest(bool is_start_of_processing) { | 590 void RequestCoordinator::TryNextRequest(bool is_start_of_processing) { |
| 578 is_starting_ = true; | 591 is_starting_ = true; |
| 579 base::TimeDelta processing_time_budget; | 592 base::TimeDelta processing_time_budget; |
| 580 if (processing_state_ == ProcessingWindowState::SCHEDULED_WINDOW) { | 593 if (processing_state_ == ProcessingWindowState::SCHEDULED_WINDOW) { |
| 581 processing_time_budget = base::TimeDelta::FromSeconds( | 594 processing_time_budget = base::TimeDelta::FromSeconds( |
| 582 policy_->GetProcessingTimeBudgetWhenBackgroundScheduledInSeconds()); | 595 policy_->GetProcessingTimeBudgetWhenBackgroundScheduledInSeconds()); |
| 583 } else { | 596 } else { |
| 584 DCHECK(processing_state_ == ProcessingWindowState::IMMEDIATE_WINDOW); | 597 DCHECK(processing_state_ == ProcessingWindowState::IMMEDIATE_WINDOW); |
| 585 processing_time_budget = base::TimeDelta::FromSeconds( | 598 processing_time_budget = base::TimeDelta::FromSeconds( |
| 586 policy_->GetProcessingTimeBudgetForImmediateLoadInSeconds()); | 599 policy_->GetProcessingTimeBudgetForImmediateLoadInSeconds()); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 597 | 610 |
| 598 // If there is no network or no time left in the budget, return to the | 611 // If there is no network or no time left in the budget, return to the |
| 599 // scheduler. We do not remove the pending scheduler task that was set | 612 // scheduler. We do not remove the pending scheduler task that was set |
| 600 // up earlier in case we run out of time, so the background scheduler | 613 // up earlier in case we run out of time, so the background scheduler |
| 601 // will return to us at the next opportunity to run background tasks. | 614 // will return to us at the next opportunity to run background tasks. |
| 602 if (connection_type == | 615 if (connection_type == |
| 603 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE || | 616 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE || |
| 604 (base::Time::Now() - operation_start_time_) > processing_time_budget) { | 617 (base::Time::Now() - operation_start_time_) > processing_time_budget) { |
| 605 is_starting_ = false; | 618 is_starting_ = false; |
| 606 | 619 |
| 620 // If we were doing immediate processing, try to start it again | |
| 621 // when we get connected. | |
| 622 if (processing_state_ == ProcessingWindowState::IMMEDIATE_WINDOW) | |
| 623 RequestConnectedEventForStarting(); | |
| 624 | |
| 607 // Let the scheduler know we are done processing. | 625 // Let the scheduler know we are done processing. |
| 608 // TODO: Make sure the scheduler callback is valid before running it. | 626 // TODO: Make sure the scheduler callback is valid before running it. |
| 609 scheduler_callback_.Run(true); | 627 scheduler_callback_.Run(true); |
| 610 DVLOG(2) << " out of time, giving up. " << __func__; | 628 DVLOG(2) << " out of time, giving up. " << __func__; |
| 611 | 629 |
| 612 return; | 630 return; |
| 613 } | 631 } |
| 614 | 632 |
| 615 // Ask request queue to make a new PickRequestTask object, then put it on the | 633 // Ask request queue to make a new PickRequestTask object, then put it on the |
| 616 // task queue. | 634 // task queue. |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 956 | 974 |
| 957 ClientPolicyController* RequestCoordinator::GetPolicyController() { | 975 ClientPolicyController* RequestCoordinator::GetPolicyController() { |
| 958 return policy_controller_.get(); | 976 return policy_controller_.get(); |
| 959 } | 977 } |
| 960 | 978 |
| 961 void RequestCoordinator::Shutdown() { | 979 void RequestCoordinator::Shutdown() { |
| 962 network_quality_estimator_ = nullptr; | 980 network_quality_estimator_ = nullptr; |
| 963 } | 981 } |
| 964 | 982 |
| 965 } // namespace offline_pages | 983 } // namespace offline_pages |
| OLD | NEW |