Chromium Code Reviews| Index: content/browser/bluetooth/bluetooth_metrics.cc |
| diff --git a/content/browser/bluetooth/bluetooth_metrics.cc b/content/browser/bluetooth/bluetooth_metrics.cc |
| index ad3205bd63cc77c8b51b9b677977dab5298d9130..14d76f46ca7ecdab95200a74c1dfb766ad77933d 100644 |
| --- a/content/browser/bluetooth/bluetooth_metrics.cc |
| +++ b/content/browser/bluetooth/bluetooth_metrics.cc |
| @@ -8,6 +8,8 @@ |
| #include <map> |
| #include <set> |
| +#include <unordered_set> |
| + |
| #include "base/hash.h" |
| #include "base/metrics/histogram_macros.h" |
| #include "base/metrics/sparse_histogram.h" |
| @@ -21,11 +23,14 @@ namespace { |
| // UMA_HISTOGRAM_SPARSE_SLOWLY (positive int). |
| // |
| // Hash values can be produced manually using tool: bluetooth_metrics_hash. |
| -int HashUUID(const std::string& canonical_uuid) { |
| - DCHECK(canonical_uuid == BluetoothUUID(canonical_uuid).canonical_value()); |
| +int HashUUID(const std::unique_ptr<BluetoothUUID>& uuid) { |
| + if (!uuid.get()) { |
| + return 0; |
| + } |
| - // TODO(520284): Other than verifying that uuid is canonical, this logic |
| + // TODO(520284): Other than verifying that uuid exists, this logic |
|
Jeffrey Yasskin
2016/05/28 04:38:06
If 'uuid' becomes a base::Optional, s/exists/conta
ortuno
2016/05/31 17:30:47
Done.
|
| // should be migrated to a dedicated histogram macro for hashed strings. |
| + const std::string& canonical_uuid = uuid->canonical_value(); |
| uint32_t data = |
| base::SuperFastHash(canonical_uuid.data(), canonical_uuid.size()); |
| @@ -60,7 +65,7 @@ static void RecordRequestDeviceFilters( |
| for (const auto& filter : filters) { |
| UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.FilterSize", |
| filter->services.size()); |
| - for (const std::string& service : filter->services) { |
| + for (const std::unique_ptr<BluetoothUUID>& service : filter->services) { |
| // TODO(ortuno): Use a macro to histogram strings. |
| // http://crbug.com/520284 |
| UMA_HISTOGRAM_SPARSE_SLOWLY( |
| @@ -70,10 +75,10 @@ static void RecordRequestDeviceFilters( |
| } |
| static void RecordRequestDeviceOptionalServices( |
| - const mojo::Array<mojo::String>& optional_services) { |
| + const mojo::Array<std::unique_ptr<BluetoothUUID>>& optional_services) { |
| UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.OptionalServices.Count", |
| optional_services.size()); |
| - for (const std::string& service : optional_services) { |
| + for (const std::unique_ptr<BluetoothUUID>& service : optional_services) { |
| // TODO(ortuno): Use a macro to histogram strings. |
| // http://crbug.com/520284 |
| UMA_HISTOGRAM_SPARSE_SLOWLY( |
| @@ -84,11 +89,17 @@ static void RecordRequestDeviceOptionalServices( |
| static void RecordUnionOfServices( |
| const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options) { |
| - std::set<mojo::String> union_of_services(options->optional_services.begin(), |
| - options->optional_services.end()); |
| + std::unordered_set<std::string> union_of_services; |
| + for (const std::unique_ptr<BluetoothUUID>& service : |
| + options->optional_services) { |
| + union_of_services.insert(service->canonical_value()); |
| + } |
| - for (const auto& filter : options->filters) |
| - union_of_services.insert(filter->services.begin(), filter->services.end()); |
| + for (const auto& filter : options->filters) { |
| + for (const std::unique_ptr<BluetoothUUID>& service : filter->services) { |
| + union_of_services.insert(service->canonical_value()); |
| + } |
| + } |
| UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.UnionOfServices.Count", |
| union_of_services.size()); |
| @@ -124,11 +135,12 @@ void RecordConnectGATTTimeFailed(const base::TimeDelta& duration) { |
| // getPrimaryService |
| -void RecordGetPrimaryServiceService(const BluetoothUUID& service) { |
| +void RecordGetPrimaryServiceService( |
| + const std::unique_ptr<BluetoothUUID>& service) { |
| // TODO(ortuno): Use a macro to histogram strings. |
| // http://crbug.com/520284 |
| UMA_HISTOGRAM_SPARSE_SLOWLY("Bluetooth.Web.GetPrimaryService.Services", |
| - HashUUID(service.canonical_value())); |
| + HashUUID(service)); |
| } |
| void RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome outcome) { |
| @@ -186,7 +198,7 @@ void RecordGetCharacteristicsOutcome( |
| void RecordGetCharacteristicsCharacteristic( |
| blink::mojom::WebBluetoothGATTQueryQuantity quantity, |
| - const std::string& characteristic) { |
| + const std::unique_ptr<BluetoothUUID>& characteristic) { |
| switch (quantity) { |
| case blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE: |
| UMA_HISTOGRAM_SPARSE_SLOWLY( |