Commit 9fd47266 authored by reillyg's avatar reillyg Committed by Commit bot

Remove the usbPrivate API.

This API was to be used by WebUI that enumerates USB devices. This is
being reimplemented as native UI so the API is no longer necessary.

BUG=

Review URL: https://codereview.chromium.org/617933002

Cr-Commit-Position: refs/heads/master@{#297548}
parent d4470ca3
...@@ -223,8 +223,6 @@ source_set("browser") { ...@@ -223,8 +223,6 @@ source_set("browser") {
"api/usb/usb_api.h", "api/usb/usb_api.h",
"api/usb/usb_device_resource.cc", "api/usb/usb_device_resource.cc",
"api/usb/usb_device_resource.h", "api/usb/usb_device_resource.h",
"api/usb_private/usb_private_api.cc",
"api/usb_private/usb_private_api.h",
"api/web_request/form_data_parser.cc", "api/web_request/form_data_parser.cc",
"api/web_request/form_data_parser.h", "api/web_request/form_data_parser.h",
"api/web_request/upload_data_presenter.cc", "api/web_request/upload_data_presenter.cc",
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "extensions/browser/api/usb_private/usb_private_api.h"
#include <string>
#include <vector>
#include "base/memory/ref_counted.h"
#include "base/strings/utf_string_conversions.h"
#include "device/core/device_client.h"
#include "device/usb/usb_device_filter.h"
#include "device/usb/usb_device_handle.h"
#include "device/usb/usb_ids.h"
#include "device/usb/usb_service.h"
#include "extensions/common/api/usb_private.h"
namespace usb = extensions::core_api::usb;
namespace usb_private = extensions::core_api::usb_private;
namespace GetDevices = usb_private::GetDevices;
namespace GetDeviceInfo = usb_private::GetDeviceInfo;
using content::BrowserThread;
using device::UsbDevice;
using device::UsbDeviceFilter;
using device::UsbDeviceHandle;
using device::UsbService;
typedef std::vector<scoped_refptr<UsbDevice> > DeviceVector;
namespace {
const char kErrorInitService[] = "Failed to initialize USB service.";
const char kErrorNoDevice[] = "No such device.";
} // namespace
namespace extensions {
UsbPrivateGetDevicesFunction::UsbPrivateGetDevicesFunction() {
}
UsbPrivateGetDevicesFunction::~UsbPrivateGetDevicesFunction() {
}
bool UsbPrivateGetDevicesFunction::Prepare() {
parameters_ = GetDevices::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(parameters_.get());
return true;
}
void UsbPrivateGetDevicesFunction::AsyncWorkStart() {
UsbService* service = device::DeviceClient::Get()->GetUsbService();
if (!service) {
CompleteWithError(kErrorInitService);
return;
}
std::vector<UsbDeviceFilter> filters;
filters.resize(parameters_->filters.size());
for (size_t i = 0; i < parameters_->filters.size(); ++i) {
CreateDeviceFilter(*parameters_->filters[i].get(), &filters[i]);
}
DeviceVector devices;
service->GetDevices(&devices);
scoped_ptr<base::ListValue> result(new base::ListValue());
for (DeviceVector::iterator it = devices.begin(); it != devices.end(); ++it) {
scoped_refptr<UsbDevice> device = *it;
if (filters.empty() || UsbDeviceFilter::MatchesAny(device, filters)) {
result->Append(new base::FundamentalValue((int)device->unique_id()));
}
}
SetResult(result.release());
AsyncWorkCompleted();
}
UsbPrivateGetDeviceInfoFunction::UsbPrivateGetDeviceInfoFunction() {
}
UsbPrivateGetDeviceInfoFunction::~UsbPrivateGetDeviceInfoFunction() {
}
bool UsbPrivateGetDeviceInfoFunction::Prepare() {
parameters_ = GetDeviceInfo::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(parameters_.get());
return true;
}
void UsbPrivateGetDeviceInfoFunction::AsyncWorkStart() {
UsbService* service = device::DeviceClient::Get()->GetUsbService();
if (!service) {
CompleteWithError(kErrorInitService);
return;
}
scoped_refptr<UsbDevice> device =
service->GetDeviceById(parameters_->device_id);
if (!device.get()) {
CompleteWithError(kErrorNoDevice);
return;
}
usb_private::DeviceInfo device_info;
device_info.vendor_id = device->vendor_id();
device_info.product_id = device->product_id();
const char* name = device::UsbIds::GetVendorName(device_info.vendor_id);
if (name) {
device_info.vendor_name.reset(new std::string(name));
}
name = device::UsbIds::GetProductName(device_info.vendor_id,
device_info.product_id);
if (name) {
device_info.product_name.reset(new std::string(name));
}
base::string16 utf16;
if (device->GetManufacturer(&utf16)) {
device_info.manufacturer_string.reset(
new std::string(base::UTF16ToUTF8(utf16)));
}
if (device->GetProduct(&utf16)) {
device_info.product_string.reset(new std::string(base::UTF16ToUTF8(utf16)));
}
if (device->GetSerialNumber(&utf16)) {
device_info.serial_string.reset(new std::string(base::UTF16ToUTF8(utf16)));
}
SetResult(device_info.ToValue().release());
AsyncWorkCompleted();
}
} // namespace extensions
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef EXTENSIONS_BROWSER_API_USB_USB_PRIVATE_API_H_
#define EXTENSIONS_BROWSER_API_USB_USB_PRIVATE_API_H_
#include "extensions/browser/api/usb/usb_api.h"
#include "extensions/common/api/usb_private.h"
namespace extensions {
class UsbPrivateGetDevicesFunction : public UsbAsyncApiFunction {
public:
DECLARE_EXTENSION_FUNCTION("usbPrivate.getDevices", USBPRIVATE_GETDEVICES)
UsbPrivateGetDevicesFunction();
virtual bool Prepare() OVERRIDE;
virtual void AsyncWorkStart() OVERRIDE;
protected:
virtual ~UsbPrivateGetDevicesFunction();
private:
scoped_ptr<extensions::core_api::usb_private::GetDevices::Params> parameters_;
};
class UsbPrivateGetDeviceInfoFunction : public UsbAsyncApiFunction {
public:
DECLARE_EXTENSION_FUNCTION("usbPrivate.getDeviceInfo",
USBPRIVATE_GETDEVICEINFO)
UsbPrivateGetDeviceInfoFunction();
virtual bool Prepare() OVERRIDE;
virtual void AsyncWorkStart() OVERRIDE;
protected:
virtual ~UsbPrivateGetDeviceInfoFunction();
private:
scoped_ptr<extensions::core_api::usb_private::GetDeviceInfo::Params>
parameters_;
};
} // namespace extensions
#endif // EXTENSIONS_BROWSER_API_USB_USB_API_H_
...@@ -248,10 +248,6 @@ ...@@ -248,10 +248,6 @@
"dependencies": ["permission:usb"], "dependencies": ["permission:usb"],
"contexts": ["blessed_extension"] "contexts": ["blessed_extension"]
}, },
"usbPrivate": {
"channel": "dev",
"contexts": ["webui"]
},
"webRequest": { "webRequest": {
"dependencies": ["permission:webRequest"], "dependencies": ["permission:webRequest"],
"contexts": ["blessed_extension"] "contexts": ["blessed_extension"]
......
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
'system_storage.idl', 'system_storage.idl',
'test.json', 'test.json',
'usb.idl', 'usb.idl',
'usb_private.idl',
'web_request.json', 'web_request.json',
'web_view_internal.json', 'web_view_internal.json',
], ],
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Use the <code>chrome.usbPrivate</code> API to interact with connected USB
// devices. This API provides private extensions to the <code>chrome.usb</code>
// API which should only be available to trusted pages.
namespace usbPrivate {
dictionary DeviceInfo {
long vendorId; // idVendor from the device
long productId; // idProduct from the device
// Vendor and product names from an internal database.
DOMString? vendorName;
DOMString? productName;
// iManufacturer, iProduct and iSerial strings from the device.
DOMString? manufacturerString;
DOMString? productString;
DOMString? serialString;
};
callback GetDevicesCallback = void (long[] deviceIds);
callback GetDeviceInfoCallback = void (DeviceInfo deviceInfo);
interface Functions {
// Lists USB devices matching any of the given filters.
// |filters|: The properties to search for on target devices.
// |callback|: Invoked with a list of device IDs on complete.
static void getDevices(usb.DeviceFilter[] filters,
GetDevicesCallback callback);
// Gets basic display information about a device.
// |deviceId|: The device ID (from |getDevices|).
// |callback|: Invoked with |DeviceInfo| from the device.
static void getDeviceInfo(long deviceId, GetDeviceInfoCallback callback);
};
};
...@@ -495,8 +495,6 @@ ...@@ -495,8 +495,6 @@
'browser/api/usb/usb_api.h', 'browser/api/usb/usb_api.h',
'browser/api/usb/usb_device_resource.cc', 'browser/api/usb/usb_device_resource.cc',
'browser/api/usb/usb_device_resource.h', 'browser/api/usb/usb_device_resource.h',
'browser/api/usb_private/usb_private_api.cc',
'browser/api/usb_private/usb_private_api.h',
'browser/api/web_request/form_data_parser.cc', 'browser/api/web_request/form_data_parser.cc',
'browser/api/web_request/form_data_parser.h', 'browser/api/web_request/form_data_parser.h',
'browser/api/web_request/upload_data_presenter.cc', 'browser/api/web_request/upload_data_presenter.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment