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

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: 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 std::unique_ptr<net::NetworkQualityEstimator::NetworkQualityProvider>
84 network_quality_provider)
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 nqe_(std::move(network_quality_provider)),
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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 375
372 void RequestCoordinator::StartProcessingIfConnected() { 376 void RequestCoordinator::StartProcessingIfConnected() {
373 // Makes sure not already busy processing. 377 // Makes 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 // Check for network connectivity.
380 net::NetworkChangeNotifier::ConnectionType connection = GetConnectionType(); 384 net::NetworkChangeNotifier::ConnectionType connection = GetConnectionType();
385 if (connection == net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE)
tbansal1 2016/09/16 19:13:50 GetEffectiveConnection type will return E_C_T_OFFL
dougarnett 2016/09/16 21:24:42 Done.
386 return;
381 387
382 if ((connection != 388 // Check for reasonable network quality.
383 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE)) { 389 if (nqe_.get()) {
384 // Create conservative device conditions for the connectivity 390 // TODO(dougarnett): Add UMA for quality type experienced.
385 // (assume no battery). 391 net::EffectiveConnectionType quality = nqe_->GetEffectiveConnectionType();
386 DeviceConditions device_conditions(false, 0, connection); 392 if (quality < net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_2G)
RyanSturm 2016/09/16 18:54:46 Normally, we use Slow 2g instead of just 2g, I'm n
tbansal1 2016/09/16 19:13:50 Currently, the method returns if ECT enum is UNKNO
dougarnett 2016/09/16 21:24:42 So this linked code is for deciding to navigate to
RyanSturm 2016/09/19 17:15:40 Totally misread this chunk of code. Seems like the
387 StartProcessing(device_conditions, base::Bind(&EmptySchedulerCallback)); 393 return;
388 } 394 }
395
396 // Start processing with manufactured conservative device conditions for the
397 // connectivity (assume no battery).
398 // TODO(dougarnett): Obtain actual conditions (from Android/Java).
399 DeviceConditions device_conditions(false, 0, connection);
400 StartProcessing(device_conditions, base::Bind(&EmptySchedulerCallback));
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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
591 } // namespace offline_pages 603 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698