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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 | 364 |
365 is_stopped_ = false; | 365 is_stopped_ = false; |
366 scheduler_callback_ = callback; | 366 scheduler_callback_ = callback; |
367 | 367 |
368 TryNextRequest(); | 368 TryNextRequest(); |
369 | 369 |
370 return true; | 370 return true; |
371 } | 371 } |
372 | 372 |
373 void RequestCoordinator::StartProcessingIfConnected() { | 373 void RequestCoordinator::StartProcessingIfConnected() { |
374 OfflinerImmediateStartStatus immediate_start_status = TryImmediateStart(); | |
375 UMA_HISTOGRAM_ENUMERATION( | |
376 "OfflinePages.Background.ImmediateStartStatus", | |
377 static_cast<int>(immediate_start_status), | |
Mark P
2016/10/06 18:54:41
Do you need static_casts here? I've never seen an
dougarnett
2016/10/06 23:05:00
Needed for scoped enums ("enum class"). Switched t
| |
378 static_cast<int>( | |
379 RequestCoordinator::OfflinerImmediateStartStatus::STATUS_COUNT)); | |
380 } | |
381 | |
382 RequestCoordinator::OfflinerImmediateStartStatus | |
383 RequestCoordinator::TryImmediateStart() { | |
374 // Make sure not already busy processing. | 384 // Make sure not already busy processing. |
375 if (is_busy_) return; | 385 if (is_busy_) |
386 return OfflinerImmediateStartStatus::BUSY; | |
376 | 387 |
377 // Make sure we are not on svelte device to start immediately. | 388 // Make sure we are not on svelte device to start immediately. |
378 if (base::SysInfo::IsLowEndDevice()) return; | 389 if (base::SysInfo::IsLowEndDevice()) |
390 return OfflinerImmediateStartStatus::NOT_STARTED_ON_SVELTE; | |
379 | 391 |
380 // Make sure we have reasonable network quality (or at least a connection). | 392 // Make sure we have reasonable network quality (or at least a connection). |
381 if (network_quality_estimator_) { | 393 if (network_quality_estimator_) { |
382 // TODO(dougarnett): Add UMA for quality type experienced. | 394 // TODO(dougarnett): Add UMA for quality type experienced. |
383 net::EffectiveConnectionType quality = | 395 net::EffectiveConnectionType quality = |
384 network_quality_estimator_->GetEffectiveConnectionType(); | 396 network_quality_estimator_->GetEffectiveConnectionType(); |
385 if (quality < net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_2G) { | 397 if (quality < net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_2G) |
386 return; | 398 return OfflinerImmediateStartStatus::NO_EFFECTIVE_CONNECTION; |
387 } | |
388 } else if (GetConnectionType() == | 399 } else if (GetConnectionType() == |
389 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) { | 400 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) { |
390 return; | 401 return OfflinerImmediateStartStatus::NO_CONNECTION; |
391 } | 402 } |
392 | 403 |
393 // Start processing with manufactured conservative battery conditions | 404 // Start processing with manufactured conservative battery conditions |
394 // (i.e., assume no battery). | 405 // (i.e., assume no battery). |
395 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java). | 406 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java). |
396 DeviceConditions device_conditions(false, 0, GetConnectionType()); | 407 DeviceConditions device_conditions(false, 0, GetConnectionType()); |
397 StartProcessing(device_conditions, base::Bind(&EmptySchedulerCallback)); | 408 if (StartProcessing(device_conditions, base::Bind(&EmptySchedulerCallback))) |
409 return OfflinerImmediateStartStatus::STARTED; | |
410 else | |
411 return OfflinerImmediateStartStatus::NOT_ACCEPTED; | |
398 } | 412 } |
399 | 413 |
400 void RequestCoordinator::TryNextRequest() { | 414 void RequestCoordinator::TryNextRequest() { |
401 // If there is no time left in the budget, return to the scheduler. | 415 // If there is no time left in the budget, return to the scheduler. |
402 // We do not remove the pending task that was set up earlier in case | 416 // We do not remove the pending task that was set up earlier in case |
403 // we run out of time, so the background scheduler will return to us | 417 // we run out of time, so the background scheduler will return to us |
404 // at the next opportunity to run background tasks. | 418 // at the next opportunity to run background tasks. |
405 if (base::Time::Now() - operation_start_time_ > | 419 if (base::Time::Now() - operation_start_time_ > |
406 base::TimeDelta::FromSeconds( | 420 base::TimeDelta::FromSeconds( |
407 policy_->GetBackgroundProcessingTimeBudgetSeconds())) { | 421 policy_->GetBackgroundProcessingTimeBudgetSeconds())) { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
599 if (!offliner_) { | 613 if (!offliner_) { |
600 offliner_ = factory_->GetOffliner(policy_.get()); | 614 offliner_ = factory_->GetOffliner(policy_.get()); |
601 } | 615 } |
602 } | 616 } |
603 | 617 |
604 void RequestCoordinator::Shutdown() { | 618 void RequestCoordinator::Shutdown() { |
605 network_quality_estimator_ = nullptr; | 619 network_quality_estimator_ = nullptr; |
606 } | 620 } |
607 | 621 |
608 } // namespace offline_pages | 622 } // namespace offline_pages |
OLD | NEW |