| 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 <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" |
| 11 #include "chrome/browser/extensions/api/usb/usb_device_resource.h" | 11 #include "chrome/browser/extensions/api/usb/usb_device_resource.h" |
| 12 #include "chrome/browser/extensions/extension_system.h" | 12 #include "chrome/browser/extensions/extension_system.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/usb/usb_service.h" | 14 #include "chrome/browser/usb/usb_service.h" |
| 15 #include "chrome/browser/usb/usb_service_factory.h" | 15 #include "chrome/browser/usb/usb_service_factory.h" |
| 16 #include "chrome/common/extensions/api/usb.h" | 16 #include "chrome/common/extensions/api/usb.h" |
| 17 #include "chrome/common/extensions/permissions/permissions_data.h" |
| 17 #include "chrome/common/extensions/permissions/usb_device_permission.h" | 18 #include "chrome/common/extensions/permissions/usb_device_permission.h" |
| 18 | 19 |
| 19 namespace BulkTransfer = extensions::api::usb::BulkTransfer; | 20 namespace BulkTransfer = extensions::api::usb::BulkTransfer; |
| 20 namespace ClaimInterface = extensions::api::usb::ClaimInterface; | 21 namespace ClaimInterface = extensions::api::usb::ClaimInterface; |
| 21 namespace CloseDevice = extensions::api::usb::CloseDevice; | 22 namespace CloseDevice = extensions::api::usb::CloseDevice; |
| 22 namespace ControlTransfer = extensions::api::usb::ControlTransfer; | 23 namespace ControlTransfer = extensions::api::usb::ControlTransfer; |
| 23 namespace FindDevices = extensions::api::usb::FindDevices; | 24 namespace FindDevices = extensions::api::usb::FindDevices; |
| 24 namespace InterruptTransfer = extensions::api::usb::InterruptTransfer; | 25 namespace InterruptTransfer = extensions::api::usb::InterruptTransfer; |
| 25 namespace IsochronousTransfer = extensions::api::usb::IsochronousTransfer; | 26 namespace IsochronousTransfer = extensions::api::usb::IsochronousTransfer; |
| 26 namespace ReleaseInterface = extensions::api::usb::ReleaseInterface; | 27 namespace ReleaseInterface = extensions::api::usb::ReleaseInterface; |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 Device device; | 323 Device device; |
| 323 result_->Append(PopulateDevice(manager_->Add(resource), 0, 0)); | 324 result_->Append(PopulateDevice(manager_->Add(resource), 0, 0)); |
| 324 SetResult(result_.release()); | 325 SetResult(result_.release()); |
| 325 AsyncWorkCompleted(); | 326 AsyncWorkCompleted(); |
| 326 return; | 327 return; |
| 327 } | 328 } |
| 328 | 329 |
| 329 const uint16_t vendor_id = parameters_->options.vendor_id; | 330 const uint16_t vendor_id = parameters_->options.vendor_id; |
| 330 const uint16_t product_id = parameters_->options.product_id; | 331 const uint16_t product_id = parameters_->options.product_id; |
| 331 UsbDevicePermission::CheckParam param(vendor_id, product_id); | 332 UsbDevicePermission::CheckParam param(vendor_id, product_id); |
| 332 if (!GetExtension()->CheckAPIPermissionWithParam( | 333 if (!PermissionsData::CheckAPIPermissionWithParam( |
| 333 APIPermission::kUsbDevice, ¶m)) { | 334 GetExtension(), APIPermission::kUsbDevice, ¶m)) { |
| 334 LOG(WARNING) << "Insufficient permissions to access device."; | 335 LOG(WARNING) << "Insufficient permissions to access device."; |
| 335 CompleteWithError(kErrorPermissionDenied); | 336 CompleteWithError(kErrorPermissionDenied); |
| 336 return; | 337 return; |
| 337 } | 338 } |
| 338 | 339 |
| 339 UsbService* const service = UsbServiceFactory::GetInstance()->GetForProfile( | 340 UsbService* const service = UsbServiceFactory::GetInstance()->GetForProfile( |
| 340 profile()); | 341 profile()); |
| 341 if (!service) { | 342 if (!service) { |
| 342 LOG(WARNING) << "Could not get UsbService for active profile."; | 343 LOG(WARNING) << "Could not get UsbService for active profile."; |
| 343 CompleteWithError(kErrorNoDevice); | 344 CompleteWithError(kErrorNoDevice); |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 } | 735 } |
| 735 | 736 |
| 736 void UsbResetDeviceFunction::OnError() { | 737 void UsbResetDeviceFunction::OnError() { |
| 737 RemoveUsbDeviceResource(parameters_->device.handle); | 738 RemoveUsbDeviceResource(parameters_->device.handle); |
| 738 SetError(kErrorResetDevice); | 739 SetError(kErrorResetDevice); |
| 739 SetResult(Value::CreateBooleanValue(false)); | 740 SetResult(Value::CreateBooleanValue(false)); |
| 740 AsyncWorkCompleted(); | 741 AsyncWorkCompleted(); |
| 741 } | 742 } |
| 742 | 743 |
| 743 } // namespace extensions | 744 } // namespace extensions |
| OLD | NEW |