Commit 534600af authored by James Hawkins's avatar James Hawkins Committed by Commit Bot

Instant Tethering: Remove unused BleScannerImpl.

R=hansberry@chromium.org

Bug: 903991
Test: none
Change-Id: I51005dc78fc632371c1ad211fcafebfbdf730caf
Reviewed-on: https://chromium-review.googlesource.com/c/1343280
Commit-Queue: James Hawkins <jhawkins@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609590}
parent ec589a5c
...@@ -23,8 +23,6 @@ static_library("tether") { ...@@ -23,8 +23,6 @@ static_library("tether") {
"ble_connection_metrics_logger.h", "ble_connection_metrics_logger.h",
"ble_scanner.cc", "ble_scanner.cc",
"ble_scanner.h", "ble_scanner.h",
"ble_scanner_impl.cc",
"ble_scanner_impl.h",
"connect_tethering_operation.cc", "connect_tethering_operation.cc",
"connect_tethering_operation.h", "connect_tethering_operation.h",
"connection_preserver.cc", "connection_preserver.cc",
...@@ -250,7 +248,6 @@ source_set("unit_tests") { ...@@ -250,7 +248,6 @@ source_set("unit_tests") {
"ble_advertisement_device_queue_unittest.cc", "ble_advertisement_device_queue_unittest.cc",
"ble_connection_manager_unittest.cc", "ble_connection_manager_unittest.cc",
"ble_connection_metrics_logger_unittest.cc", "ble_connection_metrics_logger_unittest.cc",
"ble_scanner_impl_unittest.cc",
"connect_tethering_operation_unittest.cc", "connect_tethering_operation_unittest.cc",
"connection_preserver_impl_unittest.cc", "connection_preserver_impl_unittest.cc",
"crash_recovery_manager_impl_unittest.cc", "crash_recovery_manager_impl_unittest.cc",
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "chromeos/chromeos_features.h" #include "chromeos/chromeos_features.h"
#include "chromeos/components/tether/ble_advertisement_device_queue.h" #include "chromeos/components/tether/ble_advertisement_device_queue.h"
#include "chromeos/components/tether/ble_connection_metrics_logger.h" #include "chromeos/components/tether/ble_connection_metrics_logger.h"
#include "chromeos/components/tether/ble_scanner_impl.h"
#include "chromeos/components/tether/disconnect_tethering_request_sender_impl.h" #include "chromeos/components/tether/disconnect_tethering_request_sender_impl.h"
#include "chromeos/components/tether/network_configuration_remover.h" #include "chromeos/components/tether/network_configuration_remover.h"
#include "chromeos/components/tether/wifi_hotspot_disconnector_impl.h" #include "chromeos/components/tether/wifi_hotspot_disconnector_impl.h"
...@@ -103,13 +102,6 @@ AsynchronousShutdownObjectContainerImpl:: ...@@ -103,13 +102,6 @@ AsynchronousShutdownObjectContainerImpl::
? nullptr ? nullptr
: secure_channel::BleSynchronizer::Factory::Get()->BuildInstance( : secure_channel::BleSynchronizer::Factory::Get()->BuildInstance(
adapter)), adapter)),
ble_scanner_(
base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)
? nullptr
: BleScannerImpl::Factory::NewInstance(adapter,
nullptr,
ble_synchronizer_.get(),
tether_host_fetcher_)),
ble_connection_metrics_logger_( ble_connection_metrics_logger_(
base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi) base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)
? nullptr ? nullptr
...@@ -130,10 +122,6 @@ AsynchronousShutdownObjectContainerImpl:: ...@@ -130,10 +122,6 @@ AsynchronousShutdownObjectContainerImpl::
AsynchronousShutdownObjectContainerImpl:: AsynchronousShutdownObjectContainerImpl::
~AsynchronousShutdownObjectContainerImpl() { ~AsynchronousShutdownObjectContainerImpl() {
disconnect_tethering_request_sender_->RemoveObserver(this);
if (!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
ble_scanner_->RemoveObserver(this);
}
} }
void AsynchronousShutdownObjectContainerImpl::Shutdown( void AsynchronousShutdownObjectContainerImpl::Shutdown(
...@@ -144,9 +132,6 @@ void AsynchronousShutdownObjectContainerImpl::Shutdown( ...@@ -144,9 +132,6 @@ void AsynchronousShutdownObjectContainerImpl::Shutdown(
// The objects below require asynchronous shutdowns, so start observering // The objects below require asynchronous shutdowns, so start observering
// these objects. Once they notify observers that they are finished shutting // these objects. Once they notify observers that they are finished shutting
// down, the asynchronous shutdown will complete. // down, the asynchronous shutdown will complete.
if (!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
ble_scanner_->AddObserver(this);
}
disconnect_tethering_request_sender_->AddObserver(this); disconnect_tethering_request_sender_->AddObserver(this);
ShutdownIfPossible(); ShutdownIfPossible();
...@@ -177,20 +162,12 @@ void AsynchronousShutdownObjectContainerImpl:: ...@@ -177,20 +162,12 @@ void AsynchronousShutdownObjectContainerImpl::
ShutdownIfPossible(); ShutdownIfPossible();
} }
void AsynchronousShutdownObjectContainerImpl::OnDiscoverySessionStateChanged(
bool discovery_session_active) {
ShutdownIfPossible();
}
void AsynchronousShutdownObjectContainerImpl::ShutdownIfPossible() { void AsynchronousShutdownObjectContainerImpl::ShutdownIfPossible() {
DCHECK(!shutdown_complete_callback_.is_null()); DCHECK(!shutdown_complete_callback_.is_null());
if (AreAsynchronousOperationsActive()) if (AreAsynchronousOperationsActive())
return; return;
if (!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
ble_scanner_->RemoveObserver(this);
}
disconnect_tethering_request_sender_->RemoveObserver(this); disconnect_tethering_request_sender_->RemoveObserver(this);
shutdown_complete_callback_.Run(); shutdown_complete_callback_.Run();
...@@ -210,23 +187,12 @@ bool AsynchronousShutdownObjectContainerImpl:: ...@@ -210,23 +187,12 @@ bool AsynchronousShutdownObjectContainerImpl::
return true; return true;
} }
// The BLE scanner must shut down completely before the component shuts down.
if (!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi) &&
ble_scanner_->ShouldDiscoverySessionBeActive() !=
ble_scanner_->IsDiscoverySessionActive()) {
return true;
}
return false; return false;
} }
void AsynchronousShutdownObjectContainerImpl::SetTestDoubles( void AsynchronousShutdownObjectContainerImpl::SetTestDoubles(
std::unique_ptr<BleScanner> ble_scanner,
std::unique_ptr<DisconnectTetheringRequestSender> std::unique_ptr<DisconnectTetheringRequestSender>
disconnect_tethering_request_sender) { disconnect_tethering_request_sender) {
if (!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
ble_scanner_ = std::move(ble_scanner);
}
disconnect_tethering_request_sender_ = disconnect_tethering_request_sender_ =
std::move(disconnect_tethering_request_sender); std::move(disconnect_tethering_request_sender);
} }
......
...@@ -55,7 +55,6 @@ class WifiHotspotDisconnector; ...@@ -55,7 +55,6 @@ class WifiHotspotDisconnector;
// Concrete AsynchronousShutdownObjectContainer implementation. // Concrete AsynchronousShutdownObjectContainer implementation.
class AsynchronousShutdownObjectContainerImpl class AsynchronousShutdownObjectContainerImpl
: public AsynchronousShutdownObjectContainer, : public AsynchronousShutdownObjectContainer,
public BleScanner::Observer,
public DisconnectTetheringRequestSender::Observer { public DisconnectTetheringRequestSender::Observer {
public: public:
class Factory { class Factory {
...@@ -113,9 +112,6 @@ class AsynchronousShutdownObjectContainerImpl ...@@ -113,9 +112,6 @@ class AsynchronousShutdownObjectContainerImpl
NetworkConnectionHandler* network_connection_handler, NetworkConnectionHandler* network_connection_handler,
PrefService* pref_service); PrefService* pref_service);
// BleScanner::Observer:
void OnDiscoverySessionStateChanged(bool discovery_session_active) override;
// DisconnectTetheringRequestSender::Observer: // DisconnectTetheringRequestSender::Observer:
void OnPendingDisconnectRequestsComplete() override; void OnPendingDisconnectRequestsComplete() override;
...@@ -125,8 +121,7 @@ class AsynchronousShutdownObjectContainerImpl ...@@ -125,8 +121,7 @@ class AsynchronousShutdownObjectContainerImpl
void ShutdownIfPossible(); void ShutdownIfPossible();
bool AreAsynchronousOperationsActive(); bool AreAsynchronousOperationsActive();
void SetTestDoubles(std::unique_ptr<BleScanner> ble_scanner, void SetTestDoubles(std::unique_ptr<DisconnectTetheringRequestSender>
std::unique_ptr<DisconnectTetheringRequestSender>
disconnect_tethering_request_sender); disconnect_tethering_request_sender);
scoped_refptr<device::BluetoothAdapter> adapter_; scoped_refptr<device::BluetoothAdapter> adapter_;
...@@ -136,7 +131,6 @@ class AsynchronousShutdownObjectContainerImpl ...@@ -136,7 +131,6 @@ class AsynchronousShutdownObjectContainerImpl
local_device_data_provider_; local_device_data_provider_;
std::unique_ptr<BleAdvertisementDeviceQueue> ble_advertisement_device_queue_; std::unique_ptr<BleAdvertisementDeviceQueue> ble_advertisement_device_queue_;
std::unique_ptr<secure_channel::BleSynchronizerBase> ble_synchronizer_; std::unique_ptr<secure_channel::BleSynchronizerBase> ble_synchronizer_;
std::unique_ptr<BleScanner> ble_scanner_;
std::unique_ptr<BleConnectionMetricsLogger> ble_connection_metrics_logger_; std::unique_ptr<BleConnectionMetricsLogger> ble_connection_metrics_logger_;
std::unique_ptr<DisconnectTetheringRequestSender> std::unique_ptr<DisconnectTetheringRequestSender>
disconnect_tethering_request_sender_; disconnect_tethering_request_sender_;
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/test/scoped_task_environment.h" #include "base/test/scoped_task_environment.h"
#include "chromeos/chromeos_features.h" #include "chromeos/chromeos_features.h"
#include "chromeos/components/tether/fake_ble_scanner.h"
#include "chromeos/components/tether/fake_disconnect_tethering_request_sender.h" #include "chromeos/components/tether/fake_disconnect_tethering_request_sender.h"
#include "chromeos/components/tether/fake_tether_host_fetcher.h" #include "chromeos/components/tether/fake_tether_host_fetcher.h"
#include "chromeos/components/tether/tether_component_impl.h" #include "chromeos/components/tether/tether_component_impl.h"
...@@ -99,13 +98,10 @@ class AsynchronousShutdownObjectContainerImplTest : public testing::Test { ...@@ -99,13 +98,10 @@ class AsynchronousShutdownObjectContainerImplTest : public testing::Test {
nullptr /* network_connection_handler */, nullptr /* network_connection_handler */,
test_pref_service_.get() /* pref_service */)); test_pref_service_.get() /* pref_service */));
fake_ble_scanner_ =
new FakeBleScanner(false /* automatically_update_discovery_session */);
fake_disconnect_tethering_request_sender_ = fake_disconnect_tethering_request_sender_ =
new FakeDisconnectTetheringRequestSender(); new FakeDisconnectTetheringRequestSender();
container_->SetTestDoubles( container_->SetTestDoubles(
base::WrapUnique(fake_ble_scanner_),
base::WrapUnique(fake_disconnect_tethering_request_sender_)); base::WrapUnique(fake_disconnect_tethering_request_sender_));
} }
...@@ -133,7 +129,6 @@ class AsynchronousShutdownObjectContainerImplTest : public testing::Test { ...@@ -133,7 +129,6 @@ class AsynchronousShutdownObjectContainerImplTest : public testing::Test {
test_pref_service_; test_pref_service_;
std::unique_ptr<FakeRemoteDeviceProviderFactory> std::unique_ptr<FakeRemoteDeviceProviderFactory>
fake_remote_device_provider_factory_; fake_remote_device_provider_factory_;
FakeBleScanner* fake_ble_scanner_;
FakeDisconnectTetheringRequestSender* FakeDisconnectTetheringRequestSender*
fake_disconnect_tethering_request_sender_; fake_disconnect_tethering_request_sender_;
...@@ -152,25 +147,6 @@ TEST_F(AsynchronousShutdownObjectContainerImplTest, ...@@ -152,25 +147,6 @@ TEST_F(AsynchronousShutdownObjectContainerImplTest,
EXPECT_TRUE(was_shutdown_callback_invoked_); EXPECT_TRUE(was_shutdown_callback_invoked_);
} }
TEST_F(AsynchronousShutdownObjectContainerImplTest,
TestShutdown_AsyncBleScannerShutdown) {
fake_ble_scanner_->set_is_discovery_session_active(true);
EXPECT_FALSE(fake_ble_scanner_->ShouldDiscoverySessionBeActive());
EXPECT_TRUE(fake_ble_scanner_->IsDiscoverySessionActive());
// Start the shutdown; it should not yet succeed since there is an active
// discovery session.
CallShutdown();
EXPECT_FALSE(was_shutdown_callback_invoked_);
// Now, remove the discovery session; this should cause the shutdown to
// complete.
fake_ble_scanner_->set_is_discovery_session_active(false);
fake_ble_scanner_->NotifyDiscoverySessionStateChanged(
false /* discovery_session_active */);
EXPECT_TRUE(was_shutdown_callback_invoked_);
}
TEST_F(AsynchronousShutdownObjectContainerImplTest, TEST_F(AsynchronousShutdownObjectContainerImplTest,
TestShutdown_AsyncDisconnectTetheringRequestSenderShutdown) { TestShutdown_AsyncDisconnectTetheringRequestSenderShutdown) {
fake_disconnect_tethering_request_sender_->set_has_pending_requests(true); fake_disconnect_tethering_request_sender_->set_has_pending_requests(true);
...@@ -191,10 +167,6 @@ TEST_F(AsynchronousShutdownObjectContainerImplTest, ...@@ -191,10 +167,6 @@ TEST_F(AsynchronousShutdownObjectContainerImplTest,
TEST_F(AsynchronousShutdownObjectContainerImplTest, TEST_F(AsynchronousShutdownObjectContainerImplTest,
TestShutdown_MultipleSimultaneousAsyncShutdowns) { TestShutdown_MultipleSimultaneousAsyncShutdowns) {
fake_ble_scanner_->set_is_discovery_session_active(true);
EXPECT_FALSE(fake_ble_scanner_->ShouldDiscoverySessionBeActive());
EXPECT_TRUE(fake_ble_scanner_->IsDiscoverySessionActive());
fake_disconnect_tethering_request_sender_->set_has_pending_requests(true); fake_disconnect_tethering_request_sender_->set_has_pending_requests(true);
EXPECT_TRUE(fake_disconnect_tethering_request_sender_->HasPendingRequests()); EXPECT_TRUE(fake_disconnect_tethering_request_sender_->HasPendingRequests());
...@@ -203,13 +175,6 @@ TEST_F(AsynchronousShutdownObjectContainerImplTest, ...@@ -203,13 +175,6 @@ TEST_F(AsynchronousShutdownObjectContainerImplTest,
CallShutdown(); CallShutdown();
EXPECT_FALSE(was_shutdown_callback_invoked_); EXPECT_FALSE(was_shutdown_callback_invoked_);
// Now, remove the discovery session; this should not cause the shutdown to
// complete since there are still pending requests.
fake_ble_scanner_->set_is_discovery_session_active(false);
fake_ble_scanner_->NotifyDiscoverySessionStateChanged(
false /* discovery_session_active */);
EXPECT_FALSE(was_shutdown_callback_invoked_);
// Now, finish the pending requests; this should cause the shutdown to // Now, finish the pending requests; this should cause the shutdown to
// complete. // complete.
fake_disconnect_tethering_request_sender_->set_has_pending_requests(false); fake_disconnect_tethering_request_sender_->set_has_pending_requests(false);
...@@ -220,10 +185,6 @@ TEST_F(AsynchronousShutdownObjectContainerImplTest, ...@@ -220,10 +185,6 @@ TEST_F(AsynchronousShutdownObjectContainerImplTest,
TEST_F(AsynchronousShutdownObjectContainerImplTest, TEST_F(AsynchronousShutdownObjectContainerImplTest,
TestShutdown_MultipleSimultaneousAsyncShutdowns_BluetoothDisabled) { TestShutdown_MultipleSimultaneousAsyncShutdowns_BluetoothDisabled) {
fake_ble_scanner_->set_is_discovery_session_active(true);
EXPECT_FALSE(fake_ble_scanner_->ShouldDiscoverySessionBeActive());
EXPECT_TRUE(fake_ble_scanner_->IsDiscoverySessionActive());
fake_disconnect_tethering_request_sender_->set_has_pending_requests(true); fake_disconnect_tethering_request_sender_->set_has_pending_requests(true);
EXPECT_TRUE(fake_disconnect_tethering_request_sender_->HasPendingRequests()); EXPECT_TRUE(fake_disconnect_tethering_request_sender_->HasPendingRequests());
......
This diff is collapsed.
// 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 CHROMEOS_COMPONENTS_TETHER_BLE_SCANNER_IMPL_H_
#define CHROMEOS_COMPONENTS_TETHER_BLE_SCANNER_IMPL_H_
#include <map>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "chromeos/components/tether/ble_scanner.h"
#include "components/cryptauth/remote_device_ref.h"
#include "device/bluetooth/bluetooth_adapter.h"
namespace base {
class TaskRunner;
} // namespace base
namespace device {
class BluetoothDevice;
class BluetoothDiscoverySession;
} // namespace device
namespace chromeos {
namespace secure_channel {
class BleServiceDataHelper;
class BleSynchronizerBase;
} // namespace secure_channel
namespace tether {
class TetherHostFetcher;
// Concrete BleScanner implementation.
class BleScannerImpl : public BleScanner,
public device::BluetoothAdapter::Observer {
public:
class Factory {
public:
static std::unique_ptr<BleScanner> NewInstance(
scoped_refptr<device::BluetoothAdapter> adapter,
secure_channel::BleServiceDataHelper* ble_service_data_helper,
secure_channel::BleSynchronizerBase* ble_synchronizer,
TetherHostFetcher* tether_host_fetcher);
static void SetInstanceForTesting(Factory* factory);
protected:
virtual std::unique_ptr<BleScanner> BuildInstance(
scoped_refptr<device::BluetoothAdapter> adapter,
secure_channel::BleServiceDataHelper* ble_service_data_helper,
secure_channel::BleSynchronizerBase* ble_synchronizer,
TetherHostFetcher* tether_host_fetcher);
private:
static Factory* factory_instance_;
};
~BleScannerImpl() override;
// BleScanner:
bool RegisterScanFilterForDevice(const std::string& device_id) override;
bool UnregisterScanFilterForDevice(const std::string& device_id) override;
bool ShouldDiscoverySessionBeActive() override;
bool IsDiscoverySessionActive() override;
protected:
BleScannerImpl(scoped_refptr<device::BluetoothAdapter> adapter,
secure_channel::BleServiceDataHelper* ble_service_data_helper,
secure_channel::BleSynchronizerBase* ble_synchronizer,
TetherHostFetcher* tether_host_fetcher);
// device::BluetoothAdapter::Observer:
void DeviceAdded(device::BluetoothAdapter* adapter,
device::BluetoothDevice* bluetooth_device) override;
void DeviceChanged(device::BluetoothAdapter* adapter,
device::BluetoothDevice* bluetooth_device) override;
private:
friend class BleScannerImplTest;
class ServiceDataProvider {
public:
virtual ~ServiceDataProvider() {}
virtual const std::vector<uint8_t>* GetServiceDataForUUID(
device::BluetoothDevice* bluetooth_device) = 0;
};
class ServiceDataProviderImpl : public ServiceDataProvider {
public:
ServiceDataProviderImpl();
~ServiceDataProviderImpl() override;
const std::vector<uint8_t>* GetServiceDataForUUID(
device::BluetoothDevice* bluetooth_device) override;
};
void SetTestDoubles(
std::unique_ptr<ServiceDataProvider> service_data_provider,
scoped_refptr<base::TaskRunner> test_task_runner);
bool IsDeviceRegistered(const std::string& device_id);
// A discovery session should stay active until it has been stopped. However,
// due to bugs in Bluetooth code, it is possible for a discovery status to
// transition to being off without a Stop() call ever succeeding. This
// function corrects the state of Bluetooth if such a bug occurs.
void ResetDiscoverySessionIfNotActive();
void UpdateDiscoveryStatus();
void EnsureDiscoverySessionActive();
void OnDiscoverySessionStarted(
std::unique_ptr<device::BluetoothDiscoverySession> discovery_session);
void OnStartDiscoverySessionError();
void EnsureDiscoverySessionNotActive();
void OnDiscoverySessionStopped();
void OnStopDiscoverySessionError();
void HandleDeviceUpdated(device::BluetoothDevice* bluetooth_device);
void CheckForMatchingScanFilters(device::BluetoothDevice* bluetooth_device,
const std::string& service_data);
void ScheduleStatusChangeNotification(bool discovery_session_active);
scoped_refptr<device::BluetoothAdapter> adapter_;
secure_channel::BleServiceDataHelper* ble_service_data_helper_;
secure_channel::BleSynchronizerBase* ble_synchronizer_;
TetherHostFetcher* tether_host_fetcher_;
std::unique_ptr<ServiceDataProvider> service_data_provider_;
std::vector<std::string> registered_remote_device_ids_;
bool is_initializing_discovery_session_ = false;
bool is_stopping_discovery_session_ = false;
scoped_refptr<base::TaskRunner> task_runner_;
std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_;
std::unique_ptr<base::WeakPtrFactory<device::BluetoothDiscoverySession>>
discovery_session_weak_ptr_factory_;
base::WeakPtrFactory<BleScannerImpl> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(BleScannerImpl);
};
} // namespace tether
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_TETHER_BLE_SCANNER_IMPL_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment