| 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 <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 // Each observer must not depend on any other observers' awareness of the | 36 // Each observer must not depend on any other observers' awareness of the |
| 37 // device as they could be cleaned up in any order. | 37 // device as they could be cleaned up in any order. |
| 38 virtual void OnDeviceRemovedCleanup(scoped_refptr<HidDeviceInfo> info); | 38 virtual void OnDeviceRemovedCleanup(scoped_refptr<HidDeviceInfo> info); |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 typedef base::Callback<void(const std::vector<scoped_refptr<HidDeviceInfo>>&)> | 41 typedef base::Callback<void(const std::vector<scoped_refptr<HidDeviceInfo>>&)> |
| 42 GetDevicesCallback; | 42 GetDevicesCallback; |
| 43 typedef base::Callback<void(scoped_refptr<HidConnection> connection)> | 43 typedef base::Callback<void(scoped_refptr<HidConnection> connection)> |
| 44 ConnectCallback; | 44 ConnectCallback; |
| 45 | 45 |
| 46 // Gets a pointer to the HidService singleton. This function should be called | 46 // This function should be called on a thread with a MessageLoopForUI and be |
| 47 // on a thread with a MessageLoopForUI and be passed the task runner for a | 47 // passed the task runner for a thread with a MessageLoopForIO. |
| 48 // thread with a MessageLoopForIO. | 48 static scoped_ptr<HidService> Create( |
| 49 static HidService* GetInstance( | |
| 50 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner); | 49 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner); |
| 51 | 50 |
| 52 static void SetInstanceForTest(HidService* instance); | 51 virtual ~HidService(); |
| 53 | 52 |
| 54 // Enumerates available devices. The provided callback will always be posted | 53 // Enumerates available devices. The provided callback will always be posted |
| 55 // to the calling thread's task runner. | 54 // to the calling thread's task runner. |
| 56 virtual void GetDevices(const GetDevicesCallback& callback); | 55 virtual void GetDevices(const GetDevicesCallback& callback); |
| 57 | 56 |
| 58 void AddObserver(Observer* observer); | 57 void AddObserver(Observer* observer); |
| 59 void RemoveObserver(Observer* observer); | 58 void RemoveObserver(Observer* observer); |
| 60 | 59 |
| 61 // Fills in a DeviceInfo struct with info for the given device_id. | 60 // Fills in a DeviceInfo struct with info for the given device_id. |
| 62 // Returns |nullptr| if |device_id| is invalid. | 61 // Returns |nullptr| if |device_id| is invalid. |
| 63 scoped_refptr<HidDeviceInfo> GetDeviceInfo( | 62 scoped_refptr<HidDeviceInfo> GetDeviceInfo( |
| 64 const HidDeviceId& device_id) const; | 63 const HidDeviceId& device_id) const; |
| 65 | 64 |
| 66 // Opens a connection to a device. The callback will be run with null on | 65 // Opens a connection to a device. The callback will be run with null on |
| 67 // failure. | 66 // failure. |
| 68 virtual void Connect(const HidDeviceId& device_id, | 67 virtual void Connect(const HidDeviceId& device_id, |
| 69 const ConnectCallback& callback) = 0; | 68 const ConnectCallback& callback) = 0; |
| 70 | 69 |
| 71 protected: | 70 protected: |
| 72 friend void base::DeletePointer<HidService>(HidService* service); | |
| 73 friend class HidConnectionTest; | 71 friend class HidConnectionTest; |
| 74 | 72 |
| 75 typedef std::map<HidDeviceId, scoped_refptr<HidDeviceInfo>> DeviceMap; | 73 typedef std::map<HidDeviceId, scoped_refptr<HidDeviceInfo>> DeviceMap; |
| 76 | 74 |
| 77 HidService(); | 75 HidService(); |
| 78 virtual ~HidService(); | |
| 79 | 76 |
| 80 void AddDevice(scoped_refptr<HidDeviceInfo> info); | 77 void AddDevice(scoped_refptr<HidDeviceInfo> info); |
| 81 void RemoveDevice(const HidDeviceId& device_id); | 78 void RemoveDevice(const HidDeviceId& device_id); |
| 82 void FirstEnumerationComplete(); | 79 void FirstEnumerationComplete(); |
| 83 | 80 |
| 84 const DeviceMap& devices() const { return devices_; } | 81 const DeviceMap& devices() const { return devices_; } |
| 85 | 82 |
| 86 base::ThreadChecker thread_checker_; | 83 base::ThreadChecker thread_checker_; |
| 87 | 84 |
| 88 private: | 85 private: |
| 89 DeviceMap devices_; | 86 DeviceMap devices_; |
| 90 bool enumeration_ready_; | 87 bool enumeration_ready_; |
| 91 std::vector<GetDevicesCallback> pending_enumerations_; | 88 std::vector<GetDevicesCallback> pending_enumerations_; |
| 92 base::ObserverList<Observer, true> observer_list_; | 89 base::ObserverList<Observer, true> observer_list_; |
| 93 | 90 |
| 94 DISALLOW_COPY_AND_ASSIGN(HidService); | 91 DISALLOW_COPY_AND_ASSIGN(HidService); |
| 95 }; | 92 }; |
| 96 | 93 |
| 97 } // namespace device | 94 } // namespace device |
| 98 | 95 |
| 99 #endif // DEVICE_HID_HID_SERVICE_H_ | 96 #endif // DEVICE_HID_HID_SERVICE_H_ |
| OLD | NEW |