 Chromium Code Reviews
 Chromium Code Reviews Issue 1397983004:
  bluetooth: Refactor repeated code used to find a Bluetooth object from its ID.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-characteristic-changed-1
    
  
    Issue 1397983004:
  bluetooth: Refactor repeated code used to find a Bluetooth object from its ID.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-characteristic-changed-1| OLD | NEW | 
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/browser/bluetooth/bluetooth_metrics.h" | 5 #include "content/browser/bluetooth/bluetooth_metrics.h" | 
| 6 | 6 | 
| 7 #include <map> | 7 #include <map> | 
| 8 #include <set> | 8 #include <set> | 
| 9 #include "base/hash.h" | 9 #include "base/hash.h" | 
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" | 
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 namespace content { | 29 namespace content { | 
| 30 | 30 | 
| 31 // General | 31 // General | 
| 32 | 32 | 
| 33 void RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction function) { | 33 void RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction function) { | 
| 34 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.FunctionCall.Count", | 34 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.FunctionCall.Count", | 
| 35 static_cast<int>(function), | 35 static_cast<int>(function), | 
| 36 static_cast<int>(UMAWebBluetoothFunction::COUNT)); | 36 static_cast<int>(UMAWebBluetoothFunction::COUNT)); | 
| 37 } | 37 } | 
| 38 | 38 | 
| 39 static UMAGATTOperationOutcome TranslateCacheQueryOutcomeToGATT( | |
| 40 CacheQueryOutcome outcome) { | |
| 41 switch (outcome) { | |
| 42 case CacheQueryOutcome::NO_DEVICE: | |
| 43 return UMAGATTOperationOutcome::NO_DEVICE; | |
| 44 case CacheQueryOutcome::NO_SERVICE: | |
| 45 return UMAGATTOperationOutcome::NO_SERVICE; | |
| 46 case CacheQueryOutcome::NO_CHARACTERISTIC: | |
| 47 return UMAGATTOperationOutcome::NO_CHARACTERISTIC; | |
| 48 default: | |
| 49 NOTIMPLEMENTED(); | |
| 50 return UMAGATTOperationOutcome::NOT_SUPPORTED; | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 void RecordOutcomeWithCacheQueryResult(UMAWebBluetoothFunction function, | |
| 55 CacheQueryOutcome outcome) { | |
| 56 switch (function) { | |
| 57 case UMAWebBluetoothFunction::CONNECT_GATT: | |
| 58 DCHECK(outcome == CacheQueryOutcome::NO_DEVICE); | |
| 59 RecordConnectGATTOutcome(UMAConnectGATTOutcome::NO_DEVICE); | |
| 60 return; | |
| 61 case UMAWebBluetoothFunction::GET_PRIMARY_SERVICE: | |
| 62 DCHECK(outcome == CacheQueryOutcome::NO_DEVICE); | |
| 63 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NO_DEVICE); | |
| 64 return; | |
| 65 case UMAWebBluetoothFunction::GET_CHARACTERISTIC: | |
| 66 switch (outcome) { | |
| 67 case CacheQueryOutcome::NO_DEVICE: | |
| 68 RecordGetCharacteristicOutcome( | |
| 69 UMAGetCharacteristicOutcome::NO_DEVICE); | |
| 70 return; | |
| 71 case CacheQueryOutcome::NO_SERVICE: | |
| 72 RecordGetCharacteristicOutcome( | |
| 73 UMAGetCharacteristicOutcome::NO_SERVICE); | |
| 74 return; | |
| 75 default: | |
| 76 NOTIMPLEMENTED(); | |
| 
scheib
2015/10/19 23:15:54
I suggest not using 'default' in switch statements
 
ortuno
2015/10/20 17:44:03
Done.
 | |
| 77 return; | |
| 78 } | |
| 79 case UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE: | |
| 80 RecordCharacteristicReadValueOutcome( | |
| 81 TranslateCacheQueryOutcomeToGATT(outcome)); | |
| 82 return; | |
| 83 case UMAWebBluetoothFunction::CHARACTERISTIC_WRITE_VALUE: | |
| 84 RecordCharacteristicWriteValueOutcome( | |
| 85 TranslateCacheQueryOutcomeToGATT(outcome)); | |
| 86 return; | |
| 87 case UMAWebBluetoothFunction::CHARACTERISTIC_START_NOTIFICATIONS: | |
| 88 RecordStartNotificationsOutcome( | |
| 89 TranslateCacheQueryOutcomeToGATT(outcome)); | |
| 90 return; | |
| 91 default: | |
| 92 NOTIMPLEMENTED(); | |
| 93 } | |
| 94 } | |
| 95 | |
| 39 // requestDevice() | 96 // requestDevice() | 
| 40 | 97 | 
| 41 void RecordRequestDeviceOutcome(UMARequestDeviceOutcome outcome) { | 98 void RecordRequestDeviceOutcome(UMARequestDeviceOutcome outcome) { | 
| 42 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.RequestDevice.Outcome", | 99 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.RequestDevice.Outcome", | 
| 43 static_cast<int>(outcome), | 100 static_cast<int>(outcome), | 
| 44 static_cast<int>(UMARequestDeviceOutcome::COUNT)); | 101 static_cast<int>(UMARequestDeviceOutcome::COUNT)); | 
| 45 } | 102 } | 
| 46 | 103 | 
| 47 static void RecordRequestDeviceFilters( | 104 static void RecordRequestDeviceFilters( | 
| 48 const std::vector<content::BluetoothScanFilter>& filters) { | 105 const std::vector<content::BluetoothScanFilter>& filters) { | 
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 | 236 | 
| 180 // Characteristic.startNotifications | 237 // Characteristic.startNotifications | 
| 181 void RecordStartNotificationsOutcome(UMAGATTOperationOutcome outcome) { | 238 void RecordStartNotificationsOutcome(UMAGATTOperationOutcome outcome) { | 
| 182 UMA_HISTOGRAM_ENUMERATION( | 239 UMA_HISTOGRAM_ENUMERATION( | 
| 183 "Bluetooth.Web.Characteristic.StartNotifications.Outcome", | 240 "Bluetooth.Web.Characteristic.StartNotifications.Outcome", | 
| 184 static_cast<int>(outcome), | 241 static_cast<int>(outcome), | 
| 185 static_cast<int>(UMAGATTOperationOutcome::COUNT)); | 242 static_cast<int>(UMAGATTOperationOutcome::COUNT)); | 
| 186 } | 243 } | 
| 187 | 244 | 
| 188 } // namespace content | 245 } // namespace content | 
| OLD | NEW |