1 // Copyright 2018 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef SERVICES_NETWORK_NETWORK_QUALITY_ESTIMATOR_MANAGER_H_ 6 #define SERVICES_NETWORK_NETWORK_QUALITY_ESTIMATOR_MANAGER_H_ 7 8 #include <memory> 9 10 #include "base/component_export.h" 11 #include "base/macros.h" 12 #include "base/sequence_checker.h" 13 #include "base/time/time.h" 14 #include "mojo/public/cpp/bindings/pending_remote.h" 15 #include "mojo/public/cpp/bindings/receiver_set.h" 16 #include "mojo/public/cpp/bindings/remote_set.h" 17 #include "net/nqe/effective_connection_type.h" 18 #include "net/nqe/effective_connection_type_observer.h" 19 #include "net/nqe/rtt_throughput_estimates_observer.h" 20 #include "services/network/public/mojom/network_quality_estimator_manager.mojom.h" 21 22 namespace net { 23 class NetworkQualityEstimator; 24 class NetLog; 25 } // namespace net 26 27 namespace network { 28 29 // Implementation of mojom::NetworkQualityEstimatorManager. All accesses to this 30 // class are done through mojo on the main thread. This registers itself to 31 // receive broadcasts from net::EffectiveConnectionTypeObserver and 32 // net::RTTAndThroughputEstimatesObserver. NetworkQualityEstimatorManager then 33 // rebroadcasts the notifications to 34 // mojom::NetworkQualityEstimatorManagerClients through mojo pipes. COMPONENT_EXPORT(NETWORK_SERVICE)35class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkQualityEstimatorManager 36 : public mojom::NetworkQualityEstimatorManager, 37 public net::EffectiveConnectionTypeObserver, 38 public net::RTTAndThroughputEstimatesObserver { 39 public: 40 explicit NetworkQualityEstimatorManager(net::NetLog* net_log); 41 42 ~NetworkQualityEstimatorManager() override; 43 44 // Binds a NetworkQualityEstimatorManager receiver to this object. Mojo 45 // messages coming through the associated pipe will be served by this object. 46 void AddReceiver( 47 mojo::PendingReceiver<mojom::NetworkQualityEstimatorManager> receiver); 48 49 // mojom::NetworkQualityEstimatorManager implementation: 50 void RequestNotifications( 51 mojo::PendingRemote<mojom::NetworkQualityEstimatorManagerClient> client) 52 override; 53 54 net::NetworkQualityEstimator* GetNetworkQualityEstimator() const; 55 56 private: 57 // net::EffectiveConnectionTypeObserver implementation: 58 void OnEffectiveConnectionTypeChanged( 59 net::EffectiveConnectionType type) override; 60 // net::RTTAndThroughputEstimatesObserver implementation: 61 void OnRTTOrThroughputEstimatesComputed( 62 base::TimeDelta http_rtt, 63 base::TimeDelta transport_rtt, 64 int32_t downstream_throughput_kbps) override; 65 66 std::unique_ptr<net::NetworkQualityEstimator> network_quality_estimator_; 67 mojo::ReceiverSet<mojom::NetworkQualityEstimatorManager> receivers_; 68 mojo::RemoteSet<mojom::NetworkQualityEstimatorManagerClient> clients_; 69 net::EffectiveConnectionType effective_connection_type_; 70 base::TimeDelta http_rtt_; 71 base::TimeDelta transport_rtt_; 72 int32_t downstream_throughput_kbps_; 73 74 SEQUENCE_CHECKER(sequence_checker_); 75 76 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimatorManager); 77 }; 78 79 } // namespace network 80 81 #endif // SERVICES_NETWORK_NETWORK_QUALITY_ESTIMATOR_MANAGER_H_ 82