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

Unified Diff: chrome/browser/usb/usb_device.cc

Issue 236203019: Move UsbService to its own component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move usb_service component symbols into usb_service namespace Created 6 years, 8 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 | « chrome/browser/usb/usb_device.h ('k') | chrome/browser/usb/usb_device_handle.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/usb/usb_device.cc
diff --git a/chrome/browser/usb/usb_device.cc b/chrome/browser/usb/usb_device.cc
deleted file mode 100644
index 8f71d507ef6e8509736db8fed5342e224470a9cd..0000000000000000000000000000000000000000
--- a/chrome/browser/usb/usb_device.cc
+++ /dev/null
@@ -1,154 +0,0 @@
-// Copyright 2013 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 "chrome/browser/usb/usb_device.h"
-
-#include <algorithm>
-
-#include "base/stl_util.h"
-#include "chrome/browser/usb/usb_context.h"
-#include "chrome/browser/usb/usb_device_handle.h"
-#include "content/public/browser/browser_thread.h"
-#include "third_party/libusb/src/libusb/libusb.h"
-
-#if defined(OS_CHROMEOS)
-#include "base/sys_info.h"
-#include "chromeos/dbus/dbus_thread_manager.h"
-#include "chromeos/dbus/permission_broker_client.h"
-#endif // defined(OS_CHROMEOS)
-
-using content::BrowserThread;
-
-namespace {
-
-#if defined(OS_CHROMEOS)
-void OnRequestUsbAccessReplied(
- const base::Callback<void(bool success)>& callback,
- bool success) {
- BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
- base::Bind(callback, success));
-}
-#endif // defined(OS_CHROMEOS)
-
-} // namespace
-
-UsbDevice::UsbDevice(
- scoped_refptr<UsbContext> context,
- PlatformUsbDevice platform_device,
- uint16 vendor_id,
- uint16 product_id,
- uint32 unique_id)
- : platform_device_(platform_device),
- vendor_id_(vendor_id),
- product_id_(product_id),
- unique_id_(unique_id),
- context_(context) {
- CHECK(platform_device) << "platform_device cannot be NULL";
- libusb_ref_device(platform_device);
-}
-
-UsbDevice::UsbDevice()
- : platform_device_(NULL),
- vendor_id_(0),
- product_id_(0),
- unique_id_(0),
- context_(NULL) {
-}
-
-UsbDevice::~UsbDevice() {
- DCHECK(thread_checker_.CalledOnValidThread());
- for (HandlesVector::iterator it = handles_.begin();
- it != handles_.end();
- ++it) {
- (*it)->InternalClose();
- }
- STLClearObject(&handles_);
- libusb_unref_device(platform_device_);
-}
-
-#if defined(OS_CHROMEOS)
-
-void UsbDevice::RequestUsbAcess(
- int interface_id,
- const base::Callback<void(bool success)>& callback) {
- DCHECK(thread_checker_.CalledOnValidThread());
-
- // ChromeOS builds on non-ChromeOS machines (dev) should not attempt to
- // use permission broker.
- if (base::SysInfo::IsRunningOnChromeOS()) {
- chromeos::PermissionBrokerClient* client =
- chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient();
- DCHECK(client) << "Could not get permission broker client.";
- if (!client) {
- callback.Run(false);
- return;
- }
-
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&chromeos::PermissionBrokerClient::RequestUsbAccess,
- base::Unretained(client),
- this->vendor_id_,
- this->product_id_,
- interface_id,
- base::Bind(&OnRequestUsbAccessReplied, callback)));
- }
-}
-
-#endif
-
-scoped_refptr<UsbDeviceHandle> UsbDevice::Open() {
- DCHECK(thread_checker_.CalledOnValidThread());
- PlatformUsbDeviceHandle handle;
- int rv = libusb_open(platform_device_, &handle);
- if (LIBUSB_SUCCESS == rv) {
- scoped_refptr<UsbConfigDescriptor> interfaces = ListInterfaces();
- if (!interfaces)
- return NULL;
- scoped_refptr<UsbDeviceHandle> device_handle =
- new UsbDeviceHandle(context_, this, handle, interfaces);
- handles_.push_back(device_handle);
- return device_handle;
- }
- return NULL;
-}
-
-bool UsbDevice::Close(scoped_refptr<UsbDeviceHandle> handle) {
- DCHECK(thread_checker_.CalledOnValidThread());
-
- for (HandlesVector::iterator it = handles_.begin();
- it != handles_.end();
- ++it) {
- if (*it == handle) {
- (*it)->InternalClose();
- handles_.erase(it);
- return true;
- }
- }
- return false;
-}
-
-scoped_refptr<UsbConfigDescriptor> UsbDevice::ListInterfaces() {
- DCHECK(thread_checker_.CalledOnValidThread());
-
- PlatformUsbConfigDescriptor platform_config;
- const int list_result =
- libusb_get_active_config_descriptor(platform_device_, &platform_config);
- if (list_result == 0)
- return new UsbConfigDescriptor(platform_config);
-
- return NULL;
-}
-
-void UsbDevice::OnDisconnect() {
- DCHECK(thread_checker_.CalledOnValidThread());
- HandlesVector handles;
- swap(handles, handles_);
- for (std::vector<scoped_refptr<UsbDeviceHandle> >::iterator it =
- handles.begin();
- it != handles.end();
- ++it) {
- (*it)->InternalClose();
- }
-}
« no previous file with comments | « chrome/browser/usb/usb_device.h ('k') | chrome/browser/usb/usb_device_handle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698