Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(441)

Side by Side Diff: components/offline_pages/background/request_coordinator.cc

Issue 2450293002: Tune web page background fetching (Closed)
Patch Set: CR feedback per DougArnett Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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).
496 if (network_quality_estimator_) { 497 if (network_quality_estimator_) {
497 // TODO(dougarnett): Add UMA for quality type experienced. 498 // TODO(dougarnett): Add UMA for quality type experienced.
498 net::EffectiveConnectionType quality = 499 net::EffectiveConnectionType quality =
499 network_quality_estimator_->GetEffectiveConnectionType(); 500 network_quality_estimator_->GetEffectiveConnectionType();
500 if (quality < net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_2G) 501 VLOG(2) << "TryImmediateStart: Quality estimate "
501 return OfflinerImmediateStartStatus::WEAK_CONNECTION; 502 << static_cast<int>(quality);
502 } else if (GetConnectionType() == 503 }
503 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) { 504
505 if (GetConnectionType() ==
506 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE)
504 return OfflinerImmediateStartStatus::NO_CONNECTION; 507 return OfflinerImmediateStartStatus::NO_CONNECTION;
505 }
506 508
507 // Start processing with manufactured conservative battery conditions 509 // Start processing with manufactured conservative battery conditions
508 // (i.e., assume no battery). 510 // (i.e., assume no battery).
509 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java). 511 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java).
510 512
511 DeviceConditions device_conditions(false, 0, GetConnectionType()); 513 DeviceConditions device_conditions(false, 0, GetConnectionType());
512 if (StartProcessingInternal(ProcessingWindowState::IMMEDIATE_WINDOW, 514 if (StartProcessingInternal(ProcessingWindowState::IMMEDIATE_WINDOW,
513 device_conditions, immediate_schedule_callback_)) 515 device_conditions, immediate_schedule_callback_))
514 return OfflinerImmediateStartStatus::STARTED; 516 return OfflinerImmediateStartStatus::STARTED;
515 else 517 else
(...skipping 14 matching lines...) Expand all
530 // If there is no time left in the budget, return to the scheduler. 532 // 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 533 // 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 534 // we run out of time, so the background scheduler will return to us
533 // at the next opportunity to run background tasks. 535 // at the next opportunity to run background tasks.
534 if ((base::Time::Now() - operation_start_time_) > processing_time_budget) { 536 if ((base::Time::Now() - operation_start_time_) > processing_time_budget) {
535 is_starting_ = false; 537 is_starting_ = false;
536 538
537 // Let the scheduler know we are done processing. 539 // Let the scheduler know we are done processing.
538 // TODO: Make sure the scheduler callback is valid before running it. 540 // TODO: Make sure the scheduler callback is valid before running it.
539 scheduler_callback_.Run(true); 541 scheduler_callback_.Run(true);
542 DVLOG(2) << " out of time, giving up. " << __func__;
540 543
541 return; 544 return;
542 } 545 }
543 546
544 // Choose a request to process that meets the available conditions. 547 // Choose a request to process that meets the available conditions.
545 // This is an async call, and returns right away. 548 // This is an async call, and returns right away.
546 picker_->ChooseNextRequest(base::Bind(&RequestCoordinator::RequestPicked, 549 picker_->ChooseNextRequest(base::Bind(&RequestCoordinator::RequestPicked,
547 weak_ptr_factory_.GetWeakPtr()), 550 weak_ptr_factory_.GetWeakPtr()),
548 base::Bind(&RequestCoordinator::RequestNotPicked, 551 base::Bind(&RequestCoordinator::RequestNotPicked,
549 weak_ptr_factory_.GetWeakPtr()), 552 weak_ptr_factory_.GetWeakPtr()),
550 current_conditions_.get(), 553 current_conditions_.get(),
551 disabled_requests_); 554 disabled_requests_);
552 } 555 }
553 556
554 // Called by the request picker when a request has been picked. 557 // Called by the request picker when a request has been picked.
555 void RequestCoordinator::RequestPicked(const SavePageRequest& request) { 558 void RequestCoordinator::RequestPicked(const SavePageRequest& request) {
559 DVLOG(2) << request.url() << " " << __func__;
556 is_starting_ = false; 560 is_starting_ = false;
557 561
558 // Make sure we were not stopped while picking. 562 // Make sure we were not stopped while picking.
559 if (processing_state_ != ProcessingWindowState::STOPPED) { 563 if (processing_state_ != ProcessingWindowState::STOPPED) {
560 // Send the request on to the offliner. 564 // Send the request on to the offliner.
561 SendRequestToOffliner(request); 565 SendRequestToOffliner(request);
562 } 566 }
563 } 567 }
564 568
565 void RequestCoordinator::RequestNotPicked( 569 void RequestCoordinator::RequestNotPicked(
566 bool non_user_requested_tasks_remaining) { 570 bool non_user_requested_tasks_remaining) {
571 DVLOG(2) << __func__;
567 is_starting_ = false; 572 is_starting_ = false;
568 573
569 // Clear the outstanding "safety" task in the scheduler. 574 // Clear the outstanding "safety" task in the scheduler.
570 scheduler_->Unschedule(); 575 scheduler_->Unschedule();
571 576
572 // If disabled tasks remain, post a new safety task for 5 sec from now. 577 // If disabled tasks remain, post a new safety task for 5 sec from now.
573 if (disabled_requests_.size() > 0) { 578 if (disabled_requests_.size() > 0) {
574 scheduler_->BackupSchedule(GetTriggerConditions(kUserRequest), 579 scheduler_->BackupSchedule(GetTriggerConditions(kUserRequest),
575 kDisabledTaskRecheckSeconds); 580 kDisabledTaskRecheckSeconds);
576 } else if (non_user_requested_tasks_remaining) { 581 } else if (non_user_requested_tasks_remaining) {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 814
810 ClientPolicyController* RequestCoordinator::GetPolicyController() { 815 ClientPolicyController* RequestCoordinator::GetPolicyController() {
811 return policy_controller_.get(); 816 return policy_controller_.get();
812 } 817 }
813 818
814 void RequestCoordinator::Shutdown() { 819 void RequestCoordinator::Shutdown() {
815 network_quality_estimator_ = nullptr; 820 network_quality_estimator_ = nullptr;
816 } 821 }
817 822
818 } // namespace offline_pages 823 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698