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") {
"ble_connection_metrics_logger.h",
"ble_scanner.cc",
"ble_scanner.h",
"ble_scanner_impl.cc",
"ble_scanner_impl.h",
"connect_tethering_operation.cc",
"connect_tethering_operation.h",
"connection_preserver.cc",
......@@ -250,7 +248,6 @@ source_set("unit_tests") {
"ble_advertisement_device_queue_unittest.cc",
"ble_connection_manager_unittest.cc",
"ble_connection_metrics_logger_unittest.cc",
"ble_scanner_impl_unittest.cc",
"connect_tethering_operation_unittest.cc",
"connection_preserver_impl_unittest.cc",
"crash_recovery_manager_impl_unittest.cc",
......
......@@ -8,7 +8,6 @@
#include "chromeos/chromeos_features.h"
#include "chromeos/components/tether/ble_advertisement_device_queue.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/network_configuration_remover.h"
#include "chromeos/components/tether/wifi_hotspot_disconnector_impl.h"
......@@ -103,13 +102,6 @@ AsynchronousShutdownObjectContainerImpl::
? nullptr
: secure_channel::BleSynchronizer::Factory::Get()->BuildInstance(
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_(
base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)
? nullptr
......@@ -130,10 +122,6 @@ AsynchronousShutdownObjectContainerImpl::
AsynchronousShutdownObjectContainerImpl::
~AsynchronousShutdownObjectContainerImpl() {
disconnect_tethering_request_sender_->RemoveObserver(this);
if (!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
ble_scanner_->RemoveObserver(this);
}
}
void AsynchronousShutdownObjectContainerImpl::Shutdown(
......@@ -144,9 +132,6 @@ void AsynchronousShutdownObjectContainerImpl::Shutdown(
// The objects below require asynchronous shutdowns, so start observering
// these objects. Once they notify observers that they are finished shutting
// down, the asynchronous shutdown will complete.
if (!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
ble_scanner_->AddObserver(this);
}
disconnect_tethering_request_sender_->AddObserver(this);
ShutdownIfPossible();
......@@ -177,20 +162,12 @@ void AsynchronousShutdownObjectContainerImpl::
ShutdownIfPossible();
}
void AsynchronousShutdownObjectContainerImpl::OnDiscoverySessionStateChanged(
bool discovery_session_active) {
ShutdownIfPossible();
}
void AsynchronousShutdownObjectContainerImpl::ShutdownIfPossible() {
DCHECK(!shutdown_complete_callback_.is_null());
if (AreAsynchronousOperationsActive())
return;
if (!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
ble_scanner_->RemoveObserver(this);
}
disconnect_tethering_request_sender_->RemoveObserver(this);
shutdown_complete_callback_.Run();
......@@ -210,23 +187,12 @@ bool AsynchronousShutdownObjectContainerImpl::
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;
}
void AsynchronousShutdownObjectContainerImpl::SetTestDoubles(
std::unique_ptr<BleScanner> ble_scanner,
std::unique_ptr<DisconnectTetheringRequestSender>
disconnect_tethering_request_sender) {
if (!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
ble_scanner_ = std::move(ble_scanner);
}
disconnect_tethering_request_sender_ =
std::move(disconnect_tethering_request_sender);
}
......
......@@ -55,7 +55,6 @@ class WifiHotspotDisconnector;
// Concrete AsynchronousShutdownObjectContainer implementation.
class AsynchronousShutdownObjectContainerImpl
: public AsynchronousShutdownObjectContainer,
public BleScanner::Observer,
public DisconnectTetheringRequestSender::Observer {
public:
class Factory {
......@@ -113,9 +112,6 @@ class AsynchronousShutdownObjectContainerImpl
NetworkConnectionHandler* network_connection_handler,
PrefService* pref_service);
// BleScanner::Observer:
void OnDiscoverySessionStateChanged(bool discovery_session_active) override;
// DisconnectTetheringRequestSender::Observer:
void OnPendingDisconnectRequestsComplete() override;
......@@ -125,8 +121,7 @@ class AsynchronousShutdownObjectContainerImpl
void ShutdownIfPossible();
bool AreAsynchronousOperationsActive();
void SetTestDoubles(std::unique_ptr<BleScanner> ble_scanner,
std::unique_ptr<DisconnectTetheringRequestSender>
void SetTestDoubles(std::unique_ptr<DisconnectTetheringRequestSender>
disconnect_tethering_request_sender);
scoped_refptr<device::BluetoothAdapter> adapter_;
......@@ -136,7 +131,6 @@ class AsynchronousShutdownObjectContainerImpl
local_device_data_provider_;
std::unique_ptr<BleAdvertisementDeviceQueue> ble_advertisement_device_queue_;
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<DisconnectTetheringRequestSender>
disconnect_tethering_request_sender_;
......
......@@ -11,7 +11,6 @@
#include "base/test/scoped_feature_list.h"
#include "base/test/scoped_task_environment.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_tether_host_fetcher.h"
#include "chromeos/components/tether/tether_component_impl.h"
......@@ -99,13 +98,10 @@ class AsynchronousShutdownObjectContainerImplTest : public testing::Test {
nullptr /* network_connection_handler */,
test_pref_service_.get() /* pref_service */));
fake_ble_scanner_ =
new FakeBleScanner(false /* automatically_update_discovery_session */);
fake_disconnect_tethering_request_sender_ =
new FakeDisconnectTetheringRequestSender();
container_->SetTestDoubles(
base::WrapUnique(fake_ble_scanner_),
base::WrapUnique(fake_disconnect_tethering_request_sender_));
}
......@@ -133,7 +129,6 @@ class AsynchronousShutdownObjectContainerImplTest : public testing::Test {
test_pref_service_;
std::unique_ptr<FakeRemoteDeviceProviderFactory>
fake_remote_device_provider_factory_;
FakeBleScanner* fake_ble_scanner_;
FakeDisconnectTetheringRequestSender*
fake_disconnect_tethering_request_sender_;
......@@ -152,25 +147,6 @@ TEST_F(AsynchronousShutdownObjectContainerImplTest,
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,
TestShutdown_AsyncDisconnectTetheringRequestSenderShutdown) {
fake_disconnect_tethering_request_sender_->set_has_pending_requests(true);
......@@ -191,10 +167,6 @@ TEST_F(AsynchronousShutdownObjectContainerImplTest,
TEST_F(AsynchronousShutdownObjectContainerImplTest,
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);
EXPECT_TRUE(fake_disconnect_tethering_request_sender_->HasPendingRequests());
......@@ -203,13 +175,6 @@ TEST_F(AsynchronousShutdownObjectContainerImplTest,
CallShutdown();
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
// complete.
fake_disconnect_tethering_request_sender_->set_has_pending_requests(false);
......@@ -220,10 +185,6 @@ TEST_F(AsynchronousShutdownObjectContainerImplTest,
TEST_F(AsynchronousShutdownObjectContainerImplTest,
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);
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