Commit 35e6711e authored by Jan Wilken Doerrie's avatar Jan Wilken Doerrie Committed by Commit Bot

[bluetooth] Introduce BluetoothAdapterWinrt

This change introduces BluetoothAdapterWinrt, which will contain an
adapter implementation using Mirosoft UWP BLE APIs. This change merely
provides a skeleton, where each member function is NOTIMPLEMENTED().
Further functionality will be provided in future CLs.

Bug: 579202, 821766
Change-Id: I207e14de292f9d24b7d16710437e0dae839c82ec
Reviewed-on: https://chromium-review.googlesource.com/1046589
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556748}
parent e4d5b964
...@@ -237,6 +237,11 @@ component("bluetooth") { ...@@ -237,6 +237,11 @@ component("bluetooth") {
} }
if (is_win) { if (is_win) {
sources += [
"bluetooth_adapter_winrt.cc",
"bluetooth_adapter_winrt.h",
]
libs = [ libs = [
# Bthprops must be listed before BluetoothApis or else delay loading # Bthprops must be listed before BluetoothApis or else delay loading
# crashes. # crashes.
......
...@@ -464,13 +464,18 @@ TEST_F(BluetoothTest, MAYBE_ConstructDefaultAdapter) { ...@@ -464,13 +464,18 @@ TEST_F(BluetoothTest, MAYBE_ConstructDefaultAdapter) {
} }
// TODO(scheib): Enable BluetoothTest fixture tests on all platforms. // TODO(scheib): Enable BluetoothTest fixture tests on all platforms.
#if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) #if defined(OS_ANDROID) || defined(OS_MACOSX)
#define MAYBE_ConstructWithoutDefaultAdapter ConstructWithoutDefaultAdapter #define MAYBE_ConstructWithoutDefaultAdapter ConstructWithoutDefaultAdapter
#else #else
#define MAYBE_ConstructWithoutDefaultAdapter \ #define MAYBE_ConstructWithoutDefaultAdapter \
DISABLED_ConstructWithoutDefaultAdapter DISABLED_ConstructWithoutDefaultAdapter
#endif #endif
#if defined(OS_WIN)
TEST_P(BluetoothTestWinrt, ConstructWithoutDefaultAdapter) {
#else
TEST_F(BluetoothTest, MAYBE_ConstructWithoutDefaultAdapter) { TEST_F(BluetoothTest, MAYBE_ConstructWithoutDefaultAdapter) {
#endif // defined(OS_WIN)
InitWithoutDefaultAdapter(); InitWithoutDefaultAdapter();
EXPECT_EQ(adapter_->GetAddress(), ""); EXPECT_EQ(adapter_->GetAddress(), "");
EXPECT_EQ(adapter_->GetName(), ""); EXPECT_EQ(adapter_->GetName(), "");
...@@ -1325,4 +1330,11 @@ TEST_F(BluetoothTest, DiscoverConnectedLowEnergyDeviceTwice) { ...@@ -1325,4 +1330,11 @@ TEST_F(BluetoothTest, DiscoverConnectedLowEnergyDeviceTwice) {
} }
#endif // defined(OS_MACOSX) #endif // defined(OS_MACOSX)
#if defined(OS_WIN)
INSTANTIATE_TEST_CASE_P(
/* no prefix */,
BluetoothTestWinrt,
::testing::Bool());
#endif // defined(OS_WIN)
} // namespace device } // namespace device
// Copyright 2018 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.
#include "device/bluetooth/bluetooth_adapter_winrt.h"
#include "base/logging.h"
#include "device/bluetooth/bluetooth_discovery_filter.h"
namespace device {
std::string BluetoothAdapterWinrt::GetAddress() const {
NOTIMPLEMENTED();
return std::string();
}
std::string BluetoothAdapterWinrt::GetName() const {
NOTIMPLEMENTED();
return std::string();
}
void BluetoothAdapterWinrt::SetName(const std::string& name,
const base::Closure& callback,
const ErrorCallback& error_callback) {
NOTIMPLEMENTED();
}
bool BluetoothAdapterWinrt::IsInitialized() const {
NOTIMPLEMENTED();
return false;
}
bool BluetoothAdapterWinrt::IsPresent() const {
NOTIMPLEMENTED();
return false;
}
bool BluetoothAdapterWinrt::IsPowered() const {
NOTIMPLEMENTED();
return false;
}
bool BluetoothAdapterWinrt::IsDiscoverable() const {
NOTIMPLEMENTED();
return false;
}
void BluetoothAdapterWinrt::SetDiscoverable(
bool discoverable,
const base::Closure& callback,
const ErrorCallback& error_callback) {
NOTIMPLEMENTED();
}
bool BluetoothAdapterWinrt::IsDiscovering() const {
NOTIMPLEMENTED();
return false;
}
BluetoothAdapter::UUIDList BluetoothAdapterWinrt::GetUUIDs() const {
NOTIMPLEMENTED();
return UUIDList();
}
void BluetoothAdapterWinrt::CreateRfcommService(
const BluetoothUUID& uuid,
const ServiceOptions& options,
const CreateServiceCallback& callback,
const CreateServiceErrorCallback& error_callback) {
NOTIMPLEMENTED();
}
void BluetoothAdapterWinrt::CreateL2capService(
const BluetoothUUID& uuid,
const ServiceOptions& options,
const CreateServiceCallback& callback,
const CreateServiceErrorCallback& error_callback) {
NOTIMPLEMENTED();
}
void BluetoothAdapterWinrt::RegisterAdvertisement(
std::unique_ptr<BluetoothAdvertisement::Data> advertisement_data,
const CreateAdvertisementCallback& callback,
const AdvertisementErrorCallback& error_callback) {
NOTIMPLEMENTED();
}
BluetoothLocalGattService* BluetoothAdapterWinrt::GetGattService(
const std::string& identifier) const {
NOTIMPLEMENTED();
return nullptr;
}
bool BluetoothAdapterWinrt::SetPoweredImpl(bool powered) {
NOTIMPLEMENTED();
return false;
}
void BluetoothAdapterWinrt::AddDiscoverySession(
BluetoothDiscoveryFilter* discovery_filter,
const base::Closure& callback,
DiscoverySessionErrorCallback error_callback) {
NOTIMPLEMENTED();
}
void BluetoothAdapterWinrt::RemoveDiscoverySession(
BluetoothDiscoveryFilter* discovery_filter,
const base::Closure& callback,
DiscoverySessionErrorCallback error_callback) {
NOTIMPLEMENTED();
}
void BluetoothAdapterWinrt::SetDiscoveryFilter(
std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter,
const base::Closure& callback,
DiscoverySessionErrorCallback error_callback) {
NOTIMPLEMENTED();
}
void BluetoothAdapterWinrt::RemovePairingDelegateInternal(
BluetoothDevice::PairingDelegate* pairing_delegate) {
NOTIMPLEMENTED();
}
BluetoothAdapterWinrt::BluetoothAdapterWinrt() = default;
BluetoothAdapterWinrt::~BluetoothAdapterWinrt() = default;
} // namespace device
// Copyright 2018 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 DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WINRT_H_
#define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WINRT_H_
#include <memory>
#include <string>
#include "base/callback.h"
#include "base/macros.h"
#include "device/bluetooth/bluetooth_adapter.h"
#include "device/bluetooth/bluetooth_export.h"
namespace device {
class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterWinrt : public BluetoothAdapter {
public:
// BluetoothAdapter:
std::string GetAddress() const override;
std::string GetName() const override;
void SetName(const std::string& name,
const base::Closure& callback,
const ErrorCallback& error_callback) override;
bool IsInitialized() const override;
bool IsPresent() const override;
bool IsPowered() const override;
bool IsDiscoverable() const override;
void SetDiscoverable(bool discoverable,
const base::Closure& callback,
const ErrorCallback& error_callback) override;
bool IsDiscovering() const override;
UUIDList GetUUIDs() const override;
void CreateRfcommService(
const BluetoothUUID& uuid,
const ServiceOptions& options,
const CreateServiceCallback& callback,
const CreateServiceErrorCallback& error_callback) override;
void CreateL2capService(
const BluetoothUUID& uuid,
const ServiceOptions& options,
const CreateServiceCallback& callback,
const CreateServiceErrorCallback& error_callback) override;
void RegisterAdvertisement(
std::unique_ptr<BluetoothAdvertisement::Data> advertisement_data,
const CreateAdvertisementCallback& callback,
const AdvertisementErrorCallback& error_callback) override;
BluetoothLocalGattService* GetGattService(
const std::string& identifier) const override;
protected:
// BluetoothAdapter:
bool SetPoweredImpl(bool powered) override;
void AddDiscoverySession(
BluetoothDiscoveryFilter* discovery_filter,
const base::Closure& callback,
DiscoverySessionErrorCallback error_callback) override;
void RemoveDiscoverySession(
BluetoothDiscoveryFilter* discovery_filter,
const base::Closure& callback,
DiscoverySessionErrorCallback error_callback) override;
void SetDiscoveryFilter(
std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter,
const base::Closure& callback,
DiscoverySessionErrorCallback error_callback) override;
void RemovePairingDelegateInternal(
BluetoothDevice::PairingDelegate* pairing_delegate) override;
private:
friend class BluetoothTestWin;
BluetoothAdapterWinrt();
~BluetoothAdapterWinrt() override;
DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterWinrt);
};
} // namespace device
#endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WINRT_H_
...@@ -6,12 +6,14 @@ ...@@ -6,12 +6,14 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/containers/circular_deque.h" #include "base/containers/circular_deque.h"
#include "base/feature_list.h"
#include "base/location.h" #include "base/location.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/test/test_pending_task.h" #include "base/test/test_pending_task.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "device/bluetooth/bluetooth_adapter_win.h" #include "device/bluetooth/bluetooth_adapter_win.h"
#include "device/bluetooth/bluetooth_adapter_winrt.h"
#include "device/bluetooth/bluetooth_low_energy_win.h" #include "device/bluetooth/bluetooth_low_energy_win.h"
#include "device/bluetooth/bluetooth_remote_gatt_characteristic_win.h" #include "device/bluetooth/bluetooth_remote_gatt_characteristic_win.h"
#include "device/bluetooth/bluetooth_remote_gatt_descriptor_win.h" #include "device/bluetooth/bluetooth_remote_gatt_descriptor_win.h"
...@@ -95,6 +97,11 @@ void BluetoothTestWin::InitWithDefaultAdapter() { ...@@ -95,6 +97,11 @@ void BluetoothTestWin::InitWithDefaultAdapter() {
} }
void BluetoothTestWin::InitWithoutDefaultAdapter() { void BluetoothTestWin::InitWithoutDefaultAdapter() {
if (base::FeatureList::IsEnabled(kNewBLEWinImplementation)) {
adapter_ = base::WrapRefCounted(new BluetoothAdapterWinrt());
return;
}
adapter_ = new BluetoothAdapterWin(base::Bind( adapter_ = new BluetoothAdapterWin(base::Bind(
&BluetoothTestWin::AdapterInitCallback, base::Unretained(this))); &BluetoothTestWin::AdapterInitCallback, base::Unretained(this)));
adapter_win_ = static_cast<BluetoothAdapterWin*>(adapter_.get()); adapter_win_ = static_cast<BluetoothAdapterWin*>(adapter_.get());
......
...@@ -8,8 +8,10 @@ ...@@ -8,8 +8,10 @@
#include "device/bluetooth/test/bluetooth_test.h" #include "device/bluetooth/test/bluetooth_test.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_pending_task.h" #include "base/test/test_pending_task.h"
#include "base/test/test_simple_task_runner.h" #include "base/test/test_simple_task_runner.h"
#include "device/base/features.h"
#include "device/bluetooth/bluetooth_classic_win_fake.h" #include "device/bluetooth/bluetooth_classic_win_fake.h"
#include "device/bluetooth/bluetooth_low_energy_win_fake.h" #include "device/bluetooth/bluetooth_low_energy_win_fake.h"
#include "device/bluetooth/bluetooth_task_manager_win.h" #include "device/bluetooth/bluetooth_task_manager_win.h"
...@@ -103,6 +105,24 @@ class BluetoothTestWin : public BluetoothTestBase, ...@@ -103,6 +105,24 @@ class BluetoothTestWin : public BluetoothTestBase,
// Defines common test fixture name. Use TEST_F(BluetoothTest, YourTestName). // Defines common test fixture name. Use TEST_F(BluetoothTest, YourTestName).
typedef BluetoothTestWin BluetoothTest; typedef BluetoothTestWin BluetoothTest;
// This test suite represents tests that should run with the new BLE
// implementation both enabled and disabled. This requires declaring tests
// in the following way: TEST_P(BluetoothTestWinrt, YourTestName).
class BluetoothTestWinrt : public BluetoothTestWin,
public ::testing::WithParamInterface<bool> {
public:
BluetoothTestWinrt() {
if (GetParam()) {
scoped_feature_list_.InitAndEnableFeature(kNewBLEWinImplementation);
} else {
scoped_feature_list_.InitAndDisableFeature(kNewBLEWinImplementation);
}
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
} // namespace device } // namespace device
#endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_WIN_H_ #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_WIN_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