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: device/bluetooth/bluetooth_remote_gatt_descriptor_mac.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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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 "device/bluetooth/bluetooth_remote_gatt_descriptor_mac.h" 5 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_mac.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #import "base/mac/foundation_util.h" 8 #import "base/mac/foundation_util.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
11 #import "device/bluetooth/bluetooth_adapter_mac.h" 11 #import "device/bluetooth/bluetooth_adapter_mac.h"
12 #include "device/bluetooth/bluetooth_adapter_mac_metrics.h"
12 #import "device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h" 13 #import "device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h"
13 14
14 using base::mac::ObjCCast; 15 using base::mac::ObjCCast;
15 16
16 namespace device { 17 namespace device {
17 18
18 std::vector<uint8_t> VectorValueFromObjC(id objc_value) { 19 std::vector<uint8_t> VectorValueFromObjC(id objc_value) {
19 // According to 20 // According to
20 // https://developer.apple.com/reference/corebluetooth/cbdescriptor some 21 // https://developer.apple.com/reference/corebluetooth/cbdescriptor some
21 // descriptor values can be NSData, NSString or NSNumber. 22 // descriptor values can be NSData, NSString or NSNumber.
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 void BluetoothRemoteGattDescriptorMac::DidUpdateValueForDescriptor( 134 void BluetoothRemoteGattDescriptorMac::DidUpdateValueForDescriptor(
134 NSError* error) { 135 NSError* error) {
135 if (!value_read_or_write_in_progress_) { 136 if (!value_read_or_write_in_progress_) {
136 VLOG(1) << *this << ": Value updated, no read in progress."; 137 VLOG(1) << *this << ": Value updated, no read in progress.";
137 return; 138 return;
138 } 139 }
139 std::pair<ValueCallback, ErrorCallback> callbacks; 140 std::pair<ValueCallback, ErrorCallback> callbacks;
140 callbacks.swap(read_value_callbacks_); 141 callbacks.swap(read_value_callbacks_);
141 value_read_or_write_in_progress_ = false; 142 value_read_or_write_in_progress_ = false;
142 if (error) { 143 if (error) {
144 LogNSErrorToHistogram(
145 error, WebBluetoothMacOSAPIs::
146 WEB_BLUETOOTH_MACOS_APIS_DID_UPDATE_VALUE_FOR_DESCRIPTOR);
143 BluetoothGattService::GattErrorCode error_code = 147 BluetoothGattService::GattErrorCode error_code =
144 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); 148 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error);
145 VLOG(1) << *this << ": Read value failed with error: " 149 VLOG(1) << *this << ": Read value failed with error: "
146 << BluetoothAdapterMac::String(error) 150 << BluetoothAdapterMac::String(error)
147 << ", converted to error code: " << error_code; 151 << ", converted to error code: " << error_code;
148 callbacks.second.Run(error_code); 152 callbacks.second.Run(error_code);
149 return; 153 return;
150 } 154 }
151 VLOG(1) << *this << ": Value read."; 155 VLOG(1) << *this << ": Value read.";
152 value_ = VectorValueFromObjC([cb_descriptor_ value]); 156 value_ = VectorValueFromObjC([cb_descriptor_ value]);
153 callbacks.first.Run(value_); 157 callbacks.first.Run(value_);
154 } 158 }
155 159
156 void BluetoothRemoteGattDescriptorMac::DidWriteValueForDescriptor( 160 void BluetoothRemoteGattDescriptorMac::DidWriteValueForDescriptor(
157 NSError* error) { 161 NSError* error) {
158 if (!value_read_or_write_in_progress_) { 162 if (!value_read_or_write_in_progress_) {
159 VLOG(1) << *this << ": Value written, no write in progress."; 163 VLOG(1) << *this << ": Value written, no write in progress.";
160 return; 164 return;
161 } 165 }
162 std::pair<base::Closure, ErrorCallback> callbacks; 166 std::pair<base::Closure, ErrorCallback> callbacks;
163 callbacks.swap(write_value_callbacks_); 167 callbacks.swap(write_value_callbacks_);
164 value_read_or_write_in_progress_ = false; 168 value_read_or_write_in_progress_ = false;
165 if (error) { 169 if (error) {
170 LogNSErrorToHistogram(
171 error, WebBluetoothMacOSAPIs::
172 WEB_BLUETOOTH_MACOS_APIS_DID_WRITE_VALUE_FOR_DESCRIPTOR);
166 BluetoothGattService::GattErrorCode error_code = 173 BluetoothGattService::GattErrorCode error_code =
167 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); 174 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error);
168 VLOG(1) << *this << ": Write value failed with error: " 175 VLOG(1) << *this << ": Write value failed with error: "
169 << BluetoothAdapterMac::String(error) 176 << BluetoothAdapterMac::String(error)
170 << ", converted to error code: " << error_code; 177 << ", converted to error code: " << error_code;
171 callbacks.second.Run(error_code); 178 callbacks.second.Run(error_code);
172 return; 179 return;
173 } 180 }
174 VLOG(1) << *this << ": Value written."; 181 VLOG(1) << *this << ": Value written.";
175 callbacks.first.Run(); 182 callbacks.first.Run();
(...skipping 14 matching lines...) Expand all
190 static_cast<const BluetoothRemoteGattCharacteristicMac*>( 197 static_cast<const BluetoothRemoteGattCharacteristicMac*>(
191 descriptor.GetCharacteristic()); 198 descriptor.GetCharacteristic());
192 return out << "<BluetoothRemoteGattDescriptorMac " 199 return out << "<BluetoothRemoteGattDescriptorMac "
193 << descriptor.GetUUID().canonical_value() << "/" << &descriptor 200 << descriptor.GetUUID().canonical_value() << "/" << &descriptor
194 << ", characteristic: " 201 << ", characteristic: "
195 << characteristic_mac->GetUUID().canonical_value() << "/" 202 << characteristic_mac->GetUUID().canonical_value() << "/"
196 << characteristic_mac << ">"; 203 << characteristic_mac << ">";
197 } 204 }
198 205
199 } // namespace device. 206 } // namespace device.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698