Implement nacl_irt_memory for non-sfi mode.
[chromium-blink-merge.git] / device / bluetooth / bluetooth_adapter_mac.h
blob7054acf5d0e3e11f3a36a6793ca07dd29e3701d5
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/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/observer_list.h"
17 #include "device/bluetooth/bluetooth_adapter.h"
19 #ifdef __OBJC__
20 @class BluetoothAdapterMacDelegate;
21 @class IOBluetoothDevice;
22 @class IOBluetoothDeviceInquiry;
23 @class NSArray;
24 @class NSDate;
25 #else
26 class BluetoothAdapterMacDelegate;
27 class IOBluetoothDevice;
28 class IOBluetoothDeviceInquiry;
29 class NSArray;
30 class NSDate;
31 #endif
33 namespace base {
35 class SequencedTaskRunner;
37 } // namespace base
39 namespace device {
41 class BluetoothAdapterMacTest;
43 class BluetoothAdapterMac : public BluetoothAdapter {
44 public:
45 // BluetoothAdapter override
46 virtual void AddObserver(BluetoothAdapter::Observer* observer) OVERRIDE;
47 virtual void RemoveObserver(BluetoothAdapter::Observer* observer) OVERRIDE;
48 virtual std::string GetAddress() const OVERRIDE;
49 virtual std::string GetName() const OVERRIDE;
50 virtual bool IsInitialized() const OVERRIDE;
51 virtual bool IsPresent() const OVERRIDE;
52 virtual bool IsPowered() const OVERRIDE;
53 virtual void SetPowered(
54 bool powered,
55 const base::Closure& callback,
56 const ErrorCallback& error_callback) OVERRIDE;
57 virtual bool IsDiscovering() const OVERRIDE;
59 virtual void StartDiscovering(
60 const base::Closure& callback,
61 const ErrorCallback& error_callback) OVERRIDE;
62 virtual void StopDiscovering(
63 const base::Closure& callback,
64 const ErrorCallback& error_callback) OVERRIDE;
65 virtual void ReadLocalOutOfBandPairingData(
66 const BluetoothOutOfBandPairingDataCallback& callback,
67 const ErrorCallback& error_callback) OVERRIDE;
69 // called by BluetoothAdapterMacDelegate.
70 void DeviceInquiryStarted(IOBluetoothDeviceInquiry* inquiry);
71 void DeviceFound(IOBluetoothDeviceInquiry* inquiry,
72 IOBluetoothDevice* device);
73 void DeviceInquiryComplete(IOBluetoothDeviceInquiry* inquiry,
74 IOReturn error,
75 bool aborted);
77 private:
78 friend class BluetoothAdapterFactory;
79 friend class BluetoothAdapterMacTest;
81 enum DiscoveryStatus {
82 NOT_DISCOVERING,
83 DISCOVERY_STARTING,
84 DISCOVERING,
85 DISCOVERY_STOPPING
88 BluetoothAdapterMac();
89 virtual ~BluetoothAdapterMac();
91 void Init();
92 void InitForTest(scoped_refptr<base::SequencedTaskRunner> ui_task_runner);
93 void PollAdapter();
95 // Updates |devices_| to be consistent with |devices|.
96 void UpdateDevices(NSArray* devices);
98 void MaybeStartDeviceInquiry();
99 void MaybeStopDeviceInquiry();
101 typedef std::vector<std::pair<base::Closure, ErrorCallback> >
102 DiscoveryCallbackList;
103 void RunCallbacks(const DiscoveryCallbackList& callback_list,
104 bool success) const;
106 std::string address_;
107 std::string name_;
108 bool powered_;
109 DiscoveryStatus discovery_status_;
111 DiscoveryCallbackList on_start_discovery_callbacks_;
112 DiscoveryCallbackList on_stop_discovery_callbacks_;
113 size_t num_discovery_listeners_;
115 BluetoothAdapterMacDelegate* adapter_delegate_;
116 IOBluetoothDeviceInquiry* device_inquiry_;
118 // A list of discovered device addresses.
119 // This list is used to check if the same device is discovered twice during
120 // the discovery between consecutive inquiries.
121 base::hash_set<std::string> discovered_devices_;
123 // Timestamp for the recently accessed device.
124 // Used to determine if |devices_| needs an update.
125 NSDate* recently_accessed_device_timestamp_;
127 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
129 // List of observers interested in event notifications from us.
130 ObserverList<BluetoothAdapter::Observer> observers_;
132 base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_;
134 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac);
137 } // namespace device
139 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_