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

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

Issue 2347783003: [OfflinePages, NetworkQualityEstimator] Use NetworkQualityEstimator to decide on triggering Backgro… (Closed)
Patch Set: Addressed feedback Created 4 years, 3 months 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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 int64_t GenerateOfflineId() { 68 int64_t GenerateOfflineId() {
69 return base::RandGenerator(std::numeric_limits<int64_t>::max()) + 1; 69 return base::RandGenerator(std::numeric_limits<int64_t>::max()) + 1;
70 } 70 }
71 71
72 // In case we start processing from SavePageLater, we need a callback, but there 72 // In case we start processing from SavePageLater, we need a callback, but there
73 // is nothing for it to do. 73 // is nothing for it to do.
74 void EmptySchedulerCallback(bool started) {} 74 void EmptySchedulerCallback(bool started) {}
75 75
76 } // namespace 76 } // namespace
77 77
78 RequestCoordinator::RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, 78 RequestCoordinator::RequestCoordinator(
79 std::unique_ptr<OfflinerFactory> factory, 79 std::unique_ptr<OfflinerPolicy> policy,
80 std::unique_ptr<RequestQueue> queue, 80 std::unique_ptr<OfflinerFactory> factory,
81 std::unique_ptr<Scheduler> scheduler) 81 std::unique_ptr<RequestQueue> queue,
82 std::unique_ptr<Scheduler> scheduler,
83 net::NetworkQualityEstimator::NetworkQualityProvider*
84 network_quality_estimator)
82 : is_busy_(false), 85 : is_busy_(false),
83 is_starting_(false), 86 is_starting_(false),
84 is_stopped_(false), 87 is_stopped_(false),
85 use_test_connection_type_(false), 88 use_test_connection_type_(false),
86 test_connection_type_(), 89 test_connection_type_(),
87 offliner_(nullptr), 90 offliner_(nullptr),
88 policy_(std::move(policy)), 91 policy_(std::move(policy)),
89 factory_(std::move(factory)), 92 factory_(std::move(factory)),
90 queue_(std::move(queue)), 93 queue_(std::move(queue)),
91 scheduler_(std::move(scheduler)), 94 scheduler_(std::move(scheduler)),
95 network_quality_estimator_(network_quality_estimator),
92 active_request_(nullptr), 96 active_request_(nullptr),
93 last_offlining_status_(Offliner::RequestStatus::UNKNOWN), 97 last_offlining_status_(Offliner::RequestStatus::UNKNOWN),
94 offliner_timeout_(base::TimeDelta::FromSeconds( 98 offliner_timeout_(base::TimeDelta::FromSeconds(
95 policy_->GetSinglePageTimeLimitInSeconds())), 99 policy_->GetSinglePageTimeLimitInSeconds())),
96 weak_ptr_factory_(this) { 100 weak_ptr_factory_(this) {
97 DCHECK(policy_ != nullptr); 101 DCHECK(policy_ != nullptr);
98 picker_.reset( 102 picker_.reset(
99 new RequestPicker(queue_.get(), policy_.get(), this, &event_logger_)); 103 new RequestPicker(queue_.get(), policy_.get(), this, &event_logger_));
100 } 104 }
101 105
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 367
364 is_stopped_ = false; 368 is_stopped_ = false;
365 scheduler_callback_ = callback; 369 scheduler_callback_ = callback;
366 370
367 TryNextRequest(); 371 TryNextRequest();
368 372
369 return true; 373 return true;
370 } 374 }
371 375
372 void RequestCoordinator::StartProcessingIfConnected() { 376 void RequestCoordinator::StartProcessingIfConnected() {
373 // Makes sure not already busy processing. 377 // Make sure not already busy processing.
374 if (is_busy_) return; 378 if (is_busy_) return;
375 379
376 // Make sure we are not on svelte device to start immediately. 380 // Make sure we are not on svelte device to start immediately.
377 if (base::SysInfo::IsLowEndDevice()) return; 381 if (base::SysInfo::IsLowEndDevice()) return;
378 382
379 // Check for network connectivity. 383 // Make sure we have reasonable network quality (or at least a connection).
380 net::NetworkChangeNotifier::ConnectionType connection = GetConnectionType(); 384 if (network_quality_estimator_) {
385 // TODO(dougarnett): Add UMA for quality type experienced.
386 net::EffectiveConnectionType quality =
387 network_quality_estimator_->GetEffectiveConnectionType();
388 if (quality < net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_2G) {
389 return;
390 }
391 } else if (GetConnectionType() ==
392 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) {
393 return;
394 }
381 395
382 if ((connection != 396 // Start processing with manufactured conservative battery conditions
383 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE)) { 397 // (i.e., assume no battery).
384 // Create conservative device conditions for the connectivity 398 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java).
385 // (assume no battery). 399 DeviceConditions device_conditions(false, 0, GetConnectionType());
386 DeviceConditions device_conditions(false, 0, connection); 400 StartProcessing(device_conditions, base::Bind(&EmptySchedulerCallback));
387 StartProcessing(device_conditions, base::Bind(&EmptySchedulerCallback));
388 }
389 } 401 }
390 402
391 void RequestCoordinator::TryNextRequest() { 403 void RequestCoordinator::TryNextRequest() {
392 // If there is no time left in the budget, return to the scheduler. 404 // If there is no time left in the budget, return to the scheduler.
393 // We do not remove the pending task that was set up earlier in case 405 // We do not remove the pending task that was set up earlier in case
394 // we run out of time, so the background scheduler will return to us 406 // we run out of time, so the background scheduler will return to us
395 // at the next opportunity to run background tasks. 407 // at the next opportunity to run background tasks.
396 if (base::Time::Now() - operation_start_time_ > 408 if (base::Time::Now() - operation_start_time_ >
397 base::TimeDelta::FromSeconds( 409 base::TimeDelta::FromSeconds(
398 policy_->GetBackgroundProcessingTimeBudgetSeconds())) { 410 policy_->GetBackgroundProcessingTimeBudgetSeconds())) {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 void RequestCoordinator::NotifyChanged(const SavePageRequest& request) { 593 void RequestCoordinator::NotifyChanged(const SavePageRequest& request) {
582 FOR_EACH_OBSERVER(Observer, observers_, OnChanged(request)); 594 FOR_EACH_OBSERVER(Observer, observers_, OnChanged(request));
583 } 595 }
584 596
585 void RequestCoordinator::GetOffliner() { 597 void RequestCoordinator::GetOffliner() {
586 if (!offliner_) { 598 if (!offliner_) {
587 offliner_ = factory_->GetOffliner(policy_.get()); 599 offliner_ = factory_->GetOffliner(policy_.get());
588 } 600 }
589 } 601 }
590 602
603 void RequestCoordinator::Shutdown() {
604 network_quality_estimator_ = nullptr;
605 }
606
591 } // namespace offline_pages 607 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698