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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 (*devices)[i] = new WebUSBDeviceImpl( | 61 (*devices)[i] = new WebUSBDeviceImpl( |
62 device.Pass(), mojo::ConvertTo<blink::WebUSBDeviceInfo>(results[i])); | 62 device.Pass(), mojo::ConvertTo<blink::WebUSBDeviceInfo>(results[i])); |
63 } | 63 } |
64 scoped_callbacks.PassCallbacks()->onSuccess(blink::adoptWebPtr(devices)); | 64 scoped_callbacks.PassCallbacks()->onSuccess(blink::adoptWebPtr(devices)); |
65 } | 65 } |
66 | 66 |
67 } // namespace | 67 } // namespace |
68 | 68 |
69 WebUSBClientImpl::WebUSBClientImpl(content::ServiceRegistry* service_registry) { | 69 WebUSBClientImpl::WebUSBClientImpl(content::ServiceRegistry* service_registry) { |
70 service_registry->ConnectToRemoteService(mojo::GetProxy(&device_manager_)); | 70 service_registry->ConnectToRemoteService(mojo::GetProxy(&device_manager_)); |
71 device_manager_.set_connection_error_handler( | |
72 [this]() { LOG(ERROR) << "Device manager connection failed."; }); | |
73 } | 71 } |
74 | 72 |
75 WebUSBClientImpl::~WebUSBClientImpl() {} | 73 WebUSBClientImpl::~WebUSBClientImpl() {} |
76 | 74 |
77 void WebUSBClientImpl::getDevices( | 75 void WebUSBClientImpl::getDevices( |
78 blink::WebUSBClientGetDevicesCallbacks* callbacks) { | 76 blink::WebUSBClientGetDevicesCallbacks* callbacks) { |
79 auto scoped_callbacks = MakeScopedUSBCallbacks(callbacks); | 77 auto scoped_callbacks = MakeScopedUSBCallbacks(callbacks); |
80 device_manager_->GetDevices( | 78 device_manager_->GetDevices( |
81 nullptr, | 79 nullptr, |
82 base::Bind(&OnGetDevicesComplete, base::Passed(&scoped_callbacks), | 80 base::Bind(&OnGetDevicesComplete, base::Passed(&scoped_callbacks), |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 const device::usb::DeviceInfoPtr& device_info = | 120 const device::usb::DeviceInfoPtr& device_info = |
123 notification->devices_removed[i]; | 121 notification->devices_removed[i]; |
124 device::usb::DevicePtr device; | 122 device::usb::DevicePtr device; |
125 device_manager_->GetDevice(device_info->guid, mojo::GetProxy(&device)); | 123 device_manager_->GetDevice(device_info->guid, mojo::GetProxy(&device)); |
126 observer_->onDeviceDisconnected(blink::adoptWebPtr(new WebUSBDeviceImpl( | 124 observer_->onDeviceDisconnected(blink::adoptWebPtr(new WebUSBDeviceImpl( |
127 device.Pass(), mojo::ConvertTo<blink::WebUSBDeviceInfo>(device_info)))); | 125 device.Pass(), mojo::ConvertTo<blink::WebUSBDeviceInfo>(device_info)))); |
128 } | 126 } |
129 } | 127 } |
130 | 128 |
131 } // namespace content | 129 } // namespace content |
OLD | NEW |