| 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 <iterator> | 9 #include <iterator> |
| 10 #include <utility> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/bind.h" | 13 #include "base/bind.h" |
| 13 #include "base/callback.h" | 14 #include "base/callback.h" |
| 14 #include "base/callback_forward.h" | 15 #include "base/callback_forward.h" |
| 15 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 16 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
| 17 #include "base/logging.h" | 18 #include "base/logging.h" |
| 18 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 19 #include "base/values.h" | 20 #include "base/values.h" |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 extension(), params->characteristic_id, &characteristic); | 617 extension(), params->characteristic_id, &characteristic); |
| 617 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { | 618 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { |
| 618 SetError(StatusToString(status)); | 619 SetError(StatusToString(status)); |
| 619 SendResponse(false); | 620 SendResponse(false); |
| 620 return false; | 621 return false; |
| 621 } | 622 } |
| 622 | 623 |
| 623 // Manually construct the result instead of using | 624 // Manually construct the result instead of using |
| 624 // apibtle::GetCharacteristic::Result::Create as it doesn't convert lists of | 625 // apibtle::GetCharacteristic::Result::Create as it doesn't convert lists of |
| 625 // enums correctly. | 626 // enums correctly. |
| 626 SetResult(apibtle::CharacteristicToValue(&characteristic).release()); | 627 SetResult(apibtle::CharacteristicToValue(&characteristic)); |
| 627 SendResponse(true); | 628 SendResponse(true); |
| 628 | 629 |
| 629 return true; | 630 return true; |
| 630 } | 631 } |
| 631 | 632 |
| 632 bool BluetoothLowEnergyGetCharacteristicsFunction::DoWork() { | 633 bool BluetoothLowEnergyGetCharacteristicsFunction::DoWork() { |
| 633 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 634 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 634 | 635 |
| 635 BluetoothLowEnergyEventRouter* event_router = | 636 BluetoothLowEnergyEventRouter* event_router = |
| 636 GetEventRouter(browser_context()); | 637 GetEventRouter(browser_context()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 657 return false; | 658 return false; |
| 658 } | 659 } |
| 659 | 660 |
| 660 // Manually construct the result instead of using | 661 // Manually construct the result instead of using |
| 661 // apibtle::GetCharacteristics::Result::Create as it doesn't convert lists of | 662 // apibtle::GetCharacteristics::Result::Create as it doesn't convert lists of |
| 662 // enums correctly. | 663 // enums correctly. |
| 663 std::unique_ptr<base::ListValue> result(new base::ListValue()); | 664 std::unique_ptr<base::ListValue> result(new base::ListValue()); |
| 664 for (apibtle::Characteristic& characteristic : characteristic_list) | 665 for (apibtle::Characteristic& characteristic : characteristic_list) |
| 665 result->Append(apibtle::CharacteristicToValue(&characteristic)); | 666 result->Append(apibtle::CharacteristicToValue(&characteristic)); |
| 666 | 667 |
| 667 SetResult(result.release()); | 668 SetResult(std::move(result)); |
| 668 SendResponse(true); | 669 SendResponse(true); |
| 669 | 670 |
| 670 return true; | 671 return true; |
| 671 } | 672 } |
| 672 | 673 |
| 673 bool BluetoothLowEnergyGetIncludedServicesFunction::DoWork() { | 674 bool BluetoothLowEnergyGetIncludedServicesFunction::DoWork() { |
| 674 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 675 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 675 | 676 |
| 676 BluetoothLowEnergyEventRouter* event_router = | 677 BluetoothLowEnergyEventRouter* event_router = |
| 677 GetEventRouter(browser_context()); | 678 GetEventRouter(browser_context()); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 extension(), params->descriptor_id, &descriptor); | 727 extension(), params->descriptor_id, &descriptor); |
| 727 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { | 728 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { |
| 728 SetError(StatusToString(status)); | 729 SetError(StatusToString(status)); |
| 729 SendResponse(false); | 730 SendResponse(false); |
| 730 return false; | 731 return false; |
| 731 } | 732 } |
| 732 | 733 |
| 733 // Manually construct the result instead of using | 734 // Manually construct the result instead of using |
| 734 // apibtle::GetDescriptor::Result::Create as it doesn't convert lists of enums | 735 // apibtle::GetDescriptor::Result::Create as it doesn't convert lists of enums |
| 735 // correctly. | 736 // correctly. |
| 736 SetResult(apibtle::DescriptorToValue(&descriptor).release()); | 737 SetResult(apibtle::DescriptorToValue(&descriptor)); |
| 737 SendResponse(true); | 738 SendResponse(true); |
| 738 | 739 |
| 739 return true; | 740 return true; |
| 740 } | 741 } |
| 741 | 742 |
| 742 bool BluetoothLowEnergyGetDescriptorsFunction::DoWork() { | 743 bool BluetoothLowEnergyGetDescriptorsFunction::DoWork() { |
| 743 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 744 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 744 | 745 |
| 745 BluetoothLowEnergyEventRouter* event_router = | 746 BluetoothLowEnergyEventRouter* event_router = |
| 746 GetEventRouter(browser_context()); | 747 GetEventRouter(browser_context()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 766 return false; | 767 return false; |
| 767 } | 768 } |
| 768 | 769 |
| 769 // Manually construct the result instead of using | 770 // Manually construct the result instead of using |
| 770 // apibtle::GetDescriptors::Result::Create as it doesn't convert lists of | 771 // apibtle::GetDescriptors::Result::Create as it doesn't convert lists of |
| 771 // enums correctly. | 772 // enums correctly. |
| 772 std::unique_ptr<base::ListValue> result(new base::ListValue()); | 773 std::unique_ptr<base::ListValue> result(new base::ListValue()); |
| 773 for (apibtle::Descriptor& descriptor : descriptor_list) | 774 for (apibtle::Descriptor& descriptor : descriptor_list) |
| 774 result->Append(apibtle::DescriptorToValue(&descriptor)); | 775 result->Append(apibtle::DescriptorToValue(&descriptor)); |
| 775 | 776 |
| 776 SetResult(result.release()); | 777 SetResult(std::move(result)); |
| 777 SendResponse(true); | 778 SendResponse(true); |
| 778 | 779 |
| 779 return true; | 780 return true; |
| 780 } | 781 } |
| 781 | 782 |
| 782 bool BluetoothLowEnergyReadCharacteristicValueFunction::DoWork() { | 783 bool BluetoothLowEnergyReadCharacteristicValueFunction::DoWork() { |
| 783 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 784 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 784 | 785 |
| 785 BluetoothLowEnergyEventRouter* event_router = | 786 BluetoothLowEnergyEventRouter* event_router = |
| 786 GetEventRouter(browser_context()); | 787 GetEventRouter(browser_context()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 ->GetCharacteristic(extension(), instance_id_, &characteristic); | 821 ->GetCharacteristic(extension(), instance_id_, &characteristic); |
| 821 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { | 822 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { |
| 822 SetError(StatusToString(status)); | 823 SetError(StatusToString(status)); |
| 823 SendResponse(false); | 824 SendResponse(false); |
| 824 return; | 825 return; |
| 825 } | 826 } |
| 826 | 827 |
| 827 // Manually construct the result instead of using | 828 // Manually construct the result instead of using |
| 828 // apibtle::GetCharacteristic::Result::Create as it doesn't convert lists of | 829 // apibtle::GetCharacteristic::Result::Create as it doesn't convert lists of |
| 829 // enums correctly. | 830 // enums correctly. |
| 830 SetResult(apibtle::CharacteristicToValue(&characteristic).release()); | 831 SetResult(apibtle::CharacteristicToValue(&characteristic)); |
| 831 SendResponse(true); | 832 SendResponse(true); |
| 832 } | 833 } |
| 833 | 834 |
| 834 void BluetoothLowEnergyReadCharacteristicValueFunction::ErrorCallback( | 835 void BluetoothLowEnergyReadCharacteristicValueFunction::ErrorCallback( |
| 835 BluetoothLowEnergyEventRouter::Status status) { | 836 BluetoothLowEnergyEventRouter::Status status) { |
| 836 SetError(StatusToString(status)); | 837 SetError(StatusToString(status)); |
| 837 SendResponse(false); | 838 SendResponse(false); |
| 838 } | 839 } |
| 839 | 840 |
| 840 bool BluetoothLowEnergyWriteCharacteristicValueFunction::DoWork() { | 841 bool BluetoothLowEnergyWriteCharacteristicValueFunction::DoWork() { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 ->GetDescriptor(extension(), instance_id_, &descriptor); | 1012 ->GetDescriptor(extension(), instance_id_, &descriptor); |
| 1012 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { | 1013 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { |
| 1013 SetError(StatusToString(status)); | 1014 SetError(StatusToString(status)); |
| 1014 SendResponse(false); | 1015 SendResponse(false); |
| 1015 return; | 1016 return; |
| 1016 } | 1017 } |
| 1017 | 1018 |
| 1018 // Manually construct the result instead of using | 1019 // Manually construct the result instead of using |
| 1019 // apibtle::GetDescriptor::Results::Create as it doesn't convert lists of | 1020 // apibtle::GetDescriptor::Results::Create as it doesn't convert lists of |
| 1020 // enums correctly. | 1021 // enums correctly. |
| 1021 SetResult(apibtle::DescriptorToValue(&descriptor).release()); | 1022 SetResult(apibtle::DescriptorToValue(&descriptor)); |
| 1022 SendResponse(true); | 1023 SendResponse(true); |
| 1023 } | 1024 } |
| 1024 | 1025 |
| 1025 void BluetoothLowEnergyReadDescriptorValueFunction::ErrorCallback( | 1026 void BluetoothLowEnergyReadDescriptorValueFunction::ErrorCallback( |
| 1026 BluetoothLowEnergyEventRouter::Status status) { | 1027 BluetoothLowEnergyEventRouter::Status status) { |
| 1027 SetError(StatusToString(status)); | 1028 SetError(StatusToString(status)); |
| 1028 SendResponse(false); | 1029 SendResponse(false); |
| 1029 } | 1030 } |
| 1030 | 1031 |
| 1031 bool BluetoothLowEnergyWriteDescriptorValueFunction::DoWork() { | 1032 bool BluetoothLowEnergyWriteDescriptorValueFunction::DoWork() { |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1482 params_->response.value->end()); | 1483 params_->response.value->end()); |
| 1483 } | 1484 } |
| 1484 event_router_->HandleRequestResponse( | 1485 event_router_->HandleRequestResponse( |
| 1485 extension(), params_->response.request_id, params_->response.is_error, | 1486 extension(), params_->response.request_id, params_->response.is_error, |
| 1486 uint8_vector); | 1487 uint8_vector); |
| 1487 Respond(NoArguments()); | 1488 Respond(NoArguments()); |
| 1488 } | 1489 } |
| 1489 | 1490 |
| 1490 } // namespace api | 1491 } // namespace api |
| 1491 } // namespace extensions | 1492 } // namespace extensions |
| OLD | NEW |