Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: device/usb/mojo/device_impl.cc

Issue 2752523002: Handle USB device disconnection during early setup. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/usb/mojo/device_impl.h ('k') | device/usb/usb_device_handle_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « device/usb/mojo/device_impl.h ('k') | device/usb/usb_device_handle_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698