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

Unified Diff: third_party/WebKit/LayoutTests/usb/resources/usb-helpers.js

Issue 1946063002: Replace DeviceManager::GetDeviceChanges with a client interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@proper_stubs
Patch Set: Rebase.d Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/usb/resources/usb-helpers.js
diff --git a/third_party/WebKit/LayoutTests/usb/resources/usb-helpers.js b/third_party/WebKit/LayoutTests/usb/resources/usb-helpers.js
index 0a5e41842afed2f111ce296940e8ce5accccbf56..3a91fd5448791b8894aa56811b0a621d636df762 100644
--- a/third_party/WebKit/LayoutTests/usb/resources/usb-helpers.js
+++ b/third_party/WebKit/LayoutTests/usb/resources/usb-helpers.js
@@ -325,10 +325,8 @@ function usbMocks(mojo) {
class MockDeviceManager {
constructor() {
this.mockDevices_ = new Map();
- this.addedDevices_ = [];
- this.removedDevices_ = [];
- this.deviceChangePromiseResolvers_ = [];
this.deviceCloseHandler_ = null;
+ this.client_ = null;
}
bindToPipe(pipe) {
@@ -341,10 +339,8 @@ function usbMocks(mojo) {
this.mockDevices_.forEach(device => {
for (var stub of device.stubs)
bindings.StubBindings(stub).close();
- this.removedDevices_.push(device.info);
});
this.mockDevices_.clear();
- this.maybeResolveDeviceChangePromise();
}
addMockDevice(info) {
@@ -353,8 +349,8 @@ function usbMocks(mojo) {
stubs: []
};
this.mockDevices_.set(info.guid, device);
- this.addedDevices_.push(info);
- this.maybeResolveDeviceChangePromise();
+ if (this.client_)
+ this.client_.onDeviceAdded(info);
}
removeMockDevice(info) {
@@ -362,8 +358,8 @@ function usbMocks(mojo) {
for (var stub of device.stubs)
bindings.StubBindings(stub).close();
this.mockDevices_.delete(info.guid);
- this.removedDevices_.push(info);
- this.maybeResolveDeviceChangePromise();
+ if (this.client_)
+ this.client_.onDeviceRemoved(info);
}
setDeviceCloseHandler(handler) {
@@ -378,34 +374,6 @@ function usbMocks(mojo) {
return Promise.resolve({ results: devices });
}
- getDeviceChanges() {
- let promise = new Promise((resolve, reject) => {
- this.deviceChangePromiseResolvers_.push(resolve);
- });
- this.maybeResolveDeviceChangePromise();
- return promise;
- }
-
- maybeResolveDeviceChangePromise() {
- if (this.addedDevices_.length == 0 &&
- this.removedDevices_.length == 0) {
- return;
- }
-
- let resolve = this.deviceChangePromiseResolvers_.shift();
- if (resolve === undefined)
- return;
-
- resolve({
- changes: {
- devices_added: this.addedDevices_,
- devices_removed: this.removedDevices_
- }
- });
- this.addedDevices_ = [];
- this.removedDevices_ = [];
- }
-
getDevice(guid, stub) {
let device = this.mockDevices_.get(guid);
if (device === undefined) {
@@ -420,6 +388,10 @@ function usbMocks(mojo) {
device.stubs.push(stub);
}
}
+
+ setClient(client) {
+ this.client_ = client;
+ }
}
class MockChooserService {
« no previous file with comments | « device/usb/public/interfaces/device_manager.mojom ('k') | third_party/WebKit/LayoutTests/usb/usbDevice-iframe.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698