| 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/sequence_checker.h" |
| 19 #include "base/sequenced_task_runner.h" | 20 #include "base/sequenced_task_runner.h" |
| 20 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
| 21 #include "base/task_scheduler/task_traits.h" | 22 #include "base/task_scheduler/task_traits.h" |
| 22 #include "base/threading/non_thread_safe.h" | |
| 23 | 23 |
| 24 namespace device { | 24 namespace device { |
| 25 | 25 |
| 26 class UsbDevice; | 26 class UsbDevice; |
| 27 | 27 |
| 28 // 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 |
| 29 // 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 |
| 30 // 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 |
| 31 // competition for the same USB device. | 31 // competition for the same USB device. |
| 32 class UsbService : public base::NonThreadSafe { | 32 class UsbService { |
| 33 public: | 33 public: |
| 34 using GetDevicesCallback = | 34 using GetDevicesCallback = |
| 35 base::Callback<void(const std::vector<scoped_refptr<UsbDevice>>&)>; | 35 base::Callback<void(const std::vector<scoped_refptr<UsbDevice>>&)>; |
| 36 | 36 |
| 37 class Observer { | 37 class Observer { |
| 38 public: | 38 public: |
| 39 virtual ~Observer(); | 39 virtual ~Observer(); |
| 40 | 40 |
| 41 // These events are delivered from the thread on which the UsbService object | 41 // These events are delivered from the thread on which the UsbService object |
| 42 // was created. | 42 // was created. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 } | 89 } |
| 90 | 90 |
| 91 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner() const { | 91 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner() const { |
| 92 return blocking_task_runner_; | 92 return blocking_task_runner_; |
| 93 } | 93 } |
| 94 | 94 |
| 95 std::unordered_map<std::string, scoped_refptr<UsbDevice>>& devices() { | 95 std::unordered_map<std::string, scoped_refptr<UsbDevice>>& devices() { |
| 96 return devices_; | 96 return devices_; |
| 97 } | 97 } |
| 98 | 98 |
| 99 SEQUENCE_CHECKER(sequence_checker_); |
| 100 |
| 99 private: | 101 private: |
| 100 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 102 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 101 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 103 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 102 std::unordered_map<std::string, scoped_refptr<UsbDevice>> devices_; | 104 std::unordered_map<std::string, scoped_refptr<UsbDevice>> devices_; |
| 103 std::unordered_set<std::string> testing_devices_; | 105 std::unordered_set<std::string> testing_devices_; |
| 104 base::ObserverList<Observer, true> observer_list_; | 106 base::ObserverList<Observer, true> observer_list_; |
| 105 | 107 |
| 106 DISALLOW_COPY_AND_ASSIGN(UsbService); | 108 DISALLOW_COPY_AND_ASSIGN(UsbService); |
| 107 }; | 109 }; |
| 108 | 110 |
| 109 } // namespace device | 111 } // namespace device |
| 110 | 112 |
| 111 #endif // DEVICE_USB_USB_SERVICE_H_ | 113 #endif // DEVICE_USB_USB_SERVICE_H_ |
| OLD | NEW |