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

Unified Diff: content/renderer/usb/web_usb_client_impl.cc

Issue 1331383005: Implement WebUSBClient::setObserver in WebUSBClientImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@manager_full_remove
Patch Set: Less whitespace. Created 5 years, 3 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 | « content/renderer/usb/web_usb_client_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/usb/web_usb_client_impl.cc
diff --git a/content/renderer/usb/web_usb_client_impl.cc b/content/renderer/usb/web_usb_client_impl.cc
index ac4f681a3ff34f49702e6c7e3a7c410f1524fabf..f2eee2b3db5eeb0ebb8d70efccf9b1c95716f4f8 100644
--- a/content/renderer/usb/web_usb_client_impl.cc
+++ b/content/renderer/usb/web_usb_client_impl.cc
@@ -98,4 +98,39 @@ void WebUSBClientImpl::requestDevice(
delete callbacks;
}
+void WebUSBClientImpl::setObserver(Observer* observer) {
+ if (!observer_) {
+ // Set up two sequential calls to GetDeviceChanges to avoid latency.
+ device_manager_->GetDeviceChanges(base::Bind(
+ &WebUSBClientImpl::OnDeviceChangeNotification, base::Unretained(this)));
+ device_manager_->GetDeviceChanges(base::Bind(
+ &WebUSBClientImpl::OnDeviceChangeNotification, base::Unretained(this)));
+ }
+
+ observer_ = observer;
+}
+
+void WebUSBClientImpl::OnDeviceChangeNotification(
+ device::usb::DeviceChangeNotificationPtr notification) {
+ if (!observer_)
+ return;
+
+ device_manager_->GetDeviceChanges(base::Bind(
+ &WebUSBClientImpl::OnDeviceChangeNotification, base::Unretained(this)));
+ for (size_t i = 0; i < notification->devices_added.size(); ++i) {
+ device::usb::DeviceManagerPtr device_manager;
+ mojo::ConnectToService(device_services_.get(), &device_manager);
+ observer_->onDeviceConnected(blink::adoptWebPtr(new WebUSBDeviceImpl(
+ device_manager.Pass(), mojo::ConvertTo<blink::WebUSBDeviceInfo>(
+ notification->devices_added[i]))));
+ }
+ for (size_t i = 0; i < notification->devices_removed.size(); ++i) {
+ device::usb::DeviceManagerPtr device_manager;
+ mojo::ConnectToService(device_services_.get(), &device_manager);
+ observer_->onDeviceDisconnected(blink::adoptWebPtr(new WebUSBDeviceImpl(
+ device_manager.Pass(), mojo::ConvertTo<blink::WebUSBDeviceInfo>(
+ notification->devices_removed[i]))));
+ }
+}
+
} // namespace content
« no previous file with comments | « content/renderer/usb/web_usb_client_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698