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

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: Ref count connections 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 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 // in case a hostile renderer is trying to disconnect a device that the 717 // in case a hostile renderer is trying to disconnect a device that the
718 // renderer is not allowed to access. 718 // renderer is not allowed to access.
719 if (allowed_devices_map_.GetDeviceAddress(GetOrigin(frame_routing_id), 719 if (allowed_devices_map_.GetDeviceAddress(GetOrigin(frame_routing_id),
720 device_id) 720 device_id)
721 .empty()) { 721 .empty()) {
722 bad_message::ReceivedBadMessage( 722 bad_message::ReceivedBadMessage(
723 this, bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN); 723 this, bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN);
724 return; 724 return;
725 } 725 }
726 726
727 RenderFrameHostImpl* render_frame_host =
728 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id);
729 WebContents* web_contents =
730 WebContents::FromRenderFrameHost(render_frame_host);
731 if (web_contents) {
732 web_contents->SetBluetoothDeviceConnected(false);
733 }
734
735 // The last BluetoothGattConnection for a device closes the connection when 727 // The last BluetoothGattConnection for a device closes the connection when
736 // it's destroyed. 728 // it's destroyed.
737 if (device_id_to_connection_map_.erase(device_id)) { 729 if (device_id_to_connection_map_.erase(device_id)) {
738 VLOG(1) << "Disconnecting device: " << device_id; 730 VLOG(1) << "Disconnecting device: " << device_id;
731
732 // Indicate there is one less connected device.
733 RenderFrameHostImpl* render_frame_host =
734 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id);
735 WebContents* web_contents =
736 WebContents::FromRenderFrameHost(render_frame_host);
737 if (web_contents) {
738 web_contents->DecrementBluetoothConnectedDeviceCount();
Jeffrey Yasskin 2016/03/31 18:00:25 Are we guaranteed that if a process crashes, it'll
ortuno 2016/04/04 21:20:56 From some experimentation it seems that if the Ren
739 }
739 } 740 }
740 } 741 }
741 742
742 void BluetoothDispatcherHost::OnGetPrimaryService( 743 void BluetoothDispatcherHost::OnGetPrimaryService(
743 int thread_id, 744 int thread_id,
744 int request_id, 745 int request_id,
745 int frame_routing_id, 746 int frame_routing_id,
746 const std::string& device_id, 747 const std::string& device_id,
747 const std::string& service_uuid) { 748 const std::string& service_uuid) {
748 DCHECK_CURRENTLY_ON(BrowserThread::UI); 749 DCHECK_CURRENTLY_ON(BrowserThread::UI);
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
1454 scoped_ptr<device::BluetoothGattConnection> connection) { 1455 scoped_ptr<device::BluetoothGattConnection> connection) {
1455 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1456 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1456 device_id_to_connection_map_[device_id] = std::move(connection); 1457 device_id_to_connection_map_[device_id] = std::move(connection);
1457 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time); 1458 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time);
1458 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS); 1459 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS);
1459 RenderFrameHostImpl* render_frame_host = 1460 RenderFrameHostImpl* render_frame_host =
1460 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id); 1461 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id);
1461 WebContents* web_contents = 1462 WebContents* web_contents =
1462 WebContents::FromRenderFrameHost(render_frame_host); 1463 WebContents::FromRenderFrameHost(render_frame_host);
1463 if (web_contents) { 1464 if (web_contents) {
1464 web_contents->SetBluetoothDeviceConnected(true); 1465 web_contents->IncrementBluetoothConnectedDeviceCount();
1465 } 1466 }
1466 Send(new BluetoothMsg_GATTServerConnectSuccess(thread_id, request_id)); 1467 Send(new BluetoothMsg_GATTServerConnectSuccess(thread_id, request_id));
1467 } 1468 }
1468 1469
1469 void BluetoothDispatcherHost::OnCreateGATTConnectionError( 1470 void BluetoothDispatcherHost::OnCreateGATTConnectionError(
1470 int thread_id, 1471 int thread_id,
1471 int request_id, 1472 int request_id,
1472 const std::string& device_id, 1473 const std::string& device_id,
1473 base::TimeTicks start_time, 1474 base::TimeTicks start_time,
1474 device::BluetoothDevice::ConnectErrorCode error_code) { 1475 device::BluetoothDevice::ConnectErrorCode error_code) {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1680 1681
1681 bool BluetoothDispatcherHost::CanFrameAccessCharacteristicInstance( 1682 bool BluetoothDispatcherHost::CanFrameAccessCharacteristicInstance(
1682 int frame_routing_id, 1683 int frame_routing_id,
1683 const std::string& characteristic_instance_id) { 1684 const std::string& characteristic_instance_id) {
1684 return QueryCacheForCharacteristic(GetOrigin(frame_routing_id), 1685 return QueryCacheForCharacteristic(GetOrigin(frame_routing_id),
1685 characteristic_instance_id) 1686 characteristic_instance_id)
1686 .outcome != CacheQueryOutcome::BAD_RENDERER; 1687 .outcome != CacheQueryOutcome::BAD_RENDERER;
1687 } 1688 }
1688 1689
1689 } // namespace content 1690 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698