Home | History | Annotate | Download | only in hid
      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.
      4 
      5 #ifndef EXTENSIONS_BROWSER_API_HID_HID_DEVICE_MANAGER_H_
      6 #define EXTENSIONS_BROWSER_API_HID_HID_DEVICE_MANAGER_H_
      7 
      8 #include <stdint.h>
      9 
     10 #include <map>
     11 
     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"
     19 
     20 namespace device {
     21 class HidDeviceFilter;
     22 }
     23 
     24 namespace extensions {
     25 
     26 class Extension;
     27 
     28 class HidDeviceManager : public BrowserContextKeyedAPI {
     29  public:
     30   explicit HidDeviceManager(content::BrowserContext* context);
     31   virtual ~HidDeviceManager();
     32 
     33   // BrowserContextKeyedAPI implementation.
     34   static BrowserContextKeyedAPIFactory<HidDeviceManager>* GetFactoryInstance();
     35 
     36   // Convenience method to get the HidDeviceManager for a profile.
     37   static HidDeviceManager* Get(content::BrowserContext* context) {
     38     return BrowserContextKeyedAPIFactory<HidDeviceManager>::Get(context);
     39   }
     40 
     41   scoped_ptr<base::ListValue> GetApiDevices(
     42       const Extension* extension,
     43       const std::vector<device::HidDeviceFilter>& filters);
     44 
     45   bool GetDeviceInfo(int resource_id, device::HidDeviceInfo* device_info);
     46 
     47   bool HasPermission(const Extension* extension,
     48                      const device::HidDeviceInfo& device_info);
     49 
     50  private:
     51   friend class BrowserContextKeyedAPIFactory<HidDeviceManager>;
     52 
     53   static const char* service_name() { return "HidDeviceManager"; }
     54   static bool IsCalledOnValidThread();
     55 
     56   void UpdateDevices();
     57 
     58   static const bool kServiceHasOwnInstanceInIncognito = true;
     59 
     60   int next_resource_id_;
     61 
     62   typedef std::map<int, device::HidDeviceId> ResourceIdToDeviceIdMap;
     63   typedef std::map<device::HidDeviceId, int> DeviceIdToResourceIdMap;
     64 
     65   ResourceIdToDeviceIdMap device_ids_;
     66   DeviceIdToResourceIdMap resource_ids_;
     67 
     68   DISALLOW_COPY_AND_ASSIGN(HidDeviceManager);
     69 };
     70 
     71 }  // namespace extensions
     72 
     73 #endif  // EXTENSIONS_BROWSER_API_HID_HID_DEVICE_MANAGER_H_
     74