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

Side by Side Diff: extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc

Issue 2370373002: Move chrome.bluetoothLowEnergy out of //chrome. (Closed)
Patch Set: build fix Created 4 years, 2 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 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_event_router.h" 5 #include "extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_event _router.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/containers/hash_tables.h" 13 #include "base/containers/hash_tables.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_connection.h"
19 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_notify_session.h"
20 #include "chrome/browser/extensions/api/bluetooth_low_energy/utils.h"
21 #include "content/public/browser/browser_context.h" 18 #include "content/public/browser/browser_context.h"
22 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
23 #include "device/bluetooth/bluetooth_adapter_factory.h" 20 #include "device/bluetooth/bluetooth_adapter_factory.h"
24 #include "device/bluetooth/bluetooth_gatt_characteristic.h" 21 #include "device/bluetooth/bluetooth_gatt_characteristic.h"
25 #include "device/bluetooth/bluetooth_gatt_service.h" 22 #include "device/bluetooth/bluetooth_gatt_service.h"
26 #include "device/bluetooth/bluetooth_local_gatt_characteristic.h" 23 #include "device/bluetooth/bluetooth_local_gatt_characteristic.h"
27 #include "device/bluetooth/bluetooth_local_gatt_descriptor.h" 24 #include "device/bluetooth/bluetooth_local_gatt_descriptor.h"
28 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" 25 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
29 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h" 26 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h"
30 #include "extensions/browser/api/api_resource_manager.h" 27 #include "extensions/browser/api/api_resource_manager.h"
28 #include "extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_conne ction.h"
29 #include "extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_notif y_session.h"
30 #include "extensions/browser/api/bluetooth_low_energy/utils.h"
31 #include "extensions/browser/event_listener_map.h" 31 #include "extensions/browser/event_listener_map.h"
32 #include "extensions/browser/event_router.h" 32 #include "extensions/browser/event_router.h"
33 #include "extensions/browser/extension_registry.h" 33 #include "extensions/browser/extension_registry.h"
34 #include "extensions/common/api/bluetooth/bluetooth_manifest_data.h" 34 #include "extensions/common/api/bluetooth/bluetooth_manifest_data.h"
35 #include "extensions/common/extension.h" 35 #include "extensions/common/extension.h"
36 36
37 using content::BrowserThread; 37 using content::BrowserThread;
38 38
39 using device::BluetoothAdapter; 39 using device::BluetoothAdapter;
40 using device::BluetoothAdapterFactory; 40 using device::BluetoothAdapterFactory;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 ConnectionResourceManager* manager = ConnectionResourceManager::Get(context); 160 ConnectionResourceManager* manager = ConnectionResourceManager::Get(context);
161 DCHECK(manager) 161 DCHECK(manager)
162 << "There is no Bluetooth low energy connection manager. " 162 << "There is no Bluetooth low energy connection manager. "
163 "If this assertion is failing during a test, then it is likely that " 163 "If this assertion is failing during a test, then it is likely that "
164 "TestExtensionSystem is failing to provide an instance of " 164 "TestExtensionSystem is failing to provide an instance of "
165 "ApiResourceManager<BluetoothLowEnergyConnection>."; 165 "ApiResourceManager<BluetoothLowEnergyConnection>.";
166 return manager; 166 return manager;
167 } 167 }
168 168
169 typedef extensions::ApiResourceManager< 169 typedef extensions::ApiResourceManager<
170 extensions::BluetoothLowEnergyNotifySession> NotifySessionResourceManager; 170 extensions::BluetoothLowEnergyNotifySession>
171 NotifySessionResourceManager;
171 NotifySessionResourceManager* GetNotifySessionResourceManager( 172 NotifySessionResourceManager* GetNotifySessionResourceManager(
172 content::BrowserContext* context) { 173 content::BrowserContext* context) {
173 NotifySessionResourceManager* manager = 174 NotifySessionResourceManager* manager =
174 NotifySessionResourceManager::Get(context); 175 NotifySessionResourceManager::Get(context);
175 DCHECK(manager) 176 DCHECK(manager)
176 << "There is no Bluetooth low energy value update session manager." 177 << "There is no Bluetooth low energy value update session manager."
177 "If this assertion is failing during a test, then it is likely that " 178 "If this assertion is failing during a test, then it is likely that "
178 "TestExtensionSystem is failing to provide an instance of " 179 "TestExtensionSystem is failing to provide an instance of "
179 "ApiResourceManager<BluetoothLowEnergyNotifySession>."; 180 "ApiResourceManager<BluetoothLowEnergyNotifySession>.";
180 return manager; 181 return manager;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 if (!IsBluetoothSupported()) 287 if (!IsBluetoothSupported())
287 return false; 288 return false;
288 289
289 if (adapter_.get()) { 290 if (adapter_.get()) {
290 callback.Run(); 291 callback.Run();
291 return true; 292 return true;
292 } 293 }
293 294
294 BluetoothAdapterFactory::GetAdapter( 295 BluetoothAdapterFactory::GetAdapter(
295 base::Bind(&BluetoothLowEnergyEventRouter::OnGetAdapter, 296 base::Bind(&BluetoothLowEnergyEventRouter::OnGetAdapter,
296 weak_ptr_factory_.GetWeakPtr(), 297 weak_ptr_factory_.GetWeakPtr(), callback));
297 callback));
298 return true; 298 return true;
299 } 299 }
300 300
301 bool BluetoothLowEnergyEventRouter::HasAdapter() const { 301 bool BluetoothLowEnergyEventRouter::HasAdapter() const {
302 return (adapter_.get() != NULL); 302 return (adapter_.get() != NULL);
303 } 303 }
304 304
305 void BluetoothLowEnergyEventRouter::Connect( 305 void BluetoothLowEnergyEventRouter::Connect(
306 bool persistent, 306 bool persistent,
307 const Extension* extension, 307 const Extension* extension,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 BluetoothDevice* device = adapter_->GetDevice(device_address); 339 BluetoothDevice* device = adapter_->GetDevice(device_address);
340 if (!device) { 340 if (!device) {
341 VLOG(1) << "Bluetooth device not found: " << device_address; 341 VLOG(1) << "Bluetooth device not found: " << device_address;
342 error_callback.Run(kStatusErrorNotFound); 342 error_callback.Run(kStatusErrorNotFound);
343 return; 343 return;
344 } 344 }
345 345
346 connecting_devices_.insert(connect_id); 346 connecting_devices_.insert(connect_id);
347 device->CreateGattConnection( 347 device->CreateGattConnection(
348 base::Bind(&BluetoothLowEnergyEventRouter::OnCreateGattConnection, 348 base::Bind(&BluetoothLowEnergyEventRouter::OnCreateGattConnection,
349 weak_ptr_factory_.GetWeakPtr(), 349 weak_ptr_factory_.GetWeakPtr(), persistent, extension_id,
350 persistent, 350 device_address, callback),
351 extension_id,
352 device_address,
353 callback),
354 base::Bind(&BluetoothLowEnergyEventRouter::OnConnectError, 351 base::Bind(&BluetoothLowEnergyEventRouter::OnConnectError,
355 weak_ptr_factory_.GetWeakPtr(), 352 weak_ptr_factory_.GetWeakPtr(), extension_id, device_address,
356 extension_id,
357 device_address,
358 error_callback)); 353 error_callback));
359 } 354 }
360 355
361 void BluetoothLowEnergyEventRouter::Disconnect( 356 void BluetoothLowEnergyEventRouter::Disconnect(
362 const Extension* extension, 357 const Extension* extension,
363 const std::string& device_address, 358 const std::string& device_address,
364 const base::Closure& callback, 359 const base::Closure& callback,
365 const ErrorCallback& error_callback) { 360 const ErrorCallback& error_callback) {
366 DCHECK_CURRENTLY_ON(BrowserThread::UI); 361 DCHECK_CURRENTLY_ON(BrowserThread::UI);
367 if (!adapter_.get()) { 362 if (!adapter_.get()) {
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 characteristic->GetService()->GetUUID().value()); 632 characteristic->GetService()->GetUUID().value());
638 if (!BluetoothManifestData::CheckRequest(extension, request)) { 633 if (!BluetoothManifestData::CheckRequest(extension, request)) {
639 VLOG(1) << "App has no permission to access this characteristic: " 634 VLOG(1) << "App has no permission to access this characteristic: "
640 << instance_id; 635 << instance_id;
641 error_callback.Run(kStatusErrorPermissionDenied); 636 error_callback.Run(kStatusErrorPermissionDenied);
642 return; 637 return;
643 } 638 }
644 639
645 characteristic->ReadRemoteCharacteristic( 640 characteristic->ReadRemoteCharacteristic(
646 base::Bind(&BluetoothLowEnergyEventRouter::OnValueSuccess, 641 base::Bind(&BluetoothLowEnergyEventRouter::OnValueSuccess,
647 weak_ptr_factory_.GetWeakPtr(), 642 weak_ptr_factory_.GetWeakPtr(), callback),
648 callback),
649 base::Bind(&BluetoothLowEnergyEventRouter::OnError, 643 base::Bind(&BluetoothLowEnergyEventRouter::OnError,
650 weak_ptr_factory_.GetWeakPtr(), 644 weak_ptr_factory_.GetWeakPtr(), error_callback));
651 error_callback));
652 } 645 }
653 646
654 void BluetoothLowEnergyEventRouter::WriteCharacteristicValue( 647 void BluetoothLowEnergyEventRouter::WriteCharacteristicValue(
655 const Extension* extension, 648 const Extension* extension,
656 const std::string& instance_id, 649 const std::string& instance_id,
657 const std::vector<uint8_t>& value, 650 const std::vector<uint8_t>& value,
658 const base::Closure& callback, 651 const base::Closure& callback,
659 const ErrorCallback& error_callback) { 652 const ErrorCallback& error_callback) {
660 DCHECK_CURRENTLY_ON(BrowserThread::UI); 653 DCHECK_CURRENTLY_ON(BrowserThread::UI);
661 DCHECK(extension); 654 DCHECK(extension);
(...skipping 14 matching lines...) Expand all
676 BluetoothPermissionRequest request( 669 BluetoothPermissionRequest request(
677 characteristic->GetService()->GetUUID().value()); 670 characteristic->GetService()->GetUUID().value());
678 if (!BluetoothManifestData::CheckRequest(extension, request)) { 671 if (!BluetoothManifestData::CheckRequest(extension, request)) {
679 VLOG(1) << "App has no permission to access this characteristic: " 672 VLOG(1) << "App has no permission to access this characteristic: "
680 << instance_id; 673 << instance_id;
681 error_callback.Run(kStatusErrorPermissionDenied); 674 error_callback.Run(kStatusErrorPermissionDenied);
682 return; 675 return;
683 } 676 }
684 677
685 characteristic->WriteRemoteCharacteristic( 678 characteristic->WriteRemoteCharacteristic(
686 value, 679 value, callback,
687 callback,
688 base::Bind(&BluetoothLowEnergyEventRouter::OnError, 680 base::Bind(&BluetoothLowEnergyEventRouter::OnError,
689 weak_ptr_factory_.GetWeakPtr(), 681 weak_ptr_factory_.GetWeakPtr(), error_callback));
690 error_callback));
691 } 682 }
692 683
693 void BluetoothLowEnergyEventRouter::StartCharacteristicNotifications( 684 void BluetoothLowEnergyEventRouter::StartCharacteristicNotifications(
694 bool persistent, 685 bool persistent,
695 const Extension* extension, 686 const Extension* extension,
696 const std::string& instance_id, 687 const std::string& instance_id,
697 const base::Closure& callback, 688 const base::Closure& callback,
698 const ErrorCallback& error_callback) { 689 const ErrorCallback& error_callback) {
699 DCHECK_CURRENTLY_ON(BrowserThread::UI); 690 DCHECK_CURRENTLY_ON(BrowserThread::UI);
700 if (!adapter_.get()) { 691 if (!adapter_.get()) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 if (!BluetoothManifestData::CheckRequest(extension, request)) { 728 if (!BluetoothManifestData::CheckRequest(extension, request)) {
738 VLOG(1) << "App has no permission to access this characteristic: " 729 VLOG(1) << "App has no permission to access this characteristic: "
739 << instance_id; 730 << instance_id;
740 error_callback.Run(kStatusErrorPermissionDenied); 731 error_callback.Run(kStatusErrorPermissionDenied);
741 return; 732 return;
742 } 733 }
743 734
744 pending_session_calls_.insert(session_id); 735 pending_session_calls_.insert(session_id);
745 characteristic->StartNotifySession( 736 characteristic->StartNotifySession(
746 base::Bind(&BluetoothLowEnergyEventRouter::OnStartNotifySession, 737 base::Bind(&BluetoothLowEnergyEventRouter::OnStartNotifySession,
747 weak_ptr_factory_.GetWeakPtr(), 738 weak_ptr_factory_.GetWeakPtr(), persistent, extension_id,
748 persistent, 739 instance_id, callback),
749 extension_id,
750 instance_id,
751 callback),
752 base::Bind(&BluetoothLowEnergyEventRouter::OnStartNotifySessionError, 740 base::Bind(&BluetoothLowEnergyEventRouter::OnStartNotifySessionError,
753 weak_ptr_factory_.GetWeakPtr(), 741 weak_ptr_factory_.GetWeakPtr(), extension_id, instance_id,
754 extension_id,
755 instance_id,
756 error_callback)); 742 error_callback));
757 } 743 }
758 744
759 void BluetoothLowEnergyEventRouter::StopCharacteristicNotifications( 745 void BluetoothLowEnergyEventRouter::StopCharacteristicNotifications(
760 const Extension* extension, 746 const Extension* extension,
761 const std::string& instance_id, 747 const std::string& instance_id,
762 const base::Closure& callback, 748 const base::Closure& callback,
763 const ErrorCallback& error_callback) { 749 const ErrorCallback& error_callback) {
764 DCHECK_CURRENTLY_ON(BrowserThread::UI); 750 DCHECK_CURRENTLY_ON(BrowserThread::UI);
765 if (!adapter_.get()) { 751 if (!adapter_.get()) {
766 VLOG(1) << "BluetoothAdapter not ready."; 752 VLOG(1) << "BluetoothAdapter not ready.";
767 error_callback.Run(kStatusErrorFailed); 753 error_callback.Run(kStatusErrorFailed);
768 return; 754 return;
769 } 755 }
770 756
771 const std::string extension_id = extension->id(); 757 const std::string extension_id = extension->id();
772 758
773 BluetoothLowEnergyNotifySession* session = 759 BluetoothLowEnergyNotifySession* session =
774 FindNotifySession(extension_id, instance_id); 760 FindNotifySession(extension_id, instance_id);
775 if (!session || !session->GetSession()->IsActive()) { 761 if (!session || !session->GetSession()->IsActive()) {
776 VLOG(1) << "Application has not enabled notifications from " 762 VLOG(1) << "Application has not enabled notifications from "
777 << "characteristic: " << instance_id; 763 << "characteristic: " << instance_id;
778 error_callback.Run(kStatusErrorNotNotifying); 764 error_callback.Run(kStatusErrorNotNotifying);
779 return; 765 return;
780 } 766 }
781 767
782 session->GetSession()->Stop( 768 session->GetSession()->Stop(base::Bind(
783 base::Bind(&BluetoothLowEnergyEventRouter::OnStopNotifySession, 769 &BluetoothLowEnergyEventRouter::OnStopNotifySession,
784 weak_ptr_factory_.GetWeakPtr(), 770 weak_ptr_factory_.GetWeakPtr(), extension_id, instance_id, callback));
785 extension_id,
786 instance_id,
787 callback));
788 } 771 }
789 772
790 void BluetoothLowEnergyEventRouter::ReadDescriptorValue( 773 void BluetoothLowEnergyEventRouter::ReadDescriptorValue(
791 const Extension* extension, 774 const Extension* extension,
792 const std::string& instance_id, 775 const std::string& instance_id,
793 const base::Closure& callback, 776 const base::Closure& callback,
794 const ErrorCallback& error_callback) { 777 const ErrorCallback& error_callback) {
795 DCHECK_CURRENTLY_ON(BrowserThread::UI); 778 DCHECK_CURRENTLY_ON(BrowserThread::UI);
796 DCHECK(extension); 779 DCHECK(extension);
797 if (!adapter_.get()) { 780 if (!adapter_.get()) {
(...skipping 13 matching lines...) Expand all
811 descriptor->GetCharacteristic()->GetService()->GetUUID().value()); 794 descriptor->GetCharacteristic()->GetService()->GetUUID().value());
812 if (!BluetoothManifestData::CheckRequest(extension, request)) { 795 if (!BluetoothManifestData::CheckRequest(extension, request)) {
813 VLOG(1) << "App has no permission to access this descriptor: " 796 VLOG(1) << "App has no permission to access this descriptor: "
814 << instance_id; 797 << instance_id;
815 error_callback.Run(kStatusErrorPermissionDenied); 798 error_callback.Run(kStatusErrorPermissionDenied);
816 return; 799 return;
817 } 800 }
818 801
819 descriptor->ReadRemoteDescriptor( 802 descriptor->ReadRemoteDescriptor(
820 base::Bind(&BluetoothLowEnergyEventRouter::OnValueSuccess, 803 base::Bind(&BluetoothLowEnergyEventRouter::OnValueSuccess,
821 weak_ptr_factory_.GetWeakPtr(), 804 weak_ptr_factory_.GetWeakPtr(), callback),
822 callback),
823 base::Bind(&BluetoothLowEnergyEventRouter::OnError, 805 base::Bind(&BluetoothLowEnergyEventRouter::OnError,
824 weak_ptr_factory_.GetWeakPtr(), 806 weak_ptr_factory_.GetWeakPtr(), error_callback));
825 error_callback));
826 } 807 }
827 808
828 void BluetoothLowEnergyEventRouter::WriteDescriptorValue( 809 void BluetoothLowEnergyEventRouter::WriteDescriptorValue(
829 const Extension* extension, 810 const Extension* extension,
830 const std::string& instance_id, 811 const std::string& instance_id,
831 const std::vector<uint8_t>& value, 812 const std::vector<uint8_t>& value,
832 const base::Closure& callback, 813 const base::Closure& callback,
833 const ErrorCallback& error_callback) { 814 const ErrorCallback& error_callback) {
834 DCHECK_CURRENTLY_ON(BrowserThread::UI); 815 DCHECK_CURRENTLY_ON(BrowserThread::UI);
835 DCHECK(extension); 816 DCHECK(extension);
(...skipping 13 matching lines...) Expand all
849 BluetoothPermissionRequest request( 830 BluetoothPermissionRequest request(
850 descriptor->GetCharacteristic()->GetService()->GetUUID().value()); 831 descriptor->GetCharacteristic()->GetService()->GetUUID().value());
851 if (!BluetoothManifestData::CheckRequest(extension, request)) { 832 if (!BluetoothManifestData::CheckRequest(extension, request)) {
852 VLOG(1) << "App has no permission to access this descriptor: " 833 VLOG(1) << "App has no permission to access this descriptor: "
853 << instance_id; 834 << instance_id;
854 error_callback.Run(kStatusErrorPermissionDenied); 835 error_callback.Run(kStatusErrorPermissionDenied);
855 return; 836 return;
856 } 837 }
857 838
858 descriptor->WriteRemoteDescriptor( 839 descriptor->WriteRemoteDescriptor(
859 value, 840 value, callback,
860 callback,
861 base::Bind(&BluetoothLowEnergyEventRouter::OnError, 841 base::Bind(&BluetoothLowEnergyEventRouter::OnError,
862 weak_ptr_factory_.GetWeakPtr(), 842 weak_ptr_factory_.GetWeakPtr(), error_callback));
863 error_callback));
864 } 843 }
865 844
866 void BluetoothLowEnergyEventRouter::SetAdapterForTesting( 845 void BluetoothLowEnergyEventRouter::SetAdapterForTesting(
867 device::BluetoothAdapter* adapter) { 846 device::BluetoothAdapter* adapter) {
868 adapter_ = adapter; 847 adapter_ = adapter;
869 InitializeIdentifierMappings(); 848 InitializeIdentifierMappings();
870 } 849 }
871 850
872 void BluetoothLowEnergyEventRouter::GattServiceAdded( 851 void BluetoothLowEnergyEventRouter::GattServiceAdded(
873 BluetoothAdapter* adapter, 852 BluetoothAdapter* adapter,
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 } 1393 }
1415 1394
1416 void BluetoothLowEnergyEventRouter::InitializeIdentifierMappings() { 1395 void BluetoothLowEnergyEventRouter::InitializeIdentifierMappings() {
1417 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1396 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1418 DCHECK(service_id_to_device_address_.empty()); 1397 DCHECK(service_id_to_device_address_.empty());
1419 DCHECK(chrc_id_to_service_id_.empty()); 1398 DCHECK(chrc_id_to_service_id_.empty());
1420 1399
1421 // Devices 1400 // Devices
1422 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 1401 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
1423 for (BluetoothAdapter::DeviceList::iterator iter = devices.begin(); 1402 for (BluetoothAdapter::DeviceList::iterator iter = devices.begin();
1424 iter != devices.end(); 1403 iter != devices.end(); ++iter) {
1425 ++iter) {
1426 BluetoothDevice* device = *iter; 1404 BluetoothDevice* device = *iter;
1427 1405
1428 // Services 1406 // Services
1429 std::vector<BluetoothRemoteGattService*> services = 1407 std::vector<BluetoothRemoteGattService*> services =
1430 device->GetGattServices(); 1408 device->GetGattServices();
1431 for (std::vector<BluetoothRemoteGattService*>::iterator siter = 1409 for (std::vector<BluetoothRemoteGattService*>::iterator siter =
1432 services.begin(); 1410 services.begin();
1433 siter != services.end(); ++siter) { 1411 siter != services.end(); ++siter) {
1434 BluetoothRemoteGattService* service = *siter; 1412 BluetoothRemoteGattService* service = *siter;
1435 1413
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
1806 const std::string& extension_id, 1784 const std::string& extension_id,
1807 const std::string& device_address) { 1785 const std::string& device_address) {
1808 ConnectionResourceManager* manager = 1786 ConnectionResourceManager* manager =
1809 GetConnectionResourceManager(browser_context_); 1787 GetConnectionResourceManager(browser_context_);
1810 1788
1811 base::hash_set<int>* connection_ids = manager->GetResourceIds(extension_id); 1789 base::hash_set<int>* connection_ids = manager->GetResourceIds(extension_id);
1812 if (!connection_ids) 1790 if (!connection_ids)
1813 return NULL; 1791 return NULL;
1814 1792
1815 for (base::hash_set<int>::const_iterator iter = connection_ids->begin(); 1793 for (base::hash_set<int>::const_iterator iter = connection_ids->begin();
1816 iter != connection_ids->end(); 1794 iter != connection_ids->end(); ++iter) {
1817 ++iter) {
1818 extensions::BluetoothLowEnergyConnection* conn = 1795 extensions::BluetoothLowEnergyConnection* conn =
1819 manager->Get(extension_id, *iter); 1796 manager->Get(extension_id, *iter);
1820 if (!conn) 1797 if (!conn)
1821 continue; 1798 continue;
1822 1799
1823 if (conn->GetConnection()->GetDeviceAddress() == device_address) 1800 if (conn->GetConnection()->GetDeviceAddress() == device_address)
1824 return conn; 1801 return conn;
1825 } 1802 }
1826 1803
1827 return NULL; 1804 return NULL;
1828 } 1805 }
1829 1806
1830 bool BluetoothLowEnergyEventRouter::RemoveConnection( 1807 bool BluetoothLowEnergyEventRouter::RemoveConnection(
1831 const std::string& extension_id, 1808 const std::string& extension_id,
1832 const std::string& device_address) { 1809 const std::string& device_address) {
1833 ConnectionResourceManager* manager = 1810 ConnectionResourceManager* manager =
1834 GetConnectionResourceManager(browser_context_); 1811 GetConnectionResourceManager(browser_context_);
1835 1812
1836 base::hash_set<int>* connection_ids = manager->GetResourceIds(extension_id); 1813 base::hash_set<int>* connection_ids = manager->GetResourceIds(extension_id);
1837 if (!connection_ids) 1814 if (!connection_ids)
1838 return false; 1815 return false;
1839 1816
1840 for (base::hash_set<int>::const_iterator iter = connection_ids->begin(); 1817 for (base::hash_set<int>::const_iterator iter = connection_ids->begin();
1841 iter != connection_ids->end(); 1818 iter != connection_ids->end(); ++iter) {
1842 ++iter) {
1843 extensions::BluetoothLowEnergyConnection* conn = 1819 extensions::BluetoothLowEnergyConnection* conn =
1844 manager->Get(extension_id, *iter); 1820 manager->Get(extension_id, *iter);
1845 if (!conn || conn->GetConnection()->GetDeviceAddress() != device_address) 1821 if (!conn || conn->GetConnection()->GetDeviceAddress() != device_address)
1846 continue; 1822 continue;
1847 1823
1848 manager->Remove(extension_id, *iter); 1824 manager->Remove(extension_id, *iter);
1849 return true; 1825 return true;
1850 } 1826 }
1851 1827
1852 return false; 1828 return false;
1853 } 1829 }
1854 1830
1855 BluetoothLowEnergyNotifySession* 1831 BluetoothLowEnergyNotifySession*
1856 BluetoothLowEnergyEventRouter::FindNotifySession( 1832 BluetoothLowEnergyEventRouter::FindNotifySession(
1857 const std::string& extension_id, 1833 const std::string& extension_id,
1858 const std::string& characteristic_id) { 1834 const std::string& characteristic_id) {
1859 NotifySessionResourceManager* manager = 1835 NotifySessionResourceManager* manager =
1860 GetNotifySessionResourceManager(browser_context_); 1836 GetNotifySessionResourceManager(browser_context_);
1861 1837
1862 base::hash_set<int>* ids = manager->GetResourceIds(extension_id); 1838 base::hash_set<int>* ids = manager->GetResourceIds(extension_id);
1863 if (!ids) 1839 if (!ids)
1864 return NULL; 1840 return NULL;
1865 1841
1866 for (base::hash_set<int>::const_iterator iter = ids->begin(); 1842 for (base::hash_set<int>::const_iterator iter = ids->begin();
1867 iter != ids->end(); 1843 iter != ids->end(); ++iter) {
1868 ++iter) {
1869 BluetoothLowEnergyNotifySession* session = 1844 BluetoothLowEnergyNotifySession* session =
1870 manager->Get(extension_id, *iter); 1845 manager->Get(extension_id, *iter);
1871 if (!session) 1846 if (!session)
1872 continue; 1847 continue;
1873 1848
1874 if (session->GetSession()->GetCharacteristicIdentifier() == 1849 if (session->GetSession()->GetCharacteristicIdentifier() ==
1875 characteristic_id) 1850 characteristic_id)
1876 return session; 1851 return session;
1877 } 1852 }
1878 1853
1879 return NULL; 1854 return NULL;
1880 } 1855 }
1881 1856
1882 bool BluetoothLowEnergyEventRouter::RemoveNotifySession( 1857 bool BluetoothLowEnergyEventRouter::RemoveNotifySession(
1883 const std::string& extension_id, 1858 const std::string& extension_id,
1884 const std::string& characteristic_id) { 1859 const std::string& characteristic_id) {
1885 NotifySessionResourceManager* manager = 1860 NotifySessionResourceManager* manager =
1886 GetNotifySessionResourceManager(browser_context_); 1861 GetNotifySessionResourceManager(browser_context_);
1887 1862
1888 base::hash_set<int>* ids = manager->GetResourceIds(extension_id); 1863 base::hash_set<int>* ids = manager->GetResourceIds(extension_id);
1889 if (!ids) 1864 if (!ids)
1890 return false; 1865 return false;
1891 1866
1892 for (base::hash_set<int>::const_iterator iter = ids->begin(); 1867 for (base::hash_set<int>::const_iterator iter = ids->begin();
1893 iter != ids->end(); 1868 iter != ids->end(); ++iter) {
1894 ++iter) {
1895 BluetoothLowEnergyNotifySession* session = 1869 BluetoothLowEnergyNotifySession* session =
1896 manager->Get(extension_id, *iter); 1870 manager->Get(extension_id, *iter);
1897 if (!session || 1871 if (!session ||
1898 session->GetSession()->GetCharacteristicIdentifier() != 1872 session->GetSession()->GetCharacteristicIdentifier() !=
1899 characteristic_id) 1873 characteristic_id)
1900 continue; 1874 continue;
1901 1875
1902 manager->Remove(extension_id, *iter); 1876 manager->Remove(extension_id, *iter);
1903 return true; 1877 return true;
1904 } 1878 }
(...skipping 14 matching lines...) Expand all
1919 requests_[extension_id] = std::move(new_request_id_map); 1893 requests_[extension_id] = std::move(new_request_id_map);
1920 } else { 1894 } else {
1921 request_id_map = iter->second.get(); 1895 request_id_map = iter->second.get();
1922 } 1896 }
1923 1897
1924 (*request_id_map)[++last_callback_request_id_] = std::move(request); 1898 (*request_id_map)[++last_callback_request_id_] = std::move(request);
1925 return last_callback_request_id_; 1899 return last_callback_request_id_;
1926 } 1900 }
1927 1901
1928 } // namespace extensions 1902 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698