OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "components/proximity_auth/bluetooth_util.h" | 5 #include "components/proximity_auth/bluetooth_util.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <sys/socket.h> | 8 #include <sys/socket.h> |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 std::string error_message; | 66 std::string error_message; |
67 }; | 67 }; |
68 | 68 |
69 // Writes |address| into the |result|. Return true on success, false if the | 69 // Writes |address| into the |result|. Return true on success, false if the |
70 // |address| is not a valid Bluetooth address. | 70 // |address| is not a valid Bluetooth address. |
71 bool BluetoothAddressToBdaddr(const std::string& address, bdaddr_t* result) { | 71 bool BluetoothAddressToBdaddr(const std::string& address, bdaddr_t* result) { |
72 std::string canonical_address = BluetoothDevice::CanonicalizeAddress(address); | 72 std::string canonical_address = BluetoothDevice::CanonicalizeAddress(address); |
73 if (canonical_address.empty()) | 73 if (canonical_address.empty()) |
74 return false; | 74 return false; |
75 | 75 |
76 std::vector<std::string> octets; | 76 std::vector<base::StringPiece> octets = base::SplitStringPiece( |
77 base::SplitString(canonical_address, ':', &octets); | 77 canonical_address, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
78 DCHECK_EQ(octets.size(), 6U); | 78 DCHECK_EQ(octets.size(), 6U); |
79 | 79 |
80 // BlueZ expects the octets in the reverse order. | 80 // BlueZ expects the octets in the reverse order. |
81 std::reverse(octets.begin(), octets.end()); | 81 std::reverse(octets.begin(), octets.end()); |
82 for (size_t i = 0; i < octets.size(); ++i) { | 82 for (size_t i = 0; i < octets.size(); ++i) { |
83 uint32_t octet; | 83 uint32_t octet; |
84 bool success = base::HexStringToUInt(octets[i], &octet); | 84 bool success = base::HexStringToUInt(octets[i], &octet); |
85 DCHECK(success); | 85 DCHECK(success); |
86 result->b[i] = base::checked_cast<uint8_t>(octet); | 86 result->b[i] = base::checked_cast<uint8_t>(octet); |
87 } | 87 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 task_runner, | 150 task_runner, |
151 FROM_HERE, | 151 FROM_HERE, |
152 base::Bind(&SeekDeviceByAddressImpl, | 152 base::Bind(&SeekDeviceByAddressImpl, |
153 device_address, | 153 device_address, |
154 make_scoped_refptr(task_runner)), | 154 make_scoped_refptr(task_runner)), |
155 base::Bind(&OnSeekDeviceResult, callback, error_callback)); | 155 base::Bind(&OnSeekDeviceResult, callback, error_callback)); |
156 } | 156 } |
157 | 157 |
158 } // namespace bluetooth_util | 158 } // namespace bluetooth_util |
159 } // namespace proximity_auth | 159 } // namespace proximity_auth |
OLD | NEW |