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/usb/usb_api.h" | 5 #include "extensions/browser/api/usb/usb_api.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/barrier_closure.h" | 10 #include "base/barrier_closure.h" |
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 GetConfiguration::Params::Create(*args_); | 759 GetConfiguration::Params::Create(*args_); |
760 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 760 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
761 | 761 |
762 scoped_refptr<UsbDeviceHandle> device_handle = | 762 scoped_refptr<UsbDeviceHandle> device_handle = |
763 GetDeviceHandle(parameters->handle); | 763 GetDeviceHandle(parameters->handle); |
764 if (!device_handle.get()) { | 764 if (!device_handle.get()) { |
765 return RespondNow(Error(kErrorNoConnection)); | 765 return RespondNow(Error(kErrorNoConnection)); |
766 } | 766 } |
767 | 767 |
768 const UsbConfigDescriptor* config_descriptor = | 768 const UsbConfigDescriptor* config_descriptor = |
769 device_handle->GetDevice()->GetConfiguration(); | 769 device_handle->GetDevice()->GetActiveConfiguration(); |
770 if (config_descriptor) { | 770 if (config_descriptor) { |
771 ConfigDescriptor config; | 771 ConfigDescriptor config; |
772 ConvertConfigDescriptor(*config_descriptor, &config); | 772 ConvertConfigDescriptor(*config_descriptor, &config); |
773 return RespondNow(OneArgument(config.ToValue().release())); | 773 return RespondNow(OneArgument(config.ToValue().release())); |
774 } else { | 774 } else { |
775 return RespondNow(Error(kErrorNotConfigured)); | 775 return RespondNow(Error(kErrorNotConfigured)); |
776 } | 776 } |
777 } | 777 } |
778 | 778 |
779 UsbListInterfacesFunction::UsbListInterfacesFunction() { | 779 UsbListInterfacesFunction::UsbListInterfacesFunction() { |
780 } | 780 } |
781 | 781 |
782 UsbListInterfacesFunction::~UsbListInterfacesFunction() { | 782 UsbListInterfacesFunction::~UsbListInterfacesFunction() { |
783 } | 783 } |
784 | 784 |
785 ExtensionFunction::ResponseAction UsbListInterfacesFunction::Run() { | 785 ExtensionFunction::ResponseAction UsbListInterfacesFunction::Run() { |
786 scoped_ptr<extensions::api::usb::ListInterfaces::Params> parameters = | 786 scoped_ptr<extensions::api::usb::ListInterfaces::Params> parameters = |
787 ListInterfaces::Params::Create(*args_); | 787 ListInterfaces::Params::Create(*args_); |
788 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 788 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
789 | 789 |
790 scoped_refptr<UsbDeviceHandle> device_handle = | 790 scoped_refptr<UsbDeviceHandle> device_handle = |
791 GetDeviceHandle(parameters->handle); | 791 GetDeviceHandle(parameters->handle); |
792 if (!device_handle.get()) { | 792 if (!device_handle.get()) { |
793 return RespondNow(Error(kErrorNoConnection)); | 793 return RespondNow(Error(kErrorNoConnection)); |
794 } | 794 } |
795 | 795 |
796 const UsbConfigDescriptor* config_descriptor = | 796 const UsbConfigDescriptor* config_descriptor = |
797 device_handle->GetDevice()->GetConfiguration(); | 797 device_handle->GetDevice()->GetActiveConfiguration(); |
798 if (config_descriptor) { | 798 if (config_descriptor) { |
799 ConfigDescriptor config; | 799 ConfigDescriptor config; |
800 ConvertConfigDescriptor(*config_descriptor, &config); | 800 ConvertConfigDescriptor(*config_descriptor, &config); |
801 | 801 |
802 scoped_ptr<base::ListValue> result(new base::ListValue); | 802 scoped_ptr<base::ListValue> result(new base::ListValue); |
803 for (size_t i = 0; i < config.interfaces.size(); ++i) { | 803 for (size_t i = 0; i < config.interfaces.size(); ++i) { |
804 result->Append(config.interfaces[i]->ToValue().release()); | 804 result->Append(config.interfaces[i]->ToValue().release()); |
805 } | 805 } |
806 | 806 |
807 return RespondNow(OneArgument(result.release())); | 807 return RespondNow(OneArgument(result.release())); |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 ReleaseDeviceHandle(parameters_->handle); | 1167 ReleaseDeviceHandle(parameters_->handle); |
1168 | 1168 |
1169 scoped_ptr<base::ListValue> error_args(new base::ListValue()); | 1169 scoped_ptr<base::ListValue> error_args(new base::ListValue()); |
1170 error_args->AppendBoolean(false); | 1170 error_args->AppendBoolean(false); |
1171 // Returning arguments with an error is wrong but we're stuck with it. | 1171 // Returning arguments with an error is wrong but we're stuck with it. |
1172 Respond(ErrorWithArguments(error_args.Pass(), kErrorResetDevice)); | 1172 Respond(ErrorWithArguments(error_args.Pass(), kErrorResetDevice)); |
1173 } | 1173 } |
1174 } | 1174 } |
1175 | 1175 |
1176 } // namespace extensions | 1176 } // namespace extensions |
OLD | NEW |