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

Side by Side Diff: chrome/browser/devtools/device/usb/android_usb_device.cc

Issue 1030263002: favor DCHECK_CURRENTLY_ON for better logs in chrome/browser/devtools (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
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 "chrome/browser/devtools/device/usb/android_usb_device.h" 5 #include "chrome/browser/devtools/device/usb/android_usb_device.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/barrier_closure.h" 9 #include "base/barrier_closure.h"
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 173
174 // Return all claimed devices. 174 // Return all claimed devices.
175 AndroidUsbDevices result(g_devices.Get().begin(), g_devices.Get().end()); 175 AndroidUsbDevices result(g_devices.Get().begin(), g_devices.Get().end());
176 callback.Run(result); 176 callback.Run(result);
177 } 177 }
178 178
179 static void RespondOnFileThread( 179 static void RespondOnFileThread(
180 const AndroidUsbDevicesCallback& callback, 180 const AndroidUsbDevicesCallback& callback,
181 AndroidUsbDevices* devices, 181 AndroidUsbDevices* devices,
182 scoped_refptr<base::MessageLoopProxy> caller_message_loop_proxy) { 182 scoped_refptr<base::MessageLoopProxy> caller_message_loop_proxy) {
183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 183 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
184 caller_message_loop_proxy->PostTask( 184 caller_message_loop_proxy->PostTask(
185 FROM_HERE, 185 FROM_HERE,
186 base::Bind(&RespondOnCallerThread, callback, devices)); 186 base::Bind(&RespondOnCallerThread, callback, devices));
187 } 187 }
188 188
189 static void OpenAndroidDeviceOnFileThread( 189 static void OpenAndroidDeviceOnFileThread(
190 AndroidUsbDevices* devices, 190 AndroidUsbDevices* devices,
191 crypto::RSAPrivateKey* rsa_key, 191 crypto::RSAPrivateKey* rsa_key,
192 const base::Closure& barrier, 192 const base::Closure& barrier,
193 scoped_refptr<UsbDevice> device, 193 scoped_refptr<UsbDevice> device,
194 int interface_id, 194 int interface_id,
195 bool success) { 195 bool success) {
196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 196 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
197 if (success) { 197 if (success) {
198 base::string16 serial; 198 base::string16 serial;
199 if (device->GetSerialNumber(&serial) && !serial.empty()) { 199 if (device->GetSerialNumber(&serial) && !serial.empty()) {
200 const UsbConfigDescriptor* config = device->GetConfiguration(); 200 const UsbConfigDescriptor* config = device->GetConfiguration();
201 if (config) { 201 if (config) {
202 scoped_refptr<UsbDeviceHandle> usb_handle = device->Open(); 202 scoped_refptr<UsbDeviceHandle> usb_handle = device->Open();
203 if (usb_handle.get()) { 203 if (usb_handle.get()) {
204 scoped_refptr<AndroidUsbDevice> android_device = ClaimInterface( 204 scoped_refptr<AndroidUsbDevice> android_device = ClaimInterface(
205 rsa_key, usb_handle, serial, config->interfaces[interface_id]); 205 rsa_key, usb_handle, serial, config->interfaces[interface_id]);
206 if (android_device.get()) 206 if (android_device.get())
207 devices->push_back(android_device); 207 devices->push_back(android_device);
208 else 208 else
209 usb_handle->Close(); 209 usb_handle->Close();
210 } 210 }
211 } 211 }
212 } 212 }
213 } 213 }
214 barrier.Run(); 214 barrier.Run();
215 } 215 }
216 216
217 static int CountOnFileThread() { 217 static int CountOnFileThread() {
218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 218 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
219 UsbService* service = device::DeviceClient::Get()->GetUsbService(); 219 UsbService* service = device::DeviceClient::Get()->GetUsbService();
220 UsbDevices usb_devices; 220 UsbDevices usb_devices;
221 if (service != NULL) 221 if (service != NULL)
222 service->GetDevices(&usb_devices); 222 service->GetDevices(&usb_devices);
223 int device_count = 0; 223 int device_count = 0;
224 for (const scoped_refptr<UsbDevice>& device : usb_devices) { 224 for (const scoped_refptr<UsbDevice>& device : usb_devices) {
225 const UsbConfigDescriptor* config = device->GetConfiguration(); 225 const UsbConfigDescriptor* config = device->GetConfiguration();
226 if (config) { 226 if (config) {
227 for (const UsbInterfaceDescriptor& iface : config->interfaces) { 227 for (const UsbInterfaceDescriptor& iface : config->interfaces) {
228 if (IsAndroidInterface(iface)) { 228 if (IsAndroidInterface(iface)) {
229 ++device_count; 229 ++device_count;
230 } 230 }
231 } 231 }
232 } 232 }
233 } 233 }
234 return device_count; 234 return device_count;
235 } 235 }
236 236
237 static void EnumerateOnFileThread( 237 static void EnumerateOnFileThread(
238 crypto::RSAPrivateKey* rsa_key, 238 crypto::RSAPrivateKey* rsa_key,
239 const AndroidUsbDevicesCallback& callback, 239 const AndroidUsbDevicesCallback& callback,
240 scoped_refptr<base::MessageLoopProxy> caller_message_loop_proxy) { 240 scoped_refptr<base::MessageLoopProxy> caller_message_loop_proxy) {
241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 241 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
242 242
243 UsbService* service = device::DeviceClient::Get()->GetUsbService(); 243 UsbService* service = device::DeviceClient::Get()->GetUsbService();
244 UsbDevices usb_devices; 244 UsbDevices usb_devices;
245 if (service != NULL) 245 if (service != NULL)
246 service->GetDevices(&usb_devices); 246 service->GetDevices(&usb_devices);
247 247
248 // Add new devices. 248 // Add new devices.
249 AndroidUsbDevices* devices = new AndroidUsbDevices(); 249 AndroidUsbDevices* devices = new AndroidUsbDevices();
250 base::Closure barrier = base::BarrierClosure( 250 base::Closure barrier = base::BarrierClosure(
251 usb_devices.size(), base::Bind(&RespondOnFileThread, 251 usb_devices.size(), base::Bind(&RespondOnFileThread,
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 605
606 void AndroidUsbDevice::TransferError(UsbTransferStatus status) { 606 void AndroidUsbDevice::TransferError(UsbTransferStatus status) {
607 DCHECK(message_loop_ == base::MessageLoop::current()); 607 DCHECK(message_loop_ == base::MessageLoop::current());
608 608
609 message_loop_->PostTask(FROM_HERE, 609 message_loop_->PostTask(FROM_HERE,
610 base::Bind(&AndroidUsbDevice::Terminate, this)); 610 base::Bind(&AndroidUsbDevice::Terminate, this));
611 } 611 }
612 612
613 void AndroidUsbDevice::TerminateIfReleased( 613 void AndroidUsbDevice::TerminateIfReleased(
614 scoped_refptr<UsbDeviceHandle> usb_handle) { 614 scoped_refptr<UsbDeviceHandle> usb_handle) {
615 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 615 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
616 if (usb_handle->GetDevice().get()) 616 if (usb_handle->GetDevice().get())
617 return; 617 return;
618 message_loop_->PostTask(FROM_HERE, 618 message_loop_->PostTask(FROM_HERE,
619 base::Bind(&AndroidUsbDevice::Terminate, this)); 619 base::Bind(&AndroidUsbDevice::Terminate, this));
620 } 620 }
621 621
622 void AndroidUsbDevice::Terminate() { 622 void AndroidUsbDevice::Terminate() {
623 DCHECK(message_loop_ == base::MessageLoop::current()); 623 DCHECK(message_loop_ == base::MessageLoop::current());
624 624
625 std::vector<AndroidUsbDevice*>::iterator it = 625 std::vector<AndroidUsbDevice*>::iterator it =
(...skipping 20 matching lines...) Expand all
646 BrowserThread::PostTask( 646 BrowserThread::PostTask(
647 BrowserThread::FILE, FROM_HERE, 647 BrowserThread::FILE, FROM_HERE,
648 base::Bind(&ReleaseInterface, usb_handle, interface_id_)); 648 base::Bind(&ReleaseInterface, usb_handle, interface_id_));
649 } 649 }
650 650
651 void AndroidUsbDevice::SocketDeleted(uint32 socket_id) { 651 void AndroidUsbDevice::SocketDeleted(uint32 socket_id) {
652 DCHECK(message_loop_ == base::MessageLoop::current()); 652 DCHECK(message_loop_ == base::MessageLoop::current());
653 653
654 sockets_.erase(socket_id); 654 sockets_.erase(socket_id);
655 } 655 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698