| 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_HID_HID_SERVICE_H_ | 5 #ifndef DEVICE_HID_HID_SERVICE_H_ |
| 6 #define DEVICE_HID_HID_SERVICE_H_ | 6 #define DEVICE_HID_HID_SERVICE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/logging.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 16 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 17 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 18 #include "base/threading/thread_checker.h" | 19 #include "base/threading/thread_checker.h" |
| 19 #include "device/hid/hid_device_info.h" | 20 #include "device/hid/hid_device_info.h" |
| 20 | 21 |
| 21 namespace device { | 22 namespace device { |
| 22 | 23 |
| 23 class HidConnection; | 24 class HidConnection; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 45 typedef base::Callback<void(scoped_refptr<HidConnection> connection)> | 46 typedef base::Callback<void(scoped_refptr<HidConnection> connection)> |
| 46 ConnectCallback; | 47 ConnectCallback; |
| 47 | 48 |
| 48 // This function should be called on a thread with a MessageLoopForUI and be | 49 // This function should be called on a thread with a MessageLoopForUI and be |
| 49 // passed the task runner for a thread with a MessageLoopForIO. | 50 // passed the task runner for a thread with a MessageLoopForIO. |
| 50 static std::unique_ptr<HidService> Create( | 51 static std::unique_ptr<HidService> Create( |
| 51 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner); | 52 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner); |
| 52 | 53 |
| 53 virtual ~HidService(); | 54 virtual ~HidService(); |
| 54 | 55 |
| 56 // Shuts down the HidService. Must be called before destroying the HidService |
| 57 // when tasks can still be posted to the |file_task_runner| provided to |
| 58 // Create(). |
| 59 virtual void Shutdown(); |
| 60 |
| 55 // Enumerates available devices. The provided callback will always be posted | 61 // Enumerates available devices. The provided callback will always be posted |
| 56 // to the calling thread's task runner. | 62 // to the calling thread's task runner. |
| 57 virtual void GetDevices(const GetDevicesCallback& callback); | 63 virtual void GetDevices(const GetDevicesCallback& callback); |
| 58 | 64 |
| 59 void AddObserver(Observer* observer); | 65 void AddObserver(Observer* observer); |
| 60 void RemoveObserver(Observer* observer); | 66 void RemoveObserver(Observer* observer); |
| 61 | 67 |
| 62 // Fills in a DeviceInfo struct with info for the given device_id. | 68 // Fills in a DeviceInfo struct with info for the given device_id. |
| 63 // Returns |nullptr| if |device_id| is invalid. | 69 // Returns |nullptr| if |device_id| is invalid. |
| 64 scoped_refptr<HidDeviceInfo> GetDeviceInfo( | 70 scoped_refptr<HidDeviceInfo> GetDeviceInfo( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 79 void AddDevice(scoped_refptr<HidDeviceInfo> info); | 85 void AddDevice(scoped_refptr<HidDeviceInfo> info); |
| 80 void RemoveDevice(const HidDeviceId& device_id); | 86 void RemoveDevice(const HidDeviceId& device_id); |
| 81 void FirstEnumerationComplete(); | 87 void FirstEnumerationComplete(); |
| 82 | 88 |
| 83 const DeviceMap& devices() const { return devices_; } | 89 const DeviceMap& devices() const { return devices_; } |
| 84 | 90 |
| 85 base::ThreadChecker thread_checker_; | 91 base::ThreadChecker thread_checker_; |
| 86 | 92 |
| 87 private: | 93 private: |
| 88 DeviceMap devices_; | 94 DeviceMap devices_; |
| 89 bool enumeration_ready_; | 95 bool enumeration_ready_ = false; |
| 90 std::vector<GetDevicesCallback> pending_enumerations_; | 96 std::vector<GetDevicesCallback> pending_enumerations_; |
| 91 base::ObserverList<Observer, true> observer_list_; | 97 base::ObserverList<Observer, true> observer_list_; |
| 92 | 98 |
| 99 #if DCHECK_IS_ON() |
| 100 bool did_shutdown_ = false; |
| 101 #endif |
| 102 |
| 93 DISALLOW_COPY_AND_ASSIGN(HidService); | 103 DISALLOW_COPY_AND_ASSIGN(HidService); |
| 94 }; | 104 }; |
| 95 | 105 |
| 96 } // namespace device | 106 } // namespace device |
| 97 | 107 |
| 98 #endif // DEVICE_HID_HID_SERVICE_H_ | 108 #endif // DEVICE_HID_HID_SERVICE_H_ |
| OLD | NEW |