| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <numeric> | 9 #include <numeric> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 output.remote_wakeup = input.remote_wakeup; | 361 output.remote_wakeup = input.remote_wakeup; |
| 362 output.max_power = input.maximum_power; | 362 output.max_power = input.maximum_power; |
| 363 for (const UsbInterfaceDescriptor& input_interface : input.interfaces) | 363 for (const UsbInterfaceDescriptor& input_interface : input.interfaces) |
| 364 output.interfaces.push_back(ConvertInterfaceDescriptor(input_interface)); | 364 output.interfaces.push_back(ConvertInterfaceDescriptor(input_interface)); |
| 365 output.extra_data.assign(input.extra_data.begin(), input.extra_data.end()); | 365 output.extra_data.assign(input.extra_data.begin(), input.extra_data.end()); |
| 366 return output; | 366 return output; |
| 367 } | 367 } |
| 368 | 368 |
| 369 void ConvertDeviceFilter(const usb::DeviceFilter& input, | 369 void ConvertDeviceFilter(const usb::DeviceFilter& input, |
| 370 UsbDeviceFilter* output) { | 370 UsbDeviceFilter* output) { |
| 371 if (input.vendor_id) { | 371 if (input.vendor_id) |
| 372 output->SetVendorId(*input.vendor_id); | 372 output->vendor_id = *input.vendor_id; |
| 373 } | 373 if (input.product_id) |
| 374 if (input.product_id) { | 374 output->product_id = *input.product_id; |
| 375 output->SetProductId(*input.product_id); | 375 if (input.interface_class) |
| 376 } | 376 output->interface_class = *input.interface_class; |
| 377 if (input.interface_class) { | 377 if (input.interface_subclass) |
| 378 output->SetInterfaceClass(*input.interface_class); | 378 output->interface_subclass = *input.interface_subclass; |
| 379 } | 379 if (input.interface_protocol) |
| 380 if (input.interface_subclass) { | 380 output->interface_protocol = *input.interface_protocol; |
| 381 output->SetInterfaceSubclass(*input.interface_subclass); | |
| 382 } | |
| 383 if (input.interface_protocol) { | |
| 384 output->SetInterfaceProtocol(*input.interface_protocol); | |
| 385 } | |
| 386 } | 381 } |
| 387 | 382 |
| 388 } // namespace | 383 } // namespace |
| 389 | 384 |
| 390 UsbPermissionCheckingFunction::UsbPermissionCheckingFunction() | 385 UsbPermissionCheckingFunction::UsbPermissionCheckingFunction() |
| 391 : device_permissions_manager_(nullptr) { | 386 : device_permissions_manager_(nullptr) { |
| 392 } | 387 } |
| 393 | 388 |
| 394 UsbPermissionCheckingFunction::~UsbPermissionCheckingFunction() { | 389 UsbPermissionCheckingFunction::~UsbPermissionCheckingFunction() { |
| 395 } | 390 } |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 586 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 592 | 587 |
| 593 if (parameters->options.filters) { | 588 if (parameters->options.filters) { |
| 594 filters_.resize(parameters->options.filters->size()); | 589 filters_.resize(parameters->options.filters->size()); |
| 595 for (size_t i = 0; i < parameters->options.filters->size(); ++i) { | 590 for (size_t i = 0; i < parameters->options.filters->size(); ++i) { |
| 596 ConvertDeviceFilter(parameters->options.filters->at(i), &filters_[i]); | 591 ConvertDeviceFilter(parameters->options.filters->at(i), &filters_[i]); |
| 597 } | 592 } |
| 598 } | 593 } |
| 599 if (parameters->options.vendor_id) { | 594 if (parameters->options.vendor_id) { |
| 600 filters_.resize(filters_.size() + 1); | 595 filters_.resize(filters_.size() + 1); |
| 601 filters_.back().SetVendorId(*parameters->options.vendor_id); | 596 filters_.back().vendor_id = *parameters->options.vendor_id; |
| 602 if (parameters->options.product_id) { | 597 if (parameters->options.product_id) |
| 603 filters_.back().SetProductId(*parameters->options.product_id); | 598 filters_.back().product_id = *parameters->options.product_id; |
| 604 } | |
| 605 } | 599 } |
| 606 | 600 |
| 607 UsbService* service = device::DeviceClient::Get()->GetUsbService(); | 601 UsbService* service = device::DeviceClient::Get()->GetUsbService(); |
| 608 if (!service) { | 602 if (!service) { |
| 609 return RespondNow(Error(kErrorInitService)); | 603 return RespondNow(Error(kErrorInitService)); |
| 610 } | 604 } |
| 611 | 605 |
| 612 service->GetDevices( | 606 service->GetDevices( |
| 613 base::Bind(&UsbGetDevicesFunction::OnGetDevicesComplete, this)); | 607 base::Bind(&UsbGetDevicesFunction::OnGetDevicesComplete, this)); |
| 614 return RespondLater(); | 608 return RespondLater(); |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1295 | 1289 |
| 1296 std::unique_ptr<base::ListValue> error_args(new base::ListValue()); | 1290 std::unique_ptr<base::ListValue> error_args(new base::ListValue()); |
| 1297 error_args->AppendBoolean(false); | 1291 error_args->AppendBoolean(false); |
| 1298 // Using ErrorWithArguments is discouraged but required to maintain | 1292 // Using ErrorWithArguments is discouraged but required to maintain |
| 1299 // compatibility with existing applications. | 1293 // compatibility with existing applications. |
| 1300 Respond(ErrorWithArguments(std::move(error_args), kErrorResetDevice)); | 1294 Respond(ErrorWithArguments(std::move(error_args), kErrorResetDevice)); |
| 1301 } | 1295 } |
| 1302 } | 1296 } |
| 1303 | 1297 |
| 1304 } // namespace extensions | 1298 } // namespace extensions |
| OLD | NEW |