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

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

Issue 1521803002: Match WebUSB errors more closely to the specificiation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 | « no previous file | content/renderer/usb/web_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_client_impl.h" 5 #include "content/renderer/usb/web_usb_client_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/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/move.h" 10 #include "base/move.h"
(...skipping 28 matching lines...) Expand all
39 } 39 }
40 40
41 // Create a new ScopedWebCallbacks for WebUSB client callbacks, defaulting to 41 // Create a new ScopedWebCallbacks for WebUSB client callbacks, defaulting to
42 // a "no service" rejection. 42 // a "no service" rejection.
43 template <typename CallbacksType> 43 template <typename CallbacksType>
44 ScopedWebCallbacks<CallbacksType> MakeScopedUSBCallbacks( 44 ScopedWebCallbacks<CallbacksType> MakeScopedUSBCallbacks(
45 CallbacksType* callbacks) { 45 CallbacksType* callbacks) {
46 return make_scoped_web_callbacks( 46 return make_scoped_web_callbacks(
47 callbacks, 47 callbacks,
48 base::Bind(&RejectCallbacksWithError<CallbacksType>, 48 base::Bind(&RejectCallbacksWithError<CallbacksType>,
49 blink::WebUSBError(blink::WebUSBError::Error::Service, 49 blink::WebUSBError(blink::WebUSBError::Error::NotFound,
50 base::UTF8ToUTF16(kNoServiceError)))); 50 base::ASCIIToUTF16(kNoServiceError))));
51 } 51 }
52 52
53 void OnGetDevicesComplete( 53 void OnGetDevicesComplete(
54 ScopedWebCallbacks<blink::WebUSBClientGetDevicesCallbacks> scoped_callbacks, 54 ScopedWebCallbacks<blink::WebUSBClientGetDevicesCallbacks> scoped_callbacks,
55 device::usb::DeviceManager* device_manager, 55 device::usb::DeviceManager* device_manager,
56 mojo::Array<device::usb::DeviceInfoPtr> results) { 56 mojo::Array<device::usb::DeviceInfoPtr> results) {
57 blink::WebVector<blink::WebUSBDevice*>* devices = 57 blink::WebVector<blink::WebUSBDevice*>* devices =
58 new blink::WebVector<blink::WebUSBDevice*>(results.size()); 58 new blink::WebVector<blink::WebUSBDevice*>(results.size());
59 for (size_t i = 0; i < results.size(); ++i) { 59 for (size_t i = 0; i < results.size(); ++i) {
60 device::usb::DevicePtr device; 60 device::usb::DevicePtr device;
(...skipping 10 matching lines...) Expand all
71 device::usb::DeviceInfoPtr result) { 71 device::usb::DeviceInfoPtr result) {
72 auto scoped_callbacks = callbacks.PassCallbacks(); 72 auto scoped_callbacks = callbacks.PassCallbacks();
73 if (result) { 73 if (result) {
74 device::usb::DevicePtr device; 74 device::usb::DevicePtr device;
75 device_manager->GetDevice(result->guid, mojo::GetProxy(&device)); 75 device_manager->GetDevice(result->guid, mojo::GetProxy(&device));
76 blink::WebUSBDevice* web_usb_device = new WebUSBDeviceImpl( 76 blink::WebUSBDevice* web_usb_device = new WebUSBDeviceImpl(
77 device.Pass(), mojo::ConvertTo<blink::WebUSBDeviceInfo>(result)); 77 device.Pass(), mojo::ConvertTo<blink::WebUSBDeviceInfo>(result));
78 78
79 scoped_callbacks->onSuccess(blink::adoptWebPtr(web_usb_device)); 79 scoped_callbacks->onSuccess(blink::adoptWebPtr(web_usb_device));
80 } else { 80 } else {
81 scoped_callbacks->onSuccess( 81 scoped_callbacks->onError(
82 blink::adoptWebPtr<blink::WebUSBDevice>(nullptr)); 82 blink::WebUSBError(blink::WebUSBError::Error::NotFound,
83 base::ASCIIToUTF16("No device selected.")));
83 } 84 }
84 } 85 }
85 86
86 } // namespace 87 } // namespace
87 88
88 WebUSBClientImpl::WebUSBClientImpl(content::ServiceRegistry* service_registry) 89 WebUSBClientImpl::WebUSBClientImpl(content::ServiceRegistry* service_registry)
89 : service_registry_(service_registry) {} 90 : service_registry_(service_registry) {}
90 91
91 WebUSBClientImpl::~WebUSBClientImpl() {} 92 WebUSBClientImpl::~WebUSBClientImpl() {}
92 93
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 const device::usb::DeviceInfoPtr& device_info = 157 const device::usb::DeviceInfoPtr& device_info =
157 notification->devices_removed[i]; 158 notification->devices_removed[i];
158 device::usb::DevicePtr device; 159 device::usb::DevicePtr device;
159 device_manager_->GetDevice(device_info->guid, mojo::GetProxy(&device)); 160 device_manager_->GetDevice(device_info->guid, mojo::GetProxy(&device));
160 observer_->onDeviceDisconnected(blink::adoptWebPtr(new WebUSBDeviceImpl( 161 observer_->onDeviceDisconnected(blink::adoptWebPtr(new WebUSBDeviceImpl(
161 device.Pass(), mojo::ConvertTo<blink::WebUSBDeviceInfo>(device_info)))); 162 device.Pass(), mojo::ConvertTo<blink::WebUSBDeviceInfo>(device_info))));
162 } 163 }
163 } 164 }
164 165
165 } // namespace content 166 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/usb/web_usb_device_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698