Skip to content

Commit

Permalink
Add HID support to DevicePermissionsManager and DevicePermissionsPrompt.
Browse files Browse the repository at this point in the history
This patch lays down the backend support necessary for the HID device
picker API. The DevicePermissionsManager can now manage HID device
permissions (both ephemeral devices that will be forgotten when they are
disconnected and persistent devices that are written to the prefs file).
The DevicePermissionsPrompt gains support for enumerating HID devices.

BUG=457899

Review URL: https://codereview.chromium.org/1123633002

Cr-Commit-Position: refs/heads/master@{#328379}
  • Loading branch information
reillyeon authored and Commit bot committed May 5, 2015
1 parent 09c7449 commit 7adf217
Show file tree
Hide file tree
Showing 12 changed files with 888 additions and 274 deletions.
336 changes: 281 additions & 55 deletions chrome/browser/extensions/api/device_permissions_manager_unittest.cc

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion device/hid/hid_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ void HidService::Observer::OnDeviceRemoved(
scoped_refptr<HidDeviceInfo> device_info) {
}

void HidService::Observer::OnDeviceRemovedCleanup(
scoped_refptr<HidDeviceInfo> device_info) {
}

HidService* HidService::GetInstance(
scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) {
if (g_service == NULL) {
Expand Down Expand Up @@ -124,10 +128,15 @@ void HidService::RemoveDevice(const HidDeviceId& device_id) {
if (it != devices_.end()) {
HID_LOG(USER) << "HID device removed: deviceId='" << device_id << "'";

scoped_refptr<HidDeviceInfo> device = it->second;
if (enumeration_ready_) {
FOR_EACH_OBSERVER(Observer, observer_list_, OnDeviceRemoved(it->second));
FOR_EACH_OBSERVER(Observer, observer_list_, OnDeviceRemoved(device));
}
devices_.erase(it);
if (enumeration_ready_) {
FOR_EACH_OBSERVER(Observer, observer_list_,
OnDeviceRemovedCleanup(device));
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions device/hid/hid_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ class HidService {
class Observer {
public:
virtual void OnDeviceAdded(scoped_refptr<HidDeviceInfo> info);
// Notifies all observers that a device is being removed, called before
// removing the device from HidService. Observers should not depend on the
// order in which they are notified of the OnDeviceRemove event.
virtual void OnDeviceRemoved(scoped_refptr<HidDeviceInfo> info);
// Notifies all observers again, after having first notified all observers
// with OnDeviceRemoved and removed the device from internal structures.
// Each observer must not depend on any other observers' awareness of the
// device as they could be cleaned up in any order.
virtual void OnDeviceRemovedCleanup(scoped_refptr<HidDeviceInfo> info);
};

typedef base::Callback<void(const std::vector<scoped_refptr<HidDeviceInfo>>&)>
Expand Down
1 change: 1 addition & 0 deletions extensions/browser/api/DEPS
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include_rules = [
"+device/core",
"+device/hid",
]
Loading

0 comments on commit 7adf217

Please sign in to comment.