Cleanup NearbySharingService Observer

PiperOrigin-RevId: 792702265
This commit is contained in:
Francis Tsui
2025-08-08 11:41:26 -07:00
committed by Copybara-Service
parent 31a15dc938
commit 6200a198df
6 changed files with 2 additions and 90 deletions
-21
View File
@@ -41,9 +41,6 @@ void FakeNearbySharingService::AddObserver(Observer* observer) {
void FakeNearbySharingService::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
bool FakeNearbySharingService::HasObserver(Observer* observer) {
return observers_.HasObserver(observer);
}
// Shutdown the Nearby Sharing service, and cleanup.
void FakeNearbySharingService::Shutdown(
@@ -194,24 +191,6 @@ void FakeNearbySharingService::FireStartDiscoveryResult(bool success) {
}
}
void FakeNearbySharingService::FireFastInitiationDevicesDetected() {
for (auto& observer : observers_.GetObservers()) {
observer->OnFastInitiationDevicesDetected();
}
}
void FakeNearbySharingService::FireFastInitiationDevicesNotDetected() {
for (auto& observer : observers_.GetObservers()) {
observer->OnFastInitiationDevicesNotDetected();
}
}
void FakeNearbySharingService::FireFastInitiationScanningStopped() {
for (auto& observer : observers_.GetObservers()) {
observer->OnFastInitiationScanningStopped();
}
}
void FakeNearbySharingService::FireShutdown() {
for (auto& observer : observers_.GetObservers()) {
observer->OnShutdown();
-4
View File
@@ -42,7 +42,6 @@ class FakeNearbySharingService : public NearbySharingService {
void AddObserver(Observer* observer) override;
void RemoveObserver(Observer* observer) override;
bool HasObserver(Observer* observer) override;
// Shutdown the Nearby Sharing service, and cleanup.
void Shutdown(
@@ -119,9 +118,6 @@ class FakeNearbySharingService : public NearbySharingService {
void FireHighVisibilityChanged(bool in_high_visibility);
void FireStartAdvertisingFailure();
void FireStartDiscoveryResult(bool success);
void FireFastInitiationDevicesDetected();
void FireFastInitiationDevicesNotDetected();
void FireFastInitiationScanningStopped();
void FireShutdown();
// Fire transfer update events.
-5
View File
@@ -109,10 +109,6 @@ class NearbySharingService {
virtual void OnStartAdvertisingFailure() {}
virtual void OnStartDiscoveryResult(bool success) {}
virtual void OnFastInitiationDevicesDetected() {}
virtual void OnFastInitiationDevicesNotDetected() {}
virtual void OnFastInitiationScanningStopped() {}
virtual void OnBluetoothStatusChanged(AdapterState state) {}
virtual void OnWifiStatusChanged(AdapterState state) {}
virtual void OnLanStatusChanged(AdapterState state) {}
@@ -131,7 +127,6 @@ class NearbySharingService {
virtual void AddObserver(Observer* observer) = 0;
virtual void RemoveObserver(Observer* observer) = 0;
virtual bool HasObserver(Observer* observer) = 0;
// Shutdown the Nearby Sharing service, and cleanup.
virtual void Shutdown(
+2 -26
View File
@@ -401,11 +401,6 @@ void NearbySharingServiceImpl::RemoveObserver(
observers_.RemoveObserver(observer);
}
bool NearbySharingServiceImpl::HasObserver(
NearbySharingService::Observer* observer) {
return observers_.HasObserver(observer);
}
void NearbySharingServiceImpl::RegisterSendSurface(
TransferUpdateCallback* transfer_callback,
ShareTargetDiscoveredCallback* discovery_callback, SendSurfaceState state,
@@ -2307,26 +2302,11 @@ void NearbySharingServiceImpl::StartFastInitiationScanning() {
}
nearby_fast_initiation_->StartScanning(
[this]() { OnFastInitiationDevicesDetected(); },
[this]() { OnFastInitiationDevicesNotDetected(); },
/*devices_discovered_callback=*/[]() {},
/*devices_not_discovered_callback=*/[]() {},
[this]() { StopFastInitiationScanning(); });
}
void NearbySharingServiceImpl::OnFastInitiationDevicesDetected() {
VLOG(1) << __func__;
for (auto& observer : observers_.GetObservers()) {
observer->OnFastInitiationDevicesDetected();
}
}
void NearbySharingServiceImpl::OnFastInitiationDevicesNotDetected() {
VLOG(1) << __func__;
for (auto& observer : observers_.GetObservers()) {
observer->OnFastInitiationDevicesNotDetected();
}
}
void NearbySharingServiceImpl::StopFastInitiationScanning() {
VLOG(1) << __func__ << ": Stop fast initiation scanning.";
if (!nearby_fast_initiation_->IsScanning()) {
@@ -2335,10 +2315,6 @@ void NearbySharingServiceImpl::StopFastInitiationScanning() {
nearby_fast_initiation_->StopScanning(
[]() { VLOG(1) << __func__ << ": Stopped fast initiation scanning."; });
for (auto& observer : observers_.GetObservers()) {
observer->OnFastInitiationScanningStopped();
}
VLOG(1) << __func__ << ": Stopped background scanning.";
}
-2
View File
@@ -112,7 +112,6 @@ class NearbySharingServiceImpl
// NearbySharingService
void AddObserver(NearbySharingService::Observer* observer) override;
void RemoveObserver(NearbySharingService::Observer* observer) override;
bool HasObserver(NearbySharingService::Observer* observer) override;
void Shutdown(
std::function<void(StatusCodes)> status_codes_callback) override;
ABSL_DEPRECATED("Use the variant with vendor ID instead.")
@@ -296,7 +295,6 @@ class NearbySharingServiceImpl
void InvalidateFastInitiationScanning();
void StartFastInitiationScanning();
void OnFastInitiationDevicesDetected();
void OnFastInitiationDevicesNotDetected();
void StopFastInitiationScanning();
@@ -1365,16 +1365,6 @@ class TestObserver : public NearbySharingService::Observer {
on_start_advertising_failure_called_ = true;
}
void OnFastInitiationDevicesDetected() override {
devices_detected_called_ = true;
}
void OnFastInitiationDevicesNotDetected() override {
devices_not_detected_called_ = true;
}
void OnFastInitiationScanningStopped() override {
scanning_stopped_called_ = true;
}
void OnBluetoothStatusChanged(AdapterState state) override {
bluetooth_state_ = state;
}
@@ -1394,9 +1384,6 @@ class TestObserver : public NearbySharingService::Observer {
bool in_high_visibility_ = false;
bool shutdown_called_ = false;
bool on_start_advertising_failure_called_ = false;
bool devices_detected_called_ = false;
bool devices_not_detected_called_ = false;
bool scanning_stopped_called_ = false;
bool credential_error_called_ = false;
NearbySharingService* service_;
AdapterState bluetooth_state_ = AdapterState::INVALID;
@@ -1541,25 +1528,6 @@ TEST_F(NearbySharingServiceImplTest, FastInitiationScanning_StartAndStop) {
EXPECT_EQ(fast_initiation->StopScanningCount(), 1);
}
TEST_F(NearbySharingServiceImplTest, FastInitiationScanning_NotifyObservers) {
FakeNearbyFastInitiation* fast_initiation =
nearby_fast_initiation_factory_->GetNearbyFastInitiation();
SetConnectionType(ConnectionType::kBluetooth);
TestObserver observer(service_.get());
ASSERT_EQ(fast_initiation->StartScanningCount(), 1);
fast_initiation->FireDevicesDetected();
EXPECT_TRUE(observer.devices_detected_called_);
fast_initiation->FireDevicesNotDetected();
EXPECT_TRUE(observer.devices_not_detected_called_);
// Remove the observer before it goes out of scope.
service_->RemoveObserver(&observer);
FlushTesting();
}
TEST_F(NearbySharingServiceImplTest,
FastInitiationScanning_PostTransferCooldown) {
FakeNearbyFastInitiation* fast_initiation =