diff options
-rw-r--r-- | chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_api.cc | 3 | ||||
-rw-r--r-- | components/proximity_auth/bluetooth_connection.cc | 14 | ||||
-rw-r--r-- | components/proximity_auth/bluetooth_connection.h | 8 | ||||
-rw-r--r-- | components/proximity_auth/bluetooth_connection_unittest.cc | 25 | ||||
-rw-r--r-- | components/proximity_auth/bluetooth_util.cc | 10 | ||||
-rw-r--r-- | components/proximity_auth/bluetooth_util.h | 12 | ||||
-rw-r--r-- | components/proximity_auth/bluetooth_util_chromeos.cc | 10 | ||||
-rw-r--r-- | device/bluetooth/BUILD.gn | 2 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device.h | 13 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_chromeos.h | 17 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_mac.h | 4 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_mac.mm | 9 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_win.cc | 9 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_win.h | 4 | ||||
-rw-r--r-- | device/bluetooth/test/mock_bluetooth_device.h | 4 |
15 files changed, 59 insertions, 85 deletions
diff --git a/chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_api.cc b/chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_api.cc index 700069b..1e15669 100644 --- a/chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_api.cc +++ b/chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_api.cc @@ -388,8 +388,7 @@ EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction:: void EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction:: ConnectToService(device::BluetoothDevice* device, const device::BluetoothUUID& uuid) { - proximity_auth::bluetooth_util::ConnectToServiceInsecurely( - device, + device->ConnectToServiceInsecurely( uuid, base::Bind(&EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction:: OnConnect, diff --git a/components/proximity_auth/bluetooth_connection.cc b/components/proximity_auth/bluetooth_connection.cc index d5a2b65..435793e 100644 --- a/components/proximity_auth/bluetooth_connection.cc +++ b/components/proximity_auth/bluetooth_connection.cc @@ -7,7 +7,6 @@ #include "base/bind.h" #include "base/message_loop/message_loop.h" #include "base/numerics/safe_conversions.h" -#include "components/proximity_auth/bluetooth_util.h" #include "components/proximity_auth/remote_device.h" #include "components/proximity_auth/wire_message.h" #include "device/bluetooth/bluetooth_adapter_factory.h" @@ -96,16 +95,6 @@ void BluetoothConnection::DeviceRemoved(device::BluetoothAdapter* adapter, Disconnect(); } -void BluetoothConnection::ConnectToService( - device::BluetoothDevice* device, - const device::BluetoothUUID& uuid, - const device::BluetoothDevice::ConnectToServiceCallback& callback, - const device::BluetoothDevice::ConnectToServiceErrorCallback& - error_callback) { - bluetooth_util::ConnectToServiceInsecurely( - device, uuid, callback, error_callback); -} - void BluetoothConnection::StartReceive() { base::WeakPtr<BluetoothConnection> weak_this = weak_ptr_factory_.GetWeakPtr(); socket_->Receive(kReceiveBufferSizeBytes, @@ -130,8 +119,7 @@ void BluetoothConnection::OnAdapterInitialized( adapter_->AddObserver(this); base::WeakPtr<BluetoothConnection> weak_this = weak_ptr_factory_.GetWeakPtr(); - ConnectToService( - bluetooth_device, + bluetooth_device->ConnectToServiceInsecurely( uuid_, base::Bind(&BluetoothConnection::OnConnected, weak_this), base::Bind(&BluetoothConnection::OnConnectionError, weak_this)); diff --git a/components/proximity_auth/bluetooth_connection.h b/components/proximity_auth/bluetooth_connection.h index 8b09a6f..ebe4f8d 100644 --- a/components/proximity_auth/bluetooth_connection.h +++ b/components/proximity_auth/bluetooth_connection.h @@ -45,14 +45,6 @@ class BluetoothConnection : public Connection, virtual void DeviceRemoved(device::BluetoothAdapter* adapter, device::BluetoothDevice* device) override; - // Exposed for testing. - virtual void ConnectToService( - device::BluetoothDevice* device, - const device::BluetoothUUID& uuid, - const device::BluetoothDevice::ConnectToServiceCallback& callback, - const device::BluetoothDevice::ConnectToServiceErrorCallback& - error_callback); - private: // Registers receive callbacks with the backing |socket_|. void StartReceive(); diff --git a/components/proximity_auth/bluetooth_connection_unittest.cc b/components/proximity_auth/bluetooth_connection_unittest.cc index 80c04e9..1476533 100644 --- a/components/proximity_auth/bluetooth_connection_unittest.cc +++ b/components/proximity_auth/bluetooth_connection_unittest.cc @@ -57,17 +57,6 @@ class MockBluetoothConnection : public BluetoothConnection { MockBluetoothConnection() : BluetoothConnection(kRemoteDevice, device::BluetoothUUID(kUuid)) {} - // Bluetooth dependencies. - typedef device::BluetoothDevice::ConnectToServiceCallback - ConnectToServiceCallback; - typedef device::BluetoothDevice::ConnectToServiceErrorCallback - ConnectToServiceErrorCallback; - MOCK_METHOD4(ConnectToService, - void(device::BluetoothDevice* device, - const device::BluetoothUUID& uuid, - const ConnectToServiceCallback& callback, - const ConnectToServiceErrorCallback& error_callback)); - // Calls back into the parent Connection class. MOCK_METHOD1(SetStatusProxy, void(Status status)); MOCK_METHOD1(OnBytesReceived, void(const std::string& bytes)); @@ -121,7 +110,7 @@ class ProximityAuthBluetoothConnectionTest : public testing::Test { ON_CALL(*adapter_, GetDevice(_)).WillByDefault(Return(&device_)); EXPECT_CALL(*connection, SetStatusProxy(Connection::IN_PROGRESS)); EXPECT_CALL(*adapter_, AddObserver(connection)); - EXPECT_CALL(*connection, ConnectToService(&device_, uuid_, _, _)); + EXPECT_CALL(device_, ConnectToServiceInsecurely(uuid_, _, _)); connection->Connect(); EXPECT_EQ(Connection::IN_PROGRESS, connection->status()); @@ -137,8 +126,8 @@ class ProximityAuthBluetoothConnectionTest : public testing::Test { ON_CALL(*adapter_, GetDevice(_)).WillByDefault(Return(&device_)); EXPECT_CALL(*connection, SetStatusProxy(Connection::IN_PROGRESS)); EXPECT_CALL(*adapter_, AddObserver(connection)); - EXPECT_CALL(*connection, ConnectToService(_, _, _, _)) - .WillOnce(SaveArg<2>(&callback)); + EXPECT_CALL(device_, ConnectToServiceInsecurely(_, _, _)) + .WillOnce(SaveArg<1>(&callback)); connection->Connect(); ASSERT_FALSE(callback.is_null()); @@ -261,8 +250,8 @@ TEST_F(ProximityAuthBluetoothConnectionTest, Connect_ConnectionFails) { ON_CALL(*adapter_, GetDevice(_)).WillByDefault(Return(&device_)); EXPECT_CALL(connection, SetStatusProxy(Connection::IN_PROGRESS)); EXPECT_CALL(*adapter_, AddObserver(&connection)); - EXPECT_CALL(connection, ConnectToService(&device_, uuid_, _, _)) - .WillOnce(SaveArg<3>(&error_callback)); + EXPECT_CALL(device_, ConnectToServiceInsecurely(uuid_, _, _)) + .WillOnce(SaveArg<2>(&error_callback)); connection.Connect(); ASSERT_FALSE(error_callback.is_null()); @@ -382,8 +371,8 @@ TEST_F(ProximityAuthBluetoothConnectionTest, ON_CALL(*adapter_, GetDevice(_)).WillByDefault(Return(&device_)); EXPECT_CALL(connection, SetStatusProxy(Connection::IN_PROGRESS)); EXPECT_CALL(*adapter_, AddObserver(&connection)); - EXPECT_CALL(connection, ConnectToService(&device_, uuid_, _, _)) - .WillOnce(SaveArg<2>(&callback)); + EXPECT_CALL(device_, ConnectToServiceInsecurely(uuid_, _, _)) + .WillOnce(SaveArg<1>(&callback)); connection.Connect(); ASSERT_FALSE(callback.is_null()); diff --git a/components/proximity_auth/bluetooth_util.cc b/components/proximity_auth/bluetooth_util.cc index 405dd23..27b377c 100644 --- a/components/proximity_auth/bluetooth_util.cc +++ b/components/proximity_auth/bluetooth_util.cc @@ -8,8 +8,6 @@ #include "base/callback.h" -using device::BluetoothDevice; - namespace proximity_auth { namespace bluetooth_util { namespace { @@ -23,14 +21,6 @@ void SeekDeviceByAddress(const std::string& device_address, error_callback.Run(kApiUnavailable); } -void ConnectToServiceInsecurely( - BluetoothDevice* device, - const device::BluetoothUUID& uuid, - const BluetoothDevice::ConnectToServiceCallback& callback, - const BluetoothDevice::ConnectToServiceErrorCallback& error_callback) { - error_callback.Run(kApiUnavailable); -} - } // namespace bluetooth_util } // namespace proximity_auth diff --git a/components/proximity_auth/bluetooth_util.h b/components/proximity_auth/bluetooth_util.h index 7bd94fc..ec1c2cc 100644 --- a/components/proximity_auth/bluetooth_util.h +++ b/components/proximity_auth/bluetooth_util.h @@ -8,10 +8,9 @@ #include <string> #include "base/callback_forward.h" -#include "device/bluetooth/bluetooth_device.h" -namespace device { -class BluetoothUUID; +namespace base { +class TaskRunner; } namespace proximity_auth { @@ -29,13 +28,6 @@ void SeekDeviceByAddress(const std::string& device_address, const ErrorCallback& error_callback, base::TaskRunner* task_runner); -void ConnectToServiceInsecurely( - device::BluetoothDevice* device, - const device::BluetoothUUID& uuid, - const device::BluetoothDevice::ConnectToServiceCallback& callback, - const device::BluetoothDevice::ConnectToServiceErrorCallback& - error_callback); - } // namespace bluetooth_util } // namespace proximity_auth diff --git a/components/proximity_auth/bluetooth_util_chromeos.cc b/components/proximity_auth/bluetooth_util_chromeos.cc index 162ea63..86a0758f 100644 --- a/components/proximity_auth/bluetooth_util_chromeos.cc +++ b/components/proximity_auth/bluetooth_util_chromeos.cc @@ -21,7 +21,6 @@ #include "base/threading/sequenced_worker_pool.h" #include "base/time/time.h" #include "device/bluetooth/bluetooth_device.h" -#include "device/bluetooth/bluetooth_device_chromeos.h" #include "net/socket/socket_descriptor.h" // The bluez headers are (intentionally) not available within the Chromium @@ -156,14 +155,5 @@ void SeekDeviceByAddress(const std::string& device_address, base::Bind(&OnSeekDeviceResult, callback, error_callback)); } -void ConnectToServiceInsecurely( - device::BluetoothDevice* device, - const device::BluetoothUUID& uuid, - const BluetoothDevice::ConnectToServiceCallback& callback, - const BluetoothDevice::ConnectToServiceErrorCallback& error_callback) { - static_cast<chromeos::BluetoothDeviceChromeOS*>(device) - ->ConnectToServiceInsecurely(uuid, callback, error_callback); -} - } // namespace bluetooth_util } // namespace proximity_auth diff --git a/device/bluetooth/BUILD.gn b/device/bluetooth/BUILD.gn index 772cc51..28f9478 100644 --- a/device/bluetooth/BUILD.gn +++ b/device/bluetooth/BUILD.gn @@ -101,7 +101,7 @@ static_library("bluetooth") { ] if (is_chromeos) { - public_deps = [ + deps += [ "//chromeos", "//dbus", ] diff --git a/device/bluetooth/bluetooth_device.h b/device/bluetooth/bluetooth_device.h index 4557f3b..2f3a96b 100644 --- a/device/bluetooth/bluetooth_device.h +++ b/device/bluetooth/bluetooth_device.h @@ -356,6 +356,19 @@ class BluetoothDevice { const ConnectToServiceCallback& callback, const ConnectToServiceErrorCallback& error_callback) = 0; + // Attempts to initiate an insecure outgoing L2CAP or RFCOMM connection to the + // advertised service on this device matching |uuid|, performing an SDP lookup + // if necessary to determine the correct protocol and channel for the + // connection. Unlike ConnectToService, the outgoing connection will request + // no bonding rather than general bonding. |callback| will be called on a + // successful connection with a BluetoothSocket instance that is to be owned + // by the receiver. |error_callback| will be called on failure with a message + // indicating the cause. + virtual void ConnectToServiceInsecurely( + const device::BluetoothUUID& uuid, + const ConnectToServiceCallback& callback, + const ConnectToServiceErrorCallback& error_callback) = 0; + // Opens a new GATT connection to this device. On success, a new // BluetoothGattConnection will be handed to the caller via |callback|. On // error, |error_callback| will be called. The connection will be kept alive, diff --git a/device/bluetooth/bluetooth_device_chromeos.h b/device/bluetooth/bluetooth_device_chromeos.h index aa12e0b..644bc26e 100644 --- a/device/bluetooth/bluetooth_device_chromeos.h +++ b/device/bluetooth/bluetooth_device_chromeos.h @@ -66,6 +66,10 @@ class BluetoothDeviceChromeOS const device::BluetoothUUID& uuid, const ConnectToServiceCallback& callback, const ConnectToServiceErrorCallback& error_callback) override; + virtual void ConnectToServiceInsecurely( + const device::BluetoothUUID& uuid, + const ConnectToServiceCallback& callback, + const ConnectToServiceErrorCallback& error_callback) override; virtual void CreateGattConnection( const GattConnectionCallback& callback, const ConnectErrorCallback& error_callback) override; @@ -73,19 +77,6 @@ class BluetoothDeviceChromeOS const base::Closure& callback, const ErrorCallback& error_callback) override; - // Attempts to initiate an insecure outgoing L2CAP or RFCOMM connection to the - // advertised service on this device matching |uuid|, performing an SDP lookup - // if necessary to determine the correct protocol and channel for the - // connection. Unlike ConnectToService, the outgoing connection will request - // no bonding rather than general bonding. |callback| will be called on a - // successful connection with a BluetoothSocket instance that is to be owned - // by the receiver. |error_callback| will be called on failure with a message - // indicating the cause. - void ConnectToServiceInsecurely( - const device::BluetoothUUID& uuid, - const ConnectToServiceCallback& callback, - const ConnectToServiceErrorCallback& error_callback); - // Creates a pairing object with the given delegate |pairing_delegate| and // establishes it as the pairing context for this device. All pairing-related // method calls will be forwarded to this object until it is released. diff --git a/device/bluetooth/bluetooth_device_mac.h b/device/bluetooth/bluetooth_device_mac.h index eed7816..299fe91 100644 --- a/device/bluetooth/bluetooth_device_mac.h +++ b/device/bluetooth/bluetooth_device_mac.h @@ -58,6 +58,10 @@ class BluetoothDeviceMac : public BluetoothDevice { const BluetoothUUID& uuid, const ConnectToServiceCallback& callback, const ConnectToServiceErrorCallback& error_callback) override; + virtual void ConnectToServiceInsecurely( + const BluetoothUUID& uuid, + const ConnectToServiceCallback& callback, + const ConnectToServiceErrorCallback& error_callback) override; virtual void CreateGattConnection( const GattConnectionCallback& callback, const ConnectErrorCallback& error_callback) override; diff --git a/device/bluetooth/bluetooth_device_mac.mm b/device/bluetooth/bluetooth_device_mac.mm index 888ae69..4aad7cf8 100644 --- a/device/bluetooth/bluetooth_device_mac.mm +++ b/device/bluetooth/bluetooth_device_mac.mm @@ -29,6 +29,8 @@ namespace device { namespace { +const char kApiUnavailable[] = "This API is not implemented on this platform."; + // Returns the first (should be, only) UUID contained within the // |service_class_data|. Returns an invalid (empty) UUID if none is found. BluetoothUUID ExtractUuid(IOBluetoothSDPDataElement* service_class_data) { @@ -207,6 +209,13 @@ void BluetoothDeviceMac::ConnectToService( device_.get(), uuid, base::Bind(callback, socket), error_callback); } +void BluetoothDeviceMac::ConnectToServiceInsecurely( + const BluetoothUUID& uuid, + const ConnectToServiceCallback& callback, + const ConnectToServiceErrorCallback& error_callback) { + error_callback.Run(kApiUnavailable); +} + void BluetoothDeviceMac::CreateGattConnection( const GattConnectionCallback& callback, const ConnectErrorCallback& error_callback) { diff --git a/device/bluetooth/bluetooth_device_win.cc b/device/bluetooth/bluetooth_device_win.cc index 67c2aec..a9f690a 100644 --- a/device/bluetooth/bluetooth_device_win.cc +++ b/device/bluetooth/bluetooth_device_win.cc @@ -22,6 +22,8 @@ namespace { const int kSdpBytesBufferSize = 1024; +const char kApiUnavailable[] = "This API is not implemented on this platform."; + } // namespace namespace device { @@ -263,6 +265,13 @@ void BluetoothDeviceWin::ConnectToService( socket->Connect(this, uuid, base::Bind(callback, socket), error_callback); } +void BluetoothDeviceWin::ConnectToServiceInsecurely( + const BluetoothUUID& uuid, + const ConnectToServiceCallback& callback, + const ConnectToServiceErrorCallback& error_callback) { + error_callback.Run(kApiUnavailable); +} + void BluetoothDeviceWin::CreateGattConnection( const GattConnectionCallback& callback, const ConnectErrorCallback& error_callback) { diff --git a/device/bluetooth/bluetooth_device_win.h b/device/bluetooth/bluetooth_device_win.h index ddbde8e..afa5450 100644 --- a/device/bluetooth/bluetooth_device_win.h +++ b/device/bluetooth/bluetooth_device_win.h @@ -64,6 +64,10 @@ class BluetoothDeviceWin : public BluetoothDevice { const BluetoothUUID& uuid, const ConnectToServiceCallback& callback, const ConnectToServiceErrorCallback& error_callback) override; + virtual void ConnectToServiceInsecurely( + const BluetoothUUID& uuid, + const ConnectToServiceCallback& callback, + const ConnectToServiceErrorCallback& error_callback) override; virtual void CreateGattConnection( const GattConnectionCallback& callback, const ConnectErrorCallback& error_callback) override; diff --git a/device/bluetooth/test/mock_bluetooth_device.h b/device/bluetooth/test/mock_bluetooth_device.h index 7bb24f6..6ec0af4 100644 --- a/device/bluetooth/test/mock_bluetooth_device.h +++ b/device/bluetooth/test/mock_bluetooth_device.h @@ -64,6 +64,10 @@ class MockBluetoothDevice : public BluetoothDevice { void(const BluetoothUUID& uuid, const ConnectToServiceCallback& callback, const ConnectToServiceErrorCallback& error_callback)); + MOCK_METHOD3(ConnectToServiceInsecurely, + void(const BluetoothUUID& uuid, + const ConnectToServiceCallback& callback, + const ConnectToServiceErrorCallback& error_callback)); MOCK_METHOD2(CreateGattConnection, void(const GattConnectionCallback& callback, const ConnectErrorCallback& error_callback)); |