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

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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 DCHECK(pending_primary_services_requests_.empty()); 339 DCHECK(pending_primary_services_requests_.empty());
340 340
341 // The following data structures are cleaned up when a 341 // The following data structures are cleaned up when a
342 // device/service/characteristic is removed. 342 // device/service/characteristic is removed.
343 // Since this can happen after the test is done and the cleanup function is 343 // Since this can happen after the test is done and the cleanup function is
344 // called, we clean them here. 344 // called, we clean them here.
345 service_to_device_.clear(); 345 service_to_device_.clear();
346 characteristic_to_service_.clear(); 346 characteristic_to_service_.clear();
347 characteristic_id_to_notify_session_.clear(); 347 characteristic_id_to_notify_session_.clear();
348 active_characteristic_threads_.clear(); 348 active_characteristic_threads_.clear();
349 device_id_to_connection_map_.clear(); 349 device_id_to_connection_map_.clear();
ncarter (slow) 2016/04/07 19:48:54 Do we need to decrement here?
ortuno 2016/04/07 22:34:51 This code is only run during tests. Anyway, the ne
350 allowed_devices_map_ = BluetoothAllowedDevicesMap(); 350 allowed_devices_map_ = BluetoothAllowedDevicesMap();
351 } 351 }
352 352
353 set_adapter(std::move(mock_adapter)); 353 set_adapter(std::move(mock_adapter));
354 } 354 }
355 355
356 BluetoothDispatcherHost::~BluetoothDispatcherHost() { 356 BluetoothDispatcherHost::~BluetoothDispatcherHost() {
357 DCHECK_CURRENTLY_ON(BrowserThread::UI); 357 DCHECK_CURRENTLY_ON(BrowserThread::UI);
358 // Clear adapter, releasing observer references. 358 // Clear adapter, releasing observer references.
359 set_adapter(scoped_refptr<device::BluetoothAdapter>()); 359 set_adapter(scoped_refptr<device::BluetoothAdapter>());
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 DCHECK_CURRENTLY_ON(BrowserThread::UI); 700 DCHECK_CURRENTLY_ON(BrowserThread::UI);
701 RecordWebBluetoothFunctionCall( 701 RecordWebBluetoothFunctionCall(
702 UMAWebBluetoothFunction::REMOTE_GATT_SERVER_DISCONNECT); 702 UMAWebBluetoothFunction::REMOTE_GATT_SERVER_DISCONNECT);
703 703
704 // Frames can send a disconnect request after they've started navigating, 704 // Frames can send a disconnect request after they've started navigating,
705 // making calls to GetLastCommitted origin invalid. Because we still need 705 // making calls to GetLastCommitted origin invalid. Because we still need
706 // to disconnect the device, otherwise we would leave users with no other 706 // to disconnect the device, otherwise we would leave users with no other
707 // option to disconnect than closing the tab, we purposefully don't 707 // option to disconnect than closing the tab, we purposefully don't
708 // check if the frame has permission to interact with the device. 708 // check if the frame has permission to interact with the device.
709 709
710 RenderFrameHostImpl* render_frame_host =
711 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id);
712 WebContents* web_contents =
713 WebContents::FromRenderFrameHost(render_frame_host);
714 if (web_contents) {
715 web_contents->SetBluetoothDeviceConnected(false);
716 }
717
718 // The last BluetoothGattConnection for a device closes the connection when 710 // The last BluetoothGattConnection for a device closes the connection when
719 // it's destroyed. 711 // it's destroyed.
720 if (device_id_to_connection_map_.erase(device_id)) { 712 if (device_id_to_connection_map_.erase(device_id)) {
721 VLOG(1) << "Disconnecting device: " << device_id; 713 VLOG(1) << "Disconnecting device: " << device_id;
714
715 // This only catches disconnections from the renderer. If the device
716 // disconnects by itself, or the renderer frame has been deleted
717 // due to navigation, we will not hide the indicator.
718 // TODO(ortuno): Once we move to Frame and Mojo we will be able
719 // to observe the frame's lifetime and hide the indicator when necessary.
720 // http://crbug.com/508771
721
722 // Indicate there is one less connected device.
723 RenderFrameHostImpl* render_frame_host =
724 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id);
725 WebContents* web_contents =
726 WebContents::FromRenderFrameHost(render_frame_host);
727 if (web_contents) {
728 web_contents->DecrementBluetoothConnectedDeviceCount();
729 }
722 } 730 }
723 } 731 }
724 732
725 void BluetoothDispatcherHost::OnGetPrimaryService( 733 void BluetoothDispatcherHost::OnGetPrimaryService(
726 int thread_id, 734 int thread_id,
727 int request_id, 735 int request_id,
728 int frame_routing_id, 736 int frame_routing_id,
729 const std::string& device_id, 737 const std::string& device_id,
730 const std::string& service_uuid) { 738 const std::string& service_uuid) {
731 DCHECK_CURRENTLY_ON(BrowserThread::UI); 739 DCHECK_CURRENTLY_ON(BrowserThread::UI);
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
1400 } 1408 }
1401 1409
1402 void BluetoothDispatcherHost::OnGATTConnectionCreated( 1410 void BluetoothDispatcherHost::OnGATTConnectionCreated(
1403 int thread_id, 1411 int thread_id,
1404 int request_id, 1412 int request_id,
1405 int frame_routing_id, 1413 int frame_routing_id,
1406 const std::string& device_id, 1414 const std::string& device_id,
1407 base::TimeTicks start_time, 1415 base::TimeTicks start_time,
1408 scoped_ptr<device::BluetoothGattConnection> connection) { 1416 scoped_ptr<device::BluetoothGattConnection> connection) {
1409 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1417 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1410 device_id_to_connection_map_[device_id] = std::move(connection); 1418 device_id_to_connection_map_[device_id] = std::move(connection);
ncarter (slow) 2016/04/07 19:48:54 If the device was already in the map, then the con
ortuno 2016/04/07 22:34:51 Added a new ConnectedDevicesMap. WDYT?
1411 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time); 1419 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time);
1412 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS); 1420 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS);
1413 RenderFrameHostImpl* render_frame_host = 1421 RenderFrameHostImpl* render_frame_host =
1414 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id); 1422 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id);
1415 WebContents* web_contents = 1423 WebContents* web_contents =
1416 WebContents::FromRenderFrameHost(render_frame_host); 1424 WebContents::FromRenderFrameHost(render_frame_host);
1417 if (web_contents) { 1425 if (web_contents) {
1418 web_contents->SetBluetoothDeviceConnected(true); 1426 web_contents->IncrementBluetoothConnectedDeviceCount();
1419 } 1427 }
1420 Send(new BluetoothMsg_GATTServerConnectSuccess(thread_id, request_id)); 1428 Send(new BluetoothMsg_GATTServerConnectSuccess(thread_id, request_id));
1421 } 1429 }
1422 1430
1423 void BluetoothDispatcherHost::OnCreateGATTConnectionError( 1431 void BluetoothDispatcherHost::OnCreateGATTConnectionError(
1424 int thread_id, 1432 int thread_id,
1425 int request_id, 1433 int request_id,
1426 const std::string& device_id, 1434 const std::string& device_id,
1427 base::TimeTicks start_time, 1435 base::TimeTicks start_time,
1428 device::BluetoothDevice::ConnectErrorCode error_code) { 1436 device::BluetoothDevice::ConnectErrorCode error_code) {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 1624
1617 bool BluetoothDispatcherHost::CanFrameAccessCharacteristicInstance( 1625 bool BluetoothDispatcherHost::CanFrameAccessCharacteristicInstance(
1618 int frame_routing_id, 1626 int frame_routing_id,
1619 const std::string& characteristic_instance_id) { 1627 const std::string& characteristic_instance_id) {
1620 return QueryCacheForCharacteristic(GetOrigin(frame_routing_id), 1628 return QueryCacheForCharacteristic(GetOrigin(frame_routing_id),
1621 characteristic_instance_id) 1629 characteristic_instance_id)
1622 .outcome != CacheQueryOutcome::BAD_RENDERER; 1630 .outcome != CacheQueryOutcome::BAD_RENDERER;
1623 } 1631 }
1624 1632
1625 } // namespace content 1633 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698