Make castv2 performance test work.
[chromium-blink-merge.git] / device / bluetooth / bluetooth_adapter_mac.h
blob52567b046d31c5ef8e6bc4eecdf49f3af3283ee3
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_
8 #include <IOKit/IOReturn.h>
10 #include <string>
11 #include <vector>
13 #include "base/containers/hash_tables.h"
14 #include "base/mac/scoped_nsobject.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/weak_ptr.h"
17 #include "base/observer_list.h"
18 #include "device/bluetooth/bluetooth_adapter.h"
19 #include "device/bluetooth/bluetooth_audio_sink.h"
20 #include "device/bluetooth/bluetooth_discovery_manager_mac.h"
21 #include "device/bluetooth/bluetooth_export.h"
23 @class IOBluetoothDevice;
24 @class NSArray;
25 @class NSDate;
27 namespace base {
29 class SequencedTaskRunner;
31 } // namespace base
33 namespace device {
35 class BluetoothAdapterMacTest;
37 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterMac
38 : public BluetoothAdapter,
39 public BluetoothDiscoveryManagerMac::Observer {
40 public:
41 static base::WeakPtr<BluetoothAdapter> CreateAdapter();
43 // BluetoothAdapter:
44 void AddObserver(BluetoothAdapter::Observer* observer) override;
45 void RemoveObserver(BluetoothAdapter::Observer* observer) override;
46 std::string GetAddress() const override;
47 std::string GetName() const override;
48 void SetName(const std::string& name,
49 const base::Closure& callback,
50 const ErrorCallback& error_callback) override;
51 bool IsInitialized() const override;
52 bool IsPresent() const override;
53 bool IsPowered() const override;
54 void SetPowered(bool powered,
55 const base::Closure& callback,
56 const ErrorCallback& error_callback) override;
57 bool IsDiscoverable() const override;
58 void SetDiscoverable(bool discoverable,
59 const base::Closure& callback,
60 const ErrorCallback& error_callback) override;
61 bool IsDiscovering() const override;
62 void CreateRfcommService(
63 const BluetoothUUID& uuid,
64 const ServiceOptions& options,
65 const CreateServiceCallback& callback,
66 const CreateServiceErrorCallback& error_callback) override;
67 void CreateL2capService(
68 const BluetoothUUID& uuid,
69 const ServiceOptions& options,
70 const CreateServiceCallback& callback,
71 const CreateServiceErrorCallback& error_callback) override;
72 void RegisterAudioSink(
73 const BluetoothAudioSink::Options& options,
74 const AcquiredCallback& callback,
75 const BluetoothAudioSink::ErrorCallback& error_callback) override;
77 // BluetoothDiscoveryManagerMac::Observer overrides
78 void DeviceFound(IOBluetoothDevice* device) override;
79 void DiscoveryStopped(bool unexpected) override;
81 // Registers that a new |device| has connected to the local host.
82 void DeviceConnected(IOBluetoothDevice* device);
84 protected:
85 // BluetoothAdapter:
86 void RemovePairingDelegateInternal(
87 device::BluetoothDevice::PairingDelegate* pairing_delegate) override;
89 private:
90 friend class base::DeleteHelper<BluetoothAdapterMac>;
91 friend class BluetoothAdapterMacTest;
93 BluetoothAdapterMac();
94 ~BluetoothAdapterMac() override;
96 // BluetoothAdapter:
97 void DeleteOnCorrectThread() const override;
98 void AddDiscoverySession(const base::Closure& callback,
99 const ErrorCallback& error_callback) override;
100 void RemoveDiscoverySession(const base::Closure& callback,
101 const ErrorCallback& error_callback) override;
103 void Init();
104 void InitForTest(scoped_refptr<base::SequencedTaskRunner> ui_task_runner);
105 void PollAdapter();
107 // Registers that a new |device| has replied to an Inquiry, is paired, or has
108 // connected to the local host.
109 void DeviceAdded(IOBluetoothDevice* device);
111 // Updates |devices_| to include the currently paired devices, as well as any
112 // connected, but unpaired, devices. Notifies observers if any previously
113 // paired or connected devices are no longer present.
114 void UpdateDevices();
116 std::string address_;
117 std::string name_;
118 bool powered_;
120 int num_discovery_sessions_;
122 // Discovery manager for Bluetooth Classic.
123 scoped_ptr<BluetoothDiscoveryManagerMac> classic_discovery_manager_;
125 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
127 // List of observers interested in event notifications from us.
128 ObserverList<BluetoothAdapter::Observer> observers_;
130 base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_;
132 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac);
135 } // namespace device
137 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_