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

Side by Side Diff: chrome/browser/mac/hardware_utility.mm

Issue 374203004: mac: Add metrics to record Bluetooth availability and capabilities. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First Created 6 years, 5 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
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
Avi (use Gerrit) 2014/07/08 23:38:20 No (c), 2014.
erikchen 2014/07/09 00:18:57 Done.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/mac/hardware_utility.h"
6
7 #import <Foundation/Foundation.h>
8 #include <IOKit/IOKitLib.h>
9
10 namespace hardware_utility {
11
12 // Returns the Bluetooth driver's Link Management Protocol version.
13 // Returns -1 if no Bluetooth driver is present.
14 // Returns -2 on an unexpected error.
15 int GetBluetoothLMPVersion() {
16 CFMutableDictionaryRef matching_dict =
Avi (use Gerrit) 2014/07/08 23:32:03 base::ScopedCFTypeRef<CFMutableDictionaryRef>
erikchen 2014/07/09 00:18:57 That won't work, since IOServiceGetMatchingService
Avi (use Gerrit) 2014/07/09 01:54:05 On ScopedCFTypeRef, .Pass() is spelled .release()
Avi (use Gerrit) 2014/07/09 01:55:45 Actually, release() is a lot dumber than Pass(), b
erikchen 2014/07/09 02:04:21 Right you are. I made the incorrect assumption tha
Avi (use Gerrit) 2014/07/09 03:36:43 Yeah, it's a non-awesome name conflict.
17 IOServiceMatching("IOBluetoothHCIController");
18 if (!matching_dict)
19 return -2;
20
21 io_iterator_t iter;
22 int kr =
23 IOServiceGetMatchingServices(kIOMasterPortDefault, matching_dict, &iter);
24
Avi (use Gerrit) 2014/07/08 23:32:03 Immediately after IOServiceGetMatchingServices, pu
erikchen 2014/07/09 00:18:57 Done.
25 if (kr != KERN_SUCCESS)
26 return -1;
27
28 int version = 0;
29 bool success = false;
30 io_service_t device;
31 while ((device = IOIteratorNext(iter))) {
Avi (use Gerrit) 2014/07/08 23:32:04 base::mac::ScopedIOObject<io_object_t>. See GetMAC
erikchen 2014/07/09 00:18:57 I copied the example, but used io_service_t as the
32 CFMutableDictionaryRef dict;
33 kr = IORegistryEntryCreateCFProperties(
34 device, &dict, kCFAllocatorDefault, kNilOptions);
Avi (use Gerrit) 2014/07/08 23:32:03 Put the dictionary in base::ScopedCFTypeRef<CFMuta
erikchen 2014/07/09 00:18:57 Done.
35 if (kr != KERN_SUCCESS) {
36 IOObjectRelease(device);
37 continue;
38 }
39
40 // Check the properties for an LMP version.
Avi (use Gerrit) 2014/07/08 23:32:46 Is there some documentation about LMP versions, an
erikchen 2014/07/09 00:18:57 Added the relevant links.
41 NSDictionary* objc_dict = static_cast<NSDictionary*>(dict);
Avi (use Gerrit) 2014/07/08 23:32:04 base::mac::CFCast
Avi (use Gerrit) 2014/07/08 23:38:19 Sorry, CFToNSCast.
erikchen 2014/07/09 00:18:57 Done.
42 NSNumber* lmp_version = [objc_dict objectForKey:@"LMPVersion"];
Avi (use Gerrit) 2014/07/08 23:32:03 Use ObjCCast here and drop the class check on the
erikchen 2014/07/09 00:18:57 Done.
43 if (!lmp_version || ![lmp_version isKindOfClass:[NSNumber class]]) {
44 CFRelease(dict);
45 IOObjectRelease(device);
46 continue;
47 }
48
49 // A bluetooth device with an LMP version has been found. Record the
50 // highest version among all devices.
51 success = true;
52 version = MAX(version, [lmp_version intValue]);
Avi (use Gerrit) 2014/07/08 23:32:03 std::max
erikchen 2014/07/09 00:18:56 Done.
53 CFRelease(dict);
54 IOObjectRelease(device);
55 }
56
57 IOObjectRelease(iter);
58 if (!success)
59 return -2;
60
61 return version;
62 }
63
64 BluetoothAvailability GetBluetoothAvailability() {
65 int result = GetBluetoothLMPVersion();
Avi (use Gerrit) 2014/07/08 23:32:03 If this value will never change, you might as well
erikchen 2014/07/09 00:18:57 Done.
66 if (result < 0)
67 return BLUETOOTH_NOT_AVAILABLE;
68 if (result < 6)
69 return BLUETOOTH_AVAILABLE_WITHOUT_LE;
70 return BLUETOOTH_AVAILABLE_WITH_LE;
71 }
72
73 } // namespace hardware_utility
OLDNEW
« no previous file with comments | « chrome/browser/mac/hardware_utility.h ('k') | chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698