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

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: 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..a1da1c86edb5fe0ce817afa52c997a5c8cf6b08d 100644
--- a/content/renderer/usb/web_usb_client_impl.cc
+++ b/content/renderer/usb/web_usb_client_impl.cc
@@ -98,4 +98,38 @@ 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_) {
Ken Rockot(use gerrit already) 2015/09/15 18:23:34 minor nit: just return if !observer_? less whitesp
Reilly Grant (use Gerrit) 2015/09/15 19:49:54 Done.
+ 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