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

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

Issue 1746333002: bluetooth: Show tab indicator when BT device is connected (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: mute -> connected 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 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 if (connection_iter != device_id_to_connection_map_.end()) { 689 if (connection_iter != device_id_to_connection_map_.end()) {
690 if (connection_iter->second->IsConnected()) { 690 if (connection_iter->second->IsConnected()) {
691 VLOG(1) << "Already connected."; 691 VLOG(1) << "Already connected.";
692 Send(new BluetoothMsg_GATTServerConnectSuccess(thread_id, request_id)); 692 Send(new BluetoothMsg_GATTServerConnectSuccess(thread_id, request_id));
693 return; 693 return;
694 } 694 }
695 } 695 }
696 696
697 query_result.device->CreateGattConnection( 697 query_result.device->CreateGattConnection(
698 base::Bind(&BluetoothDispatcherHost::OnGATTConnectionCreated, 698 base::Bind(&BluetoothDispatcherHost::OnGATTConnectionCreated,
699 weak_ptr_on_ui_thread_, thread_id, request_id, device_id, 699 weak_ptr_on_ui_thread_, thread_id, request_id,
700 start_time), 700 frame_routing_id, device_id, start_time),
701 base::Bind(&BluetoothDispatcherHost::OnCreateGATTConnectionError, 701 base::Bind(&BluetoothDispatcherHost::OnCreateGATTConnectionError,
702 weak_ptr_on_ui_thread_, thread_id, request_id, device_id, 702 weak_ptr_on_ui_thread_, thread_id, request_id, device_id,
703 start_time)); 703 start_time));
704 } 704 }
705 705
706 void BluetoothDispatcherHost::OnGATTServerDisconnect( 706 void BluetoothDispatcherHost::OnGATTServerDisconnect(
707 int thread_id, 707 int thread_id,
708 int frame_routing_id, 708 int frame_routing_id,
709 const std::string& device_id) { 709 const std::string& device_id) {
710 DCHECK_CURRENTLY_ON(BrowserThread::UI); 710 DCHECK_CURRENTLY_ON(BrowserThread::UI);
711 RecordWebBluetoothFunctionCall( 711 RecordWebBluetoothFunctionCall(
712 UMAWebBluetoothFunction::REMOTE_GATT_SERVER_DISCONNECT); 712 UMAWebBluetoothFunction::REMOTE_GATT_SERVER_DISCONNECT);
713 713
714 // Make sure the origin is allowed to access the device. We perform this check 714 // Make sure the origin is allowed to access the device. We perform this check
715 // in case a hostile renderer is trying to disconnect a device that the 715 // in case a hostile renderer is trying to disconnect a device that the
716 // renderer is not allowed to access. 716 // renderer is not allowed to access.
717 if (allowed_devices_map_.GetDeviceAddress(GetOrigin(frame_routing_id), 717 if (allowed_devices_map_.GetDeviceAddress(GetOrigin(frame_routing_id),
718 device_id) 718 device_id)
719 .empty()) { 719 .empty()) {
720 bad_message::ReceivedBadMessage( 720 bad_message::ReceivedBadMessage(
721 this, bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN); 721 this, bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN);
722 return; 722 return;
723 } 723 }
724 724
725 RenderFrameHostImpl* render_frame_host =
726 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id);
727 WebContents* web_contents =
728 WebContents::FromRenderFrameHost(render_frame_host);
729 if (web_contents) {
730 web_contents->SetBluetoothDeviceConnected(false);
731 }
732
725 // The last BluetoothGattConnection for a device closes the connection when 733 // The last BluetoothGattConnection for a device closes the connection when
726 // it's destroyed. 734 // it's destroyed.
727 if (device_id_to_connection_map_.erase(device_id)) { 735 if (device_id_to_connection_map_.erase(device_id)) {
728 VLOG(1) << "Disconnecting device: " << device_id; 736 VLOG(1) << "Disconnecting device: " << device_id;
729 } 737 }
730 } 738 }
731 739
732 void BluetoothDispatcherHost::OnGetPrimaryService( 740 void BluetoothDispatcherHost::OnGetPrimaryService(
733 int thread_id, 741 int thread_id,
734 int request_id, 742 int request_id,
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
1433 filtered_uuids)); // uuids 1441 filtered_uuids)); // uuids
1434 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::SUCCESS); 1442 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::SUCCESS);
1435 Send(new BluetoothMsg_RequestDeviceSuccess(session->thread_id, 1443 Send(new BluetoothMsg_RequestDeviceSuccess(session->thread_id,
1436 session->request_id, device_ipc)); 1444 session->request_id, device_ipc));
1437 request_device_sessions_.Remove(chooser_id); 1445 request_device_sessions_.Remove(chooser_id);
1438 } 1446 }
1439 1447
1440 void BluetoothDispatcherHost::OnGATTConnectionCreated( 1448 void BluetoothDispatcherHost::OnGATTConnectionCreated(
1441 int thread_id, 1449 int thread_id,
1442 int request_id, 1450 int request_id,
1451 int frame_routing_id,
1443 const std::string& device_id, 1452 const std::string& device_id,
1444 base::TimeTicks start_time, 1453 base::TimeTicks start_time,
1445 scoped_ptr<device::BluetoothGattConnection> connection) { 1454 scoped_ptr<device::BluetoothGattConnection> connection) {
1446 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1455 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1447 device_id_to_connection_map_[device_id] = std::move(connection); 1456 device_id_to_connection_map_[device_id] = std::move(connection);
1448 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time); 1457 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time);
1449 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS); 1458 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS);
1459 RenderFrameHostImpl* render_frame_host =
1460 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id);
1461 WebContents* web_contents =
1462 WebContents::FromRenderFrameHost(render_frame_host);
1463 if (web_contents) {
1464 web_contents->SetBluetoothDeviceConnected(true);
1465 }
1450 Send(new BluetoothMsg_GATTServerConnectSuccess(thread_id, request_id)); 1466 Send(new BluetoothMsg_GATTServerConnectSuccess(thread_id, request_id));
1451 } 1467 }
1452 1468
1453 void BluetoothDispatcherHost::OnCreateGATTConnectionError( 1469 void BluetoothDispatcherHost::OnCreateGATTConnectionError(
1454 int thread_id, 1470 int thread_id,
1455 int request_id, 1471 int request_id,
1456 const std::string& device_id, 1472 const std::string& device_id,
1457 base::TimeTicks start_time, 1473 base::TimeTicks start_time,
1458 device::BluetoothDevice::ConnectErrorCode error_code) { 1474 device::BluetoothDevice::ConnectErrorCode error_code) {
1459 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1475 DCHECK_CURRENTLY_ON(BrowserThread::UI);
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 1680
1665 bool BluetoothDispatcherHost::CanFrameAccessCharacteristicInstance( 1681 bool BluetoothDispatcherHost::CanFrameAccessCharacteristicInstance(
1666 int frame_routing_id, 1682 int frame_routing_id,
1667 const std::string& characteristic_instance_id) { 1683 const std::string& characteristic_instance_id) {
1668 return QueryCacheForCharacteristic(GetOrigin(frame_routing_id), 1684 return QueryCacheForCharacteristic(GetOrigin(frame_routing_id),
1669 characteristic_instance_id) 1685 characteristic_instance_id)
1670 .outcome != CacheQueryOutcome::BAD_RENDERER; 1686 .outcome != CacheQueryOutcome::BAD_RENDERER;
1671 } 1687 }
1672 1688
1673 } // namespace content 1689 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/bluetooth/bluetooth_dispatcher_host.h ('k') | content/browser/web_contents/web_contents_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698