Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 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> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 16 #include "base/strings/string16.h" | |
| 17 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 18 #include "build/build_config.h" | |
| 19 #include "device/hid/hid_device_info.h" | 16 #include "device/hid/hid_device_info.h" |
| 20 | 17 |
| 21 namespace device { | 18 namespace device { |
| 22 | 19 |
| 23 namespace { | |
| 24 | |
| 25 class HidServiceContainer; | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 class HidConnection; | 20 class HidConnection; |
| 30 class HidService; | |
| 31 | 21 |
| 32 class HidService : public base::MessageLoop::DestructionObserver { | 22 class HidService : public base::MessageLoop::DestructionObserver { |
| 33 public: | 23 public: |
| 34 // Must be called on FILE thread. | 24 // Must be called on FILE thread. |
| 35 static HidService* GetInstance(); | 25 static HidService* GetInstance(); |
| 36 | 26 |
| 37 // Enumerates and returns a list of device identifiers. | 27 // Enumerates and returns a list of device identifiers. |
| 38 virtual void GetDevices(std::vector<HidDeviceInfo>* devices); | 28 virtual void GetDevices(std::vector<HidDeviceInfo>* devices); |
| 39 | 29 |
| 40 // Fills in the device info struct of the given device_id. | 30 // Fills in the device info struct of the given device_id. |
| 41 // Returns true if succeed. | 31 // Returns true if succeed. |
| 42 // Returns false if the device_id is invalid, with info untouched. | 32 // Returns false if the device_id is invalid, with info untouched. |
| 43 bool GetInfo(std::string device_id, HidDeviceInfo* info) const; | 33 bool GetInfo(const std::string& device_id, HidDeviceInfo* info) const; |
|
Mark Mentovai
2014/02/19 22:48:15
Good call turning these into const refs.
| |
| 44 | 34 |
| 45 virtual scoped_refptr<HidConnection> Connect( | 35 virtual scoped_refptr<HidConnection> Connect( |
| 46 std::string platform_device_id) = 0; | 36 const std::string& device_id) = 0; |
| 47 | 37 |
| 48 // Implements base::MessageLoop::DestructionObserver | 38 // Implements base::MessageLoop::DestructionObserver |
| 49 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; | 39 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; |
| 50 | 40 |
| 51 // Gets whether the HidService have been successfully initialized. | |
| 52 bool initialized() const { return initialized_; } | |
| 53 | |
| 54 protected: | 41 protected: |
| 55 friend class HidServiceContainer; | |
| 56 friend struct base::DefaultDeleter<HidService>; | 42 friend struct base::DefaultDeleter<HidService>; |
| 57 friend class HidConnectionTest; | 43 friend class HidConnectionTest; |
| 58 | 44 |
| 59 HidService(); | 45 HidService(); |
| 60 virtual ~HidService(); | 46 virtual ~HidService(); |
| 61 | 47 |
| 62 static HidService* CreateInstance(); | 48 static HidService* CreateInstance(); |
| 63 | 49 |
| 64 virtual void AddDevice(HidDeviceInfo info); | 50 virtual void AddDevice(HidDeviceInfo info); |
| 65 virtual void RemoveDevice(std::string platform_device_id); | 51 virtual void RemoveDevice(const std::string& device_id); |
| 66 | 52 |
| 67 typedef std::map<std::string, HidDeviceInfo> DeviceMap; | 53 typedef std::map<std::string, HidDeviceInfo> DeviceMap; |
| 68 DeviceMap devices_; | 54 DeviceMap devices_; |
|
Mark Mentovai
2014/02/19 22:48:15
Hmm, protected data. That’s not a good sign. Can t
Ken Rockot(use gerrit already)
2014/02/21 02:15:36
Agreed. Moved to private.
| |
| 69 | 55 |
| 70 bool initialized_; | |
| 71 | |
| 72 base::ThreadChecker thread_checker_; | 56 base::ThreadChecker thread_checker_; |
| 73 | 57 |
| 74 DISALLOW_COPY_AND_ASSIGN(HidService); | 58 DISALLOW_COPY_AND_ASSIGN(HidService); |
| 75 }; | 59 }; |
| 76 | 60 |
| 77 } // namespace device | 61 } // namespace device |
| 78 | 62 |
| 79 #endif // DEVICE_HID_HID_SERVICE_H_ | 63 #endif // DEVICE_HID_HID_SERVICE_H_ |
| OLD | NEW |