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 CHROME_BROWSER_EXTENSIONS_API_HID_HID_DEVICE_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_HID_HID_DEVICE_MANAGER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_HID_HID_DEVICE_MANAGER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_HID_HID_DEVICE_MANAGER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
15 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" | |
16 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/common/extensions/api/hid.h" | 16 #include "chrome/common/extensions/api/hid.h" |
18 #include "device/hid/hid_device_info.h" | 17 #include "device/hid/hid_device_info.h" |
| 18 #include "extensions/browser/browser_context_keyed_api_factory.h" |
19 | 19 |
20 namespace extensions { | 20 namespace extensions { |
21 | 21 |
22 class HidDeviceManager : public ProfileKeyedAPI { | 22 class HidDeviceManager : public BrowserContextKeyedAPI { |
23 public: | 23 public: |
24 explicit HidDeviceManager(content::BrowserContext* context); | 24 explicit HidDeviceManager(content::BrowserContext* context); |
25 virtual ~HidDeviceManager(); | 25 virtual ~HidDeviceManager(); |
26 | 26 |
27 // ProfileKeyedAPI implementation. | 27 // BrowserContextKeyedAPI implementation. |
28 static ProfileKeyedAPIFactory<HidDeviceManager>* GetFactoryInstance(); | 28 static BrowserContextKeyedAPIFactory<HidDeviceManager>* GetFactoryInstance(); |
29 | 29 |
30 // Convenience method to get the HidDeviceManager for a profile. | 30 // Convenience method to get the HidDeviceManager for a profile. |
31 static HidDeviceManager* Get(content::BrowserContext* context) { | 31 static HidDeviceManager* Get(content::BrowserContext* context) { |
32 return ProfileKeyedAPIFactory<HidDeviceManager>::GetForProfile(context); | 32 return BrowserContextKeyedAPIFactory<HidDeviceManager>::Get(context); |
33 } | 33 } |
34 | 34 |
35 scoped_ptr<base::ListValue> GetApiDevices(uint16_t vendor_id, | 35 scoped_ptr<base::ListValue> GetApiDevices(uint16_t vendor_id, |
36 uint16_t product_id); | 36 uint16_t product_id); |
37 | 37 |
38 bool GetDeviceInfo(int resource_id, device::HidDeviceInfo* device_info); | 38 bool GetDeviceInfo(int resource_id, device::HidDeviceInfo* device_info); |
39 | 39 |
40 private: | 40 private: |
41 friend class ProfileKeyedAPIFactory<HidDeviceManager>; | 41 friend class BrowserContextKeyedAPIFactory<HidDeviceManager>; |
42 | 42 |
43 static const char* service_name() { return "HidDeviceManager"; } | 43 static const char* service_name() { return "HidDeviceManager"; } |
44 | 44 |
45 void UpdateDevices(); | 45 void UpdateDevices(); |
46 | 46 |
47 base::ThreadChecker thread_checker_; | 47 base::ThreadChecker thread_checker_; |
48 | 48 |
49 int next_resource_id_; | 49 int next_resource_id_; |
50 | 50 |
51 typedef std::map<int, device::HidDeviceId> ResourceIdToDeviceIdMap; | 51 typedef std::map<int, device::HidDeviceId> ResourceIdToDeviceIdMap; |
52 typedef std::map<device::HidDeviceId, int> DeviceIdToResourceIdMap; | 52 typedef std::map<device::HidDeviceId, int> DeviceIdToResourceIdMap; |
53 | 53 |
54 ResourceIdToDeviceIdMap device_ids_; | 54 ResourceIdToDeviceIdMap device_ids_; |
55 DeviceIdToResourceIdMap resource_ids_; | 55 DeviceIdToResourceIdMap resource_ids_; |
56 | 56 |
57 DISALLOW_COPY_AND_ASSIGN(HidDeviceManager); | 57 DISALLOW_COPY_AND_ASSIGN(HidDeviceManager); |
58 }; | 58 }; |
59 | 59 |
60 } // namespace extensions | 60 } // namespace extensions |
61 | 61 |
62 #endif // CHROME_BROWSER_EXTENSIONS_API_HID_HID_DEVICE_MANAGER_H_ | 62 #endif // CHROME_BROWSER_EXTENSIONS_API_HID_HID_DEVICE_MANAGER_H_ |
OLD | NEW |