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

Side by Side Diff: content/renderer/usb/web_usb_device_impl.cc

Issue 1358763004: Implement getConfiguration in WebUSBDeviceImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 | « content/renderer/usb/web_usb_device_impl.h ('k') | device/devices_app/usb/device_impl.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 "content/renderer/usb/web_usb_device_impl.h" 5 #include "content/renderer/usb/web_usb_device_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "content/child/scoped_web_callbacks.h" 10 #include "content/child/scoped_web_callbacks.h"
11 #include "content/renderer/usb/type_converters.h" 11 #include "content/renderer/usb/type_converters.h"
12 #include "device/devices_app/public/cpp/constants.h" 12 #include "device/devices_app/public/cpp/constants.h"
13 #include "mojo/application/public/cpp/connect.h" 13 #include "mojo/application/public/cpp/connect.h"
14 #include "mojo/application/public/interfaces/shell.mojom.h" 14 #include "mojo/application/public/interfaces/shell.mojom.h"
15 #include "third_party/WebKit/public/platform/WebVector.h" 15 #include "third_party/WebKit/public/platform/WebVector.h"
16 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBDeviceInfo.h" 16 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBDeviceInfo.h"
17 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBTransferInfo.h " 17 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBTransferInfo.h "
18 18
19 namespace content { 19 namespace content {
20 20
21 namespace { 21 namespace {
22 22
23 const char kClaimInterfaceFailed[] = "Unable to claim interface."; 23 const char kClaimInterfaceFailed[] = "Unable to claim interface.";
24 const char kClearHaltFailed[] = "Unable to clear endpoint."; 24 const char kClearHaltFailed[] = "Unable to clear endpoint.";
25 const char kDeviceNoAccess[] = "Access denied."; 25 const char kDeviceNoAccess[] = "Access denied.";
26 const char kDeviceNotConfigured[] = "Device not configured.";
26 const char kDeviceNotOpened[] = "Device not opened."; 27 const char kDeviceNotOpened[] = "Device not opened.";
27 const char kDeviceUnavailable[] = "Device unavailable."; 28 const char kDeviceUnavailable[] = "Device unavailable.";
28 const char kDeviceResetFailed[] = "Unable to reset the device."; 29 const char kDeviceResetFailed[] = "Unable to reset the device.";
29 const char kReleaseInterfaceFailed[] = "Unable to release interface."; 30 const char kReleaseInterfaceFailed[] = "Unable to release interface.";
30 const char kSetConfigurationFailed[] = "Unable to set device configuration."; 31 const char kSetConfigurationFailed[] = "Unable to set device configuration.";
31 const char kSetInterfaceFailed[] = "Unable to set device interface."; 32 const char kSetInterfaceFailed[] = "Unable to set device interface.";
32 const char kTransferFailed[] = "Transfer failed."; 33 const char kTransferFailed[] = "Transfer failed.";
33 34
34 // Generic default rejection handler for any WebUSB callbacks type. Assumes 35 // Generic default rejection handler for any WebUSB callbacks type. Assumes
35 // |CallbacksType| is a blink::WebCallbacks<T, const blink::WebUSBError&> 36 // |CallbacksType| is a blink::WebCallbacks<T, const blink::WebUSBError&>
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 default: 84 default:
84 NOTREACHED(); 85 NOTREACHED();
85 } 86 }
86 } 87 }
87 88
88 void OnDeviceClosed( 89 void OnDeviceClosed(
89 ScopedWebCallbacks<blink::WebUSBDeviceCloseCallbacks> callbacks) { 90 ScopedWebCallbacks<blink::WebUSBDeviceCloseCallbacks> callbacks) {
90 callbacks.PassCallbacks()->onSuccess(); 91 callbacks.PassCallbacks()->onSuccess();
91 } 92 }
92 93
94 void OnGetConfiguration(
95 ScopedWebCallbacks<blink::WebUSBDeviceGetConfigurationCallbacks> callbacks,
96 uint8_t configuration_value) {
97 auto scoped_callbacks = callbacks.PassCallbacks();
98 if (configuration_value == 0)
99 RejectWithDeviceError(kDeviceNotConfigured, scoped_callbacks.Pass());
100 else
101 scoped_callbacks->onSuccess(configuration_value);
102 }
103
93 void HandlePassFailDeviceOperation( 104 void HandlePassFailDeviceOperation(
94 ScopedWebCallbacks<blink::WebCallbacks<void, const blink::WebUSBError&>> 105 ScopedWebCallbacks<blink::WebCallbacks<void, const blink::WebUSBError&>>
95 callbacks, 106 callbacks,
96 const std::string& failure_message, 107 const std::string& failure_message,
97 bool success) { 108 bool success) {
98 auto scoped_callbacks = callbacks.PassCallbacks(); 109 auto scoped_callbacks = callbacks.PassCallbacks();
99 if (success) 110 if (success)
100 scoped_callbacks->onSuccess(); 111 scoped_callbacks->onSuccess();
101 else 112 else
102 RejectWithDeviceError(failure_message, scoped_callbacks.Pass()); 113 RejectWithDeviceError(failure_message, scoped_callbacks.Pass());
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 void WebUSBDeviceImpl::close(blink::WebUSBDeviceCloseCallbacks* callbacks) { 175 void WebUSBDeviceImpl::close(blink::WebUSBDeviceCloseCallbacks* callbacks) {
165 auto scoped_callbacks = MakeScopedUSBCallbacks(callbacks); 176 auto scoped_callbacks = MakeScopedUSBCallbacks(callbacks);
166 if (!device_) { 177 if (!device_) {
167 RejectWithDeviceError(kDeviceNotOpened, scoped_callbacks.PassCallbacks()); 178 RejectWithDeviceError(kDeviceNotOpened, scoped_callbacks.PassCallbacks());
168 } else { 179 } else {
169 device_->Close( 180 device_->Close(
170 base::Bind(&OnDeviceClosed, base::Passed(&scoped_callbacks))); 181 base::Bind(&OnDeviceClosed, base::Passed(&scoped_callbacks)));
171 } 182 }
172 } 183 }
173 184
185 void WebUSBDeviceImpl::getConfiguration(
186 blink::WebUSBDeviceGetConfigurationCallbacks* callbacks) {
187 auto scoped_callbacks = MakeScopedUSBCallbacks(callbacks);
188 if (!device_) {
189 RejectWithDeviceError(kDeviceNotOpened, scoped_callbacks.PassCallbacks());
190 } else {
191 device_->GetConfiguration(
192 base::Bind(&OnGetConfiguration, base::Passed(&scoped_callbacks)));
193 }
194 }
195
174 void WebUSBDeviceImpl::setConfiguration( 196 void WebUSBDeviceImpl::setConfiguration(
175 uint8_t configuration_value, 197 uint8_t configuration_value,
176 blink::WebUSBDeviceSetConfigurationCallbacks* callbacks) { 198 blink::WebUSBDeviceSetConfigurationCallbacks* callbacks) {
177 auto scoped_callbacks = MakeScopedUSBCallbacks(callbacks); 199 auto scoped_callbacks = MakeScopedUSBCallbacks(callbacks);
178 if (!device_) { 200 if (!device_) {
179 RejectWithDeviceError(kDeviceNotOpened, scoped_callbacks.PassCallbacks()); 201 RejectWithDeviceError(kDeviceNotOpened, scoped_callbacks.PassCallbacks());
180 } else { 202 } else {
181 device_->SetConfiguration( 203 device_->SetConfiguration(
182 configuration_value, 204 configuration_value,
183 base::Bind(&HandlePassFailDeviceOperation, 205 base::Bind(&HandlePassFailDeviceOperation,
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 if (!device_) { 338 if (!device_) {
317 RejectWithDeviceError(kDeviceNotOpened, scoped_callbacks.PassCallbacks()); 339 RejectWithDeviceError(kDeviceNotOpened, scoped_callbacks.PassCallbacks());
318 } else { 340 } else {
319 device_->Reset( 341 device_->Reset(
320 base::Bind(&HandlePassFailDeviceOperation, 342 base::Bind(&HandlePassFailDeviceOperation,
321 base::Passed(&scoped_callbacks), kDeviceResetFailed)); 343 base::Passed(&scoped_callbacks), kDeviceResetFailed));
322 } 344 }
323 } 345 }
324 346
325 } // namespace content 347 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/usb/web_usb_device_impl.h ('k') | device/devices_app/usb/device_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698