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

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

Issue 2662433003: Add BluetoothRemoteGATTDescriptor reporting for .writeValue(). (Closed)
Patch Set: updating comments Created 3 years, 10 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.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 // ID Not In Map Note: A service, characteristic, or descriptor ID not in the 5 // ID Not In Map Note: A service, characteristic, or descriptor ID not in the
6 // corresponding WebBluetoothServiceImpl map [service_id_to_device_address_, 6 // corresponding WebBluetoothServiceImpl map [service_id_to_device_address_,
7 // characteristic_id_to_service_id_, descriptor_id_to_characteristic_id_] 7 // characteristic_id_to_service_id_, descriptor_id_to_characteristic_id_]
8 // implies a hostile renderer because a renderer obtains the corresponding ID 8 // implies a hostile renderer because a renderer obtains the corresponding ID
9 // from this class and it will be added to the map at that time. 9 // from this class and it will be added to the map at that time.
10 10
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 weak_ptr_factory_.GetWeakPtr(), callback), 773 weak_ptr_factory_.GetWeakPtr(), callback),
774 base::Bind(&WebBluetoothServiceImpl::OnDescriptorReadValueFailed, 774 base::Bind(&WebBluetoothServiceImpl::OnDescriptorReadValueFailed,
775 weak_ptr_factory_.GetWeakPtr(), callback)); 775 weak_ptr_factory_.GetWeakPtr(), callback));
776 } 776 }
777 777
778 void WebBluetoothServiceImpl::RemoteDescriptorWriteValue( 778 void WebBluetoothServiceImpl::RemoteDescriptorWriteValue(
779 const std::string& descriptor_instance_id, 779 const std::string& descriptor_instance_id,
780 const std::vector<uint8_t>& value, 780 const std::vector<uint8_t>& value,
781 const RemoteDescriptorWriteValueCallback& callback) { 781 const RemoteDescriptorWriteValueCallback& callback) {
782 DCHECK_CURRENTLY_ON(BrowserThread::UI); 782 DCHECK_CURRENTLY_ON(BrowserThread::UI);
783 RecordWebBluetoothFunctionCall(
784 UMAWebBluetoothFunction::DESCRIPTOR_WRITE_VALUE);
783 785
784 // We perform the length check on the renderer side. So if we 786 // We perform the length check on the renderer side. So if we
785 // get a value with length > 512, we can assume it's a hostile 787 // get a value with length > 512, we can assume it's a hostile
786 // renderer and kill it. 788 // renderer and kill it.
787 if (value.size() > 512) { 789 if (value.size() > 512) {
788 CrashRendererAndClosePipe(bad_message::BDH_INVALID_WRITE_VALUE_LENGTH); 790 CrashRendererAndClosePipe(bad_message::BDH_INVALID_WRITE_VALUE_LENGTH);
789 return; 791 return;
790 } 792 }
791 793
792 const CacheQueryResult query_result = 794 const CacheQueryResult query_result =
793 QueryCacheForDescriptor(descriptor_instance_id); 795 QueryCacheForDescriptor(descriptor_instance_id);
794 796
795 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { 797 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) {
796 return; 798 return;
797 } 799 }
798 800
799 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { 801 if (query_result.outcome != CacheQueryOutcome::SUCCESS) {
802 RecordDescriptorWriteValueOutcome(query_result.outcome);
800 callback.Run(query_result.GetWebResult()); 803 callback.Run(query_result.GetWebResult());
801 return; 804 return;
802 } 805 }
803 806
804 if (BluetoothBlocklist::Get().IsExcludedFromWrites( 807 if (BluetoothBlocklist::Get().IsExcludedFromWrites(
805 query_result.descriptor->GetUUID())) { 808 query_result.descriptor->GetUUID())) {
809 RecordDescriptorWriteValueOutcome(UMAGATTOperationOutcome::BLOCKLISTED);
806 callback.Run(blink::mojom::WebBluetoothResult::BLOCKLISTED_WRITE); 810 callback.Run(blink::mojom::WebBluetoothResult::BLOCKLISTED_WRITE);
807 return; 811 return;
808 } 812 }
809 813
810 query_result.descriptor->WriteRemoteDescriptor( 814 query_result.descriptor->WriteRemoteDescriptor(
811 value, base::Bind(&WebBluetoothServiceImpl::OnDescriptorWriteValueSuccess, 815 value, base::Bind(&WebBluetoothServiceImpl::OnDescriptorWriteValueSuccess,
812 weak_ptr_factory_.GetWeakPtr(), callback), 816 weak_ptr_factory_.GetWeakPtr(), callback),
813 base::Bind(&WebBluetoothServiceImpl::OnDescriptorWriteValueFailed, 817 base::Bind(&WebBluetoothServiceImpl::OnDescriptorWriteValueFailed,
814 weak_ptr_factory_.GetWeakPtr(), callback)); 818 weak_ptr_factory_.GetWeakPtr(), callback));
815 } 819 }
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 const RemoteDescriptorWriteValueCallback& callback) { 1040 const RemoteDescriptorWriteValueCallback& callback) {
1037 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1041 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1038 // TODO(667319): We are reporting failures to UMA but not reporting successes 1042 // TODO(667319): We are reporting failures to UMA but not reporting successes
1039 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); 1043 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS);
1040 } 1044 }
1041 1045
1042 void WebBluetoothServiceImpl::OnDescriptorWriteValueFailed( 1046 void WebBluetoothServiceImpl::OnDescriptorWriteValueFailed(
1043 const RemoteDescriptorWriteValueCallback& callback, 1047 const RemoteDescriptorWriteValueCallback& callback,
1044 device::BluetoothRemoteGattService::GattErrorCode error_code) { 1048 device::BluetoothRemoteGattService::GattErrorCode error_code) {
1045 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1049 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1046 // TODO(683477) reporting for .writeValue() 1050 RecordDescriptorWriteValueOutcome(UMAGATTOperationOutcome::SUCCESS);
1047 callback.Run(TranslateGATTErrorAndRecord(error_code, 1051 callback.Run(TranslateGATTErrorAndRecord(error_code,
1048 UMAGATTOperation::DESCRIPTOR_WRITE)); 1052 UMAGATTOperation::DESCRIPTOR_WRITE));
1049 } 1053 }
1050 1054
1051 CacheQueryResult WebBluetoothServiceImpl::QueryCacheForDevice( 1055 CacheQueryResult WebBluetoothServiceImpl::QueryCacheForDevice(
1052 const WebBluetoothDeviceId& device_id) { 1056 const WebBluetoothDeviceId& device_id) {
1053 const std::string& device_address = 1057 const std::string& device_address =
1054 allowed_devices_map_.GetDeviceAddress(GetOrigin(), device_id); 1058 allowed_devices_map_.GetDeviceAddress(GetOrigin(), device_id);
1055 if (device_address.empty()) { 1059 if (device_address.empty()) {
1056 CrashRendererAndClosePipe(bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN); 1060 CrashRendererAndClosePipe(bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 characteristic_id_to_service_id_.clear(); 1187 characteristic_id_to_service_id_.clear();
1184 service_id_to_device_address_.clear(); 1188 service_id_to_device_address_.clear();
1185 connected_devices_.reset( 1189 connected_devices_.reset(
1186 new FrameConnectedBluetoothDevices(render_frame_host_)); 1190 new FrameConnectedBluetoothDevices(render_frame_host_));
1187 allowed_devices_map_ = BluetoothAllowedDevicesMap(); 1191 allowed_devices_map_ = BluetoothAllowedDevicesMap();
1188 device_chooser_controller_.reset(); 1192 device_chooser_controller_.reset();
1189 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); 1193 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this);
1190 } 1194 }
1191 1195
1192 } // namespace content 1196 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/bluetooth/bluetooth_metrics.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698