1 // Copyright 2020 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 CHROME_BROWSER_CHROMEOS_NET_NETWORK_HEALTH_NETWORK_HEALTH_H_ 6 #define CHROME_BROWSER_CHROMEOS_NET_NETWORK_HEALTH_NETWORK_HEALTH_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "chromeos/services/network_config/public/mojom/cros_network_config.mojom.h" 12 #include "chromeos/services/network_health/public/mojom/network_health.mojom.h" 13 #include "mojo/public/cpp/bindings/pending_receiver.h" 14 #include "mojo/public/cpp/bindings/receiver_set.h" 15 #include "mojo/public/cpp/bindings/remote.h" 16 17 namespace chromeos { 18 namespace network_health { 19 20 class NetworkHealth : public mojom::NetworkHealthService, 21 public network_config::mojom::CrosNetworkConfigObserver { 22 public: 23 NetworkHealth(); 24 25 ~NetworkHealth() override; 26 27 // Binds this instance to |receiver|. 28 void BindReceiver( 29 mojo::PendingReceiver<mojom::NetworkHealthService> receiver); 30 31 // Returns the current NetworkHealthState. 32 const mojom::NetworkHealthStatePtr GetNetworkHealthState(); 33 34 // NetworkHealthService 35 void GetNetworkList(GetNetworkListCallback) override; 36 void GetHealthSnapshot(GetHealthSnapshotCallback) override; 37 38 // CrosNetworkConfigObserver 39 void OnNetworkStateListChanged() override; 40 void OnDeviceStateListChanged() override; 41 void OnActiveNetworksChanged( 42 std::vector<network_config::mojom::NetworkStatePropertiesPtr>) override; 43 void OnNetworkStateChanged( 44 network_config::mojom::NetworkStatePropertiesPtr) override; 45 void OnVpnProvidersChanged() override; 46 void OnNetworkCertificatesChanged() override; 47 48 private: 49 // Handler for receiving the network state list. 50 void OnNetworkStateListReceived( 51 std::vector<network_config::mojom::NetworkStatePropertiesPtr>); 52 53 // Handler for receiving networking devices. 54 void OnDeviceStateListReceived( 55 std::vector<network_config::mojom::DeviceStatePropertiesPtr>); 56 57 // Creates the NetworkHealthState structure from cached network information. 58 void CreateNetworkHealthState(); 59 60 // Asynchronous call that refreshes the current Network Health State. 61 void RefreshNetworkHealthState(); 62 void RequestNetworkStateList(); 63 void RequestDeviceStateList(); 64 65 // Remote for sending requests to the CrosNetworkConfig service. 66 mojo::Remote<network_config::mojom::CrosNetworkConfig> 67 remote_cros_network_config_; 68 // Receiver for the CrosNetworkConfigObserver events. 69 mojo::Receiver<network_config::mojom::CrosNetworkConfigObserver> 70 cros_network_config_observer_receiver_{this}; 71 // Receivers for external requests (WebUI, Feedback, CrosHealthdClient). 72 mojo::ReceiverSet<mojom::NetworkHealthService> receivers_; 73 74 mojom::NetworkHealthState network_health_state_; 75 std::vector<network_config::mojom::DeviceStatePropertiesPtr> 76 device_properties_; 77 std::vector<network_config::mojom::NetworkStatePropertiesPtr> 78 network_properties_; 79 }; 80 81 } // namespace network_health 82 } // namespace chromeos 83 84 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_HEALTH_NETWORK_HEALTH_H_ 85