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 "extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_api.h " | 5 #include "extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_api.h " |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
786 results_ = apibtle::WriteDescriptorValue::Results::Create(); | 786 results_ = apibtle::WriteDescriptorValue::Results::Create(); |
787 SendResponse(true); | 787 SendResponse(true); |
788 } | 788 } |
789 | 789 |
790 void BluetoothLowEnergyWriteDescriptorValueFunction::ErrorCallback( | 790 void BluetoothLowEnergyWriteDescriptorValueFunction::ErrorCallback( |
791 BluetoothLowEnergyEventRouter::Status status) { | 791 BluetoothLowEnergyEventRouter::Status status) { |
792 SetError(StatusToString(status)); | 792 SetError(StatusToString(status)); |
793 SendResponse(false); | 793 SendResponse(false); |
794 } | 794 } |
795 | 795 |
796 // RegisterAdvertisement: | |
797 | |
798 bool BluetoothLowEnergyRegisterAdvertisementFunction::DoWork() { | |
799 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
800 | |
801 if (!BluetoothManifestData::CheckPeripheralPermitted(extension())) { | |
802 error_ = kErrorPermissionDenied; | |
armansito
2015/04/21 22:48:08
Call SendResponse(false)
rkc
2015/04/27 18:39:08
Done.
| |
803 return false; | |
804 } | |
805 | |
806 BluetoothLowEnergyEventRouter* event_router = | |
807 GetEventRouter(browser_context()); | |
808 | |
809 // The adapter must be initialized at this point, but return an error instead | |
810 // of asserting. | |
811 if (!event_router->HasAdapter()) { | |
812 SetError(kErrorAdapterNotInitialized); | |
813 SendResponse(false); | |
814 return false; | |
815 } | |
816 | |
817 scoped_ptr<apibtle::RegisterAdvertisement::Params> params( | |
818 apibtle::RegisterAdvertisement::Params::Create(*args_)); | |
819 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | |
armansito
2015/04/21 22:48:08
Add a TODO here to parse the arguments and do some
rkc
2015/04/27 18:39:08
Done.
| |
820 | |
821 return true; | |
822 } | |
823 | |
824 void BluetoothLowEnergyRegisterAdvertisementFunction::SuccessCallback() { | |
825 results_ = apibtle::RegisterAdvertisement::Results::Create(0); | |
armansito
2015/04/21 22:48:09
What's the magic "0" here?
rkc
2015/04/27 18:39:08
Success/Failed callbacks removed for now.
Done.
| |
826 SendResponse(true); | |
827 } | |
828 | |
829 void BluetoothLowEnergyRegisterAdvertisementFunction::ErrorCallback( | |
830 BluetoothLowEnergyEventRouter::Status status) { | |
831 SetError(StatusToString(status)); | |
832 SendResponse(false); | |
833 } | |
834 | |
835 // UnregisterAdvertisement: | |
836 | |
837 bool BluetoothLowEnergyUnregisterAdvertisementFunction::DoWork() { | |
838 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
839 | |
840 if (!BluetoothManifestData::CheckPeripheralPermitted(extension())) { | |
841 error_ = kErrorPermissionDenied; | |
armansito
2015/04/21 22:48:08
SendResponse(false);
rkc
2015/04/27 18:39:09
Done.
| |
842 return false; | |
843 } | |
844 | |
845 BluetoothLowEnergyEventRouter* event_router = | |
846 GetEventRouter(browser_context()); | |
847 | |
848 // If we don't have an initialized adapter, unregistering is a no-op. | |
849 if (!event_router->HasAdapter()) | |
850 return true; | |
851 | |
852 scoped_ptr<apibtle::UnregisterAdvertisement::Params> params( | |
853 apibtle::UnregisterAdvertisement::Params::Create(*args_)); | |
854 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | |
855 | |
armansito
2015/04/21 22:48:09
Add a TODO here.
rkc
2015/04/27 18:39:08
Done.
| |
856 return true; | |
857 } | |
858 | |
859 void BluetoothLowEnergyUnregisterAdvertisementFunction::SuccessCallback() { | |
860 results_ = apibtle::UnregisterAdvertisement::Results::Create(); | |
861 SendResponse(true); | |
862 } | |
863 | |
864 void BluetoothLowEnergyUnregisterAdvertisementFunction::ErrorCallback( | |
865 BluetoothLowEnergyEventRouter::Status status) { | |
866 SetError(StatusToString(status)); | |
867 SendResponse(false); | |
868 } | |
armansito
2015/04/21 22:48:09
Technically these Success/ErrorCallback functions
rkc
2015/04/27 18:39:08
Done.
| |
869 | |
796 } // namespace core_api | 870 } // namespace core_api |
797 } // namespace extensions | 871 } // namespace extensions |
OLD | NEW |