summaryrefslogtreecommitdiffstats
path: root/device/usb/mojo/device_manager_impl.h
diff options
context:
space:
mode:
authorreillyg <reillyg@chromium.org>2016-03-04 15:29:41 -0800
committerCommit bot <commit-bot@chromium.org>2016-03-04 23:30:56 +0000
commitd6d8ce13c1ab8141e85717f5832c4ad1af3128bb (patch)
tree3b3a395d6eb2d85cd37414b1b25b8ad31c80b1d9 /device/usb/mojo/device_manager_impl.h
parent765e7b178b46af51727af1972fa08e1fd902f08a (diff)
downloadchromium_src-d6d8ce13c1ab8141e85717f5832c4ad1af3128bb.zip
chromium_src-d6d8ce13c1ab8141e85717f5832c4ad1af3128bb.tar.gz
chromium_src-d6d8ce13c1ab8141e85717f5832c4ad1af3128bb.tar.bz2
Convert the PermissionProvider Mojo interface to plain C++.
This interface allows a separate Mojo service to provide permissions management for a DeviceManager instance. This will be useful if USB device handling is ever moved into a separate process but until then it adds needless complexity to the implementation because access checks are made asynchronous. Make it a normal C++ interface for now. BUG=None Review URL: https://codereview.chromium.org/1742333003 Cr-Commit-Position: refs/heads/master@{#379393}
Diffstat (limited to 'device/usb/mojo/device_manager_impl.h')
-rw-r--r--device/usb/mojo/device_manager_impl.h39
1 files changed, 12 insertions, 27 deletions
diff --git a/device/usb/mojo/device_manager_impl.h b/device/usb/mojo/device_manager_impl.h
index 85e46ce..6ddf5d1 100644
--- a/device/usb/mojo/device_manager_impl.h
+++ b/device/usb/mojo/device_manager_impl.h
@@ -14,7 +14,6 @@
#include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
#include "device/usb/public/interfaces/device_manager.mojom.h"
-#include "device/usb/public/interfaces/permission_provider.mojom.h"
#include "device/usb/usb_service.h"
#include "mojo/public/cpp/bindings/array.h"
#include "mojo/public/cpp/bindings/binding.h"
@@ -32,20 +31,17 @@ class UsbDeviceHandle;
namespace usb {
-class DeviceManagerDelegate;
+class PermissionProvider;
// Implementation of the public DeviceManager interface. This interface can be
// requested from the devices app located at "mojo:devices", if available.
-class DeviceManagerImpl : public DeviceManager,
- public device::UsbService::Observer {
+class DeviceManagerImpl : public DeviceManager, public UsbService::Observer {
public:
- using DeviceList = std::vector<scoped_refptr<UsbDevice>>;
- using DeviceMap = std::map<std::string, scoped_refptr<device::UsbDevice>>;
-
- static void Create(PermissionProviderPtr permission_provider,
+ static void Create(base::WeakPtr<PermissionProvider> permission_provider,
mojo::InterfaceRequest<DeviceManager> request);
- DeviceManagerImpl(PermissionProviderPtr permission_provider,
+ DeviceManagerImpl(base::WeakPtr<PermissionProvider> permission_provider,
+ UsbService* usb_service,
mojo::InterfaceRequest<DeviceManager> request);
~DeviceManagerImpl() override;
@@ -62,40 +58,29 @@ class DeviceManagerImpl : public DeviceManager,
mojo::InterfaceRequest<Device> device_request) override;
// Callbacks to handle the async responses from the underlying UsbService.
- void OnGetDevicePermissionCheckComplete(
- scoped_refptr<device::UsbDevice> device,
- mojo::InterfaceRequest<Device> device_request,
- mojo::Array<mojo::String> allowed_guids);
void OnGetDevices(EnumerationOptionsPtr options,
const GetDevicesCallback& callback,
- const DeviceList& devices);
+ const std::vector<scoped_refptr<UsbDevice>>& devices);
// UsbService::Observer implementation:
- void OnDeviceAdded(scoped_refptr<device::UsbDevice> device) override;
- void OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) override;
+ void OnDeviceAdded(scoped_refptr<UsbDevice> device) override;
+ void OnDeviceRemoved(scoped_refptr<UsbDevice> device) override;
void WillDestroyUsbService() override;
void MaybeRunDeviceChangesCallback();
- void OnEnumerationPermissionCheckComplete(
- const DeviceMap& devices_added,
- const DeviceMap& devices_removed,
- mojo::Array<mojo::String> allowed_guids);
- PermissionProviderPtr permission_provider_;
+ base::WeakPtr<PermissionProvider> permission_provider_;
// If there are unfinished calls to GetDeviceChanges their callbacks
// are stored in |device_change_callbacks_|. Otherwise device changes
// are collected in |devices_added_| and |devices_removed_| until the
// next call to GetDeviceChanges.
std::queue<GetDeviceChangesCallback> device_change_callbacks_;
- DeviceMap devices_added_;
- DeviceMap devices_removed_;
- // To ensure that GetDeviceChangesCallbacks are called in the correct order
- // only perform a single request to |permission_provider_| at a time.
- bool permission_request_pending_ = false;
+ std::map<std::string, DeviceInfoPtr> devices_added_;
+ std::vector<DeviceInfoPtr> devices_removed_;
UsbService* usb_service_;
- ScopedObserver<device::UsbService, device::UsbService::Observer> observer_;
+ ScopedObserver<UsbService, UsbService::Observer> observer_;
mojo::Closure connection_error_handler_;