| OLD | NEW |
| 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 "modules/webusb/USBDevice.h" | 5 #include "modules/webusb/USBDevice.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptPromise.h" | 7 #include "bindings/core/v8/ScriptPromise.h" |
| 8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 9 #include "bindings/core/v8/ToV8ForCore.h" | 9 #include "bindings/core/v8/ToV8ForCore.h" |
| 10 #include "core/dom/DOMArrayBuffer.h" | 10 #include "core/dom/DOMArrayBuffer.h" |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 } | 274 } |
| 275 | 275 |
| 276 ScriptPromise USBDevice::selectAlternateInterface(ScriptState* script_state, | 276 ScriptPromise USBDevice::selectAlternateInterface(ScriptState* script_state, |
| 277 uint8_t interface_number, | 277 uint8_t interface_number, |
| 278 uint8_t alternate_setting) { | 278 uint8_t alternate_setting) { |
| 279 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 279 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
| 280 ScriptPromise promise = resolver->Promise(); | 280 ScriptPromise promise = resolver->Promise(); |
| 281 if (EnsureInterfaceClaimed(interface_number, resolver)) { | 281 if (EnsureInterfaceClaimed(interface_number, resolver)) { |
| 282 // TODO(reillyg): This is duplicated work. | 282 // TODO(reillyg): This is duplicated work. |
| 283 int interface_index = FindInterfaceIndex(interface_number); | 283 int interface_index = FindInterfaceIndex(interface_number); |
| 284 ASSERT(interface_index != -1); | 284 DCHECK_NE(interface_index, -1); |
| 285 int alternate_index = | 285 int alternate_index = |
| 286 FindAlternateIndex(interface_index, alternate_setting); | 286 FindAlternateIndex(interface_index, alternate_setting); |
| 287 if (alternate_index == -1) { | 287 if (alternate_index == -1) { |
| 288 resolver->Reject(DOMException::Create(kNotFoundError, | 288 resolver->Reject(DOMException::Create(kNotFoundError, |
| 289 "The alternate setting provided is " | 289 "The alternate setting provided is " |
| 290 "not supported by the device in " | 290 "not supported by the device in " |
| 291 "its current configuration.")); | 291 "its current configuration.")); |
| 292 } else { | 292 } else { |
| 293 // Mark this old alternate interface's endpoints unavailable while | 293 // Mark this old alternate interface's endpoints unavailable while |
| 294 // the change is in progress. | 294 // the change is in progress. |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 int USBDevice::FindConfigurationIndex(uint8_t configuration_value) const { | 479 int USBDevice::FindConfigurationIndex(uint8_t configuration_value) const { |
| 480 const auto& configurations = Info().configurations; | 480 const auto& configurations = Info().configurations; |
| 481 for (size_t i = 0; i < configurations.size(); ++i) { | 481 for (size_t i = 0; i < configurations.size(); ++i) { |
| 482 if (configurations[i]->configuration_value == configuration_value) | 482 if (configurations[i]->configuration_value == configuration_value) |
| 483 return i; | 483 return i; |
| 484 } | 484 } |
| 485 return -1; | 485 return -1; |
| 486 } | 486 } |
| 487 | 487 |
| 488 int USBDevice::FindInterfaceIndex(uint8_t interface_number) const { | 488 int USBDevice::FindInterfaceIndex(uint8_t interface_number) const { |
| 489 ASSERT(configuration_index_ != -1); | 489 DCHECK_NE(configuration_index_, -1); |
| 490 const auto& interfaces = | 490 const auto& interfaces = |
| 491 Info().configurations[configuration_index_]->interfaces; | 491 Info().configurations[configuration_index_]->interfaces; |
| 492 for (size_t i = 0; i < interfaces.size(); ++i) { | 492 for (size_t i = 0; i < interfaces.size(); ++i) { |
| 493 if (interfaces[i]->interface_number == interface_number) | 493 if (interfaces[i]->interface_number == interface_number) |
| 494 return i; | 494 return i; |
| 495 } | 495 } |
| 496 return -1; | 496 return -1; |
| 497 } | 497 } |
| 498 | 498 |
| 499 int USBDevice::FindAlternateIndex(size_t interface_index, | 499 int USBDevice::FindAlternateIndex(size_t interface_index, |
| 500 uint8_t alternate_setting) const { | 500 uint8_t alternate_setting) const { |
| 501 ASSERT(configuration_index_ != -1); | 501 DCHECK_NE(configuration_index_, -1); |
| 502 const auto& alternates = Info() | 502 const auto& alternates = Info() |
| 503 .configurations[configuration_index_] | 503 .configurations[configuration_index_] |
| 504 ->interfaces[interface_index] | 504 ->interfaces[interface_index] |
| 505 ->alternates; | 505 ->alternates; |
| 506 for (size_t i = 0; i < alternates.size(); ++i) { | 506 for (size_t i = 0; i < alternates.size(); ++i) { |
| 507 if (alternates[i]->alternate_setting == alternate_setting) | 507 if (alternates[i]->alternate_setting == alternate_setting) |
| 508 return i; | 508 return i; |
| 509 } | 509 } |
| 510 return -1; | 510 return -1; |
| 511 } | 511 } |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 | 925 |
| 926 bool USBDevice::MarkRequestComplete(ScriptPromiseResolver* resolver) { | 926 bool USBDevice::MarkRequestComplete(ScriptPromiseResolver* resolver) { |
| 927 auto request_entry = device_requests_.find(resolver); | 927 auto request_entry = device_requests_.find(resolver); |
| 928 if (request_entry == device_requests_.end()) | 928 if (request_entry == device_requests_.end()) |
| 929 return false; | 929 return false; |
| 930 device_requests_.erase(request_entry); | 930 device_requests_.erase(request_entry); |
| 931 return true; | 931 return true; |
| 932 } | 932 } |
| 933 | 933 |
| 934 } // namespace blink | 934 } // namespace blink |
| OLD | NEW |