| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 mojo::InterfaceRequest<Device> request) | 131 mojo::InterfaceRequest<Device> request) |
| 132 : device_(device), | 132 : device_(device), |
| 133 device_info_(std::move(device_info)), | 133 device_info_(std::move(device_info)), |
| 134 permission_provider_(permission_provider), | 134 permission_provider_(permission_provider), |
| 135 observer_(this), | 135 observer_(this), |
| 136 binding_(this, std::move(request)), | 136 binding_(this, std::move(request)), |
| 137 weak_factory_(this) { | 137 weak_factory_(this) { |
| 138 DCHECK(device_); | 138 DCHECK(device_); |
| 139 // This object owns itself and will be destroyed if, | 139 // This object owns itself and will be destroyed if, |
| 140 // * the device is disconnected or | 140 // * the device is disconnected or |
| 141 // * the message pipe it is bound to is closed | 141 // * the message pipe it is bound to is closed or the message loop is |
| 142 // * destructed. |
| 142 observer_.Add(device_.get()); | 143 observer_.Add(device_.get()); |
| 143 binding_.set_connection_error_handler([this]() { delete this; }); | |
| 144 } | 144 } |
| 145 | 145 |
| 146 DeviceImpl::~DeviceImpl() { | 146 DeviceImpl::~DeviceImpl() { |
| 147 CloseHandle(); | 147 CloseHandle(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void DeviceImpl::CloseHandle() { | 150 void DeviceImpl::CloseHandle() { |
| 151 if (device_handle_) { | 151 if (device_handle_) { |
| 152 device_handle_->Close(); | 152 device_handle_->Close(); |
| 153 if (permission_provider_) | 153 if (permission_provider_) |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 base::Bind(&OnIsochronousTransferOut, base::Passed(&callback_ptr))); | 450 base::Bind(&OnIsochronousTransferOut, base::Passed(&callback_ptr))); |
| 451 } | 451 } |
| 452 | 452 |
| 453 void DeviceImpl::OnDeviceRemoved(scoped_refptr<UsbDevice> device) { | 453 void DeviceImpl::OnDeviceRemoved(scoped_refptr<UsbDevice> device) { |
| 454 DCHECK_EQ(device_, device); | 454 DCHECK_EQ(device_, device); |
| 455 delete this; | 455 delete this; |
| 456 } | 456 } |
| 457 | 457 |
| 458 } // namespace usb | 458 } // namespace usb |
| 459 } // namespace device | 459 } // namespace device |
| OLD | NEW |