| 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_api.h" | 5 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ
y_api.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 return extensions::BluetoothLowEnergyAPI::Get(context)->event_router(); | 127 return extensions::BluetoothLowEnergyAPI::Get(context)->event_router(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void DoWorkCallback(const base::Callback<bool()>& callback) { | 130 void DoWorkCallback(const base::Callback<bool()>& callback) { |
| 131 DCHECK(!callback.is_null()); | 131 DCHECK(!callback.is_null()); |
| 132 callback.Run(); | 132 callback.Run(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 scoped_ptr<device::BluetoothAdvertisement::ManufacturerData> | 135 scoped_ptr<device::BluetoothAdvertisement::ManufacturerData> |
| 136 CreateManufacturerData( | 136 CreateManufacturerData( |
| 137 std::vector<linked_ptr<apibtle::ManufacturerData>>* manufacturer_data) { | 137 std::vector<apibtle::ManufacturerData>* manufacturer_data) { |
| 138 scoped_ptr<device::BluetoothAdvertisement::ManufacturerData> created_data( | 138 scoped_ptr<device::BluetoothAdvertisement::ManufacturerData> created_data( |
| 139 new device::BluetoothAdvertisement::ManufacturerData()); | 139 new device::BluetoothAdvertisement::ManufacturerData()); |
| 140 for (const auto& it : *manufacturer_data) { | 140 for (const auto& it : *manufacturer_data) { |
| 141 std::vector<uint8_t> data(it->data.size()); | 141 std::vector<uint8_t> data(it.data.size()); |
| 142 std::copy(it->data.begin(), it->data.end(), data.begin()); | 142 std::copy(it.data.begin(), it.data.end(), data.begin()); |
| 143 (*created_data)[it->id] = data; | 143 (*created_data)[it.id] = data; |
| 144 } | 144 } |
| 145 return created_data; | 145 return created_data; |
| 146 } | 146 } |
| 147 | 147 |
| 148 scoped_ptr<device::BluetoothAdvertisement::ServiceData> CreateServiceData( | 148 scoped_ptr<device::BluetoothAdvertisement::ServiceData> CreateServiceData( |
| 149 std::vector<linked_ptr<apibtle::ServiceData>>* service_data) { | 149 std::vector<apibtle::ServiceData>* service_data) { |
| 150 scoped_ptr<device::BluetoothAdvertisement::ServiceData> created_data( | 150 scoped_ptr<device::BluetoothAdvertisement::ServiceData> created_data( |
| 151 new device::BluetoothAdvertisement::ServiceData()); | 151 new device::BluetoothAdvertisement::ServiceData()); |
| 152 for (const auto& it : *service_data) { | 152 for (const auto& it : *service_data) { |
| 153 std::vector<uint8_t> data(it->data.size()); | 153 std::vector<uint8_t> data(it.data.size()); |
| 154 std::copy(it->data.begin(), it->data.end(), data.begin()); | 154 std::copy(it.data.begin(), it.data.end(), data.begin()); |
| 155 (*created_data)[it->uuid] = data; | 155 (*created_data)[it.uuid] = data; |
| 156 } | 156 } |
| 157 return created_data; | 157 return created_data; |
| 158 } | 158 } |
| 159 | 159 |
| 160 } // namespace | 160 } // namespace |
| 161 | 161 |
| 162 | 162 |
| 163 static base::LazyInstance<BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI> > | 163 static base::LazyInstance<BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI> > |
| 164 g_factory = LAZY_INSTANCE_INITIALIZER; | 164 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 165 | 165 |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { | 427 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { |
| 428 SetError(StatusToString(status)); | 428 SetError(StatusToString(status)); |
| 429 SendResponse(false); | 429 SendResponse(false); |
| 430 return false; | 430 return false; |
| 431 } | 431 } |
| 432 | 432 |
| 433 // Manually construct the result instead of using | 433 // Manually construct the result instead of using |
| 434 // apibtle::GetCharacteristics::Result::Create as it doesn't convert lists of | 434 // apibtle::GetCharacteristics::Result::Create as it doesn't convert lists of |
| 435 // enums correctly. | 435 // enums correctly. |
| 436 scoped_ptr<base::ListValue> result(new base::ListValue()); | 436 scoped_ptr<base::ListValue> result(new base::ListValue()); |
| 437 for (BluetoothLowEnergyEventRouter::CharacteristicList::iterator iter = | 437 for (apibtle::Characteristic& characteristic : characteristic_list) |
| 438 characteristic_list.begin(); | 438 result->Append(apibtle::CharacteristicToValue(&characteristic)); |
| 439 iter != characteristic_list.end(); | |
| 440 ++iter) | |
| 441 result->Append(apibtle::CharacteristicToValue(iter->get()).release()); | |
| 442 | 439 |
| 443 SetResult(result.release()); | 440 SetResult(result.release()); |
| 444 SendResponse(true); | 441 SendResponse(true); |
| 445 | 442 |
| 446 return true; | 443 return true; |
| 447 } | 444 } |
| 448 | 445 |
| 449 bool BluetoothLowEnergyGetIncludedServicesFunction::DoWork() { | 446 bool BluetoothLowEnergyGetIncludedServicesFunction::DoWork() { |
| 450 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 447 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 451 | 448 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { | 536 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { |
| 540 SetError(StatusToString(status)); | 537 SetError(StatusToString(status)); |
| 541 SendResponse(false); | 538 SendResponse(false); |
| 542 return false; | 539 return false; |
| 543 } | 540 } |
| 544 | 541 |
| 545 // Manually construct the result instead of using | 542 // Manually construct the result instead of using |
| 546 // apibtle::GetDescriptors::Result::Create as it doesn't convert lists of | 543 // apibtle::GetDescriptors::Result::Create as it doesn't convert lists of |
| 547 // enums correctly. | 544 // enums correctly. |
| 548 scoped_ptr<base::ListValue> result(new base::ListValue()); | 545 scoped_ptr<base::ListValue> result(new base::ListValue()); |
| 549 for (BluetoothLowEnergyEventRouter::DescriptorList::iterator iter = | 546 for (apibtle::Descriptor& descriptor : descriptor_list) |
| 550 descriptor_list.begin(); | 547 result->Append(apibtle::DescriptorToValue(&descriptor)); |
| 551 iter != descriptor_list.end(); | |
| 552 ++iter) | |
| 553 result->Append(apibtle::DescriptorToValue(iter->get()).release()); | |
| 554 | 548 |
| 555 SetResult(result.release()); | 549 SetResult(result.release()); |
| 556 SendResponse(true); | 550 SendResponse(true); |
| 557 | 551 |
| 558 return true; | 552 return true; |
| 559 } | 553 } |
| 560 | 554 |
| 561 bool BluetoothLowEnergyReadCharacteristicValueFunction::DoWork() { | 555 bool BluetoothLowEnergyReadCharacteristicValueFunction::DoWork() { |
| 562 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 556 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 563 | 557 |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1066 SetError(kStatusAdvertisementDoesNotExist); | 1060 SetError(kStatusAdvertisementDoesNotExist); |
| 1067 break; | 1061 break; |
| 1068 default: | 1062 default: |
| 1069 SetError(kErrorOperationFailed); | 1063 SetError(kErrorOperationFailed); |
| 1070 } | 1064 } |
| 1071 SendResponse(false); | 1065 SendResponse(false); |
| 1072 } | 1066 } |
| 1073 | 1067 |
| 1074 } // namespace api | 1068 } // namespace api |
| 1075 } // namespace extensions | 1069 } // namespace extensions |
| OLD | NEW |