Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/usb/web_usb_client_impl.h" | 5 #include "content/renderer/usb/web_usb_client_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/move.h" | 10 #include "base/move.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 } | 91 } |
| 92 | 92 |
| 93 void WebUSBClientImpl::requestDevice( | 93 void WebUSBClientImpl::requestDevice( |
| 94 const blink::WebUSBDeviceRequestOptions& options, | 94 const blink::WebUSBDeviceRequestOptions& options, |
| 95 blink::WebUSBClientRequestDeviceCallbacks* callbacks) { | 95 blink::WebUSBClientRequestDeviceCallbacks* callbacks) { |
| 96 callbacks->onError(blink::WebUSBError(blink::WebUSBError::Error::Service, | 96 callbacks->onError(blink::WebUSBError(blink::WebUSBError::Error::Service, |
| 97 base::UTF8ToUTF16("Not implemented."))); | 97 base::UTF8ToUTF16("Not implemented."))); |
| 98 delete callbacks; | 98 delete callbacks; |
| 99 } | 99 } |
| 100 | 100 |
| 101 void WebUSBClientImpl::setObserver(Observer* observer) { | |
| 102 if (!observer_) { | |
| 103 // Set up two sequential calls to GetDeviceChanges to avoid latency. | |
| 104 device_manager_->GetDeviceChanges(base::Bind( | |
| 105 &WebUSBClientImpl::OnDeviceChangeNotification, base::Unretained(this))); | |
| 106 device_manager_->GetDeviceChanges(base::Bind( | |
| 107 &WebUSBClientImpl::OnDeviceChangeNotification, base::Unretained(this))); | |
| 108 } | |
| 109 | |
| 110 observer_ = observer; | |
| 111 } | |
| 112 | |
| 113 void WebUSBClientImpl::OnDeviceChangeNotification( | |
| 114 device::usb::DeviceChangeNotificationPtr notification) { | |
| 115 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.
| |
| 116 device_manager_->GetDeviceChanges(base::Bind( | |
| 117 &WebUSBClientImpl::OnDeviceChangeNotification, base::Unretained(this))); | |
| 118 for (size_t i = 0; i < notification->devices_added.size(); ++i) { | |
| 119 device::usb::DeviceManagerPtr device_manager; | |
| 120 mojo::ConnectToService(device_services_.get(), &device_manager); | |
| 121 observer_->onDeviceConnected(blink::adoptWebPtr(new WebUSBDeviceImpl( | |
| 122 device_manager.Pass(), mojo::ConvertTo<blink::WebUSBDeviceInfo>( | |
| 123 notification->devices_added[i])))); | |
| 124 } | |
| 125 for (size_t i = 0; i < notification->devices_removed.size(); ++i) { | |
| 126 device::usb::DeviceManagerPtr device_manager; | |
| 127 mojo::ConnectToService(device_services_.get(), &device_manager); | |
| 128 observer_->onDeviceDisconnected(blink::adoptWebPtr(new WebUSBDeviceImpl( | |
| 129 device_manager.Pass(), mojo::ConvertTo<blink::WebUSBDeviceInfo>( | |
| 130 notification->devices_removed[i])))); | |
| 131 } | |
| 132 } | |
| 133 } | |
| 134 | |
| 101 } // namespace content | 135 } // namespace content |
| OLD | NEW |