Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: device/bluetooth/bluetooth_adapter_mac.h

Issue 13862020: Simplified BluetoothAdapterMac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated comments Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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_MAC_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_
7 7
8 #include <IOKit/IOReturn.h> 8 #include <IOKit/IOReturn.h>
9 9
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/hash_tables.h" 13 #include "base/hash_tables.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/observer_list.h" 16 #include "base/observer_list.h"
17 #include "device/bluetooth/bluetooth_adapter.h" 17 #include "device/bluetooth/bluetooth_adapter.h"
18 18
19 #ifdef __OBJC__ 19 #ifdef __OBJC__
20 @class BluetoothAdapterMacDelegate; 20 @class BluetoothAdapterMacDelegate;
21 @class IOBluetoothDevice; 21 @class IOBluetoothDevice;
22 @class IOBluetoothDeviceInquiry; 22 @class IOBluetoothDeviceInquiry;
23 @class NSArray; 23 @class NSArray;
24 @class NSDate;
24 #else 25 #else
25 class BluetoothAdapterMacDelegate; 26 class BluetoothAdapterMacDelegate;
26 class IOBluetoothDevice; 27 class IOBluetoothDevice;
27 class IOBluetoothDeviceInquiry; 28 class IOBluetoothDeviceInquiry;
28 class NSArray; 29 class NSArray;
30 class NSDate;
29 #endif 31 #endif
30 32
31 namespace base { 33 namespace base {
32 34
33 class SequencedTaskRunner; 35 class SequencedTaskRunner;
34 36
35 } // namespace base 37 } // namespace base
36 38
37 namespace device { 39 namespace device {
38 40
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 DISCOVERY_STOPPING 85 DISCOVERY_STOPPING
84 }; 86 };
85 87
86 BluetoothAdapterMac(); 88 BluetoothAdapterMac();
87 virtual ~BluetoothAdapterMac(); 89 virtual ~BluetoothAdapterMac();
88 90
89 void Init(); 91 void Init();
90 void InitForTest(scoped_refptr<base::SequencedTaskRunner> ui_task_runner); 92 void InitForTest(scoped_refptr<base::SequencedTaskRunner> ui_task_runner);
91 void PollAdapter(); 93 void PollAdapter();
92 94
93 // Adds |devices| into |devices_| and notifies observers of the changes. 95 // Updates |devices_| to be consistent with |devices|.
94 // |devices| is an array of pointers to discovered or paired 96 void UpdateDevices(NSArray* devices);
95 // |IOBluetoothDevice| objects.
96 void AddDevices(NSArray* devices);
97
98 // Removes devices that used to be paired but are unpaired by the system from
99 // |devices_|.
100 // |devices| is an array of pointers to paired |IOBluetoothDevice| objects.
101 void RemoveUnpairedDevices(NSArray* paired_devices);
102 97
103 void MaybeStartDeviceInquiry(); 98 void MaybeStartDeviceInquiry();
104 void MaybeStopDeviceInquiry(); 99 void MaybeStopDeviceInquiry();
105 100
106 typedef std::vector<std::pair<base::Closure, ErrorCallback> > 101 typedef std::vector<std::pair<base::Closure, ErrorCallback> >
107 DiscoveryCallbackList; 102 DiscoveryCallbackList;
108 void RunCallbacks(const DiscoveryCallbackList& callback_list, 103 void RunCallbacks(const DiscoveryCallbackList& callback_list,
109 bool success) const; 104 bool success) const;
110 105
111 std::string address_; 106 std::string address_;
112 std::string name_; 107 std::string name_;
113 bool powered_; 108 bool powered_;
114 DiscoveryStatus discovery_status_; 109 DiscoveryStatus discovery_status_;
115 110
116 DiscoveryCallbackList on_start_discovery_callbacks_; 111 DiscoveryCallbackList on_start_discovery_callbacks_;
117 DiscoveryCallbackList on_stop_discovery_callbacks_; 112 DiscoveryCallbackList on_stop_discovery_callbacks_;
118 size_t num_discovery_listeners_; 113 size_t num_discovery_listeners_;
119 114
120 BluetoothAdapterMacDelegate* adapter_delegate_; 115 BluetoothAdapterMacDelegate* adapter_delegate_;
121 IOBluetoothDeviceInquiry* device_inquiry_; 116 IOBluetoothDeviceInquiry* device_inquiry_;
122 117
123 // A list of discovered device addresses. 118 // A list of discovered device addresses.
124 // This list is used to check if the same device is discovered twice during 119 // This list is used to check if the same device is discovered twice during
125 // the discovery between consecutive inquiries. 120 // the discovery between consecutive inquiries.
126 base::hash_set<std::string> discovered_devices_; 121 base::hash_set<std::string> discovered_devices_;
127 122
123 // Timestamp for the recently accessed device.
124 // Used to determine if we need to update |devices_|.
Mark Mentovai 2013/04/09 20:57:03 Avoid “we.” This is clearer as “Used to determine
125 NSDate* recently_accessed_device_timestamp_;
126
128 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; 127 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
129 128
130 // List of observers interested in event notifications from us. 129 // List of observers interested in event notifications from us.
131 ObserverList<BluetoothAdapter::Observer> observers_; 130 ObserverList<BluetoothAdapter::Observer> observers_;
132 131
133 base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_; 132 base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_;
134 133
135 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac); 134 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac);
136 }; 135 };
137 136
138 } // namespace device 137 } // namespace device
139 138
140 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ 139 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_
OLDNEW
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_adapter_mac.mm » ('j') | device/bluetooth/bluetooth_adapter_mac.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698