Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 scoped_refptr<base::SequencedTaskRunner> service_task_runner); | 43 scoped_refptr<base::SequencedTaskRunner> service_task_runner); |
| 44 ~DeviceManagerImpl() override; | 44 ~DeviceManagerImpl() override; |
| 45 | 45 |
| 46 void set_connection_error_handler(const mojo::Closure& error_handler) { | 46 void set_connection_error_handler(const mojo::Closure& error_handler) { |
| 47 connection_error_handler_ = error_handler; | 47 connection_error_handler_ = error_handler; |
| 48 } | 48 } |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 class ServiceThreadHelper; | 51 class ServiceThreadHelper; |
| 52 | 52 |
| 53 typedef std::vector<scoped_refptr<UsbDevice>> DeviceList; | |
|
Ken Rockot(use gerrit already)
2015/09/15 18:09:25
nit: using instead of typedef
Reilly Grant (use Gerrit)
2015/09/15 19:46:48
Done.
| |
| 54 typedef std::map<std::string, scoped_refptr<device::UsbDevice>> DeviceMap; | |
| 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_ |
| OLD | NEW |