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

Unified Diff: third_party/WebKit/Source/modules/webusb/USB.cpp

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
« no previous file with comments | « third_party/WebKit/Source/modules/webusb/USB.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/webusb/USB.cpp
diff --git a/third_party/WebKit/Source/modules/webusb/USB.cpp b/third_party/WebKit/Source/modules/webusb/USB.cpp
index 0d48fefee1d5251fa701692982fb2c92aaa390c3..4d5c36a448839089e42b79539c54c1a30e64ca6a 100644
--- a/third_party/WebKit/Source/modules/webusb/USB.cpp
+++ b/third_party/WebKit/Source/modules/webusb/USB.cpp
@@ -52,12 +52,12 @@ usb::DeviceFilterPtr convertDeviceFilter(const USBDeviceFilter& filter)
USB::USB(LocalFrame& frame)
: ContextLifecycleObserver(frame.document())
+ , m_clientBinding(this)
{
+ ThreadState::current()->registerPreFinalizer(this);
frame.serviceRegistry()->connectToRemoteService(mojo::GetProxy(&m_deviceManager));
m_deviceManager.set_connection_error_handler(createBaseCallback(bind(&USB::onDeviceManagerConnectionError, WeakPersistentThisPointer<USB>(this))));
- // Set up two sequential calls to GetDeviceChanges to avoid latency.
- m_deviceManager->GetDeviceChanges(createBaseCallback(bind<usb::DeviceChangeNotificationPtr>(&USB::onDeviceChanges, WeakPersistentThisPointer<USB>(this))));
- m_deviceManager->GetDeviceChanges(createBaseCallback(bind<usb::DeviceChangeNotificationPtr>(&USB::onDeviceChanges, WeakPersistentThisPointer<USB>(this))));
+ m_deviceManager->SetClient(m_clientBinding.CreateInterfacePtrAndBind());
}
USB::~USB()
@@ -69,6 +69,13 @@ USB::~USB()
DCHECK(m_chooserServiceRequests.isEmpty());
}
+void USB::dispose()
+{
+ // The pipe to this object must be closed when is marked unreachable to
+ // prevent messages from being dispatched before lazy sweeping.
+ m_clientBinding.Close();
+}
+
ScriptPromise USB::getDevices(ScriptState* scriptState)
{
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
@@ -176,16 +183,19 @@ void USB::onGetPermission(ScriptPromiseResolver* resolver, usb::DeviceInfoPtr de
}
}
-void USB::onDeviceChanges(usb::DeviceChangeNotificationPtr notification)
+void USB::OnDeviceAdded(usb::DeviceInfoPtr deviceInfo)
{
- m_deviceManager->GetDeviceChanges(createBaseCallback(bind<usb::DeviceChangeNotificationPtr>(&USB::onDeviceChanges, WeakPersistentThisPointer<USB>(this))));
- for (auto& deviceInfo : notification->devices_added.PassStorage()) {
- usb::DevicePtr device;
- m_deviceManager->GetDevice(deviceInfo->guid, mojo::GetProxy(&device));
- dispatchEvent(USBConnectionEvent::create(EventTypeNames::connect, USBDevice::create(std::move(deviceInfo), std::move(device), getExecutionContext())));
- }
- for (auto& deviceInfo : notification->devices_removed.PassStorage())
- dispatchEvent(USBConnectionEvent::create(EventTypeNames::disconnect, USBDevice::create(std::move(deviceInfo), nullptr, getExecutionContext())));
+ if (!m_deviceManager)
+ return;
+
+ usb::DevicePtr device;
+ m_deviceManager->GetDevice(deviceInfo->guid, mojo::GetProxy(&device));
+ dispatchEvent(USBConnectionEvent::create(EventTypeNames::connect, USBDevice::create(std::move(deviceInfo), std::move(device), getExecutionContext())));
+}
+
+void USB::OnDeviceRemoved(usb::DeviceInfoPtr deviceInfo)
+{
+ dispatchEvent(USBConnectionEvent::create(EventTypeNames::disconnect, USBDevice::create(std::move(deviceInfo), nullptr, getExecutionContext())));
}
void USB::onDeviceManagerConnectionError()
« no previous file with comments | « third_party/WebKit/Source/modules/webusb/USB.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698