Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 MacOSBluetoothOperationsResult GetMacOSOperationResultFromNSError( | |
| 15 NSError* error) { | |
| 16 if (!error) | |
| 17 return MacOSBluetoothOperationsResult::NO_ERROR; | |
| 18 NSString* error_domain = [error domain]; | |
| 19 NSInteger error_code = [error code]; | |
| 20 if ([error_domain isEqualToString:CBErrorDomain]) { | |
| 21 CBError cb_error_code = static_cast<CBError>(error_code); | |
| 22 switch (cb_error_code) { | |
| 23 case CBErrorUnknown: | |
| 24 return MacOSBluetoothOperationsResult::CBERROR_UNKNOWN; | |
| 25 case CBErrorInvalidParameters: | |
| 26 return MacOSBluetoothOperationsResult::CBERROR_INVALID_PARAMETERS; | |
| 27 case CBErrorInvalidHandle: | |
| 28 return MacOSBluetoothOperationsResult::CBERROR_INVALID_HANDLE; | |
| 29 case CBErrorNotConnected: | |
| 30 return MacOSBluetoothOperationsResult::CBERROR_NOT_CONNECTED; | |
| 31 case CBErrorOutOfSpace: | |
| 32 return MacOSBluetoothOperationsResult::CBERROR_OUT_OF_SPACE; | |
| 33 case CBErrorOperationCancelled: | |
| 34 return MacOSBluetoothOperationsResult::CBERROR_OPERATION_CANCELLED; | |
| 35 case CBErrorConnectionTimeout: | |
| 36 return MacOSBluetoothOperationsResult::CBERROR_CONNECTION_TIMEOUT; | |
| 37 case CBErrorPeripheralDisconnected: | |
| 38 return MacOSBluetoothOperationsResult::CBERROR_PERIPHERAL_DISCONNECTED; | |
| 39 case CBErrorUUIDNotAllowed: | |
| 40 return MacOSBluetoothOperationsResult::CBERROR_UUID_NOT_ALLOWED; | |
| 41 case CBErrorAlreadyAdvertising: | |
| 42 return MacOSBluetoothOperationsResult::CBERROR_ALREADY_ADVERTISING; | |
| 43 default: | |
| 44 if (@available(macOS 10.11, *)) { | |
| 45 if (CBErrorMaxConnection == cb_error_code) | |
| 46 return MacOSBluetoothOperationsResult::CBERROR_MAX_CONNECTION; | |
| 47 } | |
| 48 NOTREACHED(); | |
|
scheib
2017/08/15 22:20:28
Please create and record something like
CBATT_ERR
jlebel
2017/08/15 23:05:49
Done.
| |
| 49 } | |
| 50 return MacOSBluetoothOperationsResult::CBERROR_MAX; | |
| 51 } else if ([error_domain isEqualToString:CBATTErrorDomain]) { | |
| 52 switch (static_cast<CBATTError>(error_code)) { | |
| 53 case CBATTErrorSuccess: | |
| 54 return MacOSBluetoothOperationsResult::CBATT_ERROR_SUCCESS; | |
| 55 case CBATTErrorInvalidHandle: | |
| 56 return MacOSBluetoothOperationsResult::CBATT_ERROR_INVALID_HANDLE; | |
| 57 case CBATTErrorReadNotPermitted: | |
| 58 return MacOSBluetoothOperationsResult::CBATT_ERROR_READ_NOT_PERMITTED; | |
| 59 case CBATTErrorWriteNotPermitted: | |
| 60 return MacOSBluetoothOperationsResult::CBATT_ERROR_WRITE_NOT_PERMITTED; | |
| 61 case CBATTErrorInvalidPdu: | |
| 62 return MacOSBluetoothOperationsResult::CBATT_ERROR_INVALID_PDU; | |
| 63 case CBATTErrorInsufficientAuthentication: | |
| 64 return MacOSBluetoothOperationsResult:: | |
| 65 CBATT_ERROR_INSUFFICIENT_AUTHENTICATION; | |
| 66 case CBATTErrorRequestNotSupported: | |
| 67 return MacOSBluetoothOperationsResult:: | |
| 68 CBATT_ERROR_REQUEST_NOT_SUPPORTED; | |
| 69 case CBATTErrorInvalidOffset: | |
| 70 return MacOSBluetoothOperationsResult::CBATT_ERROR_INVALID_OFFSET; | |
| 71 case CBATTErrorInsufficientAuthorization: | |
| 72 return MacOSBluetoothOperationsResult:: | |
| 73 CBATT_ERROR_INSUFFICIENT_AUTHORIZATION; | |
| 74 case CBATTErrorPrepareQueueFull: | |
| 75 return MacOSBluetoothOperationsResult::CBATT_ERROR_PREPARE_QUEUE_FULL; | |
| 76 case CBATTErrorAttributeNotFound: | |
| 77 return MacOSBluetoothOperationsResult::CBATT_ERROR_ATTRIBUTE_NOT_FOUND; | |
| 78 case CBATTErrorAttributeNotLong: | |
| 79 return MacOSBluetoothOperationsResult::CBATT_ERROR_ATTRIBUTE_NOT_LONG; | |
| 80 case CBATTErrorInsufficientEncryptionKeySize: | |
| 81 return MacOSBluetoothOperationsResult:: | |
| 82 CBATT_ERROR_INSUFFICIENT_ENCRYPTION_KEY_SIZE; | |
| 83 case CBATTErrorInvalidAttributeValueLength: | |
| 84 return MacOSBluetoothOperationsResult:: | |
| 85 CBATT_ERROR_INVALID_ATTRIBUTE_VALUE_LENGTH; | |
| 86 case CBATTErrorUnlikelyError: | |
| 87 return MacOSBluetoothOperationsResult::CBATT_ERROR_UNLIKELY_ERROR; | |
| 88 case CBATTErrorInsufficientEncryption: | |
| 89 return MacOSBluetoothOperationsResult:: | |
| 90 CBATT_ERROR_INSUFFICIENT_ENCRYPTION; | |
| 91 case CBATTErrorUnsupportedGroupType: | |
| 92 return MacOSBluetoothOperationsResult:: | |
| 93 CBATT_ERROR_UNSUPPORTED_GROUP_TYPE; | |
| 94 case CBATTErrorInsufficientResources: | |
| 95 return MacOSBluetoothOperationsResult:: | |
| 96 CBATT_ERROR_INSUFFICIENT_RESOURCES; | |
| 97 } | |
| 98 return MacOSBluetoothOperationsResult::CBATT_ERROR_MAX; | |
|
scheib
2017/08/15 22:20:28
Instead, something named more clearly such as
CBE
jlebel
2017/08/15 23:05:49
Done.
| |
| 99 } | |
| 100 // TODO(crbug.com/755667): Needs to create an histogram to record unknown | |
| 101 // error domains. | |
| 102 return MacOSBluetoothOperationsResult::UNKNOWN_ERROR_DOMAIN; | |
| 103 } | |
| 104 | |
| 105 } // namespace | |
| 106 | |
| 107 void RecordDidFailToConnectPeripheralResult(NSError* error) { | |
| 108 MacOSBluetoothOperationsResult histogram_macos_error = | |
| 109 GetMacOSOperationResultFromNSError(error); | |
| 110 UMA_HISTOGRAM_ENUMERATION( | |
| 111 "Bluetooth.MacOS.Errors.DidFailToConnectToPeripheral", | |
| 112 static_cast<int>(histogram_macos_error), | |
| 113 static_cast<int>(MacOSBluetoothOperationsResult::MAX)); | |
| 114 } | |
| 115 | |
| 116 void RecordDidDisconnectPeripheralResult(NSError* error) { | |
| 117 MacOSBluetoothOperationsResult histogram_macos_error = | |
| 118 GetMacOSOperationResultFromNSError(error); | |
| 119 UMA_HISTOGRAM_ENUMERATION( | |
| 120 "Bluetooth.MacOS.Errors.DidDisconnectPeripheral", | |
| 121 static_cast<int>(histogram_macos_error), | |
| 122 static_cast<int>(MacOSBluetoothOperationsResult::MAX)); | |
| 123 } | |
| 124 | |
| 125 void RecordDidDiscoverPrimaryServicesResult(NSError* error) { | |
| 126 MacOSBluetoothOperationsResult histogram_macos_error = | |
| 127 GetMacOSOperationResultFromNSError(error); | |
| 128 UMA_HISTOGRAM_ENUMERATION( | |
| 129 "Bluetooth.MacOS.Errors.DidDiscoverPrimaryServices", | |
| 130 static_cast<int>(histogram_macos_error), | |
| 131 static_cast<int>(MacOSBluetoothOperationsResult::MAX)); | |
| 132 } | |
| 133 | |
| 134 void RecordDidDiscoverCharacteristicsResult(NSError* error) { | |
| 135 MacOSBluetoothOperationsResult histogram_macos_error = | |
| 136 GetMacOSOperationResultFromNSError(error); | |
| 137 UMA_HISTOGRAM_ENUMERATION( | |
| 138 "Bluetooth.MacOS.Errors.DidDiscoverCharacteristics", | |
| 139 static_cast<int>(histogram_macos_error), | |
| 140 static_cast<int>(MacOSBluetoothOperationsResult::MAX)); | |
| 141 } | |
| 142 | |
| 143 void RecordDidUpdateValueResult(NSError* error) { | |
| 144 MacOSBluetoothOperationsResult histogram_macos_error = | |
| 145 GetMacOSOperationResultFromNSError(error); | |
| 146 UMA_HISTOGRAM_ENUMERATION( | |
| 147 "Bluetooth.MacOS.Errors.DidUpdateValue", | |
| 148 static_cast<int>(histogram_macos_error), | |
| 149 static_cast<int>(MacOSBluetoothOperationsResult::MAX)); | |
| 150 } | |
| 151 | |
| 152 void RecordDidWriteValueResult(NSError* error) { | |
| 153 MacOSBluetoothOperationsResult histogram_macos_error = | |
| 154 GetMacOSOperationResultFromNSError(error); | |
| 155 UMA_HISTOGRAM_ENUMERATION( | |
| 156 "Bluetooth.MacOS.Errors.DidWriteValue", | |
| 157 static_cast<int>(histogram_macos_error), | |
| 158 static_cast<int>(MacOSBluetoothOperationsResult::MAX)); | |
| 159 } | |
| 160 | |
| 161 void RecordDidUpdateNotificationStateResult(NSError* error) { | |
| 162 MacOSBluetoothOperationsResult histogram_macos_error = | |
| 163 GetMacOSOperationResultFromNSError(error); | |
| 164 UMA_HISTOGRAM_ENUMERATION( | |
| 165 "Bluetooth.MacOS.Errors.DidUpdateNotificationState", | |
| 166 static_cast<int>(histogram_macos_error), | |
| 167 static_cast<int>(MacOSBluetoothOperationsResult::MAX)); | |
| 168 } | |
| 169 | |
| 170 void RecordDidDiscoverDescriptorsResult(NSError* error) { | |
| 171 MacOSBluetoothOperationsResult histogram_macos_error = | |
| 172 GetMacOSOperationResultFromNSError(error); | |
| 173 UMA_HISTOGRAM_ENUMERATION( | |
| 174 "Bluetooth.MacOS.Errors.DidDiscoverDescriptors", | |
| 175 static_cast<int>(histogram_macos_error), | |
| 176 static_cast<int>(MacOSBluetoothOperationsResult::MAX)); | |
| 177 } | |
| 178 | |
| 179 void RecordDidUpdateValueForDescriptorResult(NSError* error) { | |
| 180 MacOSBluetoothOperationsResult histogram_macos_error = | |
| 181 GetMacOSOperationResultFromNSError(error); | |
| 182 UMA_HISTOGRAM_ENUMERATION( | |
| 183 "Bluetooth.MacOS.Errors.DidUpdateValueForDescriptor", | |
| 184 static_cast<int>(histogram_macos_error), | |
| 185 static_cast<int>(MacOSBluetoothOperationsResult::MAX)); | |
| 186 } | |
| 187 | |
| 188 void RecordDidWriteValueForDescriptorResult(NSError* error) { | |
| 189 MacOSBluetoothOperationsResult histogram_macos_error = | |
| 190 GetMacOSOperationResultFromNSError(error); | |
| 191 UMA_HISTOGRAM_ENUMERATION( | |
| 192 "Bluetooth.MacOS.Errors.DidWriteValueForDescriptor", | |
| 193 static_cast<int>(histogram_macos_error), | |
| 194 static_cast<int>(MacOSBluetoothOperationsResult::MAX)); | |
| 195 } | |
| OLD | NEW |