| OLD | NEW |
| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 case BluetoothGattService::GATT_ERROR_NOT_SUPPORTED: | 201 case BluetoothGattService::GATT_ERROR_NOT_SUPPORTED: |
| 202 RecordGATTOperationOutcome(operation, | 202 RecordGATTOperationOutcome(operation, |
| 203 UMAGATTOperationOutcome::NOT_SUPPORTED); | 203 UMAGATTOperationOutcome::NOT_SUPPORTED); |
| 204 return blink::WebBluetoothError::GATT_NOT_SUPPORTED; | 204 return blink::WebBluetoothError::GATT_NOT_SUPPORTED; |
| 205 } | 205 } |
| 206 NOTREACHED(); | 206 NOTREACHED(); |
| 207 return blink::WebBluetoothError::GATT_UNTRANSLATED_ERROR_CODE; | 207 return blink::WebBluetoothError::GATT_UNTRANSLATED_ERROR_CODE; |
| 208 } | 208 } |
| 209 | 209 |
| 210 void StopDiscoverySession( | 210 void StopDiscoverySession( |
| 211 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { | 211 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session) { |
| 212 // Nothing goes wrong if the discovery session fails to stop, and we don't | 212 // Nothing goes wrong if the discovery session fails to stop, and we don't |
| 213 // need to wait for it before letting the user's script proceed, so we ignore | 213 // need to wait for it before letting the user's script proceed, so we ignore |
| 214 // the results here. | 214 // the results here. |
| 215 discovery_session->Stop(base::Bind(&base::DoNothing), | 215 discovery_session->Stop(base::Bind(&base::DoNothing), |
| 216 base::Bind(&base::DoNothing)); | 216 base::Bind(&base::DoNothing)); |
| 217 } | 217 } |
| 218 | 218 |
| 219 // TODO(ortuno): This should really be a BluetoothDevice method. | 219 // TODO(ortuno): This should really be a BluetoothDevice method. |
| 220 // Replace when implemented. http://crbug.com/552022 | 220 // Replace when implemented. http://crbug.com/552022 |
| 221 std::vector<BluetoothGattService*> GetPrimaryServicesByUUID( | 221 std::vector<BluetoothGattService*> GetPrimaryServicesByUUID( |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 origin(origin), | 378 origin(origin), |
| 379 filters(filters), | 379 filters(filters), |
| 380 optional_services(optional_services) {} | 380 optional_services(optional_services) {} |
| 381 | 381 |
| 382 void AddFilteredDevice(const device::BluetoothDevice& device) { | 382 void AddFilteredDevice(const device::BluetoothDevice& device) { |
| 383 if (chooser && MatchesFilters(device, filters)) { | 383 if (chooser && MatchesFilters(device, filters)) { |
| 384 chooser->AddDevice(device.GetAddress(), device.GetName()); | 384 chooser->AddDevice(device.GetAddress(), device.GetName()); |
| 385 } | 385 } |
| 386 } | 386 } |
| 387 | 387 |
| 388 scoped_ptr<device::BluetoothDiscoveryFilter> ComputeScanFilter() const { | 388 std::unique_ptr<device::BluetoothDiscoveryFilter> ComputeScanFilter() const { |
| 389 std::set<BluetoothUUID> services; | 389 std::set<BluetoothUUID> services; |
| 390 for (const BluetoothScanFilter& filter : filters) { | 390 for (const BluetoothScanFilter& filter : filters) { |
| 391 services.insert(filter.services.begin(), filter.services.end()); | 391 services.insert(filter.services.begin(), filter.services.end()); |
| 392 } | 392 } |
| 393 scoped_ptr<device::BluetoothDiscoveryFilter> discovery_filter( | 393 std::unique_ptr<device::BluetoothDiscoveryFilter> discovery_filter( |
| 394 new device::BluetoothDiscoveryFilter( | 394 new device::BluetoothDiscoveryFilter( |
| 395 device::BluetoothDiscoveryFilter::TRANSPORT_DUAL)); | 395 device::BluetoothDiscoveryFilter::TRANSPORT_DUAL)); |
| 396 for (const BluetoothUUID& service : services) { | 396 for (const BluetoothUUID& service : services) { |
| 397 discovery_filter->AddUUID(service); | 397 discovery_filter->AddUUID(service); |
| 398 } | 398 } |
| 399 return discovery_filter; | 399 return discovery_filter; |
| 400 } | 400 } |
| 401 | 401 |
| 402 const int thread_id; | 402 const int thread_id; |
| 403 const int request_id; | 403 const int request_id; |
| 404 const int frame_routing_id; | 404 const int frame_routing_id; |
| 405 const url::Origin origin; | 405 const url::Origin origin; |
| 406 const std::vector<BluetoothScanFilter> filters; | 406 const std::vector<BluetoothScanFilter> filters; |
| 407 const std::vector<BluetoothUUID> optional_services; | 407 const std::vector<BluetoothUUID> optional_services; |
| 408 scoped_ptr<BluetoothChooser> chooser; | 408 std::unique_ptr<BluetoothChooser> chooser; |
| 409 scoped_ptr<device::BluetoothDiscoverySession> discovery_session; | 409 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session; |
| 410 }; | 410 }; |
| 411 | 411 |
| 412 BluetoothDispatcherHost::CacheQueryResult::CacheQueryResult() {} | 412 BluetoothDispatcherHost::CacheQueryResult::CacheQueryResult() {} |
| 413 | 413 |
| 414 BluetoothDispatcherHost::CacheQueryResult::CacheQueryResult( | 414 BluetoothDispatcherHost::CacheQueryResult::CacheQueryResult( |
| 415 CacheQueryOutcome outcome) | 415 CacheQueryOutcome outcome) |
| 416 : outcome(outcome) {} | 416 : outcome(outcome) {} |
| 417 | 417 |
| 418 BluetoothDispatcherHost::CacheQueryResult::~CacheQueryResult() {} | 418 BluetoothDispatcherHost::CacheQueryResult::~CacheQueryResult() {} |
| 419 | 419 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 auto connection_iter = device_id_to_connection_map_.find(device_id); | 469 auto connection_iter = device_id_to_connection_map_.find(device_id); |
| 470 if (connection_iter != device_id_to_connection_map_.end()) { | 470 if (connection_iter != device_id_to_connection_map_.end()) { |
| 471 return connection_iter->second->IsConnected(); | 471 return connection_iter->second->IsConnected(); |
| 472 } | 472 } |
| 473 return false; | 473 return false; |
| 474 } | 474 } |
| 475 | 475 |
| 476 void BluetoothDispatcherHost::ConnectedDevicesMap::InsertOrReplace( | 476 void BluetoothDispatcherHost::ConnectedDevicesMap::InsertOrReplace( |
| 477 int frame_routing_id, | 477 int frame_routing_id, |
| 478 const std::string& device_id, | 478 const std::string& device_id, |
| 479 scoped_ptr<device::BluetoothGattConnection> connection) { | 479 std::unique_ptr<device::BluetoothGattConnection> connection) { |
| 480 auto connection_iter = device_id_to_connection_map_.find(device_id); | 480 auto connection_iter = device_id_to_connection_map_.find(device_id); |
| 481 if (connection_iter == device_id_to_connection_map_.end()) { | 481 if (connection_iter == device_id_to_connection_map_.end()) { |
| 482 IncrementBluetoothConnectedDeviceCount(frame_routing_id); | 482 IncrementBluetoothConnectedDeviceCount(frame_routing_id); |
| 483 frame_ids_device_ids_.insert(std::make_pair(frame_routing_id, device_id)); | 483 frame_ids_device_ids_.insert(std::make_pair(frame_routing_id, device_id)); |
| 484 } else { | 484 } else { |
| 485 device_id_to_connection_map_.erase(connection_iter); | 485 device_id_to_connection_map_.erase(connection_iter); |
| 486 } | 486 } |
| 487 device_id_to_connection_map_[device_id] = std::move(connection); | 487 device_id_to_connection_map_[device_id] = std::move(connection); |
| 488 } | 488 } |
| 489 | 489 |
| (...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1303 session->chooser->SetAdapterPresence( | 1303 session->chooser->SetAdapterPresence( |
| 1304 BluetoothChooser::AdapterPresence::POWERED_OFF); | 1304 BluetoothChooser::AdapterPresence::POWERED_OFF); |
| 1305 return; | 1305 return; |
| 1306 } | 1306 } |
| 1307 | 1307 |
| 1308 StartDeviceDiscovery(session, chooser_id); | 1308 StartDeviceDiscovery(session, chooser_id); |
| 1309 } | 1309 } |
| 1310 | 1310 |
| 1311 void BluetoothDispatcherHost::OnDiscoverySessionStarted( | 1311 void BluetoothDispatcherHost::OnDiscoverySessionStarted( |
| 1312 int chooser_id, | 1312 int chooser_id, |
| 1313 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { | 1313 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session) { |
| 1314 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1314 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1315 VLOG(1) << "Started discovery session for " << chooser_id; | 1315 VLOG(1) << "Started discovery session for " << chooser_id; |
| 1316 if (RequestDeviceSession* session = | 1316 if (RequestDeviceSession* session = |
| 1317 request_device_sessions_.Lookup(chooser_id)) { | 1317 request_device_sessions_.Lookup(chooser_id)) { |
| 1318 session->discovery_session = std::move(discovery_session); | 1318 session->discovery_session = std::move(discovery_session); |
| 1319 | 1319 |
| 1320 // Arrange to stop discovery later. | 1320 // Arrange to stop discovery later. |
| 1321 discovery_session_timer_.Reset(); | 1321 discovery_session_timer_.Reset(); |
| 1322 } else { | 1322 } else { |
| 1323 VLOG(1) << "Chooser " << chooser_id | 1323 VLOG(1) << "Chooser " << chooser_id |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1465 session->request_id, device_ipc)); | 1465 session->request_id, device_ipc)); |
| 1466 request_device_sessions_.Remove(chooser_id); | 1466 request_device_sessions_.Remove(chooser_id); |
| 1467 } | 1467 } |
| 1468 | 1468 |
| 1469 void BluetoothDispatcherHost::OnGATTConnectionCreated( | 1469 void BluetoothDispatcherHost::OnGATTConnectionCreated( |
| 1470 int thread_id, | 1470 int thread_id, |
| 1471 int request_id, | 1471 int request_id, |
| 1472 int frame_routing_id, | 1472 int frame_routing_id, |
| 1473 const std::string& device_id, | 1473 const std::string& device_id, |
| 1474 base::TimeTicks start_time, | 1474 base::TimeTicks start_time, |
| 1475 scoped_ptr<device::BluetoothGattConnection> connection) { | 1475 std::unique_ptr<device::BluetoothGattConnection> connection) { |
| 1476 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1476 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1477 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time); | 1477 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time); |
| 1478 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS); | 1478 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS); |
| 1479 connected_devices_map_->InsertOrReplace(frame_routing_id, device_id, | 1479 connected_devices_map_->InsertOrReplace(frame_routing_id, device_id, |
| 1480 std::move(connection)); | 1480 std::move(connection)); |
| 1481 Send(new BluetoothMsg_GATTServerConnectSuccess(thread_id, request_id)); | 1481 Send(new BluetoothMsg_GATTServerConnectSuccess(thread_id, request_id)); |
| 1482 } | 1482 } |
| 1483 | 1483 |
| 1484 void BluetoothDispatcherHost::OnCreateGATTConnectionError( | 1484 void BluetoothDispatcherHost::OnCreateGATTConnectionError( |
| 1485 int thread_id, | 1485 int thread_id, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1532 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1532 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1533 // TranslateGATTError calls RecordGATTOperationOutcome. | 1533 // TranslateGATTError calls RecordGATTOperationOutcome. |
| 1534 Send(new BluetoothMsg_ReadCharacteristicValueError( | 1534 Send(new BluetoothMsg_ReadCharacteristicValueError( |
| 1535 thread_id, request_id, | 1535 thread_id, request_id, |
| 1536 TranslateGATTError(error_code, UMAGATTOperation::CHARACTERISTIC_READ))); | 1536 TranslateGATTError(error_code, UMAGATTOperation::CHARACTERISTIC_READ))); |
| 1537 } | 1537 } |
| 1538 | 1538 |
| 1539 void BluetoothDispatcherHost::OnStartNotifySessionSuccess( | 1539 void BluetoothDispatcherHost::OnStartNotifySessionSuccess( |
| 1540 int thread_id, | 1540 int thread_id, |
| 1541 int request_id, | 1541 int request_id, |
| 1542 scoped_ptr<device::BluetoothGattNotifySession> notify_session) { | 1542 std::unique_ptr<device::BluetoothGattNotifySession> notify_session) { |
| 1543 RecordStartNotificationsOutcome(UMAGATTOperationOutcome::SUCCESS); | 1543 RecordStartNotificationsOutcome(UMAGATTOperationOutcome::SUCCESS); |
| 1544 | 1544 |
| 1545 // Copy Characteristic Instance ID before passing scoped pointer because | 1545 // Copy Characteristic Instance ID before passing scoped pointer because |
| 1546 // compilers may evaluate arguments in any order. | 1546 // compilers may evaluate arguments in any order. |
| 1547 const std::string characteristic_instance_id = | 1547 const std::string characteristic_instance_id = |
| 1548 notify_session->GetCharacteristicIdentifier(); | 1548 notify_session->GetCharacteristicIdentifier(); |
| 1549 characteristic_id_to_notify_session_.insert( | 1549 characteristic_id_to_notify_session_.insert( |
| 1550 std::make_pair(characteristic_instance_id, std::move(notify_session))); | 1550 std::make_pair(characteristic_instance_id, std::move(notify_session))); |
| 1551 | 1551 |
| 1552 Send(new BluetoothMsg_StartNotificationsSuccess(thread_id, request_id)); | 1552 Send(new BluetoothMsg_StartNotificationsSuccess(thread_id, request_id)); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1677 | 1677 |
| 1678 bool BluetoothDispatcherHost::CanFrameAccessCharacteristicInstance( | 1678 bool BluetoothDispatcherHost::CanFrameAccessCharacteristicInstance( |
| 1679 int frame_routing_id, | 1679 int frame_routing_id, |
| 1680 const std::string& characteristic_instance_id) { | 1680 const std::string& characteristic_instance_id) { |
| 1681 return QueryCacheForCharacteristic(GetOrigin(frame_routing_id), | 1681 return QueryCacheForCharacteristic(GetOrigin(frame_routing_id), |
| 1682 characteristic_instance_id) | 1682 characteristic_instance_id) |
| 1683 .outcome != CacheQueryOutcome::BAD_RENDERER; | 1683 .outcome != CacheQueryOutcome::BAD_RENDERER; |
| 1684 } | 1684 } |
| 1685 | 1685 |
| 1686 } // namespace content | 1686 } // namespace content |
| OLD | NEW |