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

Side by Side Diff: device/bluetooth/bluetooth_adapter_mac_metrics.mm

Issue 2912633002: bluetooth: macOS: Adding histograms for NSError values (Closed)
Patch Set: . Created 3 years, 6 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 2017 The Chromium Authors. All rights reserved.
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 "device/bluetooth/bluetooth_adapter_mac_metrics.h"
6
7 #import <CoreBluetooth/CoreBluetooth.h>
8 #import <Foundation/Foundation.h>
9
10 #include "base/metrics/histogram_macros.h"
11
12 namespace {
13
14 #if !defined(MAC_OS_X_VERSION_10_11)
15 // Available with macOS 10.11 SDK or after.
16 const NSInteger CBErrorMaxConnection = 11;
17 #endif // !defined(MAC_OS_X_VERSION_10_11)
18
19 WebBluetoothMacOSErrors GetWebBluetoothMacOSErrorsFromNSError(NSError* error) {
ortuno 2017/06/20 05:59:40 What do you think about renaming this to: GetMacO
jlebel 2017/08/15 20:48:44 Done.
20 NSString* error_domain = [error domain];
21 NSInteger error_code = [error code];
22 if ([error_domain isEqualToString:CBErrorDomain]) {
23 switch (static_cast<CBError>(error_code)) {
24 case CBErrorUnknown:
25 return WebBluetoothMacOSErrors::CBERROR_UNKNOWN;
26 case CBErrorInvalidParameters:
27 return WebBluetoothMacOSErrors::CBERROR_INVALID_PARAMETERS;
28 case CBErrorInvalidHandle:
29 return WebBluetoothMacOSErrors::CBERROR_INVALID_HANDLE;
30 case CBErrorNotConnected:
31 return WebBluetoothMacOSErrors::CBERROR_NOT_CONNECTED;
32 case CBErrorOutOfSpace:
33 return WebBluetoothMacOSErrors::CBERROR_OUT_OF_SPACE;
34 case CBErrorOperationCancelled:
35 return WebBluetoothMacOSErrors::CBERROR_OPERATION_CANCELLED;
36 case CBErrorConnectionTimeout:
37 return WebBluetoothMacOSErrors::CBERROR_CONNECTION_TIMEOUT;
38 case CBErrorPeripheralDisconnected:
39 return WebBluetoothMacOSErrors::CBERROR_PERIPHERAL_DISCONNECTED;
40 case CBErrorUUIDNotAllowed:
41 return WebBluetoothMacOSErrors::CBERROR_UUID_NOT_ALLOWED;
42 case CBErrorAlreadyAdvertising:
43 return WebBluetoothMacOSErrors::CBERROR_ALREADY_ADVERTISING;
44 #if defined(MAC_OS_X_VERSION_10_11)
45 case CBErrorMaxConnection:
46 return WebBluetoothMacOSErrors::CBERROR_MAX_CONNECTION;
47 #endif // defined(MAC_OS_X_VERSION_10_11)
48 }
49 #if !defined(MAC_OS_X_VERSION_10_11)
50 if (error_code == CBErrorMaxConnection) {
51 return WebBluetoothMacOSErrors::CBERROR_MAX_CONNECTION;
52 }
53 #endif // !defined(MAC_OS_X_VERSION_10_11)
54 return WebBluetoothMacOSErrors::CBERROR_MAX;
55 } else if ([error_domain isEqualToString:CBATTErrorDomain]) {
56 switch (static_cast<CBATTError>(error_code)) {
57 case CBATTErrorSuccess:
58 return WebBluetoothMacOSErrors::CBATT_ERROR_SUCCESS;
59 case CBATTErrorInvalidHandle:
60 return WebBluetoothMacOSErrors::CBATT_ERROR_INVALID_HANDLE;
61 case CBATTErrorReadNotPermitted:
62 return WebBluetoothMacOSErrors::CBATT_ERROR_READ_NOT_PERMITTED;
63 case CBATTErrorWriteNotPermitted:
64 return WebBluetoothMacOSErrors::CBATT_ERROR_WRITE_NOT_PERMITTED;
65 case CBATTErrorInvalidPdu:
66 return WebBluetoothMacOSErrors::CBATT_ERROR_INVALID_PDU;
67 case CBATTErrorInsufficientAuthentication:
68 return WebBluetoothMacOSErrors::CBATT_ERROR_INSUFFICIENT_AUTHENTICATION;
69 case CBATTErrorRequestNotSupported:
70 return WebBluetoothMacOSErrors::CBATT_ERROR_REQUEST_NOT_SUPPORTED;
71 case CBATTErrorInvalidOffset:
72 return WebBluetoothMacOSErrors::CBATT_ERROR_INVALID_OFFSET;
73 case CBATTErrorInsufficientAuthorization:
74 return WebBluetoothMacOSErrors::CBATT_ERROR_INSUFFICIENT_AUTHORIZATION;
75 case CBATTErrorPrepareQueueFull:
76 return WebBluetoothMacOSErrors::CBATT_ERROR_PREPARE_QUEUE_FULL;
77 case CBATTErrorAttributeNotFound:
78 return WebBluetoothMacOSErrors::CBATT_ERROR_ATTRIBUTE_NOT_FOUND;
79 case CBATTErrorAttributeNotLong:
80 return WebBluetoothMacOSErrors::CBATT_ERROR_ATTRIBUTE_NOT_LONG;
81 case CBATTErrorInsufficientEncryptionKeySize:
82 return WebBluetoothMacOSErrors::
83 CBATT_ERROR_INSUFFICIENT_ENCRYPTION_KEY_SIZE;
84 case CBATTErrorInvalidAttributeValueLength:
85 return WebBluetoothMacOSErrors::
86 CBATT_ERROR_INVALID_ATTRIBUTE_VALUE_LENGTH;
87 case CBATTErrorUnlikelyError:
88 return WebBluetoothMacOSErrors::CBATT_ERROR_UNLIKELY_ERROR;
89 case CBATTErrorInsufficientEncryption:
90 return WebBluetoothMacOSErrors::CBATT_ERROR_INSUFFICIENT_ENCRYPTION;
91 case CBATTErrorUnsupportedGroupType:
92 return WebBluetoothMacOSErrors::CBATT_ERROR_UNSUPPORTED_GROUP_TYPE;
93 case CBATTErrorInsufficientResources:
94 return WebBluetoothMacOSErrors::CBATT_ERROR_INSUFFICIENT_RESOURCES;
95 }
96 return WebBluetoothMacOSErrors::CBATT_ERROR_MAX;
97 }
98 return WebBluetoothMacOSErrors::UNKNOWN_ERROR_DOMAIN;
99 }
100
101 } // namespace
102
103 void LogDidFailToConnectPeripheralErrorToHistogram(NSError* error) {
104 if (!error)
105 return;
106 WebBluetoothMacOSErrors histogram_macos_error =
107 GetWebBluetoothMacOSErrorsFromNSError(error);
108 UMA_HISTOGRAM_ENUMERATION(
109 "Bluetooth.Web.MacOS.Errors.DidFailToConnectToPeripheral",
110 static_cast<int>(histogram_macos_error),
111 static_cast<int>(WebBluetoothMacOSErrors::MAX));
112 }
113
114 void LogDidDisconnectPeripheralErrorToHistogram(NSError* error) {
115 if (!error)
116 return;
117 WebBluetoothMacOSErrors histogram_macos_error =
118 GetWebBluetoothMacOSErrorsFromNSError(error);
119 UMA_HISTOGRAM_ENUMERATION(
120 "Bluetooth.Web.MacOS.Errors.DidDisconnectPeripheral",
121 static_cast<int>(histogram_macos_error),
122 static_cast<int>(WebBluetoothMacOSErrors::MAX));
123 }
124
125 void LogDidDiscoverPrimaryServicesErrorToHistogram(NSError* error) {
126 if (!error)
127 return;
128 WebBluetoothMacOSErrors histogram_macos_error =
129 GetWebBluetoothMacOSErrorsFromNSError(error);
130 UMA_HISTOGRAM_ENUMERATION(
131 "Bluetooth.Web.MacOS.Errors.DidDiscoverPrimaryServices",
132 static_cast<int>(histogram_macos_error),
133 static_cast<int>(WebBluetoothMacOSErrors::MAX));
134 }
135
136 void LogDidDiscoverCharacteristicsErrorToHistogram(NSError* error) {
137 if (!error)
138 return;
139 WebBluetoothMacOSErrors histogram_macos_error =
140 GetWebBluetoothMacOSErrorsFromNSError(error);
141 UMA_HISTOGRAM_ENUMERATION(
142 "Bluetooth.Web.MacOS.Errors.DidDiscoverCharacteristics",
143 static_cast<int>(histogram_macos_error),
144 static_cast<int>(WebBluetoothMacOSErrors::MAX));
145 }
146
147 void LogDidUpdateValueErrorToHistogram(NSError* error) {
148 if (!error)
149 return;
150 WebBluetoothMacOSErrors histogram_macos_error =
151 GetWebBluetoothMacOSErrorsFromNSError(error);
152 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.MacOS.Errors.DidUpdateValue",
153 static_cast<int>(histogram_macos_error),
154 static_cast<int>(WebBluetoothMacOSErrors::MAX));
155 }
156
157 void LogDidWriteValueErrorToHistogram(NSError* error) {
158 if (!error)
159 return;
160 WebBluetoothMacOSErrors histogram_macos_error =
161 GetWebBluetoothMacOSErrorsFromNSError(error);
162 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.MacOS.Errors.DidWriteValue",
163 static_cast<int>(histogram_macos_error),
164 static_cast<int>(WebBluetoothMacOSErrors::MAX));
165 }
166
167 void LogDidUpdateNotificationStateErrorToHistogram(NSError* error) {
168 if (!error)
169 return;
170 WebBluetoothMacOSErrors histogram_macos_error =
171 GetWebBluetoothMacOSErrorsFromNSError(error);
172 UMA_HISTOGRAM_ENUMERATION(
173 "Bluetooth.Web.MacOS.Errors.DidUpdateNotificationState",
174 static_cast<int>(histogram_macos_error),
175 static_cast<int>(WebBluetoothMacOSErrors::MAX));
176 }
177
178 void LogDidDiscoverDescriptorsErrorToHistogram(NSError* error) {
179 if (!error)
180 return;
181 WebBluetoothMacOSErrors histogram_macos_error =
182 GetWebBluetoothMacOSErrorsFromNSError(error);
183 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.MacOS.Errors.DidDiscoverDescriptors",
184 static_cast<int>(histogram_macos_error),
185 static_cast<int>(WebBluetoothMacOSErrors::MAX));
186 }
187
188 void LogDidUpdateValueForDescriptorErrorToHistogram(NSError* error) {
189 if (!error)
190 return;
191 WebBluetoothMacOSErrors histogram_macos_error =
192 GetWebBluetoothMacOSErrorsFromNSError(error);
193 UMA_HISTOGRAM_ENUMERATION(
194 "Bluetooth.Web.MacOS.Errors.DidUpdateValueForDescriptor",
195 static_cast<int>(histogram_macos_error),
196 static_cast<int>(WebBluetoothMacOSErrors::MAX));
197 }
198
199 void LogDidWriteValueForDescriptorErrorToHistogram(NSError* error) {
200 if (!error)
201 return;
202 WebBluetoothMacOSErrors histogram_macos_error =
203 GetWebBluetoothMacOSErrorsFromNSError(error);
204 UMA_HISTOGRAM_ENUMERATION(
205 "Bluetooth.Web.MacOS.Errors.DidWriteValueForDescriptor",
206 static_cast<int>(histogram_macos_error),
207 static_cast<int>(WebBluetoothMacOSErrors::MAX));
208 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698