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

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

Issue 2326913003: Privatize StrongBinding lifetime management (Closed)
Patch Set: rebase Created 4 years, 3 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/mojo/device_impl_unittest.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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 scoped_refptr<net::IOBuffer> buffer, 96 scoped_refptr<net::IOBuffer> buffer,
97 const std::vector<UsbDeviceHandle::IsochronousPacket>& packets) { 97 const std::vector<UsbDeviceHandle::IsochronousPacket>& packets) {
98 callback.Run(mojo::ConvertTo<std::vector<IsochronousPacketPtr>>(packets)); 98 callback.Run(mojo::ConvertTo<std::vector<IsochronousPacketPtr>>(packets));
99 } 99 }
100 100
101 } // namespace 101 } // namespace
102 102
103 DeviceImpl::DeviceImpl(scoped_refptr<UsbDevice> device, 103 DeviceImpl::DeviceImpl(scoped_refptr<UsbDevice> device,
104 DeviceInfoPtr device_info, 104 DeviceInfoPtr device_info,
105 base::WeakPtr<PermissionProvider> permission_provider, 105 base::WeakPtr<PermissionProvider> permission_provider,
106 mojo::InterfaceRequest<Device> request) 106 DeviceRequest request)
107 : device_(device), 107 : device_(device),
108 device_info_(std::move(device_info)), 108 device_info_(std::move(device_info)),
109 permission_provider_(permission_provider), 109 permission_provider_(permission_provider),
110 observer_(this), 110 observer_(this),
111 binding_(this, std::move(request)), 111 binding_(this, std::move(request)),
112 weak_factory_(this) { 112 weak_factory_(this) {
113 DCHECK(device_); 113 DCHECK(device_);
114 // This object owns itself and will be destroyed if, 114 // This object owns itself and will be destroyed if,
115 // * the device is disconnected or 115 // * the device is disconnected or
116 // * the message pipe it is bound to is closed or the message loop is 116 // * the message pipe it is bound to is closed or the message loop is
117 // * destructed. 117 // * destructed.
118 observer_.Add(device_.get()); 118 observer_.Add(device_.get());
119 binding_.set_connection_error_handler(
120 base::Bind([](DeviceImpl* self) { delete self; }, this));
119 } 121 }
120 122
121 DeviceImpl::~DeviceImpl() { 123 DeviceImpl::~DeviceImpl() {
122 CloseHandle(); 124 CloseHandle();
123 } 125 }
124 126
125 void DeviceImpl::CloseHandle() { 127 void DeviceImpl::CloseHandle() {
126 if (device_handle_) { 128 if (device_handle_) {
127 device_handle_->Close(); 129 device_handle_->Close();
128 if (permission_provider_) 130 if (permission_provider_)
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 base::Bind(&OnIsochronousTransferOut, callback)); 433 base::Bind(&OnIsochronousTransferOut, callback));
432 } 434 }
433 435
434 void DeviceImpl::OnDeviceRemoved(scoped_refptr<UsbDevice> device) { 436 void DeviceImpl::OnDeviceRemoved(scoped_refptr<UsbDevice> device) {
435 DCHECK_EQ(device_, device); 437 DCHECK_EQ(device_, device);
436 delete this; 438 delete this;
437 } 439 }
438 440
439 } // namespace usb 441 } // namespace usb
440 } // namespace device 442 } // namespace device
OLDNEW
« no previous file with comments | « device/usb/mojo/device_impl.h ('k') | device/usb/mojo/device_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698