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

Side by Side Diff: extensions/browser/api/usb/usb_api.cc

Issue 462753002: Add usb_service::UsbDeviceFilter class for device matching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add UsbDevice::RequestUsbAccess to the mock (and fix spelling). Created 6 years, 4 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 | « components/usb_service/usb_device_impl.cc ('k') | extensions/browser/api/usb/usb_apitest.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 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 "extensions/browser/api/usb/usb_api.h" 5 #include "extensions/browser/api/usb/usb_api.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 bool success) { 318 bool success) {
319 if (success) { 319 if (success) {
320 ++i; 320 ++i;
321 } else { 321 } else {
322 i = devices->erase(i); 322 i = devices->erase(i);
323 } 323 }
324 if (i == devices->end()) { 324 if (i == devices->end()) {
325 callback.Run(devices.Pass()); 325 callback.Run(devices.Pass());
326 return; 326 return;
327 } 327 }
328 (*i)->RequestUsbAcess(interface_id, 328 (*i)->RequestUsbAccess(interface_id,
329 base::Bind(RequestUsbDevicesAccessHelper, 329 base::Bind(RequestUsbDevicesAccessHelper,
330 base::Passed(devices.Pass()), 330 base::Passed(devices.Pass()),
331 i, 331 i,
332 interface_id, 332 interface_id,
333 callback)); 333 callback));
334 } 334 }
335 335
336 void RequestUsbDevicesAccess( 336 void RequestUsbDevicesAccess(
337 ScopedDeviceVector devices, 337 ScopedDeviceVector devices,
338 int interface_id, 338 int interface_id,
339 const base::Callback<void(ScopedDeviceVector result)>& callback) { 339 const base::Callback<void(ScopedDeviceVector result)>& callback) {
340 if (devices->empty()) { 340 if (devices->empty()) {
341 callback.Run(devices.Pass()); 341 callback.Run(devices.Pass());
342 return; 342 return;
343 } 343 }
344 std::vector<scoped_refptr<UsbDevice> >::iterator i = devices->begin(); 344 std::vector<scoped_refptr<UsbDevice> >::iterator i = devices->begin();
345 (*i)->RequestUsbAcess(interface_id, 345 (*i)->RequestUsbAccess(interface_id,
346 base::Bind(RequestUsbDevicesAccessHelper, 346 base::Bind(RequestUsbDevicesAccessHelper,
347 base::Passed(devices.Pass()), 347 base::Passed(devices.Pass()),
348 i, 348 i,
349 interface_id, 349 interface_id,
350 callback)); 350 callback));
351 } 351 }
352 #endif // OS_CHROMEOS 352 #endif // OS_CHROMEOS
353 353
354 base::DictionaryValue* CreateTransferInfo(UsbTransferStatus status, 354 base::DictionaryValue* CreateTransferInfo(UsbTransferStatus status,
355 scoped_refptr<net::IOBuffer> data, 355 scoped_refptr<net::IOBuffer> data,
356 size_t length) { 356 size_t length) {
357 base::DictionaryValue* result = new base::DictionaryValue(); 357 base::DictionaryValue* result = new base::DictionaryValue();
358 result->SetInteger(kResultCodeKey, status); 358 result->SetInteger(kResultCodeKey, status);
359 result->Set(kDataKey, 359 result->Set(kDataKey,
360 base::BinaryValue::CreateWithCopiedBuffer(data->data(), length)); 360 base::BinaryValue::CreateWithCopiedBuffer(data->data(), length));
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 return true; 673 return true;
674 } 674 }
675 675
676 void UsbRequestAccessFunction::AsyncWorkStart() { 676 void UsbRequestAccessFunction::AsyncWorkStart() {
677 #if defined(OS_CHROMEOS) 677 #if defined(OS_CHROMEOS)
678 scoped_refptr<UsbDevice> device = 678 scoped_refptr<UsbDevice> device =
679 GetDeviceOrOrCompleteWithError(parameters_->device); 679 GetDeviceOrOrCompleteWithError(parameters_->device);
680 if (!device) 680 if (!device)
681 return; 681 return;
682 682
683 device->RequestUsbAcess( 683 device->RequestUsbAccess(
684 parameters_->interface_id, 684 parameters_->interface_id,
685 base::Bind(&UsbRequestAccessFunction::OnCompleted, this)); 685 base::Bind(&UsbRequestAccessFunction::OnCompleted, this));
686 #else 686 #else
687 SetResult(new base::FundamentalValue(false)); 687 SetResult(new base::FundamentalValue(false));
688 CompleteWithError(kErrorNotSupported); 688 CompleteWithError(kErrorNotSupported);
689 #endif // OS_CHROMEOS 689 #endif // OS_CHROMEOS
690 } 690 }
691 691
692 void UsbRequestAccessFunction::OnCompleted(bool success) { 692 void UsbRequestAccessFunction::OnCompleted(bool success) {
693 SetResult(new base::FundamentalValue(success)); 693 SetResult(new base::FundamentalValue(success));
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 SetResult(new base::FundamentalValue(false)); 1199 SetResult(new base::FundamentalValue(false));
1200 CompleteWithError(kErrorResetDevice); 1200 CompleteWithError(kErrorResetDevice);
1201 return; 1201 return;
1202 } 1202 }
1203 1203
1204 SetResult(new base::FundamentalValue(true)); 1204 SetResult(new base::FundamentalValue(true));
1205 AsyncWorkCompleted(); 1205 AsyncWorkCompleted();
1206 } 1206 }
1207 1207
1208 } // namespace extensions 1208 } // namespace extensions
OLDNEW
« no previous file with comments | « components/usb_service/usb_device_impl.cc ('k') | extensions/browser/api/usb/usb_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698