Check that extensions::HidDeviceManager is used from the FILE thread.
[chromium-blink-merge.git] / extensions / browser / api / hid / hid_device_manager.h
blob7edfd23e1baace38004ffeeef4460a57db75d868
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_
8 #include <stdint.h>
10 #include <map>
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"
20 namespace device {
21 class HidDeviceFilter;
24 namespace extensions {
26 class Extension;
28 class HidDeviceManager : public BrowserContextKeyedAPI {
29 public:
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);
50 private:
51 friend class BrowserContextKeyedAPIFactory<HidDeviceManager>;
53 static const char* service_name() { return "HidDeviceManager"; }
54 static bool IsCalledOnValidThread();
56 void UpdateDevices();
58 int next_resource_id_;
60 typedef std::map<int, device::HidDeviceId> ResourceIdToDeviceIdMap;
61 typedef std::map<device::HidDeviceId, int> DeviceIdToResourceIdMap;
63 ResourceIdToDeviceIdMap device_ids_;
64 DeviceIdToResourceIdMap resource_ids_;
66 DISALLOW_COPY_AND_ASSIGN(HidDeviceManager);
69 } // namespace extensions
71 #endif // EXTENSIONS_BROWSER_API_HID_HID_DEVICE_MANAGER_H_