| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/usb/usb_api.h" | 5 #include "chrome/browser/extensions/api/usb/usb_api.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "chrome/browser/extensions/api/usb/usb_device_resource.h" | 10 #include "chrome/browser/extensions/api/usb/usb_device_resource.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 profile()); | 69 profile()); |
| 70 device = service->FindDevice(parameters_->vendor_id, | 70 device = service->FindDevice(parameters_->vendor_id, |
| 71 parameters_->product_id); | 71 parameters_->product_id); |
| 72 } | 72 } |
| 73 | 73 |
| 74 if (!device) { | 74 if (!device) { |
| 75 SetResult(base::Value::CreateNullValue()); | 75 SetResult(base::Value::CreateNullValue()); |
| 76 return; | 76 return; |
| 77 } | 77 } |
| 78 | 78 |
| 79 UsbDeviceResource* const resource = new UsbDeviceResource(event_notifier_, | 79 UsbDeviceResource* const resource = new UsbDeviceResource(extension_->id(), |
| 80 event_notifier_, |
| 80 device); | 81 device); |
| 81 | 82 |
| 82 Device result; | 83 Device result; |
| 83 result.handle = manager_->Add(resource); | 84 result.handle = manager_->Add(resource); |
| 84 result.vendor_id = parameters_->vendor_id; | 85 result.vendor_id = parameters_->vendor_id; |
| 85 result.product_id = parameters_->product_id; | 86 result.product_id = parameters_->product_id; |
| 86 results_ = FindDevice::Results::Create(result); | 87 results_ = FindDevice::Results::Create(result); |
| 87 } | 88 } |
| 88 | 89 |
| 89 bool UsbFindDeviceFunction::Respond() { | 90 bool UsbFindDeviceFunction::Respond() { |
| 90 return true; | 91 return true; |
| 91 } | 92 } |
| 92 | 93 |
| 93 UsbCloseDeviceFunction::UsbCloseDeviceFunction() {} | 94 UsbCloseDeviceFunction::UsbCloseDeviceFunction() {} |
| 94 | 95 |
| 95 UsbCloseDeviceFunction::~UsbCloseDeviceFunction() {} | 96 UsbCloseDeviceFunction::~UsbCloseDeviceFunction() {} |
| 96 | 97 |
| 97 bool UsbCloseDeviceFunction::Prepare() { | 98 bool UsbCloseDeviceFunction::Prepare() { |
| 98 parameters_ = CloseDevice::Params::Create(*args_); | 99 parameters_ = CloseDevice::Params::Create(*args_); |
| 99 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 100 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
| 100 return true; | 101 return true; |
| 101 } | 102 } |
| 102 | 103 |
| 103 void UsbCloseDeviceFunction::Work() { | 104 void UsbCloseDeviceFunction::Work() { |
| 104 UsbDeviceResource* const device = manager_->Get(parameters_->device.handle); | 105 UsbDeviceResource* const device = manager_->Get(extension_->id(), |
| 106 parameters_->device.handle); |
| 105 if (device) | 107 if (device) |
| 106 device->Close(); | 108 device->Close(); |
| 107 | 109 |
| 108 manager_->Remove(parameters_->device.handle); | 110 manager_->Remove(extension_->id(), parameters_->device.handle); |
| 109 } | 111 } |
| 110 | 112 |
| 111 bool UsbCloseDeviceFunction::Respond() { | 113 bool UsbCloseDeviceFunction::Respond() { |
| 112 return true; | 114 return true; |
| 113 } | 115 } |
| 114 | 116 |
| 115 UsbControlTransferFunction::UsbControlTransferFunction() {} | 117 UsbControlTransferFunction::UsbControlTransferFunction() {} |
| 116 | 118 |
| 117 UsbControlTransferFunction::~UsbControlTransferFunction() {} | 119 UsbControlTransferFunction::~UsbControlTransferFunction() {} |
| 118 | 120 |
| 119 bool UsbControlTransferFunction::Prepare() { | 121 bool UsbControlTransferFunction::Prepare() { |
| 120 parameters_ = ControlTransfer::Params::Create(*args_); | 122 parameters_ = ControlTransfer::Params::Create(*args_); |
| 121 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 123 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
| 122 return true; | 124 return true; |
| 123 } | 125 } |
| 124 | 126 |
| 125 void UsbControlTransferFunction::Work() { | 127 void UsbControlTransferFunction::Work() { |
| 126 UsbDeviceResource* const device = manager_->Get(parameters_->device.handle); | 128 UsbDeviceResource* const device = manager_->Get(extension_->id(), |
| 129 parameters_->device.handle); |
| 127 if (device) { | 130 if (device) { |
| 128 device->ControlTransfer(parameters_->transfer_info); | 131 device->ControlTransfer(parameters_->transfer_info); |
| 129 } | 132 } |
| 130 } | 133 } |
| 131 | 134 |
| 132 bool UsbControlTransferFunction::Respond() { | 135 bool UsbControlTransferFunction::Respond() { |
| 133 return true; | 136 return true; |
| 134 } | 137 } |
| 135 | 138 |
| 136 bool UsbBulkTransferFunction::Prepare() { | 139 bool UsbBulkTransferFunction::Prepare() { |
| 137 parameters_ = BulkTransfer::Params::Create(*args_); | 140 parameters_ = BulkTransfer::Params::Create(*args_); |
| 138 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 141 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
| 139 return true; | 142 return true; |
| 140 } | 143 } |
| 141 | 144 |
| 142 UsbBulkTransferFunction::UsbBulkTransferFunction() {} | 145 UsbBulkTransferFunction::UsbBulkTransferFunction() {} |
| 143 | 146 |
| 144 UsbBulkTransferFunction::~UsbBulkTransferFunction() {} | 147 UsbBulkTransferFunction::~UsbBulkTransferFunction() {} |
| 145 | 148 |
| 146 void UsbBulkTransferFunction::Work() { | 149 void UsbBulkTransferFunction::Work() { |
| 147 UsbDeviceResource* const device = manager_->Get(parameters_->device.handle); | 150 UsbDeviceResource* const device = manager_->Get(extension_->id(), |
| 151 parameters_->device.handle); |
| 148 if (device) { | 152 if (device) { |
| 149 device->BulkTransfer(parameters_->transfer_info); | 153 device->BulkTransfer(parameters_->transfer_info); |
| 150 } | 154 } |
| 151 } | 155 } |
| 152 | 156 |
| 153 bool UsbBulkTransferFunction::Respond() { | 157 bool UsbBulkTransferFunction::Respond() { |
| 154 return true; | 158 return true; |
| 155 } | 159 } |
| 156 | 160 |
| 157 UsbInterruptTransferFunction::UsbInterruptTransferFunction() {} | 161 UsbInterruptTransferFunction::UsbInterruptTransferFunction() {} |
| 158 | 162 |
| 159 UsbInterruptTransferFunction::~UsbInterruptTransferFunction() {} | 163 UsbInterruptTransferFunction::~UsbInterruptTransferFunction() {} |
| 160 | 164 |
| 161 bool UsbInterruptTransferFunction::Prepare() { | 165 bool UsbInterruptTransferFunction::Prepare() { |
| 162 parameters_ = InterruptTransfer::Params::Create(*args_); | 166 parameters_ = InterruptTransfer::Params::Create(*args_); |
| 163 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 167 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
| 164 return true; | 168 return true; |
| 165 } | 169 } |
| 166 | 170 |
| 167 void UsbInterruptTransferFunction::Work() { | 171 void UsbInterruptTransferFunction::Work() { |
| 168 UsbDeviceResource* const device = manager_->Get(parameters_->device.handle); | 172 UsbDeviceResource* const device = manager_->Get(extension_->id(), |
| 173 parameters_->device.handle); |
| 169 if (device) { | 174 if (device) { |
| 170 device->InterruptTransfer(parameters_->transfer_info); | 175 device->InterruptTransfer(parameters_->transfer_info); |
| 171 } | 176 } |
| 172 } | 177 } |
| 173 | 178 |
| 174 bool UsbInterruptTransferFunction::Respond() { | 179 bool UsbInterruptTransferFunction::Respond() { |
| 175 return true; | 180 return true; |
| 176 } | 181 } |
| 177 | 182 |
| 178 UsbIsochronousTransferFunction::UsbIsochronousTransferFunction() {} | 183 UsbIsochronousTransferFunction::UsbIsochronousTransferFunction() {} |
| 179 | 184 |
| 180 UsbIsochronousTransferFunction::~UsbIsochronousTransferFunction() {} | 185 UsbIsochronousTransferFunction::~UsbIsochronousTransferFunction() {} |
| 181 | 186 |
| 182 bool UsbIsochronousTransferFunction::Prepare() { | 187 bool UsbIsochronousTransferFunction::Prepare() { |
| 183 parameters_ = IsochronousTransfer::Params::Create(*args_); | 188 parameters_ = IsochronousTransfer::Params::Create(*args_); |
| 184 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 189 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
| 185 return true; | 190 return true; |
| 186 } | 191 } |
| 187 | 192 |
| 188 void UsbIsochronousTransferFunction::Work() { | 193 void UsbIsochronousTransferFunction::Work() { |
| 189 UsbDeviceResource* const device = manager_->Get(parameters_->device.handle); | 194 UsbDeviceResource* const device = manager_->Get(extension_->id(), |
| 195 parameters_->device.handle); |
| 190 if (device) { | 196 if (device) { |
| 191 device->IsochronousTransfer(parameters_->transfer_info); | 197 device->IsochronousTransfer(parameters_->transfer_info); |
| 192 } | 198 } |
| 193 } | 199 } |
| 194 | 200 |
| 195 bool UsbIsochronousTransferFunction::Respond() { | 201 bool UsbIsochronousTransferFunction::Respond() { |
| 196 return true; | 202 return true; |
| 197 } | 203 } |
| 198 | 204 |
| 199 } // namespace extensions | 205 } // namespace extensions |
| OLD | NEW |