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 <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 auto scoped_callbacks = MakeScopedUSBCallbacks(callbacks); | 100 auto scoped_callbacks = MakeScopedUSBCallbacks(callbacks); |
101 GetDeviceManager()->GetDevices( | 101 GetDeviceManager()->GetDevices( |
102 nullptr, | 102 nullptr, |
103 base::Bind(&OnGetDevicesComplete, base::Passed(&scoped_callbacks), | 103 base::Bind(&OnGetDevicesComplete, base::Passed(&scoped_callbacks), |
104 base::Unretained(device_manager_.get()))); | 104 base::Unretained(device_manager_.get()))); |
105 } | 105 } |
106 | 106 |
107 void WebUSBClientImpl::requestDevice( | 107 void WebUSBClientImpl::requestDevice( |
108 const blink::WebUSBDeviceRequestOptions& options, | 108 const blink::WebUSBDeviceRequestOptions& options, |
109 blink::WebUSBClientRequestDeviceCallbacks* callbacks) { | 109 blink::WebUSBClientRequestDeviceCallbacks* callbacks) { |
110 if (!webusb_permission_bubble_) { | 110 if (!chooser_service_) { |
111 service_registry_->ConnectToRemoteService( | 111 service_registry_->ConnectToRemoteService( |
112 mojo::GetProxy(&webusb_permission_bubble_)); | 112 mojo::GetProxy(&chooser_service_)); |
113 } | 113 } |
114 | 114 |
115 auto scoped_callbacks = MakeScopedUSBCallbacks(callbacks); | 115 auto scoped_callbacks = MakeScopedUSBCallbacks(callbacks); |
116 | 116 |
117 mojo::Array<device::usb::DeviceFilterPtr> device_filters = | 117 mojo::Array<device::usb::DeviceFilterPtr> device_filters = |
118 mojo::Array<device::usb::DeviceFilterPtr>::From(options.filters); | 118 mojo::Array<device::usb::DeviceFilterPtr>::From(options.filters); |
119 | 119 |
120 webusb_permission_bubble_->GetPermission( | 120 chooser_service_->GetPermission( |
121 std::move(device_filters), | 121 std::move(device_filters), |
122 base::Bind(&OnRequestDevicesComplete, base::Passed(&scoped_callbacks), | 122 base::Bind(&OnRequestDevicesComplete, base::Passed(&scoped_callbacks), |
123 base::Unretained(device_manager_.get()))); | 123 base::Unretained(device_manager_.get()))); |
124 } | 124 } |
125 | 125 |
126 void WebUSBClientImpl::setObserver(Observer* observer) { | 126 void WebUSBClientImpl::setObserver(Observer* observer) { |
127 if (!observer_) { | 127 if (!observer_) { |
128 // Set up two sequential calls to GetDeviceChanges to avoid latency. | 128 // Set up two sequential calls to GetDeviceChanges to avoid latency. |
129 device::usb::DeviceManager* device_manager = GetDeviceManager(); | 129 device::usb::DeviceManager* device_manager = GetDeviceManager(); |
130 device_manager->GetDeviceChanges(base::Bind( | 130 device_manager->GetDeviceChanges(base::Bind( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 notification->devices_removed[i]; | 163 notification->devices_removed[i]; |
164 device::usb::DevicePtr device; | 164 device::usb::DevicePtr device; |
165 device_manager_->GetDevice(device_info->guid, mojo::GetProxy(&device)); | 165 device_manager_->GetDevice(device_info->guid, mojo::GetProxy(&device)); |
166 observer_->onDeviceDisconnected(blink::adoptWebPtr(new WebUSBDeviceImpl( | 166 observer_->onDeviceDisconnected(blink::adoptWebPtr(new WebUSBDeviceImpl( |
167 std::move(device), | 167 std::move(device), |
168 mojo::ConvertTo<blink::WebUSBDeviceInfo>(device_info)))); | 168 mojo::ConvertTo<blink::WebUSBDeviceInfo>(device_info)))); |
169 } | 169 } |
170 } | 170 } |
171 | 171 |
172 } // namespace content | 172 } // namespace content |
OLD | NEW |