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 <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 const GetRequestsCallback& callback, | 204 const GetRequestsCallback& callback, |
| 205 RequestQueue::GetRequestsResult result, | 205 RequestQueue::GetRequestsResult result, |
| 206 std::vector<std::unique_ptr<SavePageRequest>> requests) { | 206 std::vector<std::unique_ptr<SavePageRequest>> requests) { |
| 207 callback.Run(std::move(requests)); | 207 callback.Run(std::move(requests)); |
| 208 } | 208 } |
| 209 | 209 |
| 210 void RequestCoordinator::StopPrerendering(Offliner::RequestStatus stop_status) { | 210 void RequestCoordinator::StopPrerendering(Offliner::RequestStatus stop_status) { |
| 211 if (offliner_ && is_busy_) { | 211 if (offliner_ && is_busy_) { |
| 212 DCHECK(active_request_.get()); | 212 DCHECK(active_request_.get()); |
| 213 offliner_->Cancel(); | 213 offliner_->Cancel(); |
| 214 | |
| 214 AbortRequestAttempt(active_request_.get()); | 215 AbortRequestAttempt(active_request_.get()); |
| 215 } | 216 } |
| 216 | 217 |
| 217 // Stopping offliner means it will not call callback so set last status. | 218 // Stopping offliner means it will not call callback so set last status. |
| 218 last_offlining_status_ = stop_status; | 219 last_offlining_status_ = stop_status; |
| 219 | 220 |
| 220 if (active_request_) { | 221 if (active_request_) { |
| 221 event_logger_.RecordOfflinerResult(active_request_->client_id().name_space, | 222 event_logger_.RecordOfflinerResult(active_request_->client_id().name_space, |
| 222 last_offlining_status_, | 223 last_offlining_status_, |
| 223 active_request_->request_id()); | 224 active_request_->request_id()); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 480 } | 481 } |
| 481 | 482 |
| 482 RequestCoordinator::OfflinerImmediateStartStatus | 483 RequestCoordinator::OfflinerImmediateStartStatus |
| 483 RequestCoordinator::TryImmediateStart() { | 484 RequestCoordinator::TryImmediateStart() { |
| 484 // Make sure not already busy processing. | 485 // Make sure not already busy processing. |
| 485 if (is_busy_) | 486 if (is_busy_) |
| 486 return OfflinerImmediateStartStatus::BUSY; | 487 return OfflinerImmediateStartStatus::BUSY; |
| 487 | 488 |
| 488 // Make sure we are not on svelte device to start immediately. | 489 // Make sure we are not on svelte device to start immediately. |
| 489 if (is_low_end_device_) { | 490 if (is_low_end_device_) { |
| 491 DVLOG(2) << "low end device, returning"; | |
| 490 // Let the scheduler know we are done processing and failed due to svelte. | 492 // Let the scheduler know we are done processing and failed due to svelte. |
| 491 immediate_schedule_callback_.Run(false); | 493 immediate_schedule_callback_.Run(false); |
| 492 return OfflinerImmediateStartStatus::NOT_STARTED_ON_SVELTE; | 494 return OfflinerImmediateStartStatus::NOT_STARTED_ON_SVELTE; |
| 493 } | 495 } |
| 494 | 496 |
| 495 // Make sure we have reasonable network quality (or at least a connection). | 497 if (GetConnectionType() == |
| 496 if (network_quality_estimator_) { | 498 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) |
|
dougarnett
2016/10/28 15:51:25
Let's keep the network_quality_estimator integrati
Pete Williamson
2016/10/28 17:56:54
Done.
| |
| 497 // TODO(dougarnett): Add UMA for quality type experienced. | |
|
dougarnett
2016/10/28 15:51:25
Please carry forward this TODO
Pete Williamson
2016/10/28 17:56:54
Done.
| |
| 498 net::EffectiveConnectionType quality = | |
| 499 network_quality_estimator_->GetEffectiveConnectionType(); | |
| 500 if (quality < net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_2G) | |
| 501 return OfflinerImmediateStartStatus::WEAK_CONNECTION; | |
| 502 } else if (GetConnectionType() == | |
| 503 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) { | |
| 504 return OfflinerImmediateStartStatus::NO_CONNECTION; | 499 return OfflinerImmediateStartStatus::NO_CONNECTION; |
| 505 } | |
| 506 | 500 |
| 507 // Start processing with manufactured conservative battery conditions | 501 // Start processing with manufactured conservative battery conditions |
| 508 // (i.e., assume no battery). | 502 // (i.e., assume no battery). |
| 509 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java). | 503 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java). |
| 510 | 504 |
| 511 DeviceConditions device_conditions(false, 0, GetConnectionType()); | 505 DeviceConditions device_conditions(false, 0, GetConnectionType()); |
| 512 if (StartProcessingInternal(ProcessingWindowState::IMMEDIATE_WINDOW, | 506 if (StartProcessingInternal(ProcessingWindowState::IMMEDIATE_WINDOW, |
| 513 device_conditions, immediate_schedule_callback_)) | 507 device_conditions, immediate_schedule_callback_)) |
| 514 return OfflinerImmediateStartStatus::STARTED; | 508 return OfflinerImmediateStartStatus::STARTED; |
| 515 else | 509 else |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 530 // If there is no time left in the budget, return to the scheduler. | 524 // If there is no time left in the budget, return to the scheduler. |
| 531 // We do not remove the pending task that was set up earlier in case | 525 // We do not remove the pending task that was set up earlier in case |
| 532 // we run out of time, so the background scheduler will return to us | 526 // we run out of time, so the background scheduler will return to us |
| 533 // at the next opportunity to run background tasks. | 527 // at the next opportunity to run background tasks. |
| 534 if ((base::Time::Now() - operation_start_time_) > processing_time_budget) { | 528 if ((base::Time::Now() - operation_start_time_) > processing_time_budget) { |
| 535 is_starting_ = false; | 529 is_starting_ = false; |
| 536 | 530 |
| 537 // Let the scheduler know we are done processing. | 531 // Let the scheduler know we are done processing. |
| 538 // TODO: Make sure the scheduler callback is valid before running it. | 532 // TODO: Make sure the scheduler callback is valid before running it. |
| 539 scheduler_callback_.Run(true); | 533 scheduler_callback_.Run(true); |
| 534 DVLOG(2) << " out of time, giving up. " << __func__; | |
| 540 | 535 |
| 541 return; | 536 return; |
| 542 } | 537 } |
| 543 | 538 |
| 544 // Choose a request to process that meets the available conditions. | 539 // Choose a request to process that meets the available conditions. |
| 545 // This is an async call, and returns right away. | 540 // This is an async call, and returns right away. |
| 546 picker_->ChooseNextRequest(base::Bind(&RequestCoordinator::RequestPicked, | 541 picker_->ChooseNextRequest(base::Bind(&RequestCoordinator::RequestPicked, |
| 547 weak_ptr_factory_.GetWeakPtr()), | 542 weak_ptr_factory_.GetWeakPtr()), |
| 548 base::Bind(&RequestCoordinator::RequestNotPicked, | 543 base::Bind(&RequestCoordinator::RequestNotPicked, |
| 549 weak_ptr_factory_.GetWeakPtr()), | 544 weak_ptr_factory_.GetWeakPtr()), |
| 550 current_conditions_.get(), | 545 current_conditions_.get(), |
| 551 disabled_requests_); | 546 disabled_requests_); |
| 552 } | 547 } |
| 553 | 548 |
| 554 // Called by the request picker when a request has been picked. | 549 // Called by the request picker when a request has been picked. |
| 555 void RequestCoordinator::RequestPicked(const SavePageRequest& request) { | 550 void RequestCoordinator::RequestPicked(const SavePageRequest& request) { |
| 551 DVLOG(2) << request.url() << " " << __func__; | |
| 556 is_starting_ = false; | 552 is_starting_ = false; |
| 557 | 553 |
| 558 // Make sure we were not stopped while picking. | 554 // Make sure we were not stopped while picking. |
| 559 if (processing_state_ != ProcessingWindowState::STOPPED) { | 555 if (processing_state_ != ProcessingWindowState::STOPPED) { |
| 560 // Send the request on to the offliner. | 556 // Send the request on to the offliner. |
| 561 SendRequestToOffliner(request); | 557 SendRequestToOffliner(request); |
| 562 } | 558 } |
| 563 } | 559 } |
| 564 | 560 |
| 565 void RequestCoordinator::RequestNotPicked( | 561 void RequestCoordinator::RequestNotPicked( |
| 566 bool non_user_requested_tasks_remaining) { | 562 bool non_user_requested_tasks_remaining) { |
| 563 DVLOG(2) << __func__; | |
| 567 is_starting_ = false; | 564 is_starting_ = false; |
| 568 | 565 |
| 569 // Clear the outstanding "safety" task in the scheduler. | 566 // Clear the outstanding "safety" task in the scheduler. |
| 570 scheduler_->Unschedule(); | 567 scheduler_->Unschedule(); |
| 571 | 568 |
| 572 // If disabled tasks remain, post a new safety task for 5 sec from now. | 569 // If disabled tasks remain, post a new safety task for 5 sec from now. |
| 573 if (disabled_requests_.size() > 0) { | 570 if (disabled_requests_.size() > 0) { |
| 574 scheduler_->BackupSchedule(GetTriggerConditions(kUserRequest), | 571 scheduler_->BackupSchedule(GetTriggerConditions(kUserRequest), |
| 575 kDisabledTaskRecheckSeconds); | 572 kDisabledTaskRecheckSeconds); |
| 576 } else if (non_user_requested_tasks_remaining) { | 573 } else if (non_user_requested_tasks_remaining) { |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 809 | 806 |
| 810 ClientPolicyController* RequestCoordinator::GetPolicyController() { | 807 ClientPolicyController* RequestCoordinator::GetPolicyController() { |
| 811 return policy_controller_.get(); | 808 return policy_controller_.get(); |
| 812 } | 809 } |
| 813 | 810 |
| 814 void RequestCoordinator::Shutdown() { | 811 void RequestCoordinator::Shutdown() { |
| 815 network_quality_estimator_ = nullptr; | 812 network_quality_estimator_ = nullptr; |
| 816 } | 813 } |
| 817 | 814 |
| 818 } // namespace offline_pages | 815 } // namespace offline_pages |
| OLD | NEW |