Chromium Code Reviews| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 14 #include "base/sys_info.h" | 14 #include "base/sys_info.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "components/offline_pages/background/offliner_factory.h" | 16 #include "components/offline_pages/background/offliner_factory.h" |
| 17 #include "components/offline_pages/background/offliner_policy.h" | 17 #include "components/offline_pages/background/offliner_policy.h" |
| 18 #include "components/offline_pages/background/request_picker.h" | 18 #include "components/offline_pages/background/request_picker.h" |
| 19 #include "components/offline_pages/background/save_page_request.h" | 19 #include "components/offline_pages/background/save_page_request.h" |
| 20 #include "components/offline_pages/offline_page_item.h" | 20 #include "components/offline_pages/offline_page_item.h" |
| 21 #include "components/offline_pages/offline_page_model.h" | 21 #include "components/offline_pages/offline_page_model.h" |
| 22 | 22 |
| 23 namespace offline_pages { | 23 namespace offline_pages { |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 const bool kUserRequest = true; | 26 const bool kUserRequest = true; |
| 27 | 27 |
| 28 enum class OfflinerImmediateStartStatus { | |
| 29 BUSY, | |
|
fgorski
2016/10/05 21:46:13
Can you reorder these two?
Almost feels like it s
dougarnett
2016/10/05 22:28:14
Done.
| |
| 30 STARTED, | |
| 31 NOT_ACCEPTED, | |
| 32 NO_CONNECTION, | |
| 33 NO_EFFECTIVE_CONNECTION, | |
| 34 NOT_STARTED_ON_SVELTE, | |
| 35 // NOTE: insert new values above this line and update histogram enum too. | |
| 36 STATUS_COUNT, | |
| 37 }; | |
| 38 | |
| 39 void RecordImmediateStart(OfflinerImmediateStartStatus immediate_start_status) { | |
| 40 UMA_HISTOGRAM_ENUMERATION( | |
| 41 "OfflinePages.Background.ImmediateStartStatus", | |
| 42 static_cast<int>(immediate_start_status), | |
|
fgorski
2016/10/05 21:46:13
holte@: should be using int vs. int32_t here? I ha
dougarnett
2016/10/05 22:28:15
Pete just had CL that used int so followed that ex
| |
| 43 static_cast<int>(OfflinerImmediateStartStatus::STATUS_COUNT)); | |
| 44 } | |
| 45 | |
| 28 // Records the final request status UMA for an offlining request. This should | 46 // Records the final request status UMA for an offlining request. This should |
| 29 // only be called once per Offliner::LoadAndSave request. | 47 // only be called once per Offliner::LoadAndSave request. |
| 30 void RecordOfflinerResultUMA(const ClientId& client_id, | 48 void RecordOfflinerResultUMA(const ClientId& client_id, |
| 31 Offliner::RequestStatus request_status) { | 49 Offliner::RequestStatus request_status) { |
| 32 // TODO(dougarnett): Consider exposing AddHistogramSuffix from | 50 // TODO(dougarnett): Consider exposing AddHistogramSuffix from |
| 33 // offline_page_model_impl.cc as visible utility method. | 51 // offline_page_model_impl.cc as visible utility method. |
| 34 std::string histogram_name("OfflinePages.Background.OfflinerRequestStatus"); | 52 std::string histogram_name("OfflinePages.Background.OfflinerRequestStatus"); |
| 35 if (!client_id.name_space.empty()) { | 53 if (!client_id.name_space.empty()) { |
| 36 histogram_name += "." + client_id.name_space; | 54 histogram_name += "." + client_id.name_space; |
| 37 } | 55 } |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 operation_start_time_ = base::Time::Now(); | 381 operation_start_time_ = base::Time::Now(); |
| 364 | 382 |
| 365 is_stopped_ = false; | 383 is_stopped_ = false; |
| 366 scheduler_callback_ = callback; | 384 scheduler_callback_ = callback; |
| 367 | 385 |
| 368 TryNextRequest(); | 386 TryNextRequest(); |
| 369 | 387 |
| 370 return true; | 388 return true; |
| 371 } | 389 } |
| 372 | 390 |
| 373 void RequestCoordinator::StartProcessingIfConnected() { | 391 void RequestCoordinator::StartProcessingIfConnected() { |
|
Pete Williamson
2016/10/05 21:51:53
Would it be better to have StartProcessingIfConnec
dougarnett
2016/10/05 22:28:14
It is called in two places - so capture UMA in bot
Pete Williamson
2016/10/05 22:45:03
I'm happy if you want to improve this later in M55
dougarnett
2016/10/05 23:20:37
I tried wrapper - see if you like it better.
| |
| 374 // Make sure not already busy processing. | 392 // Make sure not already busy processing. |
| 375 if (is_busy_) return; | 393 if (is_busy_) { |
| 394 RecordImmediateStart(OfflinerImmediateStartStatus::BUSY); | |
| 395 return; | |
| 396 } | |
| 376 | 397 |
| 377 // Make sure we are not on svelte device to start immediately. | 398 // Make sure we are not on svelte device to start immediately. |
| 378 if (base::SysInfo::IsLowEndDevice()) return; | 399 if (base::SysInfo::IsLowEndDevice()) { |
| 400 RecordImmediateStart(OfflinerImmediateStartStatus::NOT_STARTED_ON_SVELTE); | |
|
fgorski
2016/10/05 21:46:13
Just a thought: If you make this check above, you
dougarnett
2016/10/05 22:28:14
Happens anyway as far as unique devices goes on fi
| |
| 401 return; | |
| 402 } | |
| 379 | 403 |
| 380 // Make sure we have reasonable network quality (or at least a connection). | 404 // Make sure we have reasonable network quality (or at least a connection). |
| 381 if (network_quality_estimator_) { | 405 if (network_quality_estimator_) { |
| 382 // TODO(dougarnett): Add UMA for quality type experienced. | 406 // TODO(dougarnett): Add UMA for quality type experienced. |
| 383 net::EffectiveConnectionType quality = | 407 net::EffectiveConnectionType quality = |
| 384 network_quality_estimator_->GetEffectiveConnectionType(); | 408 network_quality_estimator_->GetEffectiveConnectionType(); |
| 385 if (quality < net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_2G) { | 409 if (quality < net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_2G) { |
| 410 RecordImmediateStart( | |
| 411 OfflinerImmediateStartStatus::NO_EFFECTIVE_CONNECTION); | |
| 386 return; | 412 return; |
| 387 } | 413 } |
| 388 } else if (GetConnectionType() == | 414 } else if (GetConnectionType() == |
| 389 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) { | 415 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) { |
| 416 RecordImmediateStart(OfflinerImmediateStartStatus::NO_CONNECTION); | |
| 390 return; | 417 return; |
| 391 } | 418 } |
| 392 | 419 |
| 393 // Start processing with manufactured conservative battery conditions | 420 // Start processing with manufactured conservative battery conditions |
| 394 // (i.e., assume no battery). | 421 // (i.e., assume no battery). |
| 395 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java). | 422 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java). |
| 396 DeviceConditions device_conditions(false, 0, GetConnectionType()); | 423 DeviceConditions device_conditions(false, 0, GetConnectionType()); |
| 397 StartProcessing(device_conditions, base::Bind(&EmptySchedulerCallback)); | 424 if (StartProcessing(device_conditions, base::Bind(&EmptySchedulerCallback))) { |
|
fgorski
2016/10/05 21:46:13
nit: braces not needed
| |
| 425 RecordImmediateStart(OfflinerImmediateStartStatus::STARTED); | |
| 426 } else { | |
| 427 RecordImmediateStart(OfflinerImmediateStartStatus::NOT_ACCEPTED); | |
| 428 } | |
| 398 } | 429 } |
| 399 | 430 |
| 400 void RequestCoordinator::TryNextRequest() { | 431 void RequestCoordinator::TryNextRequest() { |
| 401 // If there is no time left in the budget, return to the scheduler. | 432 // 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 | 433 // 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 | 434 // we run out of time, so the background scheduler will return to us |
| 404 // at the next opportunity to run background tasks. | 435 // at the next opportunity to run background tasks. |
| 405 if (base::Time::Now() - operation_start_time_ > | 436 if (base::Time::Now() - operation_start_time_ > |
| 406 base::TimeDelta::FromSeconds( | 437 base::TimeDelta::FromSeconds( |
| 407 policy_->GetBackgroundProcessingTimeBudgetSeconds())) { | 438 policy_->GetBackgroundProcessingTimeBudgetSeconds())) { |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 597 if (!offliner_) { | 628 if (!offliner_) { |
| 598 offliner_ = factory_->GetOffliner(policy_.get()); | 629 offliner_ = factory_->GetOffliner(policy_.get()); |
| 599 } | 630 } |
| 600 } | 631 } |
| 601 | 632 |
| 602 void RequestCoordinator::Shutdown() { | 633 void RequestCoordinator::Shutdown() { |
| 603 network_quality_estimator_ = nullptr; | 634 network_quality_estimator_ = nullptr; |
| 604 } | 635 } |
| 605 | 636 |
| 606 } // namespace offline_pages | 637 } // namespace offline_pages |
| OLD | NEW |