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

Side by Side Diff: content/browser/bluetooth/bluetooth_metrics.cc

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
Patch Set: Fix compile errors on bots Created 5 years, 2 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
« no previous file with comments | « content/browser/bluetooth/bluetooth_metrics.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 96 }
97 97
98 // connectGATT 98 // connectGATT
99 99
100 void RecordConnectGATTOutcome(UMAConnectGATTOutcome outcome) { 100 void RecordConnectGATTOutcome(UMAConnectGATTOutcome outcome) {
101 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.ConnectGATT.Outcome", 101 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.ConnectGATT.Outcome",
102 static_cast<int>(outcome), 102 static_cast<int>(outcome),
103 static_cast<int>(UMAConnectGATTOutcome::COUNT)); 103 static_cast<int>(UMAConnectGATTOutcome::COUNT));
104 } 104 }
105 105
106 void RecordConnectGATTOutcome(CacheQueryOutcome outcome) {
107 DCHECK(outcome == CacheQueryOutcome::NO_DEVICE);
108 RecordConnectGATTOutcome(UMAConnectGATTOutcome::NO_DEVICE);
109 }
110
106 void RecordConnectGATTTimeSuccess(const base::TimeDelta& duration) { 111 void RecordConnectGATTTimeSuccess(const base::TimeDelta& duration) {
107 UMA_HISTOGRAM_MEDIUM_TIMES("Bluetooth.Web.ConnectGATT.TimeSuccess", duration); 112 UMA_HISTOGRAM_MEDIUM_TIMES("Bluetooth.Web.ConnectGATT.TimeSuccess", duration);
108 } 113 }
109 114
110 void RecordConnectGATTTimeFailed(const base::TimeDelta& duration) { 115 void RecordConnectGATTTimeFailed(const base::TimeDelta& duration) {
111 UMA_HISTOGRAM_MEDIUM_TIMES("Bluetooth.Web.ConnectGATT.TimeFailed", duration); 116 UMA_HISTOGRAM_MEDIUM_TIMES("Bluetooth.Web.ConnectGATT.TimeFailed", duration);
112 } 117 }
113 118
114 // getPrimaryService 119 // getPrimaryService
115 120
116 void RecordGetPrimaryServiceService(const BluetoothUUID& service) { 121 void RecordGetPrimaryServiceService(const BluetoothUUID& service) {
117 // TODO(ortuno): Use a macro to histogram strings. 122 // TODO(ortuno): Use a macro to histogram strings.
118 // http://crbug.com/520284 123 // http://crbug.com/520284
119 UMA_HISTOGRAM_SPARSE_SLOWLY("Bluetooth.Web.GetPrimaryService.Services", 124 UMA_HISTOGRAM_SPARSE_SLOWLY("Bluetooth.Web.GetPrimaryService.Services",
120 HashUUID(service.canonical_value())); 125 HashUUID(service.canonical_value()));
121 } 126 }
122 127
123 void RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome outcome) { 128 void RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome outcome) {
124 UMA_HISTOGRAM_ENUMERATION( 129 UMA_HISTOGRAM_ENUMERATION(
125 "Bluetooth.Web.GetPrimaryService.Outcome", static_cast<int>(outcome), 130 "Bluetooth.Web.GetPrimaryService.Outcome", static_cast<int>(outcome),
126 static_cast<int>(UMAGetPrimaryServiceOutcome::COUNT)); 131 static_cast<int>(UMAGetPrimaryServiceOutcome::COUNT));
127 } 132 }
128 133
134 void RecordGetPrimaryServiceOutcome(CacheQueryOutcome outcome) {
135 DCHECK(outcome == CacheQueryOutcome::NO_DEVICE);
136 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NO_DEVICE);
137 }
138
129 // getCharacteristic 139 // getCharacteristic
130 140
131 void RecordGetCharacteristicOutcome(UMAGetCharacteristicOutcome outcome) { 141 void RecordGetCharacteristicOutcome(UMAGetCharacteristicOutcome outcome) {
132 UMA_HISTOGRAM_ENUMERATION( 142 UMA_HISTOGRAM_ENUMERATION(
133 "Bluetooth.Web.GetCharacteristic.Outcome", static_cast<int>(outcome), 143 "Bluetooth.Web.GetCharacteristic.Outcome", static_cast<int>(outcome),
134 static_cast<int>(UMAGetCharacteristicOutcome::COUNT)); 144 static_cast<int>(UMAGetCharacteristicOutcome::COUNT));
135 } 145 }
136 146
147 void RecordGetCharacteristicOutcome(CacheQueryOutcome outcome) {
148 switch (outcome) {
149 case CacheQueryOutcome::SUCCESS:
150 case CacheQueryOutcome::BAD_RENDERER:
151 NOTREACHED() << "No need to record a success or renderer crash";
152 return;
153 case CacheQueryOutcome::NO_DEVICE:
154 RecordGetCharacteristicOutcome(UMAGetCharacteristicOutcome::NO_DEVICE);
155 return;
156 case CacheQueryOutcome::NO_SERVICE:
157 RecordGetCharacteristicOutcome(UMAGetCharacteristicOutcome::NO_SERVICE);
158 return;
159 case CacheQueryOutcome::NO_CHARACTERISTIC:
160 NOTREACHED();
161 return;
162 }
163 }
164
137 void RecordGetCharacteristicCharacteristic(const std::string& characteristic) { 165 void RecordGetCharacteristicCharacteristic(const std::string& characteristic) {
138 UMA_HISTOGRAM_SPARSE_SLOWLY("Bluetooth.Web.GetCharacteristic.Characteristic", 166 UMA_HISTOGRAM_SPARSE_SLOWLY("Bluetooth.Web.GetCharacteristic.Characteristic",
139 HashUUID(characteristic)); 167 HashUUID(characteristic));
140 } 168 }
141 169
142 // GATT Operations 170 // GATT Operations
143 171
144 void RecordGATTOperationOutcome(UMAGATTOperation operation, 172 void RecordGATTOperationOutcome(UMAGATTOperation operation,
145 UMAGATTOperationOutcome outcome) { 173 UMAGATTOperationOutcome outcome) {
146 switch (operation) { 174 switch (operation) {
147 case UMAGATTOperation::CHARACTERISTIC_READ: 175 case UMAGATTOperation::CHARACTERISTIC_READ:
148 RecordCharacteristicReadValueOutcome(outcome); 176 RecordCharacteristicReadValueOutcome(outcome);
149 return; 177 return;
150 case UMAGATTOperation::CHARACTERISTIC_WRITE: 178 case UMAGATTOperation::CHARACTERISTIC_WRITE:
151 RecordCharacteristicWriteValueOutcome(outcome); 179 RecordCharacteristicWriteValueOutcome(outcome);
152 return; 180 return;
153 case UMAGATTOperation::START_NOTIFICATIONS: 181 case UMAGATTOperation::START_NOTIFICATIONS:
154 RecordStartNotificationsOutcome(outcome); 182 RecordStartNotificationsOutcome(outcome);
155 return; 183 return;
156 case UMAGATTOperation::COUNT: 184 case UMAGATTOperation::COUNT:
157 NOTREACHED(); 185 NOTREACHED();
158 return; 186 return;
159 } 187 }
160 NOTREACHED(); 188 NOTREACHED();
161 } 189 }
162 190
191 static UMAGATTOperationOutcome TranslateCacheQueryOutcomeToGATTOperationOutcome(
192 CacheQueryOutcome outcome) {
193 switch (outcome) {
194 case CacheQueryOutcome::SUCCESS:
195 case CacheQueryOutcome::BAD_RENDERER:
196 NOTREACHED() << "No need to record success or renderer crash";
197 return UMAGATTOperationOutcome::NOT_SUPPORTED;
198 case CacheQueryOutcome::NO_DEVICE:
199 return UMAGATTOperationOutcome::NO_DEVICE;
200 case CacheQueryOutcome::NO_SERVICE:
201 return UMAGATTOperationOutcome::NO_SERVICE;
202 case CacheQueryOutcome::NO_CHARACTERISTIC:
203 return UMAGATTOperationOutcome::NO_CHARACTERISTIC;
204 }
205 NOTREACHED() << "No need to record success or renderer crash";
206 return UMAGATTOperationOutcome::NOT_SUPPORTED;
207 }
208
163 // Characteristic.readValue 209 // Characteristic.readValue
164 210
165 // static 211 // static
166 void RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome outcome) { 212 void RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome outcome) {
167 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.Characteristic.ReadValue.Outcome", 213 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.Characteristic.ReadValue.Outcome",
168 static_cast<int>(outcome), 214 static_cast<int>(outcome),
169 static_cast<int>(UMAGATTOperationOutcome::COUNT)); 215 static_cast<int>(UMAGATTOperationOutcome::COUNT));
170 } 216 }
171 217
218 void RecordCharacteristicReadValueOutcome(CacheQueryOutcome outcome) {
219 RecordCharacteristicReadValueOutcome(
220 TranslateCacheQueryOutcomeToGATTOperationOutcome(outcome));
221 }
222
172 // Characteristic.writeValue 223 // Characteristic.writeValue
173 224
174 void RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome outcome) { 225 void RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome outcome) {
175 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.Characteristic.WriteValue.Outcome", 226 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.Characteristic.WriteValue.Outcome",
176 static_cast<int>(outcome), 227 static_cast<int>(outcome),
177 static_cast<int>(UMAGATTOperationOutcome::COUNT)); 228 static_cast<int>(UMAGATTOperationOutcome::COUNT));
178 } 229 }
179 230
231 void RecordCharacteristicWriteValueOutcome(CacheQueryOutcome outcome) {
232 RecordCharacteristicWriteValueOutcome(
233 TranslateCacheQueryOutcomeToGATTOperationOutcome(outcome));
234 }
235
180 // Characteristic.startNotifications 236 // Characteristic.startNotifications
181 void RecordStartNotificationsOutcome(UMAGATTOperationOutcome outcome) { 237 void RecordStartNotificationsOutcome(UMAGATTOperationOutcome outcome) {
182 UMA_HISTOGRAM_ENUMERATION( 238 UMA_HISTOGRAM_ENUMERATION(
183 "Bluetooth.Web.Characteristic.StartNotifications.Outcome", 239 "Bluetooth.Web.Characteristic.StartNotifications.Outcome",
184 static_cast<int>(outcome), 240 static_cast<int>(outcome),
185 static_cast<int>(UMAGATTOperationOutcome::COUNT)); 241 static_cast<int>(UMAGATTOperationOutcome::COUNT));
186 } 242 }
187 243
244 void RecordStartNotificationsOutcome(CacheQueryOutcome outcome) {
245 RecordStartNotificationsOutcome(
246 TranslateCacheQueryOutcomeToGATTOperationOutcome(outcome));
247 }
248
188 } // namespace content 249 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/bluetooth/bluetooth_metrics.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698