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

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

Issue 288903003: [Bluetooth] Standardize Bluetooth device address format to XX:XX:XX:XX:XX:XX. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix ChromeOS tests too Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « device/bluetooth/bluetooth_device.h ('k') | device/bluetooth/bluetooth_device_chromeos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "device/bluetooth/bluetooth_device.h" 5 #include "device/bluetooth/bluetooth_device.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
10 #include "device/bluetooth/bluetooth_gatt_service.h" 11 #include "device/bluetooth/bluetooth_gatt_service.h"
11 #include "grit/device_bluetooth_strings.h" 12 #include "grit/device_bluetooth_strings.h"
12 #include "ui/base/l10n/l10n_util.h" 13 #include "ui/base/l10n/l10n_util.h"
13 14
14 namespace device { 15 namespace device {
15 16
16 BluetoothDevice::BluetoothDevice() { 17 BluetoothDevice::BluetoothDevice() {
17 } 18 }
18 19
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 181 }
181 182
182 BluetoothGattService* BluetoothDevice::GetGattService( 183 BluetoothGattService* BluetoothDevice::GetGattService(
183 const std::string& identifier) const { 184 const std::string& identifier) const {
184 GattServiceMap::const_iterator iter = gatt_services_.find(identifier); 185 GattServiceMap::const_iterator iter = gatt_services_.find(identifier);
185 if (iter != gatt_services_.end()) 186 if (iter != gatt_services_.end())
186 return iter->second; 187 return iter->second;
187 return NULL; 188 return NULL;
188 } 189 }
189 190
191 // static
192 std::string BluetoothDevice::CanonicalizeAddress(const std::string& address) {
193 std::string canonicalized = address;
194 if (address.size() == 12) {
195 // Might be an address in the format "1A2B3C4D5E6F". Add separators.
196 for (size_t i = 2; i < canonicalized.size(); i += 3) {
197 canonicalized.insert(i, ":");
198 }
199 }
200
201 // Verify that the length matches the canonical format "1A:2B:3C:4D:5E:6F".
202 const size_t kCanonicalAddressLength = 17;
203 if (canonicalized.size() != kCanonicalAddressLength)
204 return std::string();
205
206 const char separator = canonicalized[2];
207 for (size_t i = 0; i < canonicalized.size(); ++i) {
208 bool is_separator = (i + 1) % 3 == 0;
209 if (is_separator) {
210 // All separators in the input |address| should be consistent.
211 if (canonicalized[i] != separator)
212 return std::string();
213
214 canonicalized[i] = ':';
215 } else {
216 if (!IsHexDigit(canonicalized[i]))
217 return std::string();
218
219 canonicalized[i] = base::ToUpperASCII(canonicalized[i]);
220 }
221 }
222
223 return canonicalized;
224 }
225
190 } // namespace device 226 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_device.h ('k') | device/bluetooth/bluetooth_device_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698