[sigslot] - Remove sigslot form NetworkMonitorInterface.

Bug: webrtc:11943
Change-Id: Iddedb2840e437dfbffcb0d6cbf71a09b0030fbab
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/226869
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34573}
This commit is contained in:
Mirko Bonadei 2021-07-27 17:00:58 +02:00 committed by WebRTC LUCI CQ
parent 9b6cd191ef
commit 3707793a57
5 changed files with 30 additions and 12 deletions

View file

@ -863,8 +863,8 @@ void BasicNetworkManager::StartNetworkMonitor() {
if (!network_monitor_) { if (!network_monitor_) {
return; return;
} }
network_monitor_->SignalNetworksChanged.connect( network_monitor_->SetNetworksChangedCallback(
this, &BasicNetworkManager::OnNetworksChanged); [this]() { OnNetworksChanged(); });
} }
if (network_monitor_->SupportsBindSocketToNetwork()) { if (network_monitor_->SupportsBindSocketToNetwork()) {

View file

@ -11,8 +11,10 @@
#ifndef RTC_BASE_NETWORK_MONITOR_H_ #ifndef RTC_BASE_NETWORK_MONITOR_H_
#define RTC_BASE_NETWORK_MONITOR_H_ #define RTC_BASE_NETWORK_MONITOR_H_
#include <functional>
#include <utility>
#include "rtc_base/network_constants.h" #include "rtc_base/network_constants.h"
#include "rtc_base/third_party/sigslot/sigslot.h"
namespace rtc { namespace rtc {
@ -73,8 +75,6 @@ class NetworkMonitorInterface {
NetworkMonitorInterface(); NetworkMonitorInterface();
virtual ~NetworkMonitorInterface(); virtual ~NetworkMonitorInterface();
sigslot::signal0<> SignalNetworksChanged;
virtual void Start() = 0; virtual void Start() = 0;
virtual void Stop() = 0; virtual void Stop() = 0;
@ -110,6 +110,20 @@ class NetworkMonitorInterface {
virtual bool IsAdapterAvailable(const std::string& interface_name) { virtual bool IsAdapterAvailable(const std::string& interface_name) {
return true; return true;
} }
void SetNetworksChangedCallback(std::function<void()> callback) {
networks_changed_callback_ = std::move(callback);
}
protected:
void InvokeNetworksChangedCallback() {
if (networks_changed_callback_) {
networks_changed_callback_();
}
}
private:
std::function<void()> networks_changed_callback_;
}; };
} // namespace rtc } // namespace rtc

View file

@ -100,6 +100,10 @@ class FakeNetworkMonitor : public NetworkMonitorInterface {
void set_adapters(std::vector<std::string> adapters) { adapters_ = adapters; } void set_adapters(std::vector<std::string> adapters) { adapters_ = adapters; }
void InovkeNetworksChangedCallbackForTesting() {
InvokeNetworksChangedCallback();
}
private: private:
bool started_ = false; bool started_ = false;
std::vector<std::string> adapters_; std::vector<std::string> adapters_;
@ -1128,7 +1132,7 @@ TEST_F(NetworkTest, TestNetworkMonitoring) {
ClearNetworks(manager); ClearNetworks(manager);
// Network manager is started, so the callback is called when the network // Network manager is started, so the callback is called when the network
// monitor fires the network-change event. // monitor fires the network-change event.
network_monitor->SignalNetworksChanged(); network_monitor->InovkeNetworksChangedCallbackForTesting();
EXPECT_TRUE_WAIT(callback_called_, 1000); EXPECT_TRUE_WAIT(callback_called_, 1000);
// Network manager is stopped. // Network manager is stopped.

View file

@ -267,8 +267,8 @@ void AndroidNetworkMonitor::Stop() {
started_ = false; started_ = false;
find_network_handle_without_ipv6_temporary_part_ = false; find_network_handle_without_ipv6_temporary_part_ = false;
// Cancel any pending tasks. We should not call SignalNetworksChanged when the // Cancel any pending tasks. We should not call
// monitor is stopped. // `InvokeNetworksChangedCallback()` when the monitor is stopped.
safety_flag_->SetNotAlive(); safety_flag_->SetNotAlive();
JNIEnv* env = AttachCurrentThreadIfNeeded(); JNIEnv* env = AttachCurrentThreadIfNeeded();
@ -411,7 +411,7 @@ void AndroidNetworkMonitor::OnNetworkConnected_n(
for (const rtc::IPAddress& address : network_info.ip_addresses) { for (const rtc::IPAddress& address : network_info.ip_addresses) {
network_handle_by_address_[address] = network_info.handle; network_handle_by_address_[address] = network_info.handle;
} }
SignalNetworksChanged(); InvokeNetworksChangedCallback();
} }
absl::optional<NetworkHandle> absl::optional<NetworkHandle>
@ -479,7 +479,7 @@ void AndroidNetworkMonitor::OnNetworkPreference_n(
<< rtc::NetworkPreferenceToString(preference); << rtc::NetworkPreferenceToString(preference);
auto adapter_type = AdapterTypeFromNetworkType(type, surface_cellular_types_); auto adapter_type = AdapterTypeFromNetworkType(type, surface_cellular_types_);
network_preference_by_adapter_type_[adapter_type] = preference; network_preference_by_adapter_type_[adapter_type] = preference;
SignalNetworksChanged(); InvokeNetworksChangedCallback();
} }
void AndroidNetworkMonitor::SetNetworkInfos( void AndroidNetworkMonitor::SetNetworkInfos(
@ -586,7 +586,7 @@ void AndroidNetworkMonitor::NotifyConnectionTypeChanged(
network_thread_->PostTask(ToQueuedTask(safety_flag_, [this] { network_thread_->PostTask(ToQueuedTask(safety_flag_, [this] {
RTC_LOG(LS_INFO) RTC_LOG(LS_INFO)
<< "Android network monitor detected connection type change."; << "Android network monitor detected connection type change.";
SignalNetworksChanged(); InvokeNetworksChangedCallback();
})); }));
} }

View file

@ -87,7 +87,7 @@ void ObjCNetworkMonitor::OnPathUpdate(
thread_->PostTask(ToQueuedTask(safety_flag_, [this, adapter_type_by_name] { thread_->PostTask(ToQueuedTask(safety_flag_, [this, adapter_type_by_name] {
RTC_DCHECK_RUN_ON(thread_); RTC_DCHECK_RUN_ON(thread_);
adapter_type_by_name_ = adapter_type_by_name; adapter_type_by_name_ = adapter_type_by_name;
SignalNetworksChanged(); InvokeNetworksChangedCallback();
})); }));
} }