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

Side by Side Diff: device/usb/usb_device_handle_impl.cc

Issue 835313003: UsbDeviceHandleImpl must hold a scoped_refptr to UsbDeviceImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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/usb_device_handle_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/usb_device_handle_impl.h" 5 #include "device/usb/usb_device_handle_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 // Because device_handle_ is a weak pointer it is guaranteed that the callback 470 // Because device_handle_ is a weak pointer it is guaranteed that the callback
471 // will be discarded if the handle has been freed. 471 // will be discarded if the handle has been freed.
472 Transfer* tmp_transfer = transfer.get(); // base::Passed invalidates transfer 472 Transfer* tmp_transfer = transfer.get(); // base::Passed invalidates transfer
473 tmp_transfer->task_runner_->PostTask( 473 tmp_transfer->task_runner_->PostTask(
474 FROM_HERE, base::Bind(&UsbDeviceHandleImpl::CompleteTransfer, 474 FROM_HERE, base::Bind(&UsbDeviceHandleImpl::CompleteTransfer,
475 tmp_transfer->device_handle_, 475 tmp_transfer->device_handle_,
476 base::Passed(&transfer))); 476 base::Passed(&transfer)));
477 } 477 }
478 478
479 UsbDeviceHandleImpl::UsbDeviceHandleImpl(scoped_refptr<UsbContext> context, 479 UsbDeviceHandleImpl::UsbDeviceHandleImpl(scoped_refptr<UsbContext> context,
480 UsbDeviceImpl* device, 480 scoped_refptr<UsbDeviceImpl> device,
481 PlatformUsbDeviceHandle handle) 481 PlatformUsbDeviceHandle handle)
482 : device_(device), 482 : device_(device),
483 handle_(handle), 483 handle_(handle),
484 context_(context), 484 context_(context),
485 task_runner_(base::ThreadTaskRunnerHandle::Get()), 485 task_runner_(base::ThreadTaskRunnerHandle::Get()),
486 weak_factory_(this) { 486 weak_factory_(this) {
487 DCHECK(handle) << "Cannot create device with NULL handle."; 487 DCHECK(handle) << "Cannot create device with NULL handle.";
488 } 488 }
489 489
490 UsbDeviceHandleImpl::~UsbDeviceHandleImpl() { 490 UsbDeviceHandleImpl::~UsbDeviceHandleImpl() {
491 DCHECK(thread_checker_.CalledOnValidThread()); 491 DCHECK(thread_checker_.CalledOnValidThread());
492 492
493 libusb_close(handle_); 493 libusb_close(handle_);
494 handle_ = NULL; 494 handle_ = NULL;
495 } 495 }
496 496
497 scoped_refptr<UsbDevice> UsbDeviceHandleImpl::GetDevice() const { 497 scoped_refptr<UsbDevice> UsbDeviceHandleImpl::GetDevice() const {
498 return static_cast<UsbDevice*>(device_); 498 return device_;
499 } 499 }
500 500
501 void UsbDeviceHandleImpl::Close() { 501 void UsbDeviceHandleImpl::Close() {
502 DCHECK(thread_checker_.CalledOnValidThread()); 502 DCHECK(thread_checker_.CalledOnValidThread());
503 if (device_) 503 if (device_)
504 device_->Close(this); 504 device_->Close(this);
505 } 505 }
506 506
507 bool UsbDeviceHandleImpl::SetConfiguration(int configuration_value) { 507 bool UsbDeviceHandleImpl::SetConfiguration(int configuration_value) {
508 DCHECK(thread_checker_.CalledOnValidThread()); 508 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 // Attempt-release all the interfaces. 856 // Attempt-release all the interfaces.
857 // It will be retained until the transfer cancellation is finished. 857 // It will be retained until the transfer cancellation is finished.
858 claimed_interfaces_.clear(); 858 claimed_interfaces_.clear();
859 859
860 // Cannot close device handle here. Need to wait for libusb_cancel_transfer to 860 // Cannot close device handle here. Need to wait for libusb_cancel_transfer to
861 // finish. 861 // finish.
862 device_ = NULL; 862 device_ = NULL;
863 } 863 }
864 864
865 } // namespace device 865 } // namespace device
OLDNEW
« no previous file with comments | « device/usb/usb_device_handle_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698