Chromium Code Reviews| 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 EXTENSIONS_BROWSER_API_HID_HID_DEVICE_MANAGER_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_HID_HID_DEVICE_MANAGER_H_ |
| 6 #define EXTENSIONS_BROWSER_API_HID_HID_DEVICE_MANAGER_H_ | 6 #define EXTENSIONS_BROWSER_API_HID_HID_DEVICE_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 14 #include "base/scoped_observer.h" | 14 #include "base/scoped_observer.h" |
| 15 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 16 #include "device/hid/hid_device_info.h" | |
| 17 #include "device/hid/hid_service.h" | 16 #include "device/hid/hid_service.h" |
| 18 #include "extensions/browser/browser_context_keyed_api_factory.h" | 17 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 19 #include "extensions/browser/event_router.h" | 18 #include "extensions/browser/event_router.h" |
| 20 #include "extensions/common/api/hid.h" | 19 #include "extensions/common/api/hid.h" |
| 21 | 20 |
| 22 namespace device { | 21 namespace device { |
| 23 class HidDeviceFilter; | 22 class HidDeviceFilter; |
| 23 class HidDeviceInfo; | |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace extensions { | 26 namespace extensions { |
| 27 | 27 |
| 28 class Extension; | 28 class Extension; |
| 29 | 29 |
| 30 // This service maps devices enumerated by device::HidService to resource IDs | 30 // This service maps devices enumerated by device::HidService to resource IDs |
| 31 // returned by the chrome.hid API. | 31 // returned by the chrome.hid API. |
| 32 class HidDeviceManager : public BrowserContextKeyedAPI, | 32 class HidDeviceManager : public BrowserContextKeyedAPI, |
| 33 public device::HidService::Observer, | 33 public device::HidService::Observer, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 48 } | 48 } |
| 49 | 49 |
| 50 // Enumerates available devices, taking into account the permissions held by | 50 // Enumerates available devices, taking into account the permissions held by |
| 51 // the given extension and the filters provided. The provided callback will | 51 // the given extension and the filters provided. The provided callback will |
| 52 // be posted to the calling thread's task runner with a list of device info | 52 // be posted to the calling thread's task runner with a list of device info |
| 53 // objects. | 53 // objects. |
| 54 void GetApiDevices(const Extension* extension, | 54 void GetApiDevices(const Extension* extension, |
| 55 const std::vector<device::HidDeviceFilter>& filters, | 55 const std::vector<device::HidDeviceFilter>& filters, |
| 56 const GetApiDevicesCallback& callback); | 56 const GetApiDevicesCallback& callback); |
| 57 | 57 |
| 58 // Converts a list of HidDeviceInfo objects into a value that can be returned | |
| 59 // through the API. | |
| 60 scoped_ptr<base::ListValue> GetApiDevicesFromList( | |
| 61 const std::vector<scoped_refptr<device::HidDeviceInfo>>& devices); | |
| 62 | |
| 58 scoped_refptr<device::HidDeviceInfo> GetDeviceInfo(int resource_id); | 63 scoped_refptr<device::HidDeviceInfo> GetDeviceInfo(int resource_id); |
| 59 | 64 |
| 60 static bool HasPermission(const Extension* extension, | 65 bool HasPermission(const Extension* extension, |
| 61 scoped_refptr<device::HidDeviceInfo> device_info); | 66 scoped_refptr<device::HidDeviceInfo> device_info, |
| 67 bool update_last_used); | |
| 62 | 68 |
| 63 private: | 69 private: |
| 64 friend class BrowserContextKeyedAPIFactory<HidDeviceManager>; | 70 friend class BrowserContextKeyedAPIFactory<HidDeviceManager>; |
| 65 | 71 |
| 66 typedef std::map<int, device::HidDeviceId> ResourceIdToDeviceIdMap; | 72 typedef std::map<int, device::HidDeviceId> ResourceIdToDeviceIdMap; |
| 67 typedef std::map<device::HidDeviceId, int> DeviceIdToResourceIdMap; | 73 typedef std::map<device::HidDeviceId, int> DeviceIdToResourceIdMap; |
| 68 | 74 |
| 69 struct GetApiDevicesParams; | 75 struct GetApiDevicesParams; |
| 70 | 76 |
| 71 // KeyedService: | 77 // KeyedService: |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 96 const Extension* extension, | 102 const Extension* extension, |
| 97 const std::vector<device::HidDeviceFilter>& filters); | 103 const std::vector<device::HidDeviceFilter>& filters); |
| 98 void OnEnumerationComplete( | 104 void OnEnumerationComplete( |
| 99 const std::vector<scoped_refptr<device::HidDeviceInfo>>& devices); | 105 const std::vector<scoped_refptr<device::HidDeviceInfo>>& devices); |
| 100 | 106 |
| 101 void DispatchEvent(const std::string& event_name, | 107 void DispatchEvent(const std::string& event_name, |
| 102 scoped_ptr<base::ListValue> event_args, | 108 scoped_ptr<base::ListValue> event_args, |
| 103 scoped_refptr<device::HidDeviceInfo> device_info); | 109 scoped_refptr<device::HidDeviceInfo> device_info); |
| 104 | 110 |
| 105 base::ThreadChecker thread_checker_; | 111 base::ThreadChecker thread_checker_; |
| 112 content::BrowserContext* browser_context_; | |
| 106 EventRouter* event_router_; | 113 EventRouter* event_router_; |
| 107 bool initialized_; | 114 bool initialized_ = false; |
|
Devlin
2015/05/05 22:19:50
please be consistent - if certain variables are go
Reilly Grant (use Gerrit)
2015/05/06 00:52:53
Done.
| |
| 108 ScopedObserver<device::HidService, device::HidService::Observer> | 115 ScopedObserver<device::HidService, device::HidService::Observer> |
| 109 hid_service_observer_; | 116 hid_service_observer_; |
| 110 bool enumeration_ready_; | 117 bool enumeration_ready_ = false; |
| 111 ScopedVector<GetApiDevicesParams> pending_enumerations_; | 118 ScopedVector<GetApiDevicesParams> pending_enumerations_; |
| 112 int next_resource_id_; | 119 int next_resource_id_ = 0; |
| 113 ResourceIdToDeviceIdMap device_ids_; | 120 ResourceIdToDeviceIdMap device_ids_; |
| 114 DeviceIdToResourceIdMap resource_ids_; | 121 DeviceIdToResourceIdMap resource_ids_; |
| 115 base::WeakPtrFactory<HidDeviceManager> weak_factory_; | 122 base::WeakPtrFactory<HidDeviceManager> weak_factory_; |
| 116 | 123 |
| 117 DISALLOW_COPY_AND_ASSIGN(HidDeviceManager); | 124 DISALLOW_COPY_AND_ASSIGN(HidDeviceManager); |
| 118 }; | 125 }; |
| 119 | 126 |
| 120 } // namespace extensions | 127 } // namespace extensions |
| 121 | 128 |
| 122 #endif // EXTENSIONS_BROWSER_API_HID_HID_DEVICE_MANAGER_H_ | 129 #endif // EXTENSIONS_BROWSER_API_HID_HID_DEVICE_MANAGER_H_ |
| OLD | NEW |