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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 | 431 |
432 UsbService* service = UsbService::GetInstance(); | 432 UsbService* service = UsbService::GetInstance(); |
433 if (!service) { | 433 if (!service) { |
434 CompleteWithError(kErrorInitService); | 434 CompleteWithError(kErrorInitService); |
435 return NULL; | 435 return NULL; |
436 } | 436 } |
437 scoped_refptr<UsbDevice> device; | 437 scoped_refptr<UsbDevice> device; |
438 | 438 |
439 device = service->GetDeviceById(input_device.device); | 439 device = service->GetDeviceById(input_device.device); |
440 | 440 |
441 if (!device) { | 441 if (!device.get()) { |
442 CompleteWithError(kErrorNoDevice); | 442 CompleteWithError(kErrorNoDevice); |
443 return NULL; | 443 return NULL; |
444 } | 444 } |
445 | 445 |
446 if (device->vendor_id() != input_device.vendor_id || | 446 if (device->vendor_id() != input_device.vendor_id || |
447 device->product_id() != input_device.product_id) { | 447 device->product_id() != input_device.product_id) { |
448 // Must act as if there is no such a device. | 448 // Must act as if there is no such a device. |
449 // Otherwise can be used to finger print unauthorized devices. | 449 // Otherwise can be used to finger print unauthorized devices. |
450 CompleteWithError(kErrorNoDevice); | 450 CompleteWithError(kErrorNoDevice); |
451 return NULL; | 451 return NULL; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 #else | 585 #else |
586 OpenDevices(devices.Pass()); | 586 OpenDevices(devices.Pass()); |
587 #endif // OS_CHROMEOS | 587 #endif // OS_CHROMEOS |
588 } | 588 } |
589 | 589 |
590 void UsbFindDevicesFunction::OpenDevices(ScopedDeviceVector devices) { | 590 void UsbFindDevicesFunction::OpenDevices(ScopedDeviceVector devices) { |
591 base::ListValue* result = new base::ListValue(); | 591 base::ListValue* result = new base::ListValue(); |
592 | 592 |
593 for (size_t i = 0; i < devices->size(); ++i) { | 593 for (size_t i = 0; i < devices->size(); ++i) { |
594 scoped_refptr<UsbDeviceHandle> device_handle = devices->at(i)->Open(); | 594 scoped_refptr<UsbDeviceHandle> device_handle = devices->at(i)->Open(); |
595 if (device_handle) | 595 if (device_handle.get()) |
596 device_handles_.push_back(device_handle); | 596 device_handles_.push_back(device_handle); |
597 } | 597 } |
598 | 598 |
599 for (size_t i = 0; i < device_handles_.size(); ++i) { | 599 for (size_t i = 0; i < device_handles_.size(); ++i) { |
600 UsbDeviceHandle* const device_handle = device_handles_[i].get(); | 600 UsbDeviceHandle* const device_handle = device_handles_[i].get(); |
601 UsbDeviceResource* const resource = | 601 UsbDeviceResource* const resource = |
602 new UsbDeviceResource(extension_->id(), device_handle); | 602 new UsbDeviceResource(extension_->id(), device_handle); |
603 | 603 |
604 result->Append(PopulateConnectionHandle(manager_->Add(resource), | 604 result->Append(PopulateConnectionHandle(manager_->Add(resource), |
605 parameters_->options.vendor_id, | 605 parameters_->options.vendor_id, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 | 702 |
703 bool UsbOpenDeviceFunction::Prepare() { | 703 bool UsbOpenDeviceFunction::Prepare() { |
704 parameters_ = OpenDevice::Params::Create(*args_); | 704 parameters_ = OpenDevice::Params::Create(*args_); |
705 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 705 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
706 return true; | 706 return true; |
707 } | 707 } |
708 | 708 |
709 void UsbOpenDeviceFunction::AsyncWorkStart() { | 709 void UsbOpenDeviceFunction::AsyncWorkStart() { |
710 scoped_refptr<UsbDevice> device = | 710 scoped_refptr<UsbDevice> device = |
711 GetDeviceOrOrCompleteWithError(parameters_->device); | 711 GetDeviceOrOrCompleteWithError(parameters_->device); |
712 if (!device) | 712 if (!device.get()) |
713 return; | 713 return; |
714 | 714 |
715 handle_ = device->Open(); | 715 handle_ = device->Open(); |
716 if (!handle_) { | 716 if (!handle_.get()) { |
717 SetError(kErrorOpen); | 717 SetError(kErrorOpen); |
718 AsyncWorkCompleted(); | 718 AsyncWorkCompleted(); |
719 return; | 719 return; |
720 } | 720 } |
721 | 721 |
722 SetResult(PopulateConnectionHandle( | 722 SetResult(PopulateConnectionHandle( |
723 manager_->Add(new UsbDeviceResource(extension_->id(), handle_)), | 723 manager_->Add(new UsbDeviceResource(extension_->id(), handle_)), |
724 handle_->GetDevice()->vendor_id(), | 724 handle_->GetDevice()->vendor_id(), |
725 handle_->GetDevice()->product_id())); | 725 handle_->GetDevice()->product_id())); |
726 AsyncWorkCompleted(); | 726 AsyncWorkCompleted(); |
727 } | 727 } |
728 | 728 |
729 UsbListInterfacesFunction::UsbListInterfacesFunction() { | 729 UsbListInterfacesFunction::UsbListInterfacesFunction() { |
730 } | 730 } |
731 | 731 |
732 UsbListInterfacesFunction::~UsbListInterfacesFunction() { | 732 UsbListInterfacesFunction::~UsbListInterfacesFunction() { |
733 } | 733 } |
734 | 734 |
735 bool UsbListInterfacesFunction::Prepare() { | 735 bool UsbListInterfacesFunction::Prepare() { |
736 parameters_ = ListInterfaces::Params::Create(*args_); | 736 parameters_ = ListInterfaces::Params::Create(*args_); |
737 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 737 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
738 return true; | 738 return true; |
739 } | 739 } |
740 | 740 |
741 void UsbListInterfacesFunction::AsyncWorkStart() { | 741 void UsbListInterfacesFunction::AsyncWorkStart() { |
742 scoped_refptr<UsbDeviceHandle> device_handle = | 742 scoped_refptr<UsbDeviceHandle> device_handle = |
743 GetDeviceHandleOrCompleteWithError(parameters_->handle); | 743 GetDeviceHandleOrCompleteWithError(parameters_->handle); |
744 if (!device_handle) | 744 if (!device_handle.get()) |
745 return; | 745 return; |
746 | 746 |
747 scoped_refptr<UsbConfigDescriptor> config = | 747 scoped_refptr<UsbConfigDescriptor> config = |
748 device_handle->GetDevice()->ListInterfaces(); | 748 device_handle->GetDevice()->ListInterfaces(); |
749 | 749 |
750 if (!config) { | 750 if (!config.get()) { |
751 SetError(kErrorCannotListInterfaces); | 751 SetError(kErrorCannotListInterfaces); |
752 AsyncWorkCompleted(); | 752 AsyncWorkCompleted(); |
753 return; | 753 return; |
754 } | 754 } |
755 | 755 |
756 result_.reset(new base::ListValue()); | 756 result_.reset(new base::ListValue()); |
757 | 757 |
758 for (size_t i = 0, num_interfaces = config->GetNumInterfaces(); | 758 for (size_t i = 0, num_interfaces = config->GetNumInterfaces(); |
759 i < num_interfaces; | 759 i < num_interfaces; |
760 ++i) { | 760 ++i) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 | 860 |
861 bool UsbCloseDeviceFunction::Prepare() { | 861 bool UsbCloseDeviceFunction::Prepare() { |
862 parameters_ = CloseDevice::Params::Create(*args_); | 862 parameters_ = CloseDevice::Params::Create(*args_); |
863 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 863 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
864 return true; | 864 return true; |
865 } | 865 } |
866 | 866 |
867 void UsbCloseDeviceFunction::AsyncWorkStart() { | 867 void UsbCloseDeviceFunction::AsyncWorkStart() { |
868 scoped_refptr<UsbDeviceHandle> device_handle = | 868 scoped_refptr<UsbDeviceHandle> device_handle = |
869 GetDeviceHandleOrCompleteWithError(parameters_->handle); | 869 GetDeviceHandleOrCompleteWithError(parameters_->handle); |
870 if (!device_handle) | 870 if (!device_handle.get()) |
871 return; | 871 return; |
872 | 872 |
873 device_handle->Close(); | 873 device_handle->Close(); |
874 RemoveUsbDeviceResource(parameters_->handle.handle); | 874 RemoveUsbDeviceResource(parameters_->handle.handle); |
875 AsyncWorkCompleted(); | 875 AsyncWorkCompleted(); |
876 } | 876 } |
877 | 877 |
878 UsbClaimInterfaceFunction::UsbClaimInterfaceFunction() { | 878 UsbClaimInterfaceFunction::UsbClaimInterfaceFunction() { |
879 } | 879 } |
880 | 880 |
881 UsbClaimInterfaceFunction::~UsbClaimInterfaceFunction() { | 881 UsbClaimInterfaceFunction::~UsbClaimInterfaceFunction() { |
882 } | 882 } |
883 | 883 |
884 bool UsbClaimInterfaceFunction::Prepare() { | 884 bool UsbClaimInterfaceFunction::Prepare() { |
885 parameters_ = ClaimInterface::Params::Create(*args_); | 885 parameters_ = ClaimInterface::Params::Create(*args_); |
886 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 886 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
887 return true; | 887 return true; |
888 } | 888 } |
889 | 889 |
890 void UsbClaimInterfaceFunction::AsyncWorkStart() { | 890 void UsbClaimInterfaceFunction::AsyncWorkStart() { |
891 scoped_refptr<UsbDeviceHandle> device_handle = | 891 scoped_refptr<UsbDeviceHandle> device_handle = |
892 GetDeviceHandleOrCompleteWithError(parameters_->handle); | 892 GetDeviceHandleOrCompleteWithError(parameters_->handle); |
893 if (!device_handle) | 893 if (!device_handle.get()) |
894 return; | 894 return; |
895 | 895 |
896 bool success = device_handle->ClaimInterface(parameters_->interface_number); | 896 bool success = device_handle->ClaimInterface(parameters_->interface_number); |
897 | 897 |
898 if (!success) | 898 if (!success) |
899 SetError(kErrorCannotClaimInterface); | 899 SetError(kErrorCannotClaimInterface); |
900 AsyncWorkCompleted(); | 900 AsyncWorkCompleted(); |
901 } | 901 } |
902 | 902 |
903 UsbReleaseInterfaceFunction::UsbReleaseInterfaceFunction() { | 903 UsbReleaseInterfaceFunction::UsbReleaseInterfaceFunction() { |
904 } | 904 } |
905 | 905 |
906 UsbReleaseInterfaceFunction::~UsbReleaseInterfaceFunction() { | 906 UsbReleaseInterfaceFunction::~UsbReleaseInterfaceFunction() { |
907 } | 907 } |
908 | 908 |
909 bool UsbReleaseInterfaceFunction::Prepare() { | 909 bool UsbReleaseInterfaceFunction::Prepare() { |
910 parameters_ = ReleaseInterface::Params::Create(*args_); | 910 parameters_ = ReleaseInterface::Params::Create(*args_); |
911 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 911 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
912 return true; | 912 return true; |
913 } | 913 } |
914 | 914 |
915 void UsbReleaseInterfaceFunction::AsyncWorkStart() { | 915 void UsbReleaseInterfaceFunction::AsyncWorkStart() { |
916 scoped_refptr<UsbDeviceHandle> device_handle = | 916 scoped_refptr<UsbDeviceHandle> device_handle = |
917 GetDeviceHandleOrCompleteWithError(parameters_->handle); | 917 GetDeviceHandleOrCompleteWithError(parameters_->handle); |
918 if (!device_handle) | 918 if (!device_handle.get()) |
919 return; | 919 return; |
920 | 920 |
921 bool success = device_handle->ReleaseInterface(parameters_->interface_number); | 921 bool success = device_handle->ReleaseInterface(parameters_->interface_number); |
922 if (!success) | 922 if (!success) |
923 SetError(kErrorCannotReleaseInterface); | 923 SetError(kErrorCannotReleaseInterface); |
924 AsyncWorkCompleted(); | 924 AsyncWorkCompleted(); |
925 } | 925 } |
926 | 926 |
927 UsbSetInterfaceAlternateSettingFunction:: | 927 UsbSetInterfaceAlternateSettingFunction:: |
928 UsbSetInterfaceAlternateSettingFunction() { | 928 UsbSetInterfaceAlternateSettingFunction() { |
929 } | 929 } |
930 | 930 |
931 UsbSetInterfaceAlternateSettingFunction:: | 931 UsbSetInterfaceAlternateSettingFunction:: |
932 ~UsbSetInterfaceAlternateSettingFunction() { | 932 ~UsbSetInterfaceAlternateSettingFunction() { |
933 } | 933 } |
934 | 934 |
935 bool UsbSetInterfaceAlternateSettingFunction::Prepare() { | 935 bool UsbSetInterfaceAlternateSettingFunction::Prepare() { |
936 parameters_ = SetInterfaceAlternateSetting::Params::Create(*args_); | 936 parameters_ = SetInterfaceAlternateSetting::Params::Create(*args_); |
937 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 937 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
938 return true; | 938 return true; |
939 } | 939 } |
940 | 940 |
941 void UsbSetInterfaceAlternateSettingFunction::AsyncWorkStart() { | 941 void UsbSetInterfaceAlternateSettingFunction::AsyncWorkStart() { |
942 scoped_refptr<UsbDeviceHandle> device_handle = | 942 scoped_refptr<UsbDeviceHandle> device_handle = |
943 GetDeviceHandleOrCompleteWithError(parameters_->handle); | 943 GetDeviceHandleOrCompleteWithError(parameters_->handle); |
944 if (!device_handle) | 944 if (!device_handle.get()) |
945 return; | 945 return; |
946 | 946 |
947 bool success = device_handle->SetInterfaceAlternateSetting( | 947 bool success = device_handle->SetInterfaceAlternateSetting( |
948 parameters_->interface_number, parameters_->alternate_setting); | 948 parameters_->interface_number, parameters_->alternate_setting); |
949 if (!success) | 949 if (!success) |
950 SetError(kErrorCannotSetInterfaceAlternateSetting); | 950 SetError(kErrorCannotSetInterfaceAlternateSetting); |
951 | 951 |
952 AsyncWorkCompleted(); | 952 AsyncWorkCompleted(); |
953 } | 953 } |
954 | 954 |
955 UsbControlTransferFunction::UsbControlTransferFunction() { | 955 UsbControlTransferFunction::UsbControlTransferFunction() { |
956 } | 956 } |
957 | 957 |
958 UsbControlTransferFunction::~UsbControlTransferFunction() { | 958 UsbControlTransferFunction::~UsbControlTransferFunction() { |
959 } | 959 } |
960 | 960 |
961 bool UsbControlTransferFunction::Prepare() { | 961 bool UsbControlTransferFunction::Prepare() { |
962 parameters_ = ControlTransfer::Params::Create(*args_); | 962 parameters_ = ControlTransfer::Params::Create(*args_); |
963 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 963 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
964 return true; | 964 return true; |
965 } | 965 } |
966 | 966 |
967 void UsbControlTransferFunction::AsyncWorkStart() { | 967 void UsbControlTransferFunction::AsyncWorkStart() { |
968 scoped_refptr<UsbDeviceHandle> device_handle = | 968 scoped_refptr<UsbDeviceHandle> device_handle = |
969 GetDeviceHandleOrCompleteWithError(parameters_->handle); | 969 GetDeviceHandleOrCompleteWithError(parameters_->handle); |
970 if (!device_handle) | 970 if (!device_handle.get()) |
971 return; | 971 return; |
972 | 972 |
973 const ControlTransferInfo& transfer = parameters_->transfer_info; | 973 const ControlTransferInfo& transfer = parameters_->transfer_info; |
974 | 974 |
975 UsbEndpointDirection direction; | 975 UsbEndpointDirection direction; |
976 UsbDeviceHandle::TransferRequestType request_type; | 976 UsbDeviceHandle::TransferRequestType request_type; |
977 UsbDeviceHandle::TransferRecipient recipient; | 977 UsbDeviceHandle::TransferRecipient recipient; |
978 size_t size = 0; | 978 size_t size = 0; |
979 | 979 |
980 if (!ConvertDirectionSafely(transfer.direction, &direction) || | 980 if (!ConvertDirectionSafely(transfer.direction, &direction) || |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 | 1017 |
1018 bool UsbBulkTransferFunction::Prepare() { | 1018 bool UsbBulkTransferFunction::Prepare() { |
1019 parameters_ = BulkTransfer::Params::Create(*args_); | 1019 parameters_ = BulkTransfer::Params::Create(*args_); |
1020 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 1020 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
1021 return true; | 1021 return true; |
1022 } | 1022 } |
1023 | 1023 |
1024 void UsbBulkTransferFunction::AsyncWorkStart() { | 1024 void UsbBulkTransferFunction::AsyncWorkStart() { |
1025 scoped_refptr<UsbDeviceHandle> device_handle = | 1025 scoped_refptr<UsbDeviceHandle> device_handle = |
1026 GetDeviceHandleOrCompleteWithError(parameters_->handle); | 1026 GetDeviceHandleOrCompleteWithError(parameters_->handle); |
1027 if (!device_handle) | 1027 if (!device_handle.get()) |
1028 return; | 1028 return; |
1029 | 1029 |
1030 const GenericTransferInfo& transfer = parameters_->transfer_info; | 1030 const GenericTransferInfo& transfer = parameters_->transfer_info; |
1031 | 1031 |
1032 UsbEndpointDirection direction; | 1032 UsbEndpointDirection direction; |
1033 size_t size = 0; | 1033 size_t size = 0; |
1034 | 1034 |
1035 if (!ConvertDirectionSafely(transfer.direction, &direction)) { | 1035 if (!ConvertDirectionSafely(transfer.direction, &direction)) { |
1036 AsyncWorkCompleted(); | 1036 AsyncWorkCompleted(); |
1037 return; | 1037 return; |
(...skipping 28 matching lines...) Expand all Loading... |
1066 | 1066 |
1067 bool UsbInterruptTransferFunction::Prepare() { | 1067 bool UsbInterruptTransferFunction::Prepare() { |
1068 parameters_ = InterruptTransfer::Params::Create(*args_); | 1068 parameters_ = InterruptTransfer::Params::Create(*args_); |
1069 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 1069 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
1070 return true; | 1070 return true; |
1071 } | 1071 } |
1072 | 1072 |
1073 void UsbInterruptTransferFunction::AsyncWorkStart() { | 1073 void UsbInterruptTransferFunction::AsyncWorkStart() { |
1074 scoped_refptr<UsbDeviceHandle> device_handle = | 1074 scoped_refptr<UsbDeviceHandle> device_handle = |
1075 GetDeviceHandleOrCompleteWithError(parameters_->handle); | 1075 GetDeviceHandleOrCompleteWithError(parameters_->handle); |
1076 if (!device_handle) | 1076 if (!device_handle.get()) |
1077 return; | 1077 return; |
1078 | 1078 |
1079 const GenericTransferInfo& transfer = parameters_->transfer_info; | 1079 const GenericTransferInfo& transfer = parameters_->transfer_info; |
1080 | 1080 |
1081 UsbEndpointDirection direction; | 1081 UsbEndpointDirection direction; |
1082 size_t size = 0; | 1082 size_t size = 0; |
1083 | 1083 |
1084 if (!ConvertDirectionSafely(transfer.direction, &direction)) { | 1084 if (!ConvertDirectionSafely(transfer.direction, &direction)) { |
1085 AsyncWorkCompleted(); | 1085 AsyncWorkCompleted(); |
1086 return; | 1086 return; |
(...skipping 28 matching lines...) Expand all Loading... |
1115 | 1115 |
1116 bool UsbIsochronousTransferFunction::Prepare() { | 1116 bool UsbIsochronousTransferFunction::Prepare() { |
1117 parameters_ = IsochronousTransfer::Params::Create(*args_); | 1117 parameters_ = IsochronousTransfer::Params::Create(*args_); |
1118 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 1118 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
1119 return true; | 1119 return true; |
1120 } | 1120 } |
1121 | 1121 |
1122 void UsbIsochronousTransferFunction::AsyncWorkStart() { | 1122 void UsbIsochronousTransferFunction::AsyncWorkStart() { |
1123 scoped_refptr<UsbDeviceHandle> device_handle = | 1123 scoped_refptr<UsbDeviceHandle> device_handle = |
1124 GetDeviceHandleOrCompleteWithError(parameters_->handle); | 1124 GetDeviceHandleOrCompleteWithError(parameters_->handle); |
1125 if (!device_handle) | 1125 if (!device_handle.get()) |
1126 return; | 1126 return; |
1127 | 1127 |
1128 const IsochronousTransferInfo& transfer = parameters_->transfer_info; | 1128 const IsochronousTransferInfo& transfer = parameters_->transfer_info; |
1129 const GenericTransferInfo& generic_transfer = transfer.transfer_info; | 1129 const GenericTransferInfo& generic_transfer = transfer.transfer_info; |
1130 | 1130 |
1131 size_t size = 0; | 1131 size_t size = 0; |
1132 UsbEndpointDirection direction; | 1132 UsbEndpointDirection direction; |
1133 | 1133 |
1134 if (!ConvertDirectionSafely(generic_transfer.direction, &direction)) { | 1134 if (!ConvertDirectionSafely(generic_transfer.direction, &direction)) { |
1135 AsyncWorkCompleted(); | 1135 AsyncWorkCompleted(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 | 1182 |
1183 bool UsbResetDeviceFunction::Prepare() { | 1183 bool UsbResetDeviceFunction::Prepare() { |
1184 parameters_ = ResetDevice::Params::Create(*args_); | 1184 parameters_ = ResetDevice::Params::Create(*args_); |
1185 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 1185 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
1186 return true; | 1186 return true; |
1187 } | 1187 } |
1188 | 1188 |
1189 void UsbResetDeviceFunction::AsyncWorkStart() { | 1189 void UsbResetDeviceFunction::AsyncWorkStart() { |
1190 scoped_refptr<UsbDeviceHandle> device_handle = | 1190 scoped_refptr<UsbDeviceHandle> device_handle = |
1191 GetDeviceHandleOrCompleteWithError(parameters_->handle); | 1191 GetDeviceHandleOrCompleteWithError(parameters_->handle); |
1192 if (!device_handle) | 1192 if (!device_handle.get()) |
1193 return; | 1193 return; |
1194 | 1194 |
1195 bool success = device_handle->ResetDevice(); | 1195 bool success = device_handle->ResetDevice(); |
1196 if (!success) { | 1196 if (!success) { |
1197 device_handle->Close(); | 1197 device_handle->Close(); |
1198 RemoveUsbDeviceResource(parameters_->handle.handle); | 1198 RemoveUsbDeviceResource(parameters_->handle.handle); |
1199 SetResult(new base::FundamentalValue(false)); | 1199 SetResult(new base::FundamentalValue(false)); |
1200 CompleteWithError(kErrorResetDevice); | 1200 CompleteWithError(kErrorResetDevice); |
1201 return; | 1201 return; |
1202 } | 1202 } |
1203 | 1203 |
1204 SetResult(new base::FundamentalValue(true)); | 1204 SetResult(new base::FundamentalValue(true)); |
1205 AsyncWorkCompleted(); | 1205 AsyncWorkCompleted(); |
1206 } | 1206 } |
1207 | 1207 |
1208 } // namespace extensions | 1208 } // namespace extensions |
OLD | NEW |