Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1411)

Unified Diff: device/devices_app/usb/device_impl.cc

Issue 1352683006: Move device opening from DeviceManager to Device. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/devices_app/usb/device_impl.h ('k') | device/devices_app/usb/device_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/devices_app/usb/device_impl.cc
diff --git a/device/devices_app/usb/device_impl.cc b/device/devices_app/usb/device_impl.cc
index 54a7c2bab65a09c89e2ea5023c318564d56d7114..73c5d77adbf47953b43cc2283c50de5761469a39 100644
--- a/device/devices_app/usb/device_impl.cc
+++ b/device/devices_app/usb/device_impl.cc
@@ -39,12 +39,9 @@ scoped_refptr<net::IOBuffer> CreateTransferBuffer(size_t size) {
} // namespace
-DeviceImpl::DeviceImpl(scoped_refptr<UsbDeviceHandle> device_handle,
+DeviceImpl::DeviceImpl(scoped_refptr<UsbDevice> device,
mojo::InterfaceRequest<Device> request)
- : binding_(this, request.Pass()),
- device_handle_(device_handle),
- weak_factory_(this) {
-}
+ : binding_(this, request.Pass()), device_(device), weak_factory_(this) {}
DeviceImpl::~DeviceImpl() {
CloseHandle();
@@ -56,6 +53,12 @@ void DeviceImpl::CloseHandle() {
device_handle_ = nullptr;
}
+void DeviceImpl::OnOpen(const OpenCallback& callback,
+ scoped_refptr<UsbDeviceHandle> handle) {
+ device_handle_ = handle;
+ callback.Run(handle ? OPEN_DEVICE_ERROR_OK : OPEN_DEVICE_ERROR_ACCESS_DENIED);
+}
+
void DeviceImpl::OnTransferIn(const MojoTransferInCallback& callback,
UsbTransferStatus status,
scoped_refptr<net::IOBuffer> buffer,
@@ -107,28 +110,23 @@ void DeviceImpl::OnIsochronousTransferOut(
callback.Run(mojo::ConvertTo<TransferStatus>(status));
}
-void DeviceImpl::Close(const CloseCallback& callback) {
- CloseHandle();
- callback.Run();
+void DeviceImpl::GetDeviceInfo(const GetDeviceInfoCallback& callback) {
+ callback.Run(DeviceInfo::From(*device_));
}
-void DeviceImpl::GetDeviceInfo(const GetDeviceInfoCallback& callback) {
- if (!device_handle_) {
- callback.Run(DeviceInfoPtr());
- return;
- }
+void DeviceImpl::GetConfiguration(const GetConfigurationCallback& callback) {
+ const UsbConfigDescriptor* config = device_->GetActiveConfiguration();
+ callback.Run(config ? ConfigurationInfo::From(*config) : nullptr);
+}
- // TODO(rockot/reillyg): Converting configuration info should be done in the
- // TypeConverter, but GetConfiguration() is non-const so we do it here for
- // now.
- DeviceInfoPtr info = DeviceInfo::From(*device_handle_->GetDevice());
- const std::vector<UsbConfigDescriptor>& configs =
- device_handle_->GetDevice()->configurations();
- info->configurations = mojo::Array<ConfigurationInfoPtr>::New(configs.size());
- for (size_t i = 0; i < configs.size(); ++i) {
- info->configurations[i] = ConfigurationInfo::From(configs[i]);
- }
- callback.Run(info.Pass());
+void DeviceImpl::Open(const OpenCallback& callback) {
+ device_->Open(
+ base::Bind(&DeviceImpl::OnOpen, weak_factory_.GetWeakPtr(), callback));
+}
+
+void DeviceImpl::Close(const CloseCallback& callback) {
+ CloseHandle();
+ callback.Run();
}
void DeviceImpl::SetConfiguration(uint8_t value,
« no previous file with comments | « device/devices_app/usb/device_impl.h ('k') | device/devices_app/usb/device_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698