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

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

Issue 2467333003: [Offline Pages] Coordinator checks for net connection before starting next req (Closed)
Patch Set: Got tests running 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
« no previous file with comments | « no previous file | components/offline_pages/background/request_coordinator_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 device_conditions, callback); 467 device_conditions, callback);
468 } 468 }
469 469
470 bool RequestCoordinator::StartProcessingInternal( 470 bool RequestCoordinator::StartProcessingInternal(
471 const ProcessingWindowState processing_state, 471 const ProcessingWindowState processing_state,
472 const DeviceConditions& device_conditions, 472 const DeviceConditions& device_conditions,
473 const base::Callback<void(bool)>& callback) { 473 const base::Callback<void(bool)>& callback) {
474 current_conditions_.reset(new DeviceConditions(device_conditions)); 474 current_conditions_.reset(new DeviceConditions(device_conditions));
475 if (is_starting_ || is_busy_) 475 if (is_starting_ || is_busy_)
476 return false; 476 return false;
477 is_starting_ = true;
478 processing_state_ = processing_state; 477 processing_state_ = processing_state;
479 scheduler_callback_ = callback; 478 scheduler_callback_ = callback;
480 479
481 // Mark the time at which we started processing so we can check our time 480 // Mark the time at which we started processing so we can check our time
482 // budget. 481 // budget.
483 operation_start_time_ = base::Time::Now(); 482 operation_start_time_ = base::Time::Now();
484 483
485 TryNextRequest(); 484 TryNextRequest();
486 485
487 return true; 486 return true;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 525
527 DeviceConditions device_conditions(false, 0, GetConnectionType()); 526 DeviceConditions device_conditions(false, 0, GetConnectionType());
528 if (StartProcessingInternal(ProcessingWindowState::IMMEDIATE_WINDOW, 527 if (StartProcessingInternal(ProcessingWindowState::IMMEDIATE_WINDOW,
529 device_conditions, immediate_schedule_callback_)) 528 device_conditions, immediate_schedule_callback_))
530 return OfflinerImmediateStartStatus::STARTED; 529 return OfflinerImmediateStartStatus::STARTED;
531 else 530 else
532 return OfflinerImmediateStartStatus::NOT_ACCEPTED; 531 return OfflinerImmediateStartStatus::NOT_ACCEPTED;
533 } 532 }
534 533
535 void RequestCoordinator::TryNextRequest() { 534 void RequestCoordinator::TryNextRequest() {
535 is_starting_ = true;
536 base::TimeDelta processing_time_budget; 536 base::TimeDelta processing_time_budget;
537 if (processing_state_ == ProcessingWindowState::SCHEDULED_WINDOW) { 537 if (processing_state_ == ProcessingWindowState::SCHEDULED_WINDOW) {
538 processing_time_budget = base::TimeDelta::FromSeconds( 538 processing_time_budget = base::TimeDelta::FromSeconds(
539 policy_->GetProcessingTimeBudgetWhenBackgroundScheduledInSeconds()); 539 policy_->GetProcessingTimeBudgetWhenBackgroundScheduledInSeconds());
540 } else { 540 } else {
541 DCHECK(processing_state_ == ProcessingWindowState::IMMEDIATE_WINDOW); 541 DCHECK(processing_state_ == ProcessingWindowState::IMMEDIATE_WINDOW);
542 processing_time_budget = base::TimeDelta::FromSeconds( 542 processing_time_budget = base::TimeDelta::FromSeconds(
543 policy_->GetProcessingTimeBudgetForImmediateLoadInSeconds()); 543 policy_->GetProcessingTimeBudgetForImmediateLoadInSeconds());
544 } 544 }
545 545
546 // If there is no time left in the budget, return to the scheduler. 546 // If there is no network or no time left in the budget, return to the
547 // We do not remove the pending task that was set up earlier in case 547 // scheduler. We do not remove the pending scheduler task that was set
548 // we run out of time, so the background scheduler will return to us 548 // up earlier in case we run out of time, so the background scheduler
549 // at the next opportunity to run background tasks. 549 // will return to us at the next opportunity to run background tasks.
550 if ((base::Time::Now() - operation_start_time_) > processing_time_budget) { 550 if (GetConnectionType() ==
551 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE ||
552 (base::Time::Now() - operation_start_time_) > processing_time_budget) {
551 is_starting_ = false; 553 is_starting_ = false;
552 554
553 // Let the scheduler know we are done processing. 555 // Let the scheduler know we are done processing.
554 // TODO: Make sure the scheduler callback is valid before running it. 556 // TODO: Make sure the scheduler callback is valid before running it.
555 scheduler_callback_.Run(true); 557 scheduler_callback_.Run(true);
556 DVLOG(2) << " out of time, giving up. " << __func__; 558 DVLOG(2) << " out of time, giving up. " << __func__;
557 559
558 return; 560 return;
559 } 561 }
560 562
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 828
827 ClientPolicyController* RequestCoordinator::GetPolicyController() { 829 ClientPolicyController* RequestCoordinator::GetPolicyController() {
828 return policy_controller_.get(); 830 return policy_controller_.get();
829 } 831 }
830 832
831 void RequestCoordinator::Shutdown() { 833 void RequestCoordinator::Shutdown() {
832 network_quality_estimator_ = nullptr; 834 network_quality_estimator_ = nullptr;
833 } 835 }
834 836
835 } // namespace offline_pages 837 } // namespace offline_pages
OLDNEW
« no previous file with comments | « no previous file | components/offline_pages/background/request_coordinator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698