From 1bd4a950be946c149226979410c5cc934b1d8b47 Mon Sep 17 00:00:00 2001 From: tbansal Date: Tue, 6 Jun 2017 16:01:46 -0700 Subject: [PATCH] Make NQE a derived class of NetworkQualityProvider NetworkQualityProvider provides functions to get network quality metrics, and to listen to changes in the network quality. This CL changes Network Quality Estimator (NQE) to be an implementation of Network Quality Provider (NQP). Long term, this allows callers to depend only on NQP when they only need to read the network quality, while the heavy-weight NQE can be used in other cases. BUG=704339 CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.android:android_cronet_tester TBR=petewil@chromium.org Review-Url: https://codereview.chromium.org/2927453002 Cr-Commit-Position: refs/heads/master@{#477452} --- chrome/browser/io_thread.h | 4 +- .../ui_network_quality_estimator_service.cc | 20 +-- .../ui_network_quality_estimator_service.h | 38 ++--- ...k_quality_estimator_service_browsertest.cc | 12 +- ...ukm_page_load_metrics_observer_unittest.cc | 17 +- .../cronet_url_request_context_adapter.h | 6 +- .../metrics/net/network_metrics_provider.cc | 3 +- .../network_quality_provider_stub.cc | 14 -- .../network_quality_provider_stub.h | 23 +-- .../net/network_quality_observer_impl.cc | 3 +- .../net/network_quality_observer_impl.h | 18 ++- .../network_quality_observer_factory.h | 9 +- net/BUILD.gn | 4 + net/nqe/effective_connection_type_observer.h | 41 +++++ net/nqe/network_quality_estimator.cc | 35 +++-- net/nqe/network_quality_estimator.h | 147 ++---------------- net/nqe/network_quality_estimator_unittest.cc | 28 +++- net/nqe/network_quality_provider.cc | 23 +++ net/nqe/network_quality_provider.h | 81 ++++++++++ net/nqe/rtt_throughput_estimates_observer.h | 48 ++++++ 20 files changed, 316 insertions(+), 258 deletions(-) create mode 100644 net/nqe/effective_connection_type_observer.h create mode 100644 net/nqe/network_quality_provider.cc create mode 100644 net/nqe/network_quality_provider.h create mode 100644 net/nqe/rtt_throughput_estimates_observer.h diff --git a/chrome/browser/io_thread.h b/chrome/browser/io_thread.h index 4f2db705cfc892..0797746a7d7576 100644 --- a/chrome/browser/io_thread.h +++ b/chrome/browser/io_thread.h @@ -83,6 +83,7 @@ class HttpAuthPreferences; class LoggingNetworkChangeObserver; class NetworkQualityEstimator; class ProxyConfigService; +class RTTAndThroughputEstimatesObserver; class SSLConfigService; class URLRequestContext; class URLRequestContextGetter; @@ -154,8 +155,7 @@ class IOThread : public content::BrowserThreadDelegate { #endif std::unique_ptr host_mapping_rules; std::unique_ptr network_quality_estimator; - std::unique_ptr< - net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver> + std::unique_ptr network_quality_observer; // NetErrorTabHelper uses |dns_probe_service| to send DNS probes when a diff --git a/chrome/browser/net/nqe/ui_network_quality_estimator_service.cc b/chrome/browser/net/nqe/ui_network_quality_estimator_service.cc index a13b2c3c923728..a118d4e7f3eca2 100644 --- a/chrome/browser/net/nqe/ui_network_quality_estimator_service.cc +++ b/chrome/browser/net/nqe/ui_network_quality_estimator_service.cc @@ -20,8 +20,10 @@ #include "components/prefs/pref_service.h" #include "components/variations/variations_associated_data.h" #include "content/public/browser/browser_thread.h" +#include "net/nqe/effective_connection_type_observer.h" #include "net/nqe/network_qualities_prefs_manager.h" #include "net/nqe/network_quality.h" +#include "net/nqe/rtt_throughput_estimates_observer.h" namespace { @@ -81,8 +83,8 @@ void SetNQEOnIOThread(net::NetworkQualitiesPrefsManager* prefs_manager, // to the UI service. // It is created on the UI thread, but used and deleted on the IO thread. class UINetworkQualityEstimatorService::IONetworkQualityObserver - : public net::NetworkQualityEstimator::EffectiveConnectionTypeObserver, - public net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver { + : public net::EffectiveConnectionTypeObserver, + public net::RTTAndThroughputEstimatesObserver { public: explicit IONetworkQualityObserver( base::WeakPtr service) @@ -221,7 +223,7 @@ void UINetworkQualityEstimatorService::RTTOrThroughputComputed( } void UINetworkQualityEstimatorService::AddEffectiveConnectionTypeObserver( - net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) { + net::EffectiveConnectionTypeObserver* observer) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); effective_connection_type_observer_list_.AddObserver(observer); @@ -235,7 +237,7 @@ void UINetworkQualityEstimatorService::AddEffectiveConnectionTypeObserver( } void UINetworkQualityEstimatorService::RemoveEffectiveConnectionTypeObserver( - net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) { + net::EffectiveConnectionTypeObserver* observer) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); effective_connection_type_observer_list_.RemoveObserver(observer); } @@ -268,7 +270,7 @@ UINetworkQualityEstimatorService::GetDownstreamThroughputKbps() const { } void UINetworkQualityEstimatorService::AddRTTAndThroughputEstimatesObserver( - net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver* observer) { + net::RTTAndThroughputEstimatesObserver* observer) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); rtt_throughput_observer_list_.AddObserver(observer); @@ -284,7 +286,7 @@ void UINetworkQualityEstimatorService::AddRTTAndThroughputEstimatesObserver( // Removes |observer| from the list of RTT and throughput estimate observers. // Must be called on the IO thread. void UINetworkQualityEstimatorService::RemoveRTTAndThroughputEstimatesObserver( - net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver* observer) { + net::RTTAndThroughputEstimatesObserver* observer) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); rtt_throughput_observer_list_.RemoveObserver(observer); } @@ -310,8 +312,7 @@ void UINetworkQualityEstimatorService::ClearPrefs() { void UINetworkQualityEstimatorService:: NotifyEffectiveConnectionTypeObserverIfPresent( - net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) - const { + net::EffectiveConnectionTypeObserver* observer) const { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); if (!effective_connection_type_observer_list_.HasObserver(observer)) @@ -322,8 +323,7 @@ void UINetworkQualityEstimatorService:: } void UINetworkQualityEstimatorService::NotifyRTTAndThroughputObserverIfPresent( - net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver* observer) - const { + net::RTTAndThroughputEstimatesObserver* observer) const { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); if (!rtt_throughput_observer_list_.HasObserver(observer)) diff --git a/chrome/browser/net/nqe/ui_network_quality_estimator_service.h b/chrome/browser/net/nqe/ui_network_quality_estimator_service.h index 128456a51700ba..20eacc0d98ebf5 100644 --- a/chrome/browser/net/nqe/ui_network_quality_estimator_service.h +++ b/chrome/browser/net/nqe/ui_network_quality_estimator_service.h @@ -24,7 +24,9 @@ class PrefRegistrySimple; class Profile; namespace net { +class EffectiveConnectionTypeObserver; class NetworkQualitiesPrefsManager; +class RTTAndThroughputEstimatesObserver; } // UI service to determine the current EffectiveConnectionType. @@ -38,33 +40,17 @@ class UINetworkQualityEstimatorService // NetworkQualityProvider implementation: // Must be called on the UI thread. net::EffectiveConnectionType GetEffectiveConnectionType() const override; - // Must be called on the UI thread. |observer| will be notified on the UI - // thread. |observer| would be notified of the current effective connection - // type in the next message pump. void AddEffectiveConnectionTypeObserver( - net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) - override; - // Must be called on the UI thread. + net::EffectiveConnectionTypeObserver* observer) override; void RemoveEffectiveConnectionTypeObserver( - net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) - override; + net::EffectiveConnectionTypeObserver* observer) override; base::Optional GetHttpRTT() const override; base::Optional GetTransportRTT() const override; base::Optional GetDownstreamThroughputKbps() const override; - - // Must be called on the UI thread. |observer| will be notified on the UI - // thread. |observer| would be notified of the changes in the HTTP RTT, - // transport RTT or throughput. |observer| would be notified of the current - // values in the next message pump. void AddRTTAndThroughputEstimatesObserver( - net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver* observer) - override; - - // Removes |observer| from the list of RTT and throughput estimate observers. - // Must be called on the UI thread. + net::RTTAndThroughputEstimatesObserver* observer) override; void RemoveRTTAndThroughputEstimatesObserver( - net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver* observer) - override; + net::RTTAndThroughputEstimatesObserver* observer) override; // Registers the profile-specific network quality estimator prefs. static void RegisterProfilePrefs(PrefRegistrySimple* registry); @@ -88,14 +74,12 @@ class UINetworkQualityEstimatorService // Notifies |observer| of the current effective connection type if |observer| // is still registered as an observer. void NotifyEffectiveConnectionTypeObserverIfPresent( - net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) - const; + net::EffectiveConnectionTypeObserver* observer) const; // Notifies |observer| of the current effective connection type if |observer| // is still registered as an observer. void NotifyRTTAndThroughputObserverIfPresent( - net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver* observer) - const; + net::RTTAndThroughputEstimatesObserver* observer) const; // KeyedService implementation: void Shutdown() override; @@ -125,13 +109,11 @@ class UINetworkQualityEstimatorService std::unique_ptr io_observer_; // Observer list for changes in effective connection type. - base::ObserverList< - net::NetworkQualityEstimator::EffectiveConnectionTypeObserver> + base::ObserverList effective_connection_type_observer_list_; // Observer list for changes in RTT or throughput values. - base::ObserverList< - net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver> + base::ObserverList rtt_throughput_observer_list_; // Prefs manager that is owned by this service. Created on the UI thread, but diff --git a/chrome/browser/net/nqe/ui_network_quality_estimator_service_browsertest.cc b/chrome/browser/net/nqe/ui_network_quality_estimator_service_browsertest.cc index 72d41e6034b411..5bd551167ff536 100644 --- a/chrome/browser/net/nqe/ui_network_quality_estimator_service_browsertest.cc +++ b/chrome/browser/net/nqe/ui_network_quality_estimator_service_browsertest.cc @@ -23,8 +23,10 @@ #include "net/base/network_change_notifier.h" #include "net/nqe/cached_network_quality.h" #include "net/nqe/effective_connection_type.h" +#include "net/nqe/effective_connection_type_observer.h" #include "net/nqe/network_id.h" #include "net/nqe/network_quality_estimator.h" +#include "net/nqe/rtt_throughput_estimates_observer.h" #include "testing/gtest/include/gtest/gtest.h" class Profile; @@ -32,14 +34,13 @@ class Profile; namespace { class TestEffectiveConnectionTypeObserver - : public net::NetworkQualityEstimator::EffectiveConnectionTypeObserver { + : public net::EffectiveConnectionTypeObserver { public: TestEffectiveConnectionTypeObserver() : effective_connection_type_(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {} ~TestEffectiveConnectionTypeObserver() override {} - // net::NetworkQualityEstimator::EffectiveConnectionTypeObserver - // implementation: + // net::EffectiveConnectionTypeObserver implementation: void OnEffectiveConnectionTypeChanged( net::EffectiveConnectionType type) override { effective_connection_type_ = type; @@ -57,7 +58,7 @@ class TestEffectiveConnectionTypeObserver }; class TestRTTAndThroughputEstimatesObserver - : public net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver { + : public net::RTTAndThroughputEstimatesObserver { public: TestRTTAndThroughputEstimatesObserver() : http_rtt_(base::TimeDelta::FromMilliseconds(-1)), @@ -65,8 +66,7 @@ class TestRTTAndThroughputEstimatesObserver downstream_throughput_kbps_(-1) {} ~TestRTTAndThroughputEstimatesObserver() override {} - // net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver - // implementation: + // net::RTTAndThroughputEstimatesObserver implementation: void OnRTTOrThroughputEstimatesComputed( base::TimeDelta http_rtt, base::TimeDelta transport_rtt, diff --git a/chrome/browser/page_load_metrics/observers/ukm_page_load_metrics_observer_unittest.cc b/chrome/browser/page_load_metrics/observers/ukm_page_load_metrics_observer_unittest.cc index f862f1c6d230f1..d71a3de5175449 100644 --- a/chrome/browser/page_load_metrics/observers/ukm_page_load_metrics_observer_unittest.cc +++ b/chrome/browser/page_load_metrics/observers/ukm_page_load_metrics_observer_unittest.cc @@ -12,6 +12,8 @@ #include "chrome/test/base/testing_browser_process.h" #include "components/ukm/test_ukm_recorder.h" #include "components/ukm/ukm_source.h" +#include "net/nqe/effective_connection_type.h" +#include "net/nqe/network_quality_provider.h" #include "testing/gmock/include/gmock/gmock.h" using testing::AnyNumber; @@ -23,25 +25,12 @@ namespace { const char kTestUrl1[] = "https://www.google.com/"; const char kTestUrl2[] = "https://www.example.com/"; -class MockNetworkQualityProvider - : public net::NetworkQualityEstimator::NetworkQualityProvider { +class MockNetworkQualityProvider : public net::NetworkQualityProvider { public: MOCK_CONST_METHOD0(GetEffectiveConnectionType, net::EffectiveConnectionType()); MOCK_CONST_METHOD0(GetHttpRTT, base::Optional()); MOCK_CONST_METHOD0(GetTransportRTT, base::Optional()); - MOCK_METHOD1( - AddEffectiveConnectionTypeObserver, - void(net::NetworkQualityEstimator::EffectiveConnectionTypeObserver*)); - MOCK_METHOD1( - RemoveEffectiveConnectionTypeObserver, - void(net::NetworkQualityEstimator::EffectiveConnectionTypeObserver*)); - MOCK_METHOD1( - AddRTTAndThroughputEstimatesObserver, - void(net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver*)); - MOCK_METHOD1( - RemoveRTTAndThroughputEstimatesObserver, - void(net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver*)); }; } // namespace diff --git a/components/cronet/android/cronet_url_request_context_adapter.h b/components/cronet/android/cronet_url_request_context_adapter.h index b90874ab8dc822..0a94920717ca97 100644 --- a/components/cronet/android/cronet_url_request_context_adapter.h +++ b/components/cronet/android/cronet_url_request_context_adapter.h @@ -19,8 +19,10 @@ #include "base/threading/thread.h" #include "components/prefs/json_pref_store.h" #include "net/nqe/effective_connection_type.h" +#include "net/nqe/effective_connection_type_observer.h" #include "net/nqe/network_quality_estimator.h" #include "net/nqe/network_quality_observation_source.h" +#include "net/nqe/rtt_throughput_estimates_observer.h" class PrefService; @@ -48,8 +50,8 @@ bool CronetUrlRequestContextAdapterRegisterJni(JNIEnv* env); // Adapter between Java CronetUrlRequestContext and net::URLRequestContext. class CronetURLRequestContextAdapter - : public net::NetworkQualityEstimator::EffectiveConnectionTypeObserver, - public net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver, + : public net::EffectiveConnectionTypeObserver, + public net::RTTAndThroughputEstimatesObserver, public net::NetworkQualityEstimator::RTTObserver, public net::NetworkQualityEstimator::ThroughputObserver { public: diff --git a/components/metrics/net/network_metrics_provider.cc b/components/metrics/net/network_metrics_provider.cc index cd2f4f5b0f37c3..643b4ae558aa54 100644 --- a/components/metrics/net/network_metrics_provider.cc +++ b/components/metrics/net/network_metrics_provider.cc @@ -21,6 +21,7 @@ #include "base/threading/thread_task_runner_handle.h" #include "build/build_config.h" #include "net/base/net_errors.h" +#include "net/nqe/effective_connection_type_observer.h" #include "net/nqe/network_quality_estimator.h" #if defined(OS_CHROMEOS) @@ -45,7 +46,7 @@ void GetAndSetNetworkQualityEstimator( // Listens to the changes in the effective conection type. class NetworkMetricsProvider::EffectiveConnectionTypeObserver - : public net::NetworkQualityEstimator::EffectiveConnectionTypeObserver { + : public net::EffectiveConnectionTypeObserver { public: // |network_quality_estimator| is used to provide the network quality // estimates. Guaranteed to be non-null. |callback| is run on diff --git a/components/offline_pages/core/background/network_quality_provider_stub.cc b/components/offline_pages/core/background/network_quality_provider_stub.cc index 9c5cf28f00f5b2..168d277e09a7ef 100644 --- a/components/offline_pages/core/background/network_quality_provider_stub.cc +++ b/components/offline_pages/core/background/network_quality_provider_stub.cc @@ -30,20 +30,6 @@ void NetworkQualityProviderStub::SetUserData( supports_user_data->SetUserData(&kOfflineNQPKey, std::move(stub)); } -void NetworkQualityProviderStub::AddEffectiveConnectionTypeObserver( - net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) {} - -void NetworkQualityProviderStub::RemoveEffectiveConnectionTypeObserver( - net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) {} - -void NetworkQualityProviderStub::AddRTTAndThroughputEstimatesObserver( - net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver* observer) { -} - -void NetworkQualityProviderStub::RemoveRTTAndThroughputEstimatesObserver( - net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver* observer) { -} - net::EffectiveConnectionType NetworkQualityProviderStub::GetEffectiveConnectionType() const { return connection_type_; diff --git a/components/offline_pages/core/background/network_quality_provider_stub.h b/components/offline_pages/core/background/network_quality_provider_stub.h index 54923f02392c1b..b6341b94f4e265 100644 --- a/components/offline_pages/core/background/network_quality_provider_stub.h +++ b/components/offline_pages/core/background/network_quality_provider_stub.h @@ -7,15 +7,14 @@ #include "base/supports_user_data.h" #include "net/nqe/effective_connection_type.h" -#include "net/nqe/network_quality_estimator.h" +#include "net/nqe/network_quality_provider.h" namespace offline_pages { // Test class stubbing out the functionality of NQE::NetworkQualityProvider. // It is only used for test support. -class NetworkQualityProviderStub - : public net::NetworkQualityEstimator::NetworkQualityProvider, - public base::SupportsUserData::Data { +class NetworkQualityProviderStub : public net::NetworkQualityProvider, + public base::SupportsUserData::Data { public: NetworkQualityProviderStub(); ~NetworkQualityProviderStub() override; @@ -27,22 +26,6 @@ class NetworkQualityProviderStub net::EffectiveConnectionType GetEffectiveConnectionType() const override; - void AddEffectiveConnectionTypeObserver( - net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) - override; - - void RemoveEffectiveConnectionTypeObserver( - net::NetworkQualityEstimator::EffectiveConnectionTypeObserver* observer) - override; - - void AddRTTAndThroughputEstimatesObserver( - net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver* observer) - override; - - void RemoveRTTAndThroughputEstimatesObserver( - net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver* observer) - override; - void SetEffectiveConnectionTypeForTest(net::EffectiveConnectionType type) { connection_type_ = type; } diff --git a/content/browser/net/network_quality_observer_impl.cc b/content/browser/net/network_quality_observer_impl.cc index b7da9886f644ca..1d871bc782bdb3 100644 --- a/content/browser/net/network_quality_observer_impl.cc +++ b/content/browser/net/network_quality_observer_impl.cc @@ -13,6 +13,7 @@ #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_types.h" #include "content/public/browser/render_process_host.h" +#include "net/nqe/network_quality_estimator.h" namespace { @@ -213,7 +214,7 @@ void NetworkQualityObserverImpl::OnRTTOrThroughputEstimatesComputed( last_notified_network_quality_)); } -std::unique_ptr +std::unique_ptr CreateNetworkQualityObserver( net::NetworkQualityEstimator* network_quality_estimator) { return base::MakeUnique( diff --git a/content/browser/net/network_quality_observer_impl.h b/content/browser/net/network_quality_observer_impl.h index 915ec17260be76..2c5a18188391d4 100644 --- a/content/browser/net/network_quality_observer_impl.h +++ b/content/browser/net/network_quality_observer_impl.h @@ -11,19 +11,25 @@ #include "base/macros.h" #include "base/threading/thread_checker.h" +#include "base/time/time.h" #include "content/common/content_export.h" #include "content/public/browser/network_quality_observer_factory.h" #include "net/nqe/effective_connection_type.h" +#include "net/nqe/effective_connection_type_observer.h" #include "net/nqe/network_quality.h" -#include "net/nqe/network_quality_estimator.h" +#include "net/nqe/rtt_throughput_estimates_observer.h" + +namespace net { +class NetworkQualityEstimator; +} namespace content { // Listens for changes to the network quality and manages sending updates to // each RenderProcess via mojo. class CONTENT_EXPORT NetworkQualityObserverImpl - : public net::NetworkQualityEstimator::EffectiveConnectionTypeObserver, - public net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver { + : public net::EffectiveConnectionTypeObserver, + public net::RTTAndThroughputEstimatesObserver { public: explicit NetworkQualityObserverImpl( net::NetworkQualityEstimator* network_quality_estimator); @@ -33,13 +39,11 @@ class CONTENT_EXPORT NetworkQualityObserverImpl private: class UiThreadObserver; - // net::NetworkQualityEstimator::EffectiveConnectionTypeObserver - // implementation: + // net::EffectiveConnectionTypeObserver implementation: void OnEffectiveConnectionTypeChanged( net::EffectiveConnectionType type) override; - // net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver - // implementation: + // net::RTTAndThroughputEstimatesObserver implementation: void OnRTTOrThroughputEstimatesComputed( base::TimeDelta http_rtt, base::TimeDelta transport_rtt, diff --git a/content/public/browser/network_quality_observer_factory.h b/content/public/browser/network_quality_observer_factory.h index b6102a0ba28edc..f0ae95b8059f0e 100644 --- a/content/public/browser/network_quality_observer_factory.h +++ b/content/public/browser/network_quality_observer_factory.h @@ -12,14 +12,17 @@ #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_types.h" #include "content/public/browser/render_process_host.h" -#include "net/nqe/network_quality_estimator.h" +#include "net/nqe/rtt_throughput_estimates_observer.h" + +namespace net { +class NetworkQualityEstimator; +} namespace content { // Creates network quality observer that listens for changes to the network // quality and manages sending updates to each RenderProcess. -CONTENT_EXPORT std::unique_ptr< - net::NetworkQualityEstimator::RTTAndThroughputEstimatesObserver> +CONTENT_EXPORT std::unique_ptr CreateNetworkQualityObserver( net::NetworkQualityEstimator* network_quality_estimator); diff --git a/net/BUILD.gn b/net/BUILD.gn index 48e955956e4ec0..7e94fbcdadc166 100644 --- a/net/BUILD.gn +++ b/net/BUILD.gn @@ -992,6 +992,7 @@ component("net") { "nqe/cached_network_quality.h", "nqe/effective_connection_type.cc", "nqe/effective_connection_type.h", + "nqe/effective_connection_type_observer.h", "nqe/event_creator.cc", "nqe/event_creator.h", "nqe/external_estimate_provider.h", @@ -1006,9 +1007,12 @@ component("net") { "nqe/network_quality_estimator_params.h", "nqe/network_quality_observation.h", "nqe/network_quality_observation_source.h", + "nqe/network_quality_provider.cc", + "nqe/network_quality_provider.h", "nqe/network_quality_store.cc", "nqe/network_quality_store.h", "nqe/observation_buffer.h", + "nqe/rtt_throughput_estimates_observer.h", "nqe/socket_watcher.cc", "nqe/socket_watcher.h", "nqe/socket_watcher_factory.cc", diff --git a/net/nqe/effective_connection_type_observer.h b/net/nqe/effective_connection_type_observer.h new file mode 100644 index 00000000000000..ba42b33deaad88 --- /dev/null +++ b/net/nqe/effective_connection_type_observer.h @@ -0,0 +1,41 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_NQE_NETWORK_QUALITY_EFFECTIVE_CONNECTION_TYPE_OBSERVER_H_ +#define NET_NQE_NETWORK_QUALITY_EFFECTIVE_CONNECTION_TYPE_OBSERVER_H_ + +#include "base/compiler_specific.h" +#include "base/macros.h" +#include "net/base/net_export.h" +#include "net/nqe/effective_connection_type.h" + +namespace net { + +// Observes changes in effective connection type. +class NET_EXPORT EffectiveConnectionTypeObserver { + public: + // Notifies the observer of a change in the effective connection type. + // NetworkQualityEstimator computes the effective connection type once in + // every interval of duration + // |effective_connection_type_recomputation_interval_|. Additionally, when + // there is a change in the connection type of the device, then the + // effective connection type is immediately recomputed. + // + // If the computed effective connection type is different from the + // previously notified effective connection type, then all the registered + // observers are notified of the new effective connection type. + virtual void OnEffectiveConnectionTypeChanged( + EffectiveConnectionType type) = 0; + + protected: + EffectiveConnectionTypeObserver() {} + virtual ~EffectiveConnectionTypeObserver() {} + + private: + DISALLOW_COPY_AND_ASSIGN(EffectiveConnectionTypeObserver); +}; + +} // namespace net + +#endif // NET_NQE_NETWORK_QUALITY_EFFECTIVE_CONNECTION_TYPE_OBSERVER_H_ \ No newline at end of file diff --git a/net/nqe/network_quality_estimator.cc b/net/nqe/network_quality_estimator.cc index 8759b0fb4324ce..643a0efc92a39c 100644 --- a/net/nqe/network_quality_estimator.cc +++ b/net/nqe/network_quality_estimator.cc @@ -1767,6 +1767,14 @@ void NetworkQualityEstimator::OnPrefsRead( } } +base::Optional NetworkQualityEstimator::GetHttpRTT() const { + DCHECK(thread_checker_.CalledOnValidThread()); + + if (network_quality_.http_rtt() == nqe::internal::InvalidRTT()) + return base::Optional(); + return network_quality_.http_rtt(); +} + base::Optional NetworkQualityEstimator::GetTransportRTT() const { DCHECK(thread_checker_.CalledOnValidThread()); @@ -1776,6 +1784,17 @@ base::Optional NetworkQualityEstimator::GetTransportRTT() return network_quality_.transport_rtt(); } +base::Optional NetworkQualityEstimator::GetDownstreamThroughputKbps() + const { + DCHECK(thread_checker_.CalledOnValidThread()); + + if (network_quality_.downstream_throughput_kbps() == + nqe::internal::kInvalidThroughput) { + return base::Optional(); + } + return network_quality_.downstream_throughput_kbps(); +} + void NetworkQualityEstimator::MaybeUpdateNetworkQualityFromCache( const nqe::internal::NetworkID& network_id, const nqe::internal::CachedNetworkQuality& cached_network_quality) { @@ -1832,20 +1851,4 @@ const char* NetworkQualityEstimator::GetNameForStatistic(int i) const { return ""; } -base::Optional -NetworkQualityEstimator::NetworkQualityProvider::GetHttpRTT() const { - return base::Optional(); -} - -base::Optional -NetworkQualityEstimator::NetworkQualityProvider::GetTransportRTT() const { - return base::Optional(); -} - -base::Optional -NetworkQualityEstimator::NetworkQualityProvider::GetDownstreamThroughputKbps() - const { - return base::Optional(); -} - } // namespace net diff --git a/net/nqe/network_quality_estimator.h b/net/nqe/network_quality_estimator.h index 1165b9b90fb565..19e460a5a5c350 100644 --- a/net/nqe/network_quality_estimator.h +++ b/net/nqe/network_quality_estimator.h @@ -24,6 +24,7 @@ #include "net/base/network_change_notifier.h" #include "net/nqe/cached_network_quality.h" #include "net/nqe/effective_connection_type.h" +#include "net/nqe/effective_connection_type_observer.h" #include "net/nqe/event_creator.h" #include "net/nqe/external_estimate_provider.h" #include "net/nqe/network_id.h" @@ -31,8 +32,10 @@ #include "net/nqe/network_quality_estimator_params.h" #include "net/nqe/network_quality_observation.h" #include "net/nqe/network_quality_observation_source.h" +#include "net/nqe/network_quality_provider.h" #include "net/nqe/network_quality_store.h" #include "net/nqe/observation_buffer.h" +#include "net/nqe/rtt_throughput_estimates_observer.h" #include "net/socket/socket_performance_watcher_factory.h" namespace base { @@ -61,65 +64,9 @@ class URLRequest; // observed traffic characteristics. class NET_EXPORT NetworkQualityEstimator : public NetworkChangeNotifier::ConnectionTypeObserver, - public ExternalEstimateProvider::UpdatedEstimateDelegate { + public ExternalEstimateProvider::UpdatedEstimateDelegate, + public NetworkQualityProvider { public: - // Observes changes in effective connection type. - class NET_EXPORT EffectiveConnectionTypeObserver { - public: - // Notifies the observer of a change in the effective connection type. - // NetworkQualityEstimator computes the effective connection type once in - // every interval of duration - // |effective_connection_type_recomputation_interval_|. Additionally, when - // there is a change in the connection type of the device, then the - // effective connection type is immediately recomputed. The observer must - // register and unregister itself on the IO thread. All the observers would - // be notified on the IO thread. - // - // If the computed effective connection type is different from the - // previously notified effective connection type, then all the registered - // observers are notified of the new effective connection type. - virtual void OnEffectiveConnectionTypeChanged( - EffectiveConnectionType type) = 0; - - protected: - EffectiveConnectionTypeObserver() {} - virtual ~EffectiveConnectionTypeObserver() {} - - private: - DISALLOW_COPY_AND_ASSIGN(EffectiveConnectionTypeObserver); - }; - - // Observes changes in the network quality. - class NET_EXPORT RTTAndThroughputEstimatesObserver { - public: - // Notifies the observer when estimated HTTP RTT, estimated transport RTT or - // estimated downstream throughput is computed. NetworkQualityEstimator - // computes the RTT and throughput estimates at regular intervals. - // Additionally, when there is a change in the connection type of the - // device, then the estimates are immediately computed. The observer must - // register and unregister itself on the IO thread. All the observers would - // be notified on the IO thread. - // - // |http_rtt|, |transport_rtt| and |downstream_throughput_kbps| are the - // computed estimates of the HTTP RTT, transport RTT and downstream - // throughput (in kilobits per second), respectively. If an estimate of the - // HTTP or transport RTT is unavailable, it will be set to - // nqe::internal::InvalidRTT(). If the throughput estimate is unavailable, - // it will be set to nqe::internal::kInvalidThroughput. - virtual void OnRTTOrThroughputEstimatesComputed( - base::TimeDelta http_rtt, - base::TimeDelta transport_rtt, - int32_t downstream_throughput_kbps) = 0; - - virtual ~RTTAndThroughputEstimatesObserver() {} - - protected: - RTTAndThroughputEstimatesObserver() {} - - private: - DISALLOW_COPY_AND_ASSIGN(RTTAndThroughputEstimatesObserver); - }; - // Observes measurements of round trip time. class NET_EXPORT_PRIVATE RTTObserver { public: @@ -156,53 +103,6 @@ class NET_EXPORT NetworkQualityEstimator DISALLOW_COPY_AND_ASSIGN(ThroughputObserver); }; - // Provides simple interface to obtain the effective connection type. - class NET_EXPORT NetworkQualityProvider { - public: - virtual ~NetworkQualityProvider() {} - - // Returns the current effective connection type. - virtual EffectiveConnectionType GetEffectiveConnectionType() const = 0; - - // Adds |observer| to a list of effective connection type observers. - virtual void AddEffectiveConnectionTypeObserver( - EffectiveConnectionTypeObserver* observer) = 0; - - // Removes |observer| from a list of effective connection type observers. - virtual void RemoveEffectiveConnectionTypeObserver( - EffectiveConnectionTypeObserver* observer) = 0; - - // Returns the current HTTP RTT estimate. If the estimate is unavailable, - // the returned optional value is null. - virtual base::Optional GetHttpRTT() const; - - // Returns the current transport RTT estimate. If the estimate is - // unavailable, the returned optional value is null. - virtual base::Optional GetTransportRTT() const; - - // Returns the current downstream throughput estimate (in kilobits per - // second). If the estimate is unavailable, the returned optional value is - // null. - virtual base::Optional GetDownstreamThroughputKbps() const; - - // Adds |observer| to the list of RTT and throughput estimate observers. - // |observer| would be notified of the current RTT and throughput estimates - // in the next message pump. - virtual void AddRTTAndThroughputEstimatesObserver( - RTTAndThroughputEstimatesObserver* observer) = 0; - - // Removes |observer| from the list of RTT and throughput estimate - // observers. - virtual void RemoveRTTAndThroughputEstimatesObserver( - RTTAndThroughputEstimatesObserver* observer) = 0; - - protected: - NetworkQualityProvider() {} - - private: - DISALLOW_COPY_AND_ASSIGN(NetworkQualityProvider); - }; - // Creates a new NetworkQualityEstimator. // |variation_params| is the map containing all field trial parameters // related to NetworkQualityEstimator field trial. @@ -235,39 +135,26 @@ class NET_EXPORT NetworkQualityEstimator ~NetworkQualityEstimator() override; - // Returns the last computed effective type of the current connection. The - // effective connection type is computed by the network quality estimator at - // regular intervals and at certain events (e.g., connection change). - // Virtualized for testing. - virtual EffectiveConnectionType GetEffectiveConnectionType() const; - // Returns the effective type of the current connection based on only the // samples observed after |start_time|. This should only be used for // recording the metrics. Virtualized for testing. virtual EffectiveConnectionType GetRecentEffectiveConnectionType( const base::TimeTicks& start_time) const; - // Adds |observer| to the list of effective connection type observers. Must be - // called on the IO thread. |observer| would be notified of the current - // effective connection type in the next message pump. - void AddEffectiveConnectionTypeObserver( - EffectiveConnectionTypeObserver* observer); - - // Removes |observer| from the list of effective connection type observers. + // NetworkQualityProvider implementation: // Must be called on the IO thread. + EffectiveConnectionType GetEffectiveConnectionType() const override; + void AddEffectiveConnectionTypeObserver( + EffectiveConnectionTypeObserver* observer) override; void RemoveEffectiveConnectionTypeObserver( - EffectiveConnectionTypeObserver* observer); - - // Adds |observer| to the list of RTT and throughput estimate observers. Must - // be called on the IO thread. |observer| would be notified of the current RTT - // and throughput estimates in the next message pump. + EffectiveConnectionTypeObserver* observer) override; + base::Optional GetHttpRTT() const override; + base::Optional GetTransportRTT() const override; + base::Optional GetDownstreamThroughputKbps() const override; void AddRTTAndThroughputEstimatesObserver( - RTTAndThroughputEstimatesObserver* observer); - - // Removes |observer| from the list of RTT and throughput estimate observers. - // Must be called on the IO thread. + RTTAndThroughputEstimatesObserver* observer) override; void RemoveRTTAndThroughputEstimatesObserver( - RTTAndThroughputEstimatesObserver* observer); + RTTAndThroughputEstimatesObserver* observer) override; // Notifies NetworkQualityEstimator that the response header of |request| has // been received. @@ -341,10 +228,6 @@ class NET_EXPORT NetworkQualityEstimator const std::map read_prefs); - // Returns the current transport RTT estimate. If the estimate is unavailable, - // the returned optional has no value. - base::Optional GetTransportRTT() const; - protected: // A protected constructor for testing that allows setting the value of // |add_default_platform_observations_|. diff --git a/net/nqe/network_quality_estimator_unittest.cc b/net/nqe/network_quality_estimator_unittest.cc index 4f7941ed9fda5e..29e12aa30440bd 100644 --- a/net/nqe/network_quality_estimator_unittest.cc +++ b/net/nqe/network_quality_estimator_unittest.cc @@ -33,11 +33,13 @@ #include "net/http/http_status_code.h" #include "net/log/test_net_log.h" #include "net/nqe/effective_connection_type.h" +#include "net/nqe/effective_connection_type_observer.h" #include "net/nqe/external_estimate_provider.h" #include "net/nqe/network_quality_estimator_test_util.h" #include "net/nqe/network_quality_observation.h" #include "net/nqe/network_quality_observation_source.h" #include "net/nqe/observation_buffer.h" +#include "net/nqe/rtt_throughput_estimates_observer.h" #include "net/socket/socket_performance_watcher.h" #include "net/socket/socket_performance_watcher_factory.h" #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" @@ -73,7 +75,7 @@ namespace net { namespace { class TestEffectiveConnectionTypeObserver - : public NetworkQualityEstimator::EffectiveConnectionTypeObserver { + : public EffectiveConnectionTypeObserver { public: std::vector& effective_connection_types() { return effective_connection_types_; @@ -89,7 +91,7 @@ class TestEffectiveConnectionTypeObserver }; class TestRTTAndThroughputEstimatesObserver - : public NetworkQualityEstimator::RTTAndThroughputEstimatesObserver { + : public RTTAndThroughputEstimatesObserver { public: TestRTTAndThroughputEstimatesObserver() : http_rtt_(nqe::internal::InvalidRTT()), @@ -221,8 +223,10 @@ TEST(NetworkQualityEstimatorTest, TestKbpsRTTUpdates) { // Both RTT and downstream throughput should be updated. base::TimeDelta http_rtt; EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &http_rtt)); + EXPECT_EQ(http_rtt, estimator.GetHttpRTT().value()); EXPECT_TRUE( estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); + EXPECT_EQ(kbps, estimator.GetDownstreamThroughputKbps().value()); base::TimeDelta transport_rtt; EXPECT_FALSE(estimator.GetTransportRTT()); EXPECT_FALSE( @@ -397,8 +401,10 @@ TEST(NetworkQualityEstimatorTest, Caching) { // Both RTT and downstream throughput should be updated. EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); + EXPECT_EQ(rtt, estimator.GetHttpRTT().value()); EXPECT_TRUE( estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); + EXPECT_EQ(kbps, estimator.GetDownstreamThroughputKbps().value()); EXPECT_NE(EFFECTIVE_CONNECTION_TYPE_UNKNOWN, estimator.GetEffectiveConnectionType()); EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); @@ -504,8 +510,10 @@ TEST(NetworkQualityEstimatorTest, CachingDisabled) { // Both RTT and downstream throughput should be updated. EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); + EXPECT_EQ(rtt, estimator.GetHttpRTT().value()); EXPECT_TRUE( estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); + EXPECT_EQ(kbps, estimator.GetDownstreamThroughputKbps().value()); EXPECT_NE(EFFECTIVE_CONNECTION_TYPE_UNKNOWN, estimator.GetEffectiveConnectionType()); EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); @@ -692,12 +700,14 @@ TEST(NetworkQualityEstimatorTest, DefaultObservations) { // Default estimates should be available. EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); EXPECT_EQ(base::TimeDelta::FromMilliseconds(115), rtt); + EXPECT_EQ(rtt, estimator.GetHttpRTT().value()); EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); EXPECT_EQ(base::TimeDelta::FromMilliseconds(55), rtt); EXPECT_EQ(rtt, estimator.GetTransportRTT().value()); EXPECT_TRUE( estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); EXPECT_EQ(1961, kbps); + EXPECT_EQ(kbps, estimator.GetDownstreamThroughputKbps().value()); estimator.AddEffectiveConnectionTypeObserver( &effective_connection_type_observer); @@ -712,12 +722,14 @@ TEST(NetworkQualityEstimatorTest, DefaultObservations) { EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); // Taken from network_quality_estimator_params.cc. EXPECT_EQ(base::TimeDelta::FromMilliseconds(272), rtt); + EXPECT_EQ(rtt, estimator.GetHttpRTT().value()); EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); EXPECT_EQ(base::TimeDelta::FromMilliseconds(209), rtt); EXPECT_EQ(rtt, estimator.GetTransportRTT()); EXPECT_TRUE( estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); EXPECT_EQ(749, kbps); + EXPECT_EQ(kbps, estimator.GetDownstreamThroughputKbps().value()); EXPECT_NE(EFFECTIVE_CONNECTION_TYPE_UNKNOWN, estimator.GetEffectiveConnectionType()); @@ -788,24 +800,28 @@ TEST(NetworkQualityEstimatorTest, DefaultObservationsOverridden) { EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000), rtt); + EXPECT_EQ(rtt, estimator.GetHttpRTT().value()); EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); EXPECT_EQ(base::TimeDelta::FromMilliseconds(500), rtt); EXPECT_EQ(rtt, estimator.GetTransportRTT().value()); EXPECT_TRUE( estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); EXPECT_EQ(100, kbps); + EXPECT_EQ(kbps, estimator.GetDownstreamThroughputKbps().value()); // Simulate network change to Wi-Fi. estimator.SimulateNetworkChange( NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); EXPECT_EQ(base::TimeDelta::FromMilliseconds(2000), rtt); + EXPECT_EQ(rtt, estimator.GetHttpRTT().value()); EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000), rtt); EXPECT_EQ(rtt, estimator.GetTransportRTT().value()); EXPECT_TRUE( estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); EXPECT_EQ(200, kbps); + EXPECT_EQ(kbps, estimator.GetDownstreamThroughputKbps().value()); // Peak network quality should not be affected by the network quality // estimator field trial. @@ -821,24 +837,28 @@ TEST(NetworkQualityEstimatorTest, DefaultObservationsOverridden) { EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); // Taken from network_quality_estimator_params.cc. EXPECT_EQ(base::TimeDelta::FromMilliseconds(1726), rtt); + EXPECT_EQ(rtt, estimator.GetHttpRTT().value()); EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); EXPECT_EQ(base::TimeDelta::FromMilliseconds(1531), rtt); EXPECT_EQ(rtt, estimator.GetTransportRTT().value()); EXPECT_TRUE( estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); EXPECT_EQ(300, kbps); + EXPECT_EQ(kbps, estimator.GetDownstreamThroughputKbps().value()); // Simulate network change to 3G. Default estimates should be available. estimator.SimulateNetworkChange( NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-3"); EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); EXPECT_EQ(base::TimeDelta::FromMilliseconds(272), rtt); + EXPECT_EQ(rtt, estimator.GetHttpRTT().value()); EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); EXPECT_EQ(base::TimeDelta::FromMilliseconds(209), rtt); EXPECT_EQ(rtt, estimator.GetTransportRTT().value()); EXPECT_TRUE( estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); EXPECT_EQ(749, kbps); + EXPECT_EQ(kbps, estimator.GetDownstreamThroughputKbps().value()); } TEST(NetworkQualityEstimatorTest, ObtainAlgorithmToUseFromParams) { @@ -1533,10 +1553,12 @@ TEST(NetworkQualityEstimatorTest, TestExternalEstimateProvider) { base::TimeDelta rtt; int32_t kbps; EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); + EXPECT_EQ(rtt, estimator.GetHttpRTT().value()); EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); EXPECT_FALSE(estimator.GetTransportRTT()); EXPECT_TRUE( estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); + EXPECT_EQ(kbps, estimator.GetDownstreamThroughputKbps().value()); histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 5); @@ -2168,6 +2190,7 @@ TEST(NetworkQualityEstimatorTest, MAYBE_TestTCPSocketRTT) { EXPECT_EQ(0U, rtt_observer.observations().size()); base::TimeDelta rtt; EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); + EXPECT_EQ(rtt, estimator.GetHttpRTT().value()); EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); EXPECT_EQ(rtt, estimator.GetTransportRTT().value()); @@ -2200,6 +2223,7 @@ TEST(NetworkQualityEstimatorTest, MAYBE_TestTCPSocketRTT) { << i; } EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); + EXPECT_NE(nqe::internal::InvalidRTT(), estimator.GetHttpRTT().value()); EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); EXPECT_EQ(rtt, estimator.GetTransportRTT().value()); diff --git a/net/nqe/network_quality_provider.cc b/net/nqe/network_quality_provider.cc new file mode 100644 index 00000000000000..030e0d8a7dc8d3 --- /dev/null +++ b/net/nqe/network_quality_provider.cc @@ -0,0 +1,23 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/nqe/network_quality_provider.h" + +namespace net { + +base::Optional NetworkQualityProvider::GetHttpRTT() const { + return base::Optional(); +} + +base::Optional NetworkQualityProvider::GetTransportRTT() + const { + return base::Optional(); +} + +base::Optional NetworkQualityProvider::GetDownstreamThroughputKbps() + const { + return base::Optional(); +} + +} // namespace net \ No newline at end of file diff --git a/net/nqe/network_quality_provider.h b/net/nqe/network_quality_provider.h new file mode 100644 index 00000000000000..47eca719ba4426 --- /dev/null +++ b/net/nqe/network_quality_provider.h @@ -0,0 +1,81 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_NQE_NETWORK_QUALITY_PROVIDER_H_ +#define NET_NQE_NETWORK_QUALITY_PROVIDER_H_ + +#include + +#include "base/compiler_specific.h" +#include "base/gtest_prod_util.h" +#include "base/macros.h" +#include "base/optional.h" +#include "base/time/time.h" +#include "net/base/net_export.h" +#include "net/nqe/effective_connection_type.h" + +namespace net { + +class EffectiveConnectionTypeObserver; +class RTTAndThroughputEstimatesObserver; + +// Provides simple interface to obtain the network quality, and to listen to +// the changes in the network quality. +class NET_EXPORT NetworkQualityProvider { + public: + virtual ~NetworkQualityProvider() {} + + // Returns the current effective connection type. The effective connection + // type is computed by the network quality estimator at regular intervals and + // at certain events (e.g., connection change). + virtual EffectiveConnectionType GetEffectiveConnectionType() const = 0; + + // Adds |observer| to a list of effective connection type observers. + // The observer must register and unregister itself on the same thread. + // |observer| would be notified on the thread on which it registered. + // |observer| would be notified of the current effective connection + // type in the next message pump. + virtual void AddEffectiveConnectionTypeObserver( + EffectiveConnectionTypeObserver* observer) {} + + // Removes |observer| from a list of effective connection type observers. + virtual void RemoveEffectiveConnectionTypeObserver( + EffectiveConnectionTypeObserver* observer) {} + + // Returns the current HTTP RTT estimate. If the estimate is unavailable, + // the returned optional value is null. + virtual base::Optional GetHttpRTT() const; + + // Returns the current transport RTT estimate. If the estimate is + // unavailable, the returned optional value is null. + virtual base::Optional GetTransportRTT() const; + + // Returns the current downstream throughput estimate (in kilobits per + // second). If the estimate is unavailable, the returned optional value is + // null. + virtual base::Optional GetDownstreamThroughputKbps() const; + + // Adds |observer| to the list of RTT and throughput estimate observers. + // The observer must register and unregister itself on the same thread. + // |observer| would be notified on the thread on which it registered. + // |observer| would be notified of the current values in the next message + // pump. + virtual void AddRTTAndThroughputEstimatesObserver( + RTTAndThroughputEstimatesObserver* observer) {} + + // Removes |observer| from the list of RTT and throughput estimate + // observers. + virtual void RemoveRTTAndThroughputEstimatesObserver( + RTTAndThroughputEstimatesObserver* observer) {} + + protected: + NetworkQualityProvider() {} + + private: + DISALLOW_COPY_AND_ASSIGN(NetworkQualityProvider); +}; + +} // namespace net + +#endif // NET_NQE_NETWORK_QUALITY_PROVIDER_H_ \ No newline at end of file diff --git a/net/nqe/rtt_throughput_estimates_observer.h b/net/nqe/rtt_throughput_estimates_observer.h new file mode 100644 index 00000000000000..26c77bcb4cf9d7 --- /dev/null +++ b/net/nqe/rtt_throughput_estimates_observer.h @@ -0,0 +1,48 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_NQE_NETWORK_QUALITY_RTT_THROUGHPUT_ESTIMATES_OBSERVER_H_ +#define NET_NQE_NETWORK_QUALITY_RTT_THROUGHPUT_ESTIMATES_OBSERVER_H_ + +#include + +#include "base/compiler_specific.h" +#include "base/macros.h" +#include "base/time/time.h" +#include "net/base/net_export.h" + +namespace net { + +// Observes changes in the network quality. +class NET_EXPORT RTTAndThroughputEstimatesObserver { + public: + // Notifies the observer when estimated HTTP RTT, estimated transport RTT or + // estimated downstream throughput is computed. NetworkQualityEstimator + // computes the RTT and throughput estimates at regular intervals. + // Additionally, when there is a change in the connection type of the + // device, then the estimates are immediately computed. + // + // |http_rtt|, |transport_rtt| and |downstream_throughput_kbps| are the + // computed estimates of the HTTP RTT, transport RTT and downstream + // throughput (in kilobits per second), respectively. If an estimate of the + // HTTP or transport RTT is unavailable, it will be set to + // nqe::internal::InvalidRTT(). If the throughput estimate is unavailable, + // it will be set to nqe::internal::kInvalidThroughput. + virtual void OnRTTOrThroughputEstimatesComputed( + base::TimeDelta http_rtt, + base::TimeDelta transport_rtt, + int32_t downstream_throughput_kbps) = 0; + + virtual ~RTTAndThroughputEstimatesObserver() {} + + protected: + RTTAndThroughputEstimatesObserver() {} + + private: + DISALLOW_COPY_AND_ASSIGN(RTTAndThroughputEstimatesObserver); +}; + +} // namespace net + +#endif // NET_NQE_NETWORK_QUALITY_RTT_THROUGHPUT_ESTIMATES_OBSERVER_H_ \ No newline at end of file