summaryrefslogtreecommitdiffstats
path: root/device
diff options
context:
space:
mode:
authorccameron <ccameron@chromium.org>2015-02-07 00:33:32 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-07 08:34:13 +0000
commit46b4983d6119b1e4b0c441c61fcbe10b4eb56335 (patch)
tree8cef71a289cf434c45771c99ee8003bdf08dea4d /device
parent42f79f8b08a99190627f3a67e86a378987104a4a (diff)
downloadchromium_src-46b4983d6119b1e4b0c441c61fcbe10b4eb56335.zip
chromium_src-46b4983d6119b1e4b0c441c61fcbe10b4eb56335.tar.gz
chromium_src-46b4983d6119b1e4b0c441c61fcbe10b4eb56335.tar.bz2
Revert of Added bluetooth LE support on Mac platform (patchset #13 id:340001 of https://codereview.chromium.org/791763005/)
Reason for revert: Breaks compile: http://build.chromium.org/p/chromium.mac/builders/Mac%20Builder/builds/17750 ../../device/bluetooth/bluetooth_low_energy_discovery_manager_mac.mm:119:30: error: class method '+UUIDWithString:' not found (return type defaults to 'id') [-Werror,-Wobjc-method-access] CBUUID* uuid = [CBUUID UUIDWithString:uuidString]; ^~~~~~~~~~~~~~ ../../device/bluetooth/bluetooth_low_energy_device_mac.mm:82:39: error: use of undeclared identifier 'CBAdvertisementDataIsConnectable' [advertisementData objectForKey:CBAdvertisementDataIsConnectable]; ^ ../../device/bluetooth/bluetooth_low_energy_device_mac.mm:85:39: error: use of undeclared identifier 'CBAdvertisementDataServiceDataKey' [advertisementData objectForKey:CBAdvertisementDataServiceDataKey]; ^ 2 errors generated. Original issue's description: > Added bluetooth LE support on Mac platform > > BUG=449682 > > Committed: https://crrev.com/42f79f8b08a99190627f3a67e86a378987104a4a > Cr-Commit-Position: refs/heads/master@{#315190} TBR=armansito@chromium.org,avi@chromium.org,groby@chromium.org,dvh@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=449682 Review URL: https://codereview.chromium.org/871843009 Cr-Commit-Position: refs/heads/master@{#315191}
Diffstat (limited to 'device')
-rw-r--r--device/bluetooth/BUILD.gn4
-rw-r--r--device/bluetooth/bluetooth.gyp4
-rw-r--r--device/bluetooth/bluetooth_discovery_manager_mac.h3
-rw-r--r--device/bluetooth/bluetooth_low_energy_device_mac.h99
-rw-r--r--device/bluetooth/bluetooth_low_energy_device_mac.mm237
-rw-r--r--device/bluetooth/bluetooth_low_energy_discovery_manager_mac.h103
-rw-r--r--device/bluetooth/bluetooth_low_energy_discovery_manager_mac.mm180
7 files changed, 0 insertions, 630 deletions
diff --git a/device/bluetooth/BUILD.gn b/device/bluetooth/BUILD.gn
index 0e70391..d8bc665 100644
--- a/device/bluetooth/BUILD.gn
+++ b/device/bluetooth/BUILD.gn
@@ -69,10 +69,6 @@ component("bluetooth") {
"bluetooth_l2cap_channel_mac.h",
"bluetooth_low_energy_defs_win.cc",
"bluetooth_low_energy_defs_win.h",
- "bluetooth_low_energy_device_mac.h",
- "bluetooth_low_energy_device_mac.mm",
- "bluetooth_low_energy_discovery_manager_mac.h",
- "bluetooth_low_energy_discovery_manager_mac.mm",
"bluetooth_low_energy_win.cc",
"bluetooth_low_energy_win.h",
"bluetooth_pairing_chromeos.cc",
diff --git a/device/bluetooth/bluetooth.gyp b/device/bluetooth/bluetooth.gyp
index f4d3f1f..30b9ffe 100644
--- a/device/bluetooth/bluetooth.gyp
+++ b/device/bluetooth/bluetooth.gyp
@@ -72,10 +72,6 @@
'bluetooth_l2cap_channel_mac.h',
'bluetooth_low_energy_defs_win.cc',
'bluetooth_low_energy_defs_win.h',
- 'bluetooth_low_energy_device_mac.h',
- 'bluetooth_low_energy_device_mac.mm',
- 'bluetooth_low_energy_discovery_manager_mac.h',
- 'bluetooth_low_energy_discovery_manager_mac.mm',
'bluetooth_low_energy_win.cc',
'bluetooth_low_energy_win.h',
'bluetooth_pairing_chromeos.cc',
diff --git a/device/bluetooth/bluetooth_discovery_manager_mac.h b/device/bluetooth/bluetooth_discovery_manager_mac.h
index f6a003c..534646a 100644
--- a/device/bluetooth/bluetooth_discovery_manager_mac.h
+++ b/device/bluetooth/bluetooth_discovery_manager_mac.h
@@ -28,9 +28,6 @@ class BluetoothDiscoveryManagerMac {
// such as when a user disables the controller, in which case the value of
// |unexpected| will be true.
virtual void DiscoveryStopped(bool unexpected) = 0;
-
- protected:
- virtual ~Observer() {}
};
virtual ~BluetoothDiscoveryManagerMac();
diff --git a/device/bluetooth/bluetooth_low_energy_device_mac.h b/device/bluetooth/bluetooth_low_energy_device_mac.h
deleted file mode 100644
index bb5ffca..0000000
--- a/device/bluetooth/bluetooth_low_energy_device_mac.h
+++ /dev/null
@@ -1,99 +0,0 @@
-// Copyright 2015 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_LOW_ENERGY_DEVICE_MAC_H_
-#define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_
-
-#if defined(OS_IOS)
-#import <CoreBluetooth/CoreBluetooth.h>
-#else
-#import <IOBluetooth/IOBluetooth.h>
-#endif
-
-#include "base/mac/scoped_nsobject.h"
-#include "base/mac/sdk_forward_declarations.h"
-#include "device/bluetooth/bluetooth_device.h"
-
-namespace device {
-
-class BluetoothLowEnergyDiscoverManagerMac;
-
-class BluetoothLowEnergyDeviceMac : public BluetoothDevice {
- public:
- BluetoothLowEnergyDeviceMac(CBPeripheral* peripheral,
- NSDictionary* advertisementData,
- int rssi);
- ~BluetoothLowEnergyDeviceMac() override;
-
- int GetRSSI() const;
-
- // BluetoothDevice overrides.
- std::string GetIdentifier() const override;
- uint32 GetBluetoothClass() const override;
- std::string GetAddress() const override;
- BluetoothDevice::VendorIDSource GetVendorIDSource() const override;
- uint16 GetVendorID() const override;
- uint16 GetProductID() const override;
- uint16 GetDeviceID() const override;
- bool IsPaired() const override;
- bool IsConnected() const override;
- bool IsConnectable() const override;
- bool IsConnecting() const override;
- BluetoothDevice::UUIDList GetUUIDs() const override;
- bool ExpectingPinCode() const override;
- bool ExpectingPasskey() const override;
- bool ExpectingConfirmation() const override;
- void GetConnectionInfo(const ConnectionInfoCallback& callback) override;
- void Connect(PairingDelegate* pairing_delegate,
- const base::Closure& callback,
- const ConnectErrorCallback& error_callback) override;
- void SetPinCode(const std::string& pincode) override;
- void SetPasskey(uint32 passkey) override;
- void ConfirmPairing() override;
- void RejectPairing() override;
- void CancelPairing() override;
- void Disconnect(const base::Closure& callback,
- const ErrorCallback& error_callback) override;
- void Forget(const ErrorCallback& error_callback) override;
- void ConnectToService(
- const BluetoothUUID& uuid,
- const ConnectToServiceCallback& callback,
- const ConnectToServiceErrorCallback& error_callback) override;
- void ConnectToServiceInsecurely(
- const device::BluetoothUUID& uuid,
- const ConnectToServiceCallback& callback,
- const ConnectToServiceErrorCallback& error_callback) override;
- void CreateGattConnection(
- const GattConnectionCallback& callback,
- const ConnectErrorCallback& error_callback) override;
-
- protected:
- // BluetoothDevice override.
- std::string GetDeviceName() const override;
-
- // Updates information about the device.
- virtual void Update(CBPeripheral* peripheral,
- NSDictionary* advertisementData,
- int rssi);
-
- static std::string GetPeripheralIdentifier(CBPeripheral* peripheral);
-
- private:
- friend class BluetoothLowEnergyDiscoveryManagerMac;
-
- // CoreBluetooth data structure.
- base::scoped_nsobject<CBPeripheral> peripheral_;
-
- // RSSI value.
- int rssi_;
-
- // Whether the device is connectable.
- bool connectable_;
-
- DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDeviceMac);
-};
-
-} // namespace device
-
-#endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_
diff --git a/device/bluetooth/bluetooth_low_energy_device_mac.mm b/device/bluetooth/bluetooth_low_energy_device_mac.mm
deleted file mode 100644
index ae56d53..0000000
--- a/device/bluetooth/bluetooth_low_energy_device_mac.mm
+++ /dev/null
@@ -1,237 +0,0 @@
-// Copyright 2015 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_low_energy_device_mac.h"
-
-#import <CoreFoundation/CoreFoundation.h>
-
-#include "base/mac/scoped_cftyperef.h"
-#include "base/mac/sdk_forward_declarations.h"
-#include "base/strings/sys_string_conversions.h"
-
-using device::BluetoothDevice;
-using device::BluetoothLowEnergyDeviceMac;
-
-namespace {
-
-// Converts a CBUUID to a Cocoa string.
-//
-// The string representation can have the following formats:
-// - 16 bit: xxxx
-// - 128 bit: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
-// CBUUID supports only 16 bits and 128 bits formats.
-//
-// In OSX < 10.10, -[uuid UUIDString] method is not implemented. It's why we
-// need to provide this function.
-NSString* stringWithCBUUID(CBUUID* uuid) {
- NSData* data = [uuid data];
-
- NSUInteger bytesToConvert = [data length];
- const unsigned char* uuidBytes = (const unsigned char*)[data bytes];
- NSMutableString* outputString = [NSMutableString stringWithCapacity:16];
-
- for (NSUInteger currentByteIndex = 0; currentByteIndex < bytesToConvert;
- currentByteIndex++) {
- switch (currentByteIndex) {
- case 3:
- case 5:
- case 7:
- case 9:
- [outputString appendFormat:@"%02x-", uuidBytes[currentByteIndex]];
- break;
- default:
- [outputString appendFormat:@"%02x", uuidBytes[currentByteIndex]];
- }
- }
- return outputString;
-}
-
-// Converts a CBUUID to a BluetoothUUID.
-device::BluetoothUUID BluetoothUUIDWithCBUUID(CBUUID* uuid) {
- NSString* uuidString = nil;
- // TODO(dvh): Remove this once we moved to OSX SDK >= 10.10.
- if ([uuid respondsToSelector:@selector(UUIDString)]) {
- uuidString = [uuid UUIDString];
- } else {
- uuidString = stringWithCBUUID(uuid);
- }
- std::string uuid_c_string = base::SysNSStringToUTF8(uuidString);
- return device::BluetoothUUID(uuid_c_string);
-}
-
-} // namespace
-
-BluetoothLowEnergyDeviceMac::BluetoothLowEnergyDeviceMac(
- CBPeripheral* peripheral,
- NSDictionary* advertisementData,
- int rssi) {
- Update(peripheral, advertisementData, rssi);
-}
-
-BluetoothLowEnergyDeviceMac::~BluetoothLowEnergyDeviceMac() {
-}
-
-void BluetoothLowEnergyDeviceMac::Update(CBPeripheral* peripheral,
- NSDictionary* advertisementData,
- int rssi) {
- peripheral_.reset([peripheral retain]);
- rssi_ = rssi;
- ClearServiceData();
- NSNumber* nbConnectable =
- [advertisementData objectForKey:CBAdvertisementDataIsConnectable];
- connectable_ = [nbConnectable boolValue];
- NSDictionary* serviceData =
- [advertisementData objectForKey:CBAdvertisementDataServiceDataKey];
- for (CBUUID* uuid in serviceData) {
- NSData* data = [serviceData objectForKey:uuid];
- BluetoothUUID serviceUUID = BluetoothUUIDWithCBUUID(uuid);
- SetServiceData(serviceUUID, (const char*)[data bytes], [data length]);
- }
-}
-
-std::string BluetoothLowEnergyDeviceMac::GetIdentifier() const {
- return GetPeripheralIdentifier(peripheral_);
-}
-
-uint32 BluetoothLowEnergyDeviceMac::GetBluetoothClass() const {
- return 0;
-}
-
-std::string BluetoothLowEnergyDeviceMac::GetAddress() const {
- return std::string();
-}
-
-BluetoothDevice::VendorIDSource BluetoothLowEnergyDeviceMac::GetVendorIDSource()
- const {
- return VENDOR_ID_UNKNOWN;
-}
-
-uint16 BluetoothLowEnergyDeviceMac::GetVendorID() const {
- return 0;
-}
-
-uint16 BluetoothLowEnergyDeviceMac::GetProductID() const {
- return 0;
-}
-
-uint16 BluetoothLowEnergyDeviceMac::GetDeviceID() const {
- return 0;
-}
-
-int BluetoothLowEnergyDeviceMac::GetRSSI() const {
- return rssi_;
-}
-
-bool BluetoothLowEnergyDeviceMac::IsPaired() const {
- return false;
-}
-
-bool BluetoothLowEnergyDeviceMac::IsConnected() const {
- return [peripheral_ isConnected];
-}
-
-bool BluetoothLowEnergyDeviceMac::IsConnectable() const {
- return connectable_;
-}
-
-bool BluetoothLowEnergyDeviceMac::IsConnecting() const {
- return false;
-}
-
-BluetoothDevice::UUIDList BluetoothLowEnergyDeviceMac::GetUUIDs() const {
- return std::vector<device::BluetoothUUID>();
-}
-
-bool BluetoothLowEnergyDeviceMac::ExpectingPinCode() const {
- return false;
-}
-
-bool BluetoothLowEnergyDeviceMac::ExpectingPasskey() const {
- return false;
-}
-
-bool BluetoothLowEnergyDeviceMac::ExpectingConfirmation() const {
- return false;
-}
-
-void BluetoothLowEnergyDeviceMac::GetConnectionInfo(
- const ConnectionInfoCallback& callback) {
- NOTIMPLEMENTED();
-}
-
-void BluetoothLowEnergyDeviceMac::Connect(
- PairingDelegate* pairing_delegate,
- const base::Closure& callback,
- const ConnectErrorCallback& error_callback) {
- NOTIMPLEMENTED();
-}
-
-void BluetoothLowEnergyDeviceMac::SetPinCode(const std::string& pincode) {
- NOTIMPLEMENTED();
-}
-
-void BluetoothLowEnergyDeviceMac::SetPasskey(uint32 passkey) {
- NOTIMPLEMENTED();
-}
-
-void BluetoothLowEnergyDeviceMac::ConfirmPairing() {
- NOTIMPLEMENTED();
-}
-
-void BluetoothLowEnergyDeviceMac::RejectPairing() {
- NOTIMPLEMENTED();
-}
-
-void BluetoothLowEnergyDeviceMac::CancelPairing() {
- NOTIMPLEMENTED();
-}
-
-void BluetoothLowEnergyDeviceMac::Disconnect(
- const base::Closure& callback,
- const ErrorCallback& error_callback) {
- NOTIMPLEMENTED();
-}
-
-void BluetoothLowEnergyDeviceMac::Forget(const ErrorCallback& error_callback) {
- NOTIMPLEMENTED();
-}
-
-void BluetoothLowEnergyDeviceMac::ConnectToService(
- const BluetoothUUID& uuid,
- const ConnectToServiceCallback& callback,
- const ConnectToServiceErrorCallback& error_callback) {
- NOTIMPLEMENTED();
-}
-
-void BluetoothLowEnergyDeviceMac::ConnectToServiceInsecurely(
- const device::BluetoothUUID& uuid,
- const ConnectToServiceCallback& callback,
- const ConnectToServiceErrorCallback& error_callback) {
- NOTIMPLEMENTED();
-}
-
-void BluetoothLowEnergyDeviceMac::CreateGattConnection(
- const GattConnectionCallback& callback,
- const ConnectErrorCallback& error_callback) {
- NOTIMPLEMENTED();
-}
-
-std::string BluetoothLowEnergyDeviceMac::GetDeviceName() const {
- return base::SysNSStringToUTF8([peripheral_ name]);
-}
-
-std::string BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier(
- CBPeripheral* peripheral) {
- // TODO(dvh): Remove this once we moved to OSX SDK >= 10.9.
- if ([peripheral respondsToSelector:@selector(identifier)]) {
- // When -[CBPeripheral identifier] is available.
- NSUUID* uuid = [peripheral identifier];
- NSString* uuidString = [uuid UUIDString];
- return base::SysNSStringToUTF8(uuidString);
- }
-
- base::ScopedCFTypeRef<CFStringRef> str(
- CFUUIDCreateString(NULL, [peripheral UUID]));
- return SysCFStringRefToUTF8(str);
-}
diff --git a/device/bluetooth/bluetooth_low_energy_discovery_manager_mac.h b/device/bluetooth/bluetooth_low_energy_discovery_manager_mac.h
deleted file mode 100644
index 29ad529..0000000
--- a/device/bluetooth/bluetooth_low_energy_discovery_manager_mac.h
+++ /dev/null
@@ -1,103 +0,0 @@
-// Copyright 2015 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_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_
-#define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_
-
-#if defined(OS_IOS)
-#import <CoreBluetooth/CoreBluetooth.h>
-#else
-#import <IOBluetooth/IOBluetooth.h>
-#endif
-
-#include "base/mac/scoped_nsobject.h"
-#include "base/mac/sdk_forward_declarations.h"
-#include "device/bluetooth/bluetooth_device.h"
-
-@class BluetoothLowEnergyDiscoveryManagerMacBridge;
-
-namespace device {
-
-class BluetoothLowEnergyDeviceMac;
-class BluetoothLowEnergyDiscoveryManagerMacDelegate;
-
-// This class will scan for Bluetooth LE device on Mac.
-class BluetoothLowEnergyDiscoveryManagerMac {
- public:
- // Interface for being notified of events during a device discovery session.
- class Observer {
- public:
- // Called when |this| manager has found a device.
- virtual void DeviceFound(BluetoothLowEnergyDeviceMac* device) = 0;
-
- // Called when |this| manager has updated on a device.
- virtual void DeviceUpdated(BluetoothLowEnergyDeviceMac* device) = 0;
-
- protected:
- virtual ~Observer() {}
- };
-
- virtual ~BluetoothLowEnergyDiscoveryManagerMac();
-
- // Returns true, if discovery is currently being performed.
- virtual bool IsDiscovering() const;
-
- // Initiates a discovery session.
- // BluetoothLowEnergyDeviceMac objects discovered within a previous
- // discovery session will be invalid.
- virtual void StartDiscovery(BluetoothDevice::UUIDList services_uuids);
-
- // Stops a discovery session.
- virtual void StopDiscovery();
-
- // Returns a new BluetoothLowEnergyDiscoveryManagerMac.
- static BluetoothLowEnergyDiscoveryManagerMac* Create(Observer* observer);
-
- protected:
- // Called when a discovery or an update of a BLE device occurred.
- virtual void DiscoveredPeripheral(CBPeripheral* peripheral,
- NSDictionary* advertisementData,
- int rssi);
-
- // The device discovery can really be started when Bluetooth is powered on.
- // The method TryStartDiscovery() is called when it's a good time to try to
- // start the BLE device discovery. It will check if the discovery session has
- // been started and if the Bluetooth is powered and then really start the
- // CoreBluetooth BLE device discovery.
- virtual void TryStartDiscovery();
-
- private:
- explicit BluetoothLowEnergyDiscoveryManagerMac(Observer* observer);
- void ClearDevices();
-
- friend class BluetoothLowEnergyDiscoveryManagerMacDelegate;
-
- // Observer interested in notifications from us.
- Observer* observer_;
-
- // Underlaying CoreBluetooth central manager.
- base::scoped_nsobject<CBCentralManager> manager_;
-
- // Discovery has been initiated by calling the API StartDiscovery().
- bool discovering_;
-
- // A discovery has been initiated but has not started yet because it's
- // waiting for Bluetooth to turn on.
- bool pending_;
-
- // Delegate of the central manager.
- base::scoped_nsobject<BluetoothLowEnergyDiscoveryManagerMacBridge> bridge_;
-
- // Map of the device identifiers to the discovered device.
- std::map<const std::string, BluetoothLowEnergyDeviceMac*> devices_;
-
- // List of service UUIDs to scan.
- BluetoothDevice::UUIDList services_uuids_;
-
- DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDiscoveryManagerMac);
-};
-
-} // namespace device
-
-#endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_
diff --git a/device/bluetooth/bluetooth_low_energy_discovery_manager_mac.mm b/device/bluetooth/bluetooth_low_energy_discovery_manager_mac.mm
deleted file mode 100644
index 1d7e409..0000000
--- a/device/bluetooth/bluetooth_low_energy_discovery_manager_mac.mm
+++ /dev/null
@@ -1,180 +0,0 @@
-// Copyright 2015 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_low_energy_discovery_manager_mac.h"
-
-#include "base/mac/mac_util.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/strings/sys_string_conversions.h"
-#include "device/bluetooth/bluetooth_low_energy_device_mac.h"
-
-using device::BluetoothLowEnergyDeviceMac;
-using device::BluetoothLowEnergyDiscoveryManagerMac;
-using device::BluetoothLowEnergyDiscoveryManagerMacDelegate;
-
-namespace device {
-
-// This class is a helper to call some protected methods in
-// BluetoothLowEnergyDiscoveryManagerMac.
-class BluetoothLowEnergyDiscoveryManagerMacDelegate {
- public:
- BluetoothLowEnergyDiscoveryManagerMacDelegate(
- BluetoothLowEnergyDiscoveryManagerMac* manager)
- : manager_(manager) {}
-
- virtual ~BluetoothLowEnergyDiscoveryManagerMacDelegate() {}
-
- virtual void DiscoveredPeripheral(CBPeripheral* peripheral,
- NSDictionary* advertisementData,
- int rssi) {
- manager_->DiscoveredPeripheral(peripheral, advertisementData, rssi);
- }
-
- virtual void TryStartDiscovery() { manager_->TryStartDiscovery(); }
-
- private:
- BluetoothLowEnergyDiscoveryManagerMac* manager_;
-};
-
-} // namespace device
-
-// This class will serve as the Objective-C delegate of CBCentralManager.
-@interface BluetoothLowEnergyDiscoveryManagerMacBridge
- : NSObject<CBCentralManagerDelegate>
-
-- (id)initWithManager:(BluetoothLowEnergyDiscoveryManagerMac*)manager;
-
-@end
-
-@implementation BluetoothLowEnergyDiscoveryManagerMacBridge {
- BluetoothLowEnergyDiscoveryManagerMac* manager_;
- scoped_ptr<BluetoothLowEnergyDiscoveryManagerMacDelegate> delegate_;
-}
-
-- (id)initWithManager:(BluetoothLowEnergyDiscoveryManagerMac*)manager {
- if ((self = [super init])) {
- manager_ = manager;
- delegate_.reset(
- new BluetoothLowEnergyDiscoveryManagerMacDelegate(manager_));
- }
- return self;
-}
-
-- (void)centralManager:(CBCentralManager*)central
- didDiscoverPeripheral:(CBPeripheral*)peripheral
- advertisementData:(NSDictionary*)advertisementData
- RSSI:(NSNumber*)RSSI {
- // Notifies the discovery of a device.
- delegate_->DiscoveredPeripheral(peripheral, advertisementData,
- [RSSI intValue]);
-}
-
-- (void)centralManagerDidUpdateState:(CBCentralManager*)central {
- // Notifies when the powered state of the central manager changed.
- delegate_->TryStartDiscovery();
-}
-
-@end
-
-BluetoothLowEnergyDiscoveryManagerMac::
- ~BluetoothLowEnergyDiscoveryManagerMac() {
- ClearDevices();
-}
-
-bool BluetoothLowEnergyDiscoveryManagerMac::IsDiscovering() const {
- return discovering_;
-}
-
-void BluetoothLowEnergyDiscoveryManagerMac::StartDiscovery(
- BluetoothDevice::UUIDList services_uuids) {
- ClearDevices();
- discovering_ = true;
- pending_ = true;
- services_uuids_ = services_uuids;
- TryStartDiscovery();
-}
-
-void BluetoothLowEnergyDiscoveryManagerMac::TryStartDiscovery() {
- if (!discovering_) {
- return;
- }
-
- if (!pending_) {
- return;
- }
-
- // Can only start if the bluetooth power is turned on.
- if ([manager_ state] != CBCentralManagerStatePoweredOn) {
- return;
- }
-
- // Converts the services UUIDs to a CoreBluetooth data structure.
- NSMutableArray* services = nil;
- if (!services_uuids_.empty()) {
- services = [NSMutableArray array];
- for (auto& service_uuid : services_uuids_) {
- NSString* uuidString =
- base::SysUTF8ToNSString(service_uuid.canonical_value().c_str());
- CBUUID* uuid = [CBUUID UUIDWithString:uuidString];
- [services addObject:uuid];
- }
- }
-
- [manager_ scanForPeripheralsWithServices:services options:nil];
- pending_ = false;
-}
-
-void BluetoothLowEnergyDiscoveryManagerMac::StopDiscovery() {
- if (discovering_ && !pending_) {
- [manager_ stopScan];
- }
- discovering_ = false;
-}
-
-void BluetoothLowEnergyDiscoveryManagerMac::DiscoveredPeripheral(
- CBPeripheral* peripheral,
- NSDictionary* advertisementData,
- int rssi) {
- // Look for existing device.
- auto iter = devices_.find(
- BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier(peripheral));
- if (iter == devices_.end()) {
- // A device has been added.
- BluetoothLowEnergyDeviceMac* device =
- new BluetoothLowEnergyDeviceMac(peripheral, advertisementData, rssi);
- devices_.insert(devices_.begin(),
- std::make_pair(device->GetIdentifier(), device));
- observer_->DeviceFound(device);
- return;
- }
-
- // A device has an update.
- BluetoothLowEnergyDeviceMac* old_device = iter->second;
- old_device->Update(peripheral, advertisementData, rssi);
- observer_->DeviceUpdated(old_device);
-}
-
-BluetoothLowEnergyDiscoveryManagerMac*
-BluetoothLowEnergyDiscoveryManagerMac::Create(Observer* observer) {
- return new BluetoothLowEnergyDiscoveryManagerMac(observer);
-}
-
-BluetoothLowEnergyDiscoveryManagerMac::BluetoothLowEnergyDiscoveryManagerMac(
- Observer* observer)
- : observer_(observer) {
- bridge_.reset([[BluetoothLowEnergyDiscoveryManagerMacBridge alloc]
- initWithManager:this]);
- // Since CoreBluetooth is only available on OS X 10.7 or later, we
- // instantiate CBCentralManager only for OS X >= 10.7.
- if (base::mac::IsOSLionOrLater()) {
- manager_.reset(
- [[CBCentralManager alloc] initWithDelegate:bridge_
- queue:dispatch_get_main_queue()]);
- }
- discovering_ = false;
-}
-
-void BluetoothLowEnergyDiscoveryManagerMac::ClearDevices() {
- STLDeleteValues(&devices_);
-}