OLD | NEW |
---|---|
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 Loading... | |
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* nqe) | |
82 : is_busy_(false), | 84 : is_busy_(false), |
83 is_starting_(false), | 85 is_starting_(false), |
84 is_stopped_(false), | 86 is_stopped_(false), |
85 use_test_connection_type_(false), | 87 use_test_connection_type_(false), |
86 test_connection_type_(), | 88 test_connection_type_(), |
87 offliner_(nullptr), | 89 offliner_(nullptr), |
88 policy_(std::move(policy)), | 90 policy_(std::move(policy)), |
89 factory_(std::move(factory)), | 91 factory_(std::move(factory)), |
90 queue_(std::move(queue)), | 92 queue_(std::move(queue)), |
91 scheduler_(std::move(scheduler)), | 93 scheduler_(std::move(scheduler)), |
94 nqe_(nqe), | |
92 active_request_(nullptr), | 95 active_request_(nullptr), |
93 last_offlining_status_(Offliner::RequestStatus::UNKNOWN), | 96 last_offlining_status_(Offliner::RequestStatus::UNKNOWN), |
94 offliner_timeout_(base::TimeDelta::FromSeconds( | 97 offliner_timeout_(base::TimeDelta::FromSeconds( |
95 policy_->GetSinglePageTimeLimitInSeconds())), | 98 policy_->GetSinglePageTimeLimitInSeconds())), |
96 weak_ptr_factory_(this) { | 99 weak_ptr_factory_(this) { |
97 DCHECK(policy_ != nullptr); | 100 DCHECK(policy_ != nullptr); |
98 picker_.reset( | 101 picker_.reset( |
99 new RequestPicker(queue_.get(), policy_.get(), this, &event_logger_)); | 102 new RequestPicker(queue_.get(), policy_.get(), this, &event_logger_)); |
100 } | 103 } |
101 | 104 |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
363 | 366 |
364 is_stopped_ = false; | 367 is_stopped_ = false; |
365 scheduler_callback_ = callback; | 368 scheduler_callback_ = callback; |
366 | 369 |
367 TryNextRequest(); | 370 TryNextRequest(); |
368 | 371 |
369 return true; | 372 return true; |
370 } | 373 } |
371 | 374 |
372 void RequestCoordinator::StartProcessingIfConnected() { | 375 void RequestCoordinator::StartProcessingIfConnected() { |
373 // Makes sure not already busy processing. | 376 // Make sure not already busy processing. |
374 if (is_busy_) return; | 377 if (is_busy_) return; |
375 | 378 |
376 // Make sure we are not on svelte device to start immediately. | 379 // Make sure we are not on svelte device to start immediately. |
377 if (base::SysInfo::IsLowEndDevice()) return; | 380 if (base::SysInfo::IsLowEndDevice()) return; |
378 | 381 |
379 // Check for network connectivity. | 382 // Make sure we have reasonable network quality. |
380 net::NetworkChangeNotifier::ConnectionType connection = GetConnectionType(); | 383 if (nqe_) { |
381 | 384 // TODO(dougarnett): Add UMA for quality type experienced. |
382 if ((connection != | 385 net::EffectiveConnectionType quality = nqe_->GetEffectiveConnectionType(); |
383 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE)) { | 386 if (quality >= net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_2G) { |
tbansal1
2016/09/16 22:05:55
nit: I kind of liked it the old way
if(quality < n
Pete Williamson
2016/09/16 22:26:01
This excludes EFFECTIVE_CONNECTION_TYPE_SLOW_2G.
dougarnett
2016/09/19 19:34:32
Key question. Yes, as a starting point I am thinki
dougarnett
2016/09/19 19:34:32
Yeah, this was due to taking out the basic network
| |
384 // Create conservative device conditions for the connectivity | 387 // Start processing with manufactured conservative battery conditions |
385 // (assume no battery). | 388 // (i.e., assume no battery). |
386 DeviceConditions device_conditions(false, 0, connection); | 389 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java). |
387 StartProcessing(device_conditions, base::Bind(&EmptySchedulerCallback)); | 390 DeviceConditions device_conditions(false, 0, GetConnectionType()); |
391 StartProcessing(device_conditions, base::Bind(&EmptySchedulerCallback)); | |
392 } | |
388 } | 393 } |
389 } | 394 } |
390 | 395 |
391 void RequestCoordinator::TryNextRequest() { | 396 void RequestCoordinator::TryNextRequest() { |
392 // If there is no time left in the budget, return to the scheduler. | 397 // 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 | 398 // 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 | 399 // we run out of time, so the background scheduler will return to us |
395 // at the next opportunity to run background tasks. | 400 // at the next opportunity to run background tasks. |
396 if (base::Time::Now() - operation_start_time_ > | 401 if (base::Time::Now() - operation_start_time_ > |
397 base::TimeDelta::FromSeconds( | 402 base::TimeDelta::FromSeconds( |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
581 void RequestCoordinator::NotifyChanged(const SavePageRequest& request) { | 586 void RequestCoordinator::NotifyChanged(const SavePageRequest& request) { |
582 FOR_EACH_OBSERVER(Observer, observers_, OnChanged(request)); | 587 FOR_EACH_OBSERVER(Observer, observers_, OnChanged(request)); |
583 } | 588 } |
584 | 589 |
585 void RequestCoordinator::GetOffliner() { | 590 void RequestCoordinator::GetOffliner() { |
586 if (!offliner_) { | 591 if (!offliner_) { |
587 offliner_ = factory_->GetOffliner(policy_.get()); | 592 offliner_ = factory_->GetOffliner(policy_.get()); |
588 } | 593 } |
589 } | 594 } |
590 | 595 |
596 void RequestCoordinator::Shutdown() { | |
597 nqe_ = nullptr; | |
598 } | |
599 | |
591 } // namespace offline_pages | 600 } // namespace offline_pages |
OLD | NEW |