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

Side by Side Diff: device/devices_app/usb/device_manager_impl.h

Issue 1342663003: Pass full Mojo USB DeviceInfo object with removal notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. 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 unified diff | Download patch
« no previous file with comments | « no previous file | device/devices_app/usb/device_manager_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #ifndef DEVICE_USB_DEVICE_MANAGER_IMPL_H_ 5 #ifndef DEVICE_USB_DEVICE_MANAGER_IMPL_H_
6 #define DEVICE_USB_DEVICE_MANAGER_IMPL_H_ 6 #define DEVICE_USB_DEVICE_MANAGER_IMPL_H_
7 7
8 #include <queue> 8 #include <queue>
9 #include <set> 9 #include <set>
10 10
(...skipping 19 matching lines...) Expand all
30 class UsbDeviceHandle; 30 class UsbDeviceHandle;
31 31
32 namespace usb { 32 namespace usb {
33 33
34 class DeviceManagerDelegate; 34 class DeviceManagerDelegate;
35 35
36 // Implementation of the public DeviceManager interface. This interface can be 36 // Implementation of the public DeviceManager interface. This interface can be
37 // requested from the devices app located at "mojo:devices", if available. 37 // requested from the devices app located at "mojo:devices", if available.
38 class DeviceManagerImpl : public DeviceManager { 38 class DeviceManagerImpl : public DeviceManager {
39 public: 39 public:
40 using DeviceList = std::vector<scoped_refptr<UsbDevice>>;
41 using DeviceMap = std::map<std::string, scoped_refptr<device::UsbDevice>>;
42
40 DeviceManagerImpl( 43 DeviceManagerImpl(
41 mojo::InterfaceRequest<DeviceManager> request, 44 mojo::InterfaceRequest<DeviceManager> request,
42 PermissionProviderPtr permission_provider, 45 PermissionProviderPtr permission_provider,
43 scoped_refptr<base::SequencedTaskRunner> service_task_runner); 46 scoped_refptr<base::SequencedTaskRunner> service_task_runner);
44 ~DeviceManagerImpl() override; 47 ~DeviceManagerImpl() override;
45 48
46 void set_connection_error_handler(const mojo::Closure& error_handler) { 49 void set_connection_error_handler(const mojo::Closure& error_handler) {
47 connection_error_handler_ = error_handler; 50 connection_error_handler_ = error_handler;
48 } 51 }
49 52
50 private: 53 private:
51 class ServiceThreadHelper; 54 class ServiceThreadHelper;
52 55
53 // DeviceManager implementation: 56 // DeviceManager implementation:
54 void GetDevices(EnumerationOptionsPtr options, 57 void GetDevices(EnumerationOptionsPtr options,
55 const GetDevicesCallback& callback) override; 58 const GetDevicesCallback& callback) override;
56 void GetDeviceChanges(const GetDeviceChangesCallback& callback) override; 59 void GetDeviceChanges(const GetDeviceChangesCallback& callback) override;
57 void OpenDevice(const mojo::String& guid, 60 void OpenDevice(const mojo::String& guid,
58 mojo::InterfaceRequest<Device> device_request, 61 mojo::InterfaceRequest<Device> device_request,
59 const OpenDeviceCallback& callback) override; 62 const OpenDeviceCallback& callback) override;
60 63
61 void OnOpenDevicePermissionCheckComplete( 64 void OnOpenDevicePermissionCheckComplete(
62 mojo::InterfaceRequest<Device> device_request, 65 mojo::InterfaceRequest<Device> device_request,
63 const OpenDeviceCallback& callback, 66 const OpenDeviceCallback& callback,
64 mojo::Array<mojo::String> allowed_guids); 67 mojo::Array<mojo::String> allowed_guids);
65 68
66 // Callbacks to handle the async responses from the underlying UsbService. 69 // Callbacks to handle the async responses from the underlying UsbService.
67 void OnGetDevices(const GetDevicesCallback& callback, 70 void OnGetDevices(EnumerationOptionsPtr options,
68 mojo::Array<DeviceInfoPtr> devices); 71 const GetDevicesCallback& callback,
72 const DeviceList& devices);
69 73
70 // Methods called by |helper_| when devices are added or removed. 74 // Methods called by |helper_| when devices are added or removed.
71 void OnDeviceAdded(DeviceInfoPtr device); 75 void OnDeviceAdded(scoped_refptr<device::UsbDevice> device);
72 void OnDeviceRemoved(std::string device_guid); 76 void OnDeviceRemoved(scoped_refptr<device::UsbDevice> device);
73 void MaybeRunDeviceChangesCallback(); 77 void MaybeRunDeviceChangesCallback();
74 void OnEnumerationPermissionCheckComplete( 78 void OnEnumerationPermissionCheckComplete(
75 mojo::Array<DeviceInfoPtr> devices_added, 79 const DeviceMap& devices_added,
76 const std::set<std::string>& devices_removed, 80 const DeviceMap& devices_removed,
77 mojo::Array<mojo::String> allowed_guids); 81 mojo::Array<mojo::String> allowed_guids);
78 82
79 PermissionProviderPtr permission_provider_; 83 PermissionProviderPtr permission_provider_;
80 scoped_refptr<base::SequencedTaskRunner> service_task_runner_; 84 scoped_refptr<base::SequencedTaskRunner> service_task_runner_;
81 85
82 // If there are unfinished calls to GetDeviceChanges their callbacks 86 // If there are unfinished calls to GetDeviceChanges their callbacks
83 // are stored in |device_change_callbacks_|. Otherwise device changes 87 // are stored in |device_change_callbacks_|. Otherwise device changes
84 // are collected in |devices_added_| and |devices_removed_| until the 88 // are collected in |devices_added_| and |devices_removed_| until the
85 // next call to GetDeviceChanges. 89 // next call to GetDeviceChanges.
86 std::queue<GetDeviceChangesCallback> device_change_callbacks_; 90 std::queue<GetDeviceChangesCallback> device_change_callbacks_;
87 mojo::Array<DeviceInfoPtr> devices_added_; 91 DeviceMap devices_added_;
88 std::set<std::string> devices_removed_; 92 DeviceMap devices_removed_;
89 // To ensure that GetDeviceChangesCallbacks are called in the correct order 93 // To ensure that GetDeviceChangesCallbacks are called in the correct order
90 // only perform a single request to |permission_provider_| at a time. 94 // only perform a single request to |permission_provider_| at a time.
91 bool permission_request_pending_ = false; 95 bool permission_request_pending_ = false;
92 96
93 // |helper_| is owned by the service thread and holds a weak reference 97 // |helper_| is owned by the service thread and holds a weak reference
94 // back to the device manager that created it. 98 // back to the device manager that created it.
95 ServiceThreadHelper* helper_; 99 ServiceThreadHelper* helper_;
96 100
97 mojo::Closure connection_error_handler_; 101 mojo::Closure connection_error_handler_;
98 102
99 mojo::Binding<DeviceManager> binding_; 103 mojo::Binding<DeviceManager> binding_;
100 base::WeakPtrFactory<DeviceManagerImpl> weak_factory_; 104 base::WeakPtrFactory<DeviceManagerImpl> weak_factory_;
101 105
102 DISALLOW_COPY_AND_ASSIGN(DeviceManagerImpl); 106 DISALLOW_COPY_AND_ASSIGN(DeviceManagerImpl);
103 }; 107 };
104 108
105 } // namespace usb 109 } // namespace usb
106 } // namespace device 110 } // namespace device
107 111
108 #endif // DEVICE_USB_DEVICE_MANAGER_IMPL_H_ 112 #endif // DEVICE_USB_DEVICE_MANAGER_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | device/devices_app/usb/device_manager_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698