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

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

Issue 1857033003: Implement tab indicator for WebUSB. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't try to update tab indicator on Android. Created 4 years, 8 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
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 <numeric> 10 #include <numeric>
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 // * the message pipe it is bound to is closed 139 // * the message pipe it is bound to is closed
140 observer_.Add(device_.get()); 140 observer_.Add(device_.get());
141 binding_.set_connection_error_handler([this]() { delete this; }); 141 binding_.set_connection_error_handler([this]() { delete this; });
142 } 142 }
143 143
144 DeviceImpl::~DeviceImpl() { 144 DeviceImpl::~DeviceImpl() {
145 CloseHandle(); 145 CloseHandle();
146 } 146 }
147 147
148 void DeviceImpl::CloseHandle() { 148 void DeviceImpl::CloseHandle() {
149 if (device_handle_) 149 if (device_handle_) {
150 device_handle_->Close(); 150 device_handle_->Close();
151 if (permission_provider_)
152 permission_provider_->DecrementConnectionCount();
153 }
151 device_handle_ = nullptr; 154 device_handle_ = nullptr;
152 } 155 }
153 156
154 bool DeviceImpl::HasControlTransferPermission( 157 bool DeviceImpl::HasControlTransferPermission(
155 ControlTransferRecipient recipient, 158 ControlTransferRecipient recipient,
156 uint16_t index) { 159 uint16_t index) {
157 DCHECK(device_handle_); 160 DCHECK(device_handle_);
158 const UsbConfigDescriptor* config = device_->GetActiveConfiguration(); 161 const UsbConfigDescriptor* config = device_->GetActiveConfiguration();
159 162
160 if (!permission_provider_) 163 if (!permission_provider_)
(...skipping 26 matching lines...) Expand all
187 config->configuration_value, *device_info_); 190 config->configuration_value, *device_info_);
188 } else { 191 } else {
189 // Client must already have device permission to have gotten this far. 192 // Client must already have device permission to have gotten this far.
190 return true; 193 return true;
191 } 194 }
192 } 195 }
193 196
194 void DeviceImpl::OnOpen(const OpenCallback& callback, 197 void DeviceImpl::OnOpen(const OpenCallback& callback,
195 scoped_refptr<UsbDeviceHandle> handle) { 198 scoped_refptr<UsbDeviceHandle> handle) {
196 device_handle_ = handle; 199 device_handle_ = handle;
200 if (device_handle_ && permission_provider_)
201 permission_provider_->IncrementConnectionCount();
197 callback.Run(handle ? OpenDeviceError::OK : OpenDeviceError::ACCESS_DENIED); 202 callback.Run(handle ? OpenDeviceError::OK : OpenDeviceError::ACCESS_DENIED);
198 } 203 }
199 204
200 void DeviceImpl::GetDeviceInfo(const GetDeviceInfoCallback& callback) { 205 void DeviceImpl::GetDeviceInfo(const GetDeviceInfoCallback& callback) {
201 const UsbConfigDescriptor* config = device_->GetActiveConfiguration(); 206 const UsbConfigDescriptor* config = device_->GetActiveConfiguration();
202 device_info_->active_configuration = config ? config->configuration_value : 0; 207 device_info_->active_configuration = config ? config->configuration_value : 0;
203 callback.Run(device_info_->Clone()); 208 callback.Run(device_info_->Clone());
204 } 209 }
205 210
206 void DeviceImpl::Open(const OpenCallback& callback) { 211 void DeviceImpl::Open(const OpenCallback& callback) {
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 base::Bind(&OnIsochronousTransferOut, base::Passed(&callback_ptr))); 447 base::Bind(&OnIsochronousTransferOut, base::Passed(&callback_ptr)));
443 } 448 }
444 449
445 void DeviceImpl::OnDeviceRemoved(scoped_refptr<UsbDevice> device) { 450 void DeviceImpl::OnDeviceRemoved(scoped_refptr<UsbDevice> device) {
446 DCHECK_EQ(device_, device); 451 DCHECK_EQ(device_, device);
447 delete this; 452 delete this;
448 } 453 }
449 454
450 } // namespace usb 455 } // namespace usb
451 } // namespace device 456 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698