Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(568)

Side by Side Diff: extensions/browser/api/hid/hid_device_manager.h

Issue 1115213004: Add chrome.hid.getUserSelectedDevices API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // Checks if |extension| has permission to open |device_info|. Set
61 scoped_refptr<device::HidDeviceInfo> device_info); 66 // |update_last_used| to update the timestamp in the DevicePermissionsManager.
67 bool HasPermission(const Extension* extension,
68 scoped_refptr<device::HidDeviceInfo> device_info,
69 bool update_last_used);
62 70
63 private: 71 private:
64 friend class BrowserContextKeyedAPIFactory<HidDeviceManager>; 72 friend class BrowserContextKeyedAPIFactory<HidDeviceManager>;
65 73
66 typedef std::map<int, device::HidDeviceId> ResourceIdToDeviceIdMap; 74 typedef std::map<int, device::HidDeviceId> ResourceIdToDeviceIdMap;
67 typedef std::map<device::HidDeviceId, int> DeviceIdToResourceIdMap; 75 typedef std::map<device::HidDeviceId, int> DeviceIdToResourceIdMap;
68 76
69 struct GetApiDevicesParams; 77 struct GetApiDevicesParams;
70 78
71 // KeyedService: 79 // KeyedService:
(...skipping 24 matching lines...) Expand all
96 const Extension* extension, 104 const Extension* extension,
97 const std::vector<device::HidDeviceFilter>& filters); 105 const std::vector<device::HidDeviceFilter>& filters);
98 void OnEnumerationComplete( 106 void OnEnumerationComplete(
99 const std::vector<scoped_refptr<device::HidDeviceInfo>>& devices); 107 const std::vector<scoped_refptr<device::HidDeviceInfo>>& devices);
100 108
101 void DispatchEvent(const std::string& event_name, 109 void DispatchEvent(const std::string& event_name,
102 scoped_ptr<base::ListValue> event_args, 110 scoped_ptr<base::ListValue> event_args,
103 scoped_refptr<device::HidDeviceInfo> device_info); 111 scoped_refptr<device::HidDeviceInfo> device_info);
104 112
105 base::ThreadChecker thread_checker_; 113 base::ThreadChecker thread_checker_;
106 EventRouter* event_router_; 114 content::BrowserContext* browser_context_ = nullptr;
107 bool initialized_; 115 EventRouter* event_router_ = nullptr;
116 bool initialized_ = false;
108 ScopedObserver<device::HidService, device::HidService::Observer> 117 ScopedObserver<device::HidService, device::HidService::Observer>
109 hid_service_observer_; 118 hid_service_observer_;
110 bool enumeration_ready_; 119 bool enumeration_ready_ = false;
111 ScopedVector<GetApiDevicesParams> pending_enumerations_; 120 ScopedVector<GetApiDevicesParams> pending_enumerations_;
112 int next_resource_id_; 121 int next_resource_id_ = 0;
113 ResourceIdToDeviceIdMap device_ids_; 122 ResourceIdToDeviceIdMap device_ids_;
114 DeviceIdToResourceIdMap resource_ids_; 123 DeviceIdToResourceIdMap resource_ids_;
115 base::WeakPtrFactory<HidDeviceManager> weak_factory_; 124 base::WeakPtrFactory<HidDeviceManager> weak_factory_;
116 125
117 DISALLOW_COPY_AND_ASSIGN(HidDeviceManager); 126 DISALLOW_COPY_AND_ASSIGN(HidDeviceManager);
118 }; 127 };
119 128
120 } // namespace extensions 129 } // namespace extensions
121 130
122 #endif // EXTENSIONS_BROWSER_API_HID_HID_DEVICE_MANAGER_H_ 131 #endif // EXTENSIONS_BROWSER_API_HID_HID_DEVICE_MANAGER_H_
OLDNEW
« no previous file with comments | « extensions/browser/api/hid/hid_apitest.cc ('k') | extensions/browser/api/hid/hid_device_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698