| 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 "device/usb/mojo/device_impl.h" | 5 #include "device/usb/mojo/device_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 interface->first_interface, config->configuration_value, device_); | 165 interface->first_interface, config->configuration_value, device_); |
| 166 } else if (config) { | 166 } else if (config) { |
| 167 return permission_provider_->HasConfigurationPermission( | 167 return permission_provider_->HasConfigurationPermission( |
| 168 config->configuration_value, device_); | 168 config->configuration_value, device_); |
| 169 } else { | 169 } else { |
| 170 // Client must already have device permission to have gotten this far. | 170 // Client must already have device permission to have gotten this far. |
| 171 return true; | 171 return true; |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 | 174 |
| 175 void DeviceImpl::OnOpen(const OpenCallback& callback, | 175 // static |
| 176 void DeviceImpl::OnOpen(base::WeakPtr<DeviceImpl> self, |
| 177 const OpenCallback& callback, |
| 176 scoped_refptr<UsbDeviceHandle> handle) { | 178 scoped_refptr<UsbDeviceHandle> handle) { |
| 177 device_handle_ = handle; | 179 if (!self) { |
| 178 if (device_handle_ && permission_provider_) | 180 handle->Close(); |
| 179 permission_provider_->IncrementConnectionCount(); | 181 return; |
| 180 callback.Run(handle ? OpenDeviceError::OK : OpenDeviceError::ACCESS_DENIED); | 182 } |
| 183 |
| 184 self->device_handle_ = std::move(handle); |
| 185 if (self->device_handle_ && self->permission_provider_) |
| 186 self->permission_provider_->IncrementConnectionCount(); |
| 187 callback.Run(self->device_handle_ ? OpenDeviceError::OK |
| 188 : OpenDeviceError::ACCESS_DENIED); |
| 181 } | 189 } |
| 182 | 190 |
| 183 void DeviceImpl::OnPermissionGrantedForOpen(const OpenCallback& callback, | 191 void DeviceImpl::OnPermissionGrantedForOpen(const OpenCallback& callback, |
| 184 bool granted) { | 192 bool granted) { |
| 185 if (granted && permission_provider_ && | 193 if (granted && permission_provider_ && |
| 186 permission_provider_->HasDevicePermission(device_)) { | 194 permission_provider_->HasDevicePermission(device_)) { |
| 187 device_->Open( | 195 device_->Open( |
| 188 base::Bind(&DeviceImpl::OnOpen, weak_factory_.GetWeakPtr(), callback)); | 196 base::Bind(&DeviceImpl::OnOpen, weak_factory_.GetWeakPtr(), callback)); |
| 189 } else { | 197 } else { |
| 190 callback.Run(OpenDeviceError::ACCESS_DENIED); | 198 callback.Run(OpenDeviceError::ACCESS_DENIED); |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 base::Bind(&OnIsochronousTransferOut, callback)); | 440 base::Bind(&OnIsochronousTransferOut, callback)); |
| 433 } | 441 } |
| 434 | 442 |
| 435 void DeviceImpl::OnDeviceRemoved(scoped_refptr<UsbDevice> device) { | 443 void DeviceImpl::OnDeviceRemoved(scoped_refptr<UsbDevice> device) { |
| 436 DCHECK_EQ(device_, device); | 444 DCHECK_EQ(device_, device); |
| 437 delete this; | 445 delete this; |
| 438 } | 446 } |
| 439 | 447 |
| 440 } // namespace usb | 448 } // namespace usb |
| 441 } // namespace device | 449 } // namespace device |
| OLD | NEW |