| 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 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ
y_event_router.h" | 5 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ
y_event_router.h" |
| 6 | 6 |
| 7 #include <iterator> |
| 7 #include <utility> | 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback_forward.h" |
| 12 #include "base/containers/hash_tables.h" |
| 10 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/memory/ref_counted.h" |
| 11 #include "base/values.h" | 16 #include "base/values.h" |
| 12 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ
y_connection.h" | 17 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ
y_connection.h" |
| 13 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ
y_notify_session.h" | 18 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ
y_notify_session.h" |
| 14 #include "chrome/browser/extensions/api/bluetooth_low_energy/utils.h" | 19 #include "chrome/browser/extensions/api/bluetooth_low_energy/utils.h" |
| 20 #include "content/public/browser/browser_context.h" |
| 15 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 16 #include "device/bluetooth/bluetooth_adapter_factory.h" | 22 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 23 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
| 17 #include "device/bluetooth/bluetooth_gatt_connection.h" | 24 #include "device/bluetooth/bluetooth_gatt_connection.h" |
| 25 #include "device/bluetooth/bluetooth_gatt_notify_session.h" |
| 26 #include "device/bluetooth/bluetooth_gatt_service.h" |
| 18 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" | 27 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
| 19 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h" | 28 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h" |
| 29 #include "device/bluetooth/bluetooth_uuid.h" |
| 30 #include "extensions/browser/api/api_resource_manager.h" |
| 31 #include "extensions/browser/event_listener_map.h" |
| 20 #include "extensions/browser/event_router.h" | 32 #include "extensions/browser/event_router.h" |
| 21 #include "extensions/browser/extension_registry.h" | 33 #include "extensions/browser/extension_registry.h" |
| 22 #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" |
| 23 | 36 |
| 24 using content::BrowserThread; | 37 using content::BrowserThread; |
| 25 | 38 |
| 26 using device::BluetoothAdapter; | 39 using device::BluetoothAdapter; |
| 27 using device::BluetoothAdapterFactory; | 40 using device::BluetoothAdapterFactory; |
| 28 using device::BluetoothDevice; | 41 using device::BluetoothDevice; |
| 29 using device::BluetoothRemoteGattCharacteristic; | 42 using device::BluetoothRemoteGattCharacteristic; |
| 30 using device::BluetoothGattConnection; | 43 using device::BluetoothGattConnection; |
| 31 using device::BluetoothRemoteGattDescriptor; | 44 using device::BluetoothRemoteGattDescriptor; |
| 32 using device::BluetoothRemoteGattService; | 45 using device::BluetoothRemoteGattService; |
| 33 | 46 |
| 34 namespace apibtle = extensions::api::bluetooth_low_energy; | 47 namespace apibtle = extensions::api::bluetooth_low_energy; |
| 35 | 48 |
| 36 namespace { | 49 namespace { |
| 37 | 50 |
| 38 void PopulateService(const BluetoothRemoteGattService* service, | 51 void PopulateService(const BluetoothRemoteGattService* service, |
| 39 apibtle::Service* out) { | 52 apibtle::Service* out) { |
| 40 DCHECK(out); | 53 DCHECK(out); |
| 41 | 54 |
| 42 out->uuid = service->GetUUID().canonical_value(); | 55 out->uuid = service->GetUUID().canonical_value(); |
| 43 out->is_primary = service->IsPrimary(); | 56 out->is_primary = service->IsPrimary(); |
| 44 out->is_local = false; | |
| 45 out->instance_id.reset(new std::string(service->GetIdentifier())); | 57 out->instance_id.reset(new std::string(service->GetIdentifier())); |
| 46 | 58 |
| 47 if (!service->GetDevice()) | 59 if (!service->GetDevice()) |
| 48 return; | 60 return; |
| 49 | 61 |
| 50 out->device_address.reset( | 62 out->device_address.reset( |
| 51 new std::string(service->GetDevice()->GetAddress())); | 63 new std::string(service->GetDevice()->GetAddress())); |
| 52 } | 64 } |
| 53 | 65 |
| 54 void PopulateCharacteristicProperties( | 66 void PopulateCharacteristicProperties( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 apibtle::CHARACTERISTIC_PROPERTY_WRITABLEAUXILIARIES); | 104 apibtle::CHARACTERISTIC_PROPERTY_WRITABLEAUXILIARIES); |
| 93 } | 105 } |
| 94 } | 106 } |
| 95 | 107 |
| 96 void PopulateCharacteristic( | 108 void PopulateCharacteristic( |
| 97 const BluetoothRemoteGattCharacteristic* characteristic, | 109 const BluetoothRemoteGattCharacteristic* characteristic, |
| 98 apibtle::Characteristic* out) { | 110 apibtle::Characteristic* out) { |
| 99 DCHECK(out); | 111 DCHECK(out); |
| 100 | 112 |
| 101 out->uuid = characteristic->GetUUID().canonical_value(); | 113 out->uuid = characteristic->GetUUID().canonical_value(); |
| 102 out->is_local = false; | |
| 103 out->instance_id.reset(new std::string(characteristic->GetIdentifier())); | 114 out->instance_id.reset(new std::string(characteristic->GetIdentifier())); |
| 104 | 115 |
| 105 PopulateService(characteristic->GetService(), &out->service); | 116 out->service = base::WrapUnique(new apibtle::Service()); |
| 117 PopulateService(characteristic->GetService(), out->service.get()); |
| 106 PopulateCharacteristicProperties(characteristic->GetProperties(), | 118 PopulateCharacteristicProperties(characteristic->GetProperties(), |
| 107 &out->properties); | 119 &out->properties); |
| 108 | 120 |
| 109 const std::vector<uint8_t>& value = characteristic->GetValue(); | 121 const std::vector<uint8_t>& value = characteristic->GetValue(); |
| 110 if (value.empty()) | 122 if (value.empty()) |
| 111 return; | 123 return; |
| 112 | 124 |
| 113 out->value.reset(new std::vector<char>(value.begin(), value.end())); | 125 out->value.reset(new std::vector<char>(value.begin(), value.end())); |
| 114 } | 126 } |
| 115 | 127 |
| 116 void PopulateDescriptor(const BluetoothRemoteGattDescriptor* descriptor, | 128 void PopulateDescriptor(const BluetoothRemoteGattDescriptor* descriptor, |
| 117 apibtle::Descriptor* out) { | 129 apibtle::Descriptor* out) { |
| 118 DCHECK(out); | 130 DCHECK(out); |
| 119 | 131 |
| 120 out->uuid = descriptor->GetUUID().canonical_value(); | 132 out->uuid = descriptor->GetUUID().canonical_value(); |
| 121 out->is_local = false; | |
| 122 out->instance_id.reset(new std::string(descriptor->GetIdentifier())); | 133 out->instance_id.reset(new std::string(descriptor->GetIdentifier())); |
| 123 | 134 |
| 124 PopulateCharacteristic(descriptor->GetCharacteristic(), &out->characteristic); | 135 out->characteristic = base::WrapUnique(new apibtle::Characteristic()); |
| 136 PopulateCharacteristic(descriptor->GetCharacteristic(), |
| 137 out->characteristic.get()); |
| 125 | 138 |
| 126 const std::vector<uint8_t>& value = descriptor->GetValue(); | 139 const std::vector<uint8_t>& value = descriptor->GetValue(); |
| 127 if (value.empty()) | 140 if (value.empty()) |
| 128 return; | 141 return; |
| 129 | 142 |
| 130 out->value.reset(new std::vector<char>(value.begin(), value.end())); | 143 out->value.reset(new std::vector<char>(value.begin(), value.end())); |
| 131 } | 144 } |
| 132 | 145 |
| 133 typedef extensions::ApiResourceManager<extensions::BluetoothLowEnergyConnection> | 146 typedef extensions::ApiResourceManager<extensions::BluetoothLowEnergyConnection> |
| 134 ConnectionResourceManager; | 147 ConnectionResourceManager; |
| (...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1503 continue; | 1516 continue; |
| 1504 | 1517 |
| 1505 manager->Remove(extension_id, *iter); | 1518 manager->Remove(extension_id, *iter); |
| 1506 return true; | 1519 return true; |
| 1507 } | 1520 } |
| 1508 | 1521 |
| 1509 return false; | 1522 return false; |
| 1510 } | 1523 } |
| 1511 | 1524 |
| 1512 } // namespace extensions | 1525 } // namespace extensions |
| OLD | NEW |