OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_service_win.h" | 5 #include "device/usb/usb_service_win.h" |
6 | 6 |
7 #include <setupapi.h> | 7 #include <setupapi.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <usbiodef.h> | 9 #include <usbiodef.h> |
10 | 10 |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 | 327 |
328 void UsbServiceWin::CreateDeviceObject(const std::string& device_path, | 328 void UsbServiceWin::CreateDeviceObject(const std::string& device_path, |
329 const std::string& hub_path, | 329 const std::string& hub_path, |
330 int port_number) { | 330 int port_number) { |
331 // Devices that appear during initial enumeration are gathered into the first | 331 // Devices that appear during initial enumeration are gathered into the first |
332 // result returned by GetDevices() and prevent device add/remove notifications | 332 // result returned by GetDevices() and prevent device add/remove notifications |
333 // from being sent. | 333 // from being sent. |
334 if (!enumeration_ready()) | 334 if (!enumeration_ready()) |
335 ++first_enumeration_countdown_; | 335 ++first_enumeration_countdown_; |
336 | 336 |
337 scoped_refptr<UsbDeviceWin> device(new UsbDeviceWin( | 337 scoped_refptr<UsbDeviceWin> device( |
338 device_path, hub_path, port_number, blocking_task_runner())); | 338 new UsbDeviceWin(device_path, hub_path, port_number, task_runner())); |
339 devices_by_path_[device->device_path()] = device; | 339 devices_by_path_[device->device_path()] = device; |
340 | 340 device->ReadDescriptors(base::Bind(&UsbServiceWin::DeviceReady, |
341 // TODO(reillyg): Read device descriptors. | 341 weak_factory_.GetWeakPtr(), device)); |
342 DeviceReady(device, true); | |
343 } | 342 } |
344 | 343 |
345 void UsbServiceWin::DeviceReady(scoped_refptr<UsbDeviceWin> device, | 344 void UsbServiceWin::DeviceReady(scoped_refptr<UsbDeviceWin> device, |
346 bool success) { | 345 bool success) { |
347 DCHECK(CalledOnValidThread()); | 346 DCHECK(CalledOnValidThread()); |
348 | 347 |
349 bool enumeration_became_ready = false; | 348 bool enumeration_became_ready = false; |
350 if (!enumeration_ready()) { | 349 if (!enumeration_ready()) { |
351 DCHECK_GT(first_enumeration_countdown_, 0u); | 350 DCHECK_GT(first_enumeration_countdown_, 0u); |
352 first_enumeration_countdown_--; | 351 first_enumeration_countdown_--; |
(...skipping 27 matching lines...) Expand all Loading... |
380 result.push_back(map_entry.second); | 379 result.push_back(map_entry.second); |
381 for (const auto& callback : enumeration_callbacks_) | 380 for (const auto& callback : enumeration_callbacks_) |
382 callback.Run(result); | 381 callback.Run(result); |
383 enumeration_callbacks_.clear(); | 382 enumeration_callbacks_.clear(); |
384 } else if (success && enumeration_ready()) { | 383 } else if (success && enumeration_ready()) { |
385 NotifyDeviceAdded(device); | 384 NotifyDeviceAdded(device); |
386 } | 385 } |
387 } | 386 } |
388 | 387 |
389 } // namespace device | 388 } // namespace device |
OLD | NEW |