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
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_BROWSER_API_HID_HID_DEVICE_MANAGER_H_
6 #define EXTENSIONS_BROWSER_API_HID_HID_DEVICE_MANAGER_H_
12 #include "base/basictypes.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/threading/thread_checker.h"
16 #include "device/hid/hid_device_info.h"
17 #include "extensions/browser/browser_context_keyed_api_factory.h"
18 #include "extensions/common/api/hid.h"
21 class HidDeviceFilter
;
24 namespace extensions
{
28 class HidDeviceManager
: public BrowserContextKeyedAPI
{
30 explicit HidDeviceManager(content::BrowserContext
* context
);
31 virtual ~HidDeviceManager();
33 // BrowserContextKeyedAPI implementation.
34 static BrowserContextKeyedAPIFactory
<HidDeviceManager
>* GetFactoryInstance();
36 // Convenience method to get the HidDeviceManager for a profile.
37 static HidDeviceManager
* Get(content::BrowserContext
* context
) {
38 return BrowserContextKeyedAPIFactory
<HidDeviceManager
>::Get(context
);
41 scoped_ptr
<base::ListValue
> GetApiDevices(
42 const Extension
* extension
,
43 const std::vector
<device::HidDeviceFilter
>& filters
);
45 bool GetDeviceInfo(int resource_id
, device::HidDeviceInfo
* device_info
);
47 bool HasPermission(const Extension
* extension
,
48 const device::HidDeviceInfo
& device_info
);
51 friend class BrowserContextKeyedAPIFactory
<HidDeviceManager
>;
53 static const char* service_name() { return "HidDeviceManager"; }
57 base::ThreadChecker thread_checker_
;
59 int next_resource_id_
;
61 typedef std::map
<int, device::HidDeviceId
> ResourceIdToDeviceIdMap
;
62 typedef std::map
<device::HidDeviceId
, int> DeviceIdToResourceIdMap
;
64 ResourceIdToDeviceIdMap device_ids_
;
65 DeviceIdToResourceIdMap resource_ids_
;
67 DISALLOW_COPY_AND_ASSIGN(HidDeviceManager
);
70 } // namespace extensions
72 #endif // EXTENSIONS_BROWSER_API_HID_HID_DEVICE_MANAGER_H_