OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_ANDROID_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_ANDROID_H_ |
7 | 7 |
8 #include <IOKit/IOReturn.h> | |
9 | |
10 #include <string> | |
11 #include <vector> | |
12 | |
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" | 8 #include "base/memory/weak_ptr.h" |
17 #include "base/observer_list.h" | |
18 #include "device/bluetooth/bluetooth_adapter.h" | 9 #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" | |
22 | |
23 @class IOBluetoothDevice; | |
24 @class NSArray; | |
25 @class NSDate; | |
26 | 10 |
27 namespace base { | 11 namespace base { |
28 | |
29 class SequencedTaskRunner; | 12 class SequencedTaskRunner; |
30 | |
31 } // namespace base | 13 } // namespace base |
32 | 14 |
33 namespace device { | 15 namespace device { |
34 | 16 |
35 class BluetoothAdapterMacTest; | 17 // The BluetoothAdapterAndroid class implements BluetoothAdapter for the |
36 | 18 // Android platform. |
37 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterMac | 19 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterAndroid final |
38 : public BluetoothAdapter, | 20 : public BluetoothAdapter { |
39 public BluetoothDiscoveryManagerMac::Observer { | |
40 public: | 21 public: |
41 static base::WeakPtr<BluetoothAdapter> CreateAdapter(); | 22 static base::WeakPtr<BluetoothAdapter> CreateAdapter(); |
42 | 23 |
43 // BluetoothAdapter: | 24 // BluetoothAdapter: |
44 std::string GetAddress() const override; | 25 std::string GetAddress() const override; |
45 std::string GetName() const override; | 26 std::string GetName() const override; |
46 void SetName(const std::string& name, | 27 void SetName(const std::string& name, |
47 const base::Closure& callback, | 28 const base::Closure& callback, |
48 const ErrorCallback& error_callback) override; | 29 const ErrorCallback& error_callback) override; |
49 bool IsInitialized() const override; | 30 bool IsInitialized() const override; |
(...skipping 12 matching lines...) Expand all Loading... | |
62 const ServiceOptions& options, | 43 const ServiceOptions& options, |
63 const CreateServiceCallback& callback, | 44 const CreateServiceCallback& callback, |
64 const CreateServiceErrorCallback& error_callback) override; | 45 const CreateServiceErrorCallback& error_callback) override; |
65 void CreateL2capService( | 46 void CreateL2capService( |
66 const BluetoothUUID& uuid, | 47 const BluetoothUUID& uuid, |
67 const ServiceOptions& options, | 48 const ServiceOptions& options, |
68 const CreateServiceCallback& callback, | 49 const CreateServiceCallback& callback, |
69 const CreateServiceErrorCallback& error_callback) override; | 50 const CreateServiceErrorCallback& error_callback) override; |
70 void RegisterAudioSink( | 51 void RegisterAudioSink( |
71 const BluetoothAudioSink::Options& options, | 52 const BluetoothAudioSink::Options& options, |
72 const AcquiredCallback& callback, | 53 const BluetoothAdapter::AcquiredCallback& callback, |
armansito
2015/04/29 01:17:28
The BluetoothAdapter:: part shouldn't be necessary
scheib
2015/04/29 01:35:14
Done.
| |
73 const BluetoothAudioSink::ErrorCallback& error_callback) override; | 54 const BluetoothAudioSink::ErrorCallback& error_callback) override; |
74 void RegisterAdvertisement( | 55 void RegisterAdvertisement( |
75 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, | 56 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, |
76 const CreateAdvertisementCallback& callback, | 57 const CreateAdvertisementCallback& callback, |
77 const CreateAdvertisementErrorCallback& error_callback) override; | 58 const CreateAdvertisementErrorCallback& error_callback) override; |
78 | 59 |
79 // BluetoothDiscoveryManagerMac::Observer overrides | |
80 void DeviceFound(IOBluetoothDevice* device) override; | |
81 void DiscoveryStopped(bool unexpected) override; | |
82 | |
83 // Registers that a new |device| has connected to the local host. | |
84 void DeviceConnected(IOBluetoothDevice* device); | |
85 | |
86 protected: | 60 protected: |
87 // BluetoothAdapter: | 61 BluetoothAdapterAndroid(); |
88 void RemovePairingDelegateInternal( | 62 ~BluetoothAdapterAndroid() override; |
89 device::BluetoothDevice::PairingDelegate* pairing_delegate) override; | |
90 | |
91 private: | |
92 friend class BluetoothAdapterMacTest; | |
93 | |
94 BluetoothAdapterMac(); | |
95 ~BluetoothAdapterMac() override; | |
96 | 63 |
97 // BluetoothAdapter: | 64 // BluetoothAdapter: |
98 void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, | 65 void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, |
99 const base::Closure& callback, | 66 const base::Closure& callback, |
100 const ErrorCallback& error_callback) override; | 67 const ErrorCallback& error_callback) override; |
101 void RemoveDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, | 68 void RemoveDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, |
102 const base::Closure& callback, | 69 const base::Closure& callback, |
103 const ErrorCallback& error_callback) override; | 70 const ErrorCallback& error_callback) override; |
104 void SetDiscoveryFilter(scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, | 71 void SetDiscoveryFilter(scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, |
105 const base::Closure& callback, | 72 const base::Closure& callback, |
106 const ErrorCallback& error_callback) override; | 73 const ErrorCallback& error_callback) override; |
107 | 74 void RemovePairingDelegateInternal( |
108 void Init(); | 75 BluetoothDevice::PairingDelegate* pairing_delegate) override; |
109 void InitForTest(scoped_refptr<base::SequencedTaskRunner> ui_task_runner); | |
110 void PollAdapter(); | |
111 | |
112 // Registers that a new |device| has replied to an Inquiry, is paired, or has | |
113 // connected to the local host. | |
114 void DeviceAdded(IOBluetoothDevice* device); | |
115 | |
116 // Updates |devices_| to include the currently paired devices, as well as any | |
117 // connected, but unpaired, devices. Notifies observers if any previously | |
118 // paired or connected devices are no longer present. | |
119 void UpdateDevices(); | |
120 | 76 |
121 std::string address_; | 77 std::string address_; |
122 std::string name_; | 78 std::string name_; |
123 bool powered_; | |
124 | 79 |
125 int num_discovery_sessions_; | 80 // Note: This should remain the last member so it'll be destroyed and |
81 // invalidate its weak pointers before any other members are destroyed. | |
82 base::WeakPtrFactory<BluetoothAdapterAndroid> weak_ptr_factory_; | |
126 | 83 |
127 // Discovery manager for Bluetooth Classic. | 84 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterAndroid); |
128 scoped_ptr<BluetoothDiscoveryManagerMac> classic_discovery_manager_; | |
129 | |
130 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | |
131 | |
132 base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_; | |
133 | |
134 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac); | |
135 }; | 85 }; |
136 | 86 |
137 } // namespace device | 87 } // namespace device |
138 | 88 |
139 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ | 89 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_ANDROID_H_ |
OLD | NEW |