| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_USB_SERVICE_H_ | 5 #ifndef DEVICE_USB_USB_SERVICE_H_ |
| 6 #define DEVICE_USB_USB_SERVICE_H_ | 6 #define DEVICE_USB_USB_SERVICE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <unordered_map> | 10 #include <unordered_map> |
| 11 #include <unordered_set> | 11 #include <unordered_set> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
| 19 #include "base/sequenced_task_runner.h" | 19 #include "base/sequenced_task_runner.h" |
| 20 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
| 21 #include "base/task_scheduler/task_traits.h" |
| 21 #include "base/threading/non_thread_safe.h" | 22 #include "base/threading/non_thread_safe.h" |
| 22 | 23 |
| 23 namespace device { | 24 namespace device { |
| 24 | 25 |
| 25 class UsbDevice; | 26 class UsbDevice; |
| 26 | 27 |
| 27 // The USB service handles creating and managing an event handler thread that is | 28 // The USB service handles creating and managing an event handler thread that is |
| 28 // used to manage and dispatch USB events. It is also responsible for device | 29 // used to manage and dispatch USB events. It is also responsible for device |
| 29 // discovery on the system, which allows it to re-use device handles to prevent | 30 // discovery on the system, which allows it to re-use device handles to prevent |
| 30 // competition for the same USB device. | 31 // competition for the same USB device. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 42 virtual void OnDeviceAdded(scoped_refptr<UsbDevice> device); | 43 virtual void OnDeviceAdded(scoped_refptr<UsbDevice> device); |
| 43 virtual void OnDeviceRemoved(scoped_refptr<UsbDevice> device); | 44 virtual void OnDeviceRemoved(scoped_refptr<UsbDevice> device); |
| 44 // For observers that need to process device removal after others have run. | 45 // For observers that need to process device removal after others have run. |
| 45 // Should not depend on any other service's knowledge of connected devices. | 46 // Should not depend on any other service's knowledge of connected devices. |
| 46 virtual void OnDeviceRemovedCleanup(scoped_refptr<UsbDevice> device); | 47 virtual void OnDeviceRemovedCleanup(scoped_refptr<UsbDevice> device); |
| 47 | 48 |
| 48 // Notifies the observer that the UsbService it depends on is shutting down. | 49 // Notifies the observer that the UsbService it depends on is shutting down. |
| 49 virtual void WillDestroyUsbService(); | 50 virtual void WillDestroyUsbService(); |
| 50 }; | 51 }; |
| 51 | 52 |
| 53 // These task traits are to be used for posting blocking tasks to the task |
| 54 // scheduler. |
| 55 static constexpr base::TaskTraits kBlockingTaskTraits = { |
| 56 base::MayBlock(), base::TaskPriority::USER_VISIBLE, |
| 57 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}; |
| 58 |
| 52 // Returns nullptr when initialization fails. | 59 // Returns nullptr when initialization fails. |
| 53 static std::unique_ptr<UsbService> Create(); | 60 static std::unique_ptr<UsbService> Create(); |
| 54 | 61 |
| 55 // Creates a SequencedTaskRunner appropriate for blocking I/O operations. | 62 // Creates a SequencedTaskRunner with kBlockingTaskTraits. |
| 56 static scoped_refptr<base::SequencedTaskRunner> CreateBlockingTaskRunner(); | 63 static scoped_refptr<base::SequencedTaskRunner> CreateBlockingTaskRunner(); |
| 57 | 64 |
| 58 virtual ~UsbService(); | 65 virtual ~UsbService(); |
| 59 | 66 |
| 60 scoped_refptr<UsbDevice> GetDevice(const std::string& guid); | 67 scoped_refptr<UsbDevice> GetDevice(const std::string& guid); |
| 61 | 68 |
| 62 // Shuts down the UsbService. Must be called before destroying the UsbService | 69 // Shuts down the UsbService. Must be called before destroying the UsbService |
| 63 // when tasks can still be posted to the |blocking_task_runner| provided to | 70 // when tasks can still be posted to the |blocking_task_runner| provided to |
| 64 // Create(). | 71 // Create(). |
| 65 virtual void Shutdown(); | 72 virtual void Shutdown(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 #if DCHECK_IS_ON() | 111 #if DCHECK_IS_ON() |
| 105 bool did_shutdown_ = false; | 112 bool did_shutdown_ = false; |
| 106 #endif | 113 #endif |
| 107 | 114 |
| 108 DISALLOW_COPY_AND_ASSIGN(UsbService); | 115 DISALLOW_COPY_AND_ASSIGN(UsbService); |
| 109 }; | 116 }; |
| 110 | 117 |
| 111 } // namespace device | 118 } // namespace device |
| 112 | 119 |
| 113 #endif // DEVICE_USB_USB_SERVICE_H_ | 120 #endif // DEVICE_USB_USB_SERVICE_H_ |
| OLD | NEW |