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

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

Issue 2567903004: Replace ScopedVector/ScopedPtrHashMap with std::vector and std::unordered_map (Closed)
Patch Set: Mac bustage Created 4 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_DEVICE_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ 6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <memory> 11 #include <memory>
12 #include <set> 12 #include <set>
13 #include <string> 13 #include <string>
14 #include <unordered_map> 14 #include <unordered_map>
15 #include <unordered_set> 15 #include <unordered_set>
16 #include <vector> 16 #include <vector>
17 17
18 #include "base/callback.h" 18 #include "base/callback.h"
19 #include "base/containers/scoped_ptr_hash_map.h" 19 #include "base/containers/scoped_ptr_hash_map.h"
20 #include "base/gtest_prod_util.h" 20 #include "base/gtest_prod_util.h"
21 #include "base/memory/ref_counted.h" 21 #include "base/memory/ref_counted.h"
22 #include "base/optional.h" 22 #include "base/optional.h"
23 #include "base/strings/string16.h" 23 #include "base/strings/string16.h"
24 #include "base/time/time.h" 24 #include "base/time/time.h"
25 #include "device/bluetooth/bluetooth_common.h" 25 #include "device/bluetooth/bluetooth_common.h"
26 #include "device/bluetooth/bluetooth_export.h" 26 #include "device/bluetooth/bluetooth_export.h"
27 #include "device/bluetooth/bluetooth_remote_gatt_service.h"
27 #include "device/bluetooth/bluetooth_uuid.h" 28 #include "device/bluetooth/bluetooth_uuid.h"
28 29
29 namespace device { 30 namespace device {
30 31
31 class BluetoothAdapter; 32 class BluetoothAdapter;
32 class BluetoothGattConnection; 33 class BluetoothGattConnection;
33 class BluetoothRemoteGattService;
34 class BluetoothSocket; 34 class BluetoothSocket;
35 class BluetoothUUID; 35 class BluetoothUUID;
36 36
37 // BluetoothDevice represents a remote Bluetooth device, both its properties and 37 // BluetoothDevice represents a remote Bluetooth device, both its properties and
38 // capabilities as discovered by a local adapter and actions that may be 38 // capabilities as discovered by a local adapter and actions that may be
39 // performed on the remove device such as pairing, connection and disconnection. 39 // performed on the remove device such as pairing, connection and disconnection.
40 // 40 //
41 // The class is instantiated and managed by the BluetoothAdapter class 41 // The class is instantiated and managed by the BluetoothAdapter class
42 // and pointers should only be obtained from that class and not cached, 42 // and pointers should only be obtained from that class and not cached,
43 // instead use the GetAddress() method as a unique key for a device. 43 // instead use the GetAddress() method as a unique key for a device.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 ERROR_INSUFFICIENT_ENCRYPTION, 86 ERROR_INSUFFICIENT_ENCRYPTION,
87 ERROR_OFFSET_INVALID, 87 ERROR_OFFSET_INVALID,
88 ERROR_READ_NOT_PERMITTED, 88 ERROR_READ_NOT_PERMITTED,
89 ERROR_REQUEST_NOT_SUPPORTED, 89 ERROR_REQUEST_NOT_SUPPORTED,
90 ERROR_UNKNOWN, 90 ERROR_UNKNOWN,
91 ERROR_UNSUPPORTED_DEVICE, 91 ERROR_UNSUPPORTED_DEVICE,
92 ERROR_WRITE_NOT_PERMITTED, 92 ERROR_WRITE_NOT_PERMITTED,
93 NUM_CONNECT_ERROR_CODES // Keep as last enum. 93 NUM_CONNECT_ERROR_CODES // Keep as last enum.
94 }; 94 };
95 95
96 typedef std::vector<BluetoothUUID> UUIDList; 96 using UUIDList = std::vector<BluetoothUUID>;
97 typedef std::unordered_set<BluetoothUUID, BluetoothUUIDHash> UUIDSet; 97 using UUIDSet = std::unordered_set<BluetoothUUID, BluetoothUUIDHash>;
98 typedef std::unordered_map<BluetoothUUID, 98 using ServiceDataMap = std::
99 std::vector<uint8_t>, 99 unordered_map<BluetoothUUID, std::vector<uint8_t>, BluetoothUUIDHash>;
100 BluetoothUUIDHash> 100 using ManufacturerId = uint16_t;
101 ServiceDataMap; 101 using ManufacturerDataMap =
102 typedef uint16_t ManufacturerId; 102 std::unordered_map<ManufacturerId, std::vector<uint8_t>>;
103 typedef std::unordered_map<ManufacturerId, std::vector<uint8_t>> 103 using ManufacturerIDSet = std::unordered_set<ManufacturerId>;
104 ManufacturerDataMap;
105 typedef std::unordered_set<ManufacturerId> ManufacturerIDSet;
106 104
107 // Mapping from the platform-specific GATT service identifiers to 105 // Mapping from the platform-specific GATT service identifiers to
108 // BluetoothRemoteGattService objects. 106 // BluetoothRemoteGattService objects.
109 typedef base::ScopedPtrHashMap<std::string, 107 using GattServiceMap =
110 std::unique_ptr<BluetoothRemoteGattService>> 108 std::unordered_map<std::string,
111 GattServiceMap; 109 std::unique_ptr<BluetoothRemoteGattService>>;
112 110
113 // Interface for negotiating pairing of bluetooth devices. 111 // Interface for negotiating pairing of bluetooth devices.
114 class PairingDelegate { 112 class PairingDelegate {
115 public: 113 public:
116 virtual ~PairingDelegate() {} 114 virtual ~PairingDelegate() {}
117 115
118 // This method will be called when the Bluetooth daemon requires a 116 // This method will be called when the Bluetooth daemon requires a
119 // PIN Code for authentication of the device |device|, the delegate should 117 // PIN Code for authentication of the device |device|, the delegate should
120 // obtain the code from the user and call SetPinCode() on the device to 118 // obtain the code from the user and call SetPinCode() on the device to
121 // provide it, or RejectPairing() or CancelPairing() to reject or cancel 119 // provide it, or RejectPairing() or CancelPairing() to reject or cancel
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 638
641 // Callbacks for pending success and error result of CreateGattConnection. 639 // Callbacks for pending success and error result of CreateGattConnection.
642 std::vector<GattConnectionCallback> create_gatt_connection_success_callbacks_; 640 std::vector<GattConnectionCallback> create_gatt_connection_success_callbacks_;
643 std::vector<ConnectErrorCallback> create_gatt_connection_error_callbacks_; 641 std::vector<ConnectErrorCallback> create_gatt_connection_error_callbacks_;
644 642
645 // BluetoothGattConnection objects keeping the GATT connection alive. 643 // BluetoothGattConnection objects keeping the GATT connection alive.
646 std::set<BluetoothGattConnection*> gatt_connections_; 644 std::set<BluetoothGattConnection*> gatt_connections_;
647 645
648 GattServiceMap gatt_services_; 646 GattServiceMap gatt_services_;
649 bool gatt_services_discovery_complete_; 647 bool gatt_services_discovery_complete_;
648 bool gatt_services_shutting_down_;
650 649
651 // Received Signal Strength Indicator of the advertisement received. 650 // Received Signal Strength Indicator of the advertisement received.
652 base::Optional<int8_t> inquiry_rssi_; 651 base::Optional<int8_t> inquiry_rssi_;
653 652
654 // Tx Power advertised by the device. 653 // Tx Power advertised by the device.
655 base::Optional<int8_t> inquiry_tx_power_; 654 base::Optional<int8_t> inquiry_tx_power_;
656 655
657 // Advertising Data flags of the device. 656 // Advertising Data flags of the device.
658 base::Optional<uint8_t> advertising_data_flags_; 657 base::Optional<uint8_t> advertising_data_flags_;
659 658
660 // Class that holds the union of Advertised UUIDs and Service UUIDs. 659 // Class that holds the union of Advertised UUIDs and Service UUIDs.
661 DeviceUUIDs device_uuids_; 660 DeviceUUIDs device_uuids_;
662 661
663 // Map of BluetoothUUIDs to their advertised Service Data. 662 // Map of BluetoothUUIDs to their advertised Service Data.
664 ServiceDataMap service_data_; 663 ServiceDataMap service_data_;
665 664
666 // Map of Manufacturer IDs to their advertised Manufacturer Data. 665 // Map of Manufacturer IDs to their advertised Manufacturer Data.
667 ManufacturerDataMap manufacturer_data_; 666 ManufacturerDataMap manufacturer_data_;
668 667
669 // Timestamp for when an advertisement was last seen. 668 // Timestamp for when an advertisement was last seen.
670 base::Time last_update_time_; 669 base::Time last_update_time_;
671 670
672 private: 671 private:
673 // Returns a localized string containing the device's bluetooth address and 672 // Returns a localized string containing the device's bluetooth address and
674 // a device type for display when |name_| is empty. 673 // a device type for display when |name_| is empty.
675 base::string16 GetAddressWithLocalizedDeviceTypeName() const; 674 base::string16 GetAddressWithLocalizedDeviceTypeName() const;
675
676 DISALLOW_COPY_AND_ASSIGN(BluetoothDevice);
676 }; 677 };
677 678
678 } // namespace device 679 } // namespace device
679 680
680 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ 681 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698