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

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

Issue 2450293002: Tune web page background fetching (Closed)
Patch Set: 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
215 // If we timed out, let the offliner done callback handle it.
216 if (stop_status == Offliner::RequestStatus::REQUEST_COORDINATOR_TIMED_OUT) {
dougarnett 2016/10/26 23:23:26 It would be good to break this change out into a s
Pete Williamson 2016/10/28 00:39:44 Done. I think we should check it in anyway, since
217 return;
218 }
219
220 // Otherwise, this attempt never really had a chance to run, mark it
221 // aborted.
214 AbortRequestAttempt(active_request_.get()); 222 AbortRequestAttempt(active_request_.get());
215 } 223 }
216 224
217 // Stopping offliner means it will not call callback so set last status. 225 // Stopping offliner means it will not call callback so set last status.
218 last_offlining_status_ = stop_status; 226 last_offlining_status_ = stop_status;
219 227
220 if (active_request_) { 228 if (active_request_) {
221 event_logger_.RecordOfflinerResult(active_request_->client_id().name_space, 229 event_logger_.RecordOfflinerResult(active_request_->client_id().name_space,
222 last_offlining_status_, 230 last_offlining_status_,
223 active_request_->request_id()); 231 active_request_->request_id());
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 } 488 }
481 489
482 RequestCoordinator::OfflinerImmediateStartStatus 490 RequestCoordinator::OfflinerImmediateStartStatus
483 RequestCoordinator::TryImmediateStart() { 491 RequestCoordinator::TryImmediateStart() {
484 // Make sure not already busy processing. 492 // Make sure not already busy processing.
485 if (is_busy_) 493 if (is_busy_)
486 return OfflinerImmediateStartStatus::BUSY; 494 return OfflinerImmediateStartStatus::BUSY;
487 495
488 // Make sure we are not on svelte device to start immediately. 496 // Make sure we are not on svelte device to start immediately.
489 if (is_low_end_device_) { 497 if (is_low_end_device_) {
498 DVLOG(2) << "low end device, returning";
490 // Let the scheduler know we are done processing and failed due to svelte. 499 // Let the scheduler know we are done processing and failed due to svelte.
491 immediate_schedule_callback_.Run(false); 500 immediate_schedule_callback_.Run(false);
492 return OfflinerImmediateStartStatus::NOT_STARTED_ON_SVELTE; 501 return OfflinerImmediateStartStatus::NOT_STARTED_ON_SVELTE;
493 } 502 }
494 503
495 // Make sure we have reasonable network quality (or at least a connection). 504 if (GetConnectionType() ==
496 if (network_quality_estimator_) { 505 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE)
497 // TODO(dougarnett): Add UMA for quality type experienced.
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; 506 return OfflinerImmediateStartStatus::NO_CONNECTION;
505 }
506 507
507 // Start processing with manufactured conservative battery conditions 508 // Start processing with manufactured conservative battery conditions
508 // (i.e., assume no battery). 509 // (i.e., assume no battery).
509 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java). 510 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java).
510 511
511 DeviceConditions device_conditions(false, 0, GetConnectionType()); 512 DeviceConditions device_conditions(false, 0, GetConnectionType());
512 if (StartProcessingInternal(ProcessingWindowState::IMMEDIATE_WINDOW, 513 if (StartProcessingInternal(ProcessingWindowState::IMMEDIATE_WINDOW,
513 device_conditions, immediate_schedule_callback_)) 514 device_conditions, immediate_schedule_callback_))
514 return OfflinerImmediateStartStatus::STARTED; 515 return OfflinerImmediateStartStatus::STARTED;
515 else 516 else
(...skipping 14 matching lines...) Expand all
530 // If there is no time left in the budget, return to the scheduler. 531 // 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 532 // 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 533 // we run out of time, so the background scheduler will return to us
533 // at the next opportunity to run background tasks. 534 // at the next opportunity to run background tasks.
534 if ((base::Time::Now() - operation_start_time_) > processing_time_budget) { 535 if ((base::Time::Now() - operation_start_time_) > processing_time_budget) {
535 is_starting_ = false; 536 is_starting_ = false;
536 537
537 // Let the scheduler know we are done processing. 538 // Let the scheduler know we are done processing.
538 // TODO: Make sure the scheduler callback is valid before running it. 539 // TODO: Make sure the scheduler callback is valid before running it.
539 scheduler_callback_.Run(true); 540 scheduler_callback_.Run(true);
541 DVLOG(2) << " out of time, giving up. " << __func__;
540 542
541 return; 543 return;
542 } 544 }
543 545
544 // Choose a request to process that meets the available conditions. 546 // Choose a request to process that meets the available conditions.
545 // This is an async call, and returns right away. 547 // This is an async call, and returns right away.
546 picker_->ChooseNextRequest(base::Bind(&RequestCoordinator::RequestPicked, 548 picker_->ChooseNextRequest(base::Bind(&RequestCoordinator::RequestPicked,
547 weak_ptr_factory_.GetWeakPtr()), 549 weak_ptr_factory_.GetWeakPtr()),
548 base::Bind(&RequestCoordinator::RequestNotPicked, 550 base::Bind(&RequestCoordinator::RequestNotPicked,
549 weak_ptr_factory_.GetWeakPtr()), 551 weak_ptr_factory_.GetWeakPtr()),
550 current_conditions_.get(), 552 current_conditions_.get(),
551 disabled_requests_); 553 disabled_requests_);
552 } 554 }
553 555
554 // Called by the request picker when a request has been picked. 556 // Called by the request picker when a request has been picked.
555 void RequestCoordinator::RequestPicked(const SavePageRequest& request) { 557 void RequestCoordinator::RequestPicked(const SavePageRequest& request) {
558 DVLOG(2) << request.url() << " " << __func__;
556 is_starting_ = false; 559 is_starting_ = false;
557 560
558 // Make sure we were not stopped while picking. 561 // Make sure we were not stopped while picking.
559 if (processing_state_ != ProcessingWindowState::STOPPED) { 562 if (processing_state_ != ProcessingWindowState::STOPPED) {
560 // Send the request on to the offliner. 563 // Send the request on to the offliner.
561 SendRequestToOffliner(request); 564 SendRequestToOffliner(request);
562 } 565 }
563 } 566 }
564 567
565 void RequestCoordinator::RequestNotPicked( 568 void RequestCoordinator::RequestNotPicked(
566 bool non_user_requested_tasks_remaining) { 569 bool non_user_requested_tasks_remaining) {
570 DVLOG(2) << __func__;
567 is_starting_ = false; 571 is_starting_ = false;
568 572
569 // Clear the outstanding "safety" task in the scheduler. 573 // Clear the outstanding "safety" task in the scheduler.
570 scheduler_->Unschedule(); 574 scheduler_->Unschedule();
571 575
572 // If disabled tasks remain, post a new safety task for 5 sec from now. 576 // If disabled tasks remain, post a new safety task for 5 sec from now.
573 if (disabled_requests_.size() > 0) { 577 if (disabled_requests_.size() > 0) {
574 scheduler_->BackupSchedule(GetTriggerConditions(kUserRequest), 578 scheduler_->BackupSchedule(GetTriggerConditions(kUserRequest),
575 kDisabledTaskRecheckSeconds); 579 kDisabledTaskRecheckSeconds);
576 } else if (non_user_requested_tasks_remaining) { 580 } else if (non_user_requested_tasks_remaining) {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 813
810 ClientPolicyController* RequestCoordinator::GetPolicyController() { 814 ClientPolicyController* RequestCoordinator::GetPolicyController() {
811 return policy_controller_.get(); 815 return policy_controller_.get();
812 } 816 }
813 817
814 void RequestCoordinator::Shutdown() { 818 void RequestCoordinator::Shutdown() {
815 network_quality_estimator_ = nullptr; 819 network_quality_estimator_ = nullptr;
816 } 820 }
817 821
818 } // namespace offline_pages 822 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698