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

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

Issue 1848663002: bluetooth: Remove indicator only when there are no more devices connected (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Address jyasskin's comments Created 4 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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: 5 // ID Not In Map Note:
6 // A service, characteristic, or descriptor ID not in the corresponding 6 // A service, characteristic, or descriptor ID not in the corresponding
7 // BluetoothDispatcherHost map [service_to_device_, characteristic_to_service_, 7 // BluetoothDispatcherHost map [service_to_device_, characteristic_to_service_,
8 // descriptor_to_characteristic_] implies a hostile renderer because a renderer 8 // descriptor_to_characteristic_] implies a hostile renderer because a renderer
9 // obtains the corresponding ID from this class and it will be added to the map 9 // obtains the corresponding ID from this class and it will be added to the map
10 // at that time. 10 // at that time.
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 // in case a hostile renderer is trying to disconnect a device that the 705 // in case a hostile renderer is trying to disconnect a device that the
706 // renderer is not allowed to access. 706 // renderer is not allowed to access.
707 if (allowed_devices_map_.GetDeviceAddress(GetOrigin(frame_routing_id), 707 if (allowed_devices_map_.GetDeviceAddress(GetOrigin(frame_routing_id),
708 device_id) 708 device_id)
709 .empty()) { 709 .empty()) {
710 bad_message::ReceivedBadMessage( 710 bad_message::ReceivedBadMessage(
711 this, bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN); 711 this, bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN);
712 return; 712 return;
713 } 713 }
714 714
715 RenderFrameHostImpl* render_frame_host =
716 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id);
717 WebContents* web_contents =
718 WebContents::FromRenderFrameHost(render_frame_host);
719 if (web_contents) {
720 web_contents->SetBluetoothDeviceConnected(false);
721 }
722
723 // The last BluetoothGattConnection for a device closes the connection when 715 // The last BluetoothGattConnection for a device closes the connection when
724 // it's destroyed. 716 // it's destroyed.
725 if (device_id_to_connection_map_.erase(device_id)) { 717 if (device_id_to_connection_map_.erase(device_id)) {
726 VLOG(1) << "Disconnecting device: " << device_id; 718 VLOG(1) << "Disconnecting device: " << device_id;
719
720 // Indicate there is one less connected device.
Jeffrey Yasskin 2016/04/06 23:05:13 Add a TODO here saying that this can miss disconne
ortuno 2016/04/07 15:09:20 Done.
721 RenderFrameHostImpl* render_frame_host =
722 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id);
723 WebContents* web_contents =
724 WebContents::FromRenderFrameHost(render_frame_host);
725 if (web_contents) {
726 web_contents->DecrementBluetoothConnectedDeviceCount();
727 }
727 } 728 }
728 } 729 }
729 730
730 void BluetoothDispatcherHost::OnGetPrimaryService( 731 void BluetoothDispatcherHost::OnGetPrimaryService(
731 int thread_id, 732 int thread_id,
732 int request_id, 733 int request_id,
733 int frame_routing_id, 734 int frame_routing_id,
734 const std::string& device_id, 735 const std::string& device_id,
735 const std::string& service_uuid) { 736 const std::string& service_uuid) {
736 DCHECK_CURRENTLY_ON(BrowserThread::UI); 737 DCHECK_CURRENTLY_ON(BrowserThread::UI);
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 scoped_ptr<device::BluetoothGattConnection> connection) { 1414 scoped_ptr<device::BluetoothGattConnection> connection) {
1414 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1415 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1415 device_id_to_connection_map_[device_id] = std::move(connection); 1416 device_id_to_connection_map_[device_id] = std::move(connection);
1416 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time); 1417 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time);
1417 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS); 1418 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS);
1418 RenderFrameHostImpl* render_frame_host = 1419 RenderFrameHostImpl* render_frame_host =
1419 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id); 1420 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id);
1420 WebContents* web_contents = 1421 WebContents* web_contents =
1421 WebContents::FromRenderFrameHost(render_frame_host); 1422 WebContents::FromRenderFrameHost(render_frame_host);
1422 if (web_contents) { 1423 if (web_contents) {
1423 web_contents->SetBluetoothDeviceConnected(true); 1424 web_contents->IncrementBluetoothConnectedDeviceCount();
1424 } 1425 }
1425 Send(new BluetoothMsg_GATTServerConnectSuccess(thread_id, request_id)); 1426 Send(new BluetoothMsg_GATTServerConnectSuccess(thread_id, request_id));
1426 } 1427 }
1427 1428
1428 void BluetoothDispatcherHost::OnCreateGATTConnectionError( 1429 void BluetoothDispatcherHost::OnCreateGATTConnectionError(
1429 int thread_id, 1430 int thread_id,
1430 int request_id, 1431 int request_id,
1431 const std::string& device_id, 1432 const std::string& device_id,
1432 base::TimeTicks start_time, 1433 base::TimeTicks start_time,
1433 device::BluetoothDevice::ConnectErrorCode error_code) { 1434 device::BluetoothDevice::ConnectErrorCode error_code) {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 1622
1622 bool BluetoothDispatcherHost::CanFrameAccessCharacteristicInstance( 1623 bool BluetoothDispatcherHost::CanFrameAccessCharacteristicInstance(
1623 int frame_routing_id, 1624 int frame_routing_id,
1624 const std::string& characteristic_instance_id) { 1625 const std::string& characteristic_instance_id) {
1625 return QueryCacheForCharacteristic(GetOrigin(frame_routing_id), 1626 return QueryCacheForCharacteristic(GetOrigin(frame_routing_id),
1626 characteristic_instance_id) 1627 characteristic_instance_id)
1627 .outcome != CacheQueryOutcome::BAD_RENDERER; 1628 .outcome != CacheQueryOutcome::BAD_RENDERER;
1628 } 1629 }
1629 1630
1630 } // namespace content 1631 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698