Fix the flushing process of DecryptingVideoDecoder.
[chromium-blink-merge.git] / device / bluetooth / bluetooth_adapter_mac.h
blob02a6e8a7f04b84b4d32de025f79a1baa8c986aec
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_discovery_manager_mac.h"
21 @class IOBluetoothDevice;
22 @class NSArray;
23 @class NSDate;
25 namespace base {
27 class SequencedTaskRunner;
29 } // namespace base
31 namespace device {
33 class BluetoothAdapterMacTest;
35 class BluetoothAdapterMac : public BluetoothAdapter,
36 public BluetoothDiscoveryManagerMac::Observer {
37 public:
38 static base::WeakPtr<BluetoothAdapter> CreateAdapter();
40 // BluetoothAdapter:
41 virtual void AddObserver(BluetoothAdapter::Observer* observer) OVERRIDE;
42 virtual void RemoveObserver(BluetoothAdapter::Observer* observer) OVERRIDE;
43 virtual std::string GetAddress() const OVERRIDE;
44 virtual std::string GetName() const OVERRIDE;
45 virtual void SetName(const std::string& name,
46 const base::Closure& callback,
47 const ErrorCallback& error_callback) OVERRIDE;
48 virtual bool IsInitialized() const OVERRIDE;
49 virtual bool IsPresent() const OVERRIDE;
50 virtual bool IsPowered() const OVERRIDE;
51 virtual void SetPowered(
52 bool powered,
53 const base::Closure& callback,
54 const ErrorCallback& error_callback) OVERRIDE;
55 virtual bool IsDiscoverable() const OVERRIDE;
56 virtual void SetDiscoverable(
57 bool discoverable,
58 const base::Closure& callback,
59 const ErrorCallback& error_callback) OVERRIDE;
60 virtual bool IsDiscovering() const OVERRIDE;
61 virtual void CreateRfcommService(
62 const BluetoothUUID& uuid,
63 int channel,
64 const CreateServiceCallback& callback,
65 const CreateServiceErrorCallback& error_callback) OVERRIDE;
66 virtual void CreateL2capService(
67 const BluetoothUUID& uuid,
68 int psm,
69 const CreateServiceCallback& callback,
70 const CreateServiceErrorCallback& error_callback) OVERRIDE;
72 // BluetoothDiscoveryManagerMac::Observer overrides
73 virtual void DeviceFound(BluetoothDiscoveryManagerMac* manager,
74 IOBluetoothDevice* device) OVERRIDE;
75 virtual void DiscoveryStopped(BluetoothDiscoveryManagerMac* manager,
76 bool unexpected) OVERRIDE;
78 protected:
79 // BluetoothAdapter:
80 virtual void RemovePairingDelegateInternal(
81 device::BluetoothDevice::PairingDelegate* pairing_delegate) OVERRIDE;
83 private:
84 friend class BluetoothAdapterMacTest;
86 BluetoothAdapterMac();
87 virtual ~BluetoothAdapterMac();
89 // BluetoothAdapter:
90 virtual void AddDiscoverySession(
91 const base::Closure& callback,
92 const ErrorCallback& error_callback) OVERRIDE;
93 virtual void RemoveDiscoverySession(
94 const base::Closure& callback,
95 const ErrorCallback& error_callback) OVERRIDE;
97 void Init();
98 void InitForTest(scoped_refptr<base::SequencedTaskRunner> ui_task_runner);
99 void PollAdapter();
101 // Updates |devices_| to be consistent with |devices|.
102 void UpdateDevices(NSArray* devices);
104 std::string address_;
105 std::string name_;
106 bool powered_;
108 int num_discovery_sessions_;
110 // Discovery manager for Bluetooth Classic.
111 scoped_ptr<BluetoothDiscoveryManagerMac> classic_discovery_manager_;
113 // A list of discovered device addresses.
114 // This list is used to check if the same device is discovered twice during
115 // the discovery between consecutive inquiries.
116 base::hash_set<std::string> discovered_devices_;
118 // Timestamp for the recently accessed device.
119 // Used to determine if |devices_| needs an update.
120 base::scoped_nsobject<NSDate> recently_accessed_device_timestamp_;
122 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
124 // List of observers interested in event notifications from us.
125 ObserverList<BluetoothAdapter::Observer> observers_;
127 base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_;
129 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac);
132 } // namespace device
134 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_