| 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_MOJO_DEVICE_MANAGER_IMPL_H_ | 5 #ifndef DEVICE_USB_MOJO_DEVICE_MANAGER_IMPL_H_ |
| 6 #define DEVICE_USB_MOJO_DEVICE_MANAGER_IMPL_H_ | 6 #define DEVICE_USB_MOJO_DEVICE_MANAGER_IMPL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 ~DeviceManagerImpl() override; | 46 ~DeviceManagerImpl() override; |
| 47 | 47 |
| 48 void set_connection_error_handler(const mojo::Closure& error_handler) { | 48 void set_connection_error_handler(const mojo::Closure& error_handler) { |
| 49 connection_error_handler_ = error_handler; | 49 connection_error_handler_ = error_handler; |
| 50 } | 50 } |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 // DeviceManager implementation: | 53 // DeviceManager implementation: |
| 54 void GetDevices(EnumerationOptionsPtr options, | 54 void GetDevices(EnumerationOptionsPtr options, |
| 55 const GetDevicesCallback& callback) override; | 55 const GetDevicesCallback& callback) override; |
| 56 void GetDeviceChanges(const GetDeviceChangesCallback& callback) override; | |
| 57 void GetDevice(const mojo::String& guid, | 56 void GetDevice(const mojo::String& guid, |
| 58 mojo::InterfaceRequest<Device> device_request) override; | 57 mojo::InterfaceRequest<Device> device_request) override; |
| 58 void SetClient(DeviceManagerClientPtr client) override; |
| 59 | 59 |
| 60 // Callbacks to handle the async responses from the underlying UsbService. | 60 // Callbacks to handle the async responses from the underlying UsbService. |
| 61 void OnGetDevices(EnumerationOptionsPtr options, | 61 void OnGetDevices(EnumerationOptionsPtr options, |
| 62 const GetDevicesCallback& callback, | 62 const GetDevicesCallback& callback, |
| 63 const std::vector<scoped_refptr<UsbDevice>>& devices); | 63 const std::vector<scoped_refptr<UsbDevice>>& devices); |
| 64 | 64 |
| 65 // UsbService::Observer implementation: | 65 // UsbService::Observer implementation: |
| 66 void OnDeviceAdded(scoped_refptr<UsbDevice> device) override; | 66 void OnDeviceAdded(scoped_refptr<UsbDevice> device) override; |
| 67 void OnDeviceRemoved(scoped_refptr<UsbDevice> device) override; | 67 void OnDeviceRemoved(scoped_refptr<UsbDevice> device) override; |
| 68 void WillDestroyUsbService() override; | 68 void WillDestroyUsbService() override; |
| 69 | 69 |
| 70 void MaybeRunDeviceChangesCallback(); | 70 void MaybeRunDeviceChangesCallback(); |
| 71 | 71 |
| 72 base::WeakPtr<PermissionProvider> permission_provider_; | 72 base::WeakPtr<PermissionProvider> permission_provider_; |
| 73 | 73 |
| 74 // If there are unfinished calls to GetDeviceChanges their callbacks | |
| 75 // are stored in |device_change_callbacks_|. Otherwise device changes | |
| 76 // are collected in |devices_added_| and |devices_removed_| until the | |
| 77 // next call to GetDeviceChanges. | |
| 78 std::queue<GetDeviceChangesCallback> device_change_callbacks_; | |
| 79 std::map<std::string, DeviceInfoPtr> devices_added_; | |
| 80 std::vector<DeviceInfoPtr> devices_removed_; | |
| 81 | |
| 82 UsbService* usb_service_; | 74 UsbService* usb_service_; |
| 83 ScopedObserver<UsbService, UsbService::Observer> observer_; | 75 ScopedObserver<UsbService, UsbService::Observer> observer_; |
| 76 DeviceManagerClientPtr client_; |
| 84 | 77 |
| 85 mojo::Closure connection_error_handler_; | 78 mojo::Closure connection_error_handler_; |
| 86 | 79 |
| 87 mojo::StrongBinding<DeviceManager> binding_; | 80 mojo::StrongBinding<DeviceManager> binding_; |
| 88 base::WeakPtrFactory<DeviceManagerImpl> weak_factory_; | 81 base::WeakPtrFactory<DeviceManagerImpl> weak_factory_; |
| 89 | 82 |
| 90 DISALLOW_COPY_AND_ASSIGN(DeviceManagerImpl); | 83 DISALLOW_COPY_AND_ASSIGN(DeviceManagerImpl); |
| 91 }; | 84 }; |
| 92 | 85 |
| 93 } // namespace usb | 86 } // namespace usb |
| 94 } // namespace device | 87 } // namespace device |
| 95 | 88 |
| 96 #endif // DEVICE_USB_MOJO_DEVICE_MANAGER_IMPL_H_ | 89 #endif // DEVICE_USB_MOJO_DEVICE_MANAGER_IMPL_H_ |
| OLD | NEW |