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

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

Issue 12226137: Fix missing callback chaining in UsbService. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 10 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 | « chrome/browser/extensions/api/usb/usb_api.h ('k') | chrome/browser/usb/usb_service.h » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/usb/usb_api.h" 5 #include "chrome/browser/extensions/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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 device_for_test_ = device; 295 device_for_test_ = device;
296 } 296 }
297 297
298 bool UsbFindDevicesFunction::Prepare() { 298 bool UsbFindDevicesFunction::Prepare() {
299 parameters_ = FindDevices::Params::Create(*args_); 299 parameters_ = FindDevices::Params::Create(*args_);
300 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); 300 EXTENSION_FUNCTION_VALIDATE(parameters_.get());
301 return true; 301 return true;
302 } 302 }
303 303
304 void UsbFindDevicesFunction::AsyncWorkStart() { 304 void UsbFindDevicesFunction::AsyncWorkStart() {
305 scoped_ptr<base::ListValue> result(new base::ListValue()); 305 result_.reset(new base::ListValue());
306 306
307 if (device_for_test_) { 307 if (device_for_test_) {
308 UsbDeviceResource* const resource = new UsbDeviceResource( 308 UsbDeviceResource* const resource = new UsbDeviceResource(
309 extension_->id(), 309 extension_->id(),
310 device_for_test_); 310 device_for_test_);
311 311
312 Device device; 312 Device device;
313 result->Append(PopulateDevice(manager_->Add(resource), 0, 0)); 313 result_->Append(PopulateDevice(manager_->Add(resource), 0, 0));
314 SetResult(result.release()); 314 SetResult(result_.release());
315 AsyncWorkCompleted(); 315 AsyncWorkCompleted();
316 return; 316 return;
317 } 317 }
318 318
319 const uint16_t vendor_id = parameters_->options.vendor_id; 319 const uint16_t vendor_id = parameters_->options.vendor_id;
320 const uint16_t product_id = parameters_->options.product_id; 320 const uint16_t product_id = parameters_->options.product_id;
321 UsbDevicePermission::CheckParam param(vendor_id, product_id); 321 UsbDevicePermission::CheckParam param(vendor_id, product_id);
322 if (!GetExtension()->CheckAPIPermissionWithParam( 322 if (!GetExtension()->CheckAPIPermissionWithParam(
323 APIPermission::kUsbDevice, &param)) { 323 APIPermission::kUsbDevice, &param)) {
324 LOG(WARNING) << "Insufficient permissions to access device."; 324 LOG(WARNING) << "Insufficient permissions to access device.";
325 CompleteWithError(kErrorPermissionDenied); 325 CompleteWithError(kErrorPermissionDenied);
326 return; 326 return;
327 } 327 }
328 328
329 UsbService* const service = UsbServiceFactory::GetInstance()->GetForProfile( 329 UsbService* const service = UsbServiceFactory::GetInstance()->GetForProfile(
330 profile()); 330 profile());
331 if (!service) { 331 if (!service) {
332 LOG(WARNING) << "Could not get UsbService for active profile."; 332 LOG(WARNING) << "Could not get UsbService for active profile.";
333 CompleteWithError(kErrorNoDevice); 333 CompleteWithError(kErrorNoDevice);
334 return; 334 return;
335 } 335 }
336 336
337 vector<scoped_refptr<UsbDevice> > devices; 337 service->FindDevices(vendor_id, product_id, &devices_, base::Bind(
338 service->FindDevices(vendor_id, product_id, &devices); 338 &UsbFindDevicesFunction::OnCompleted, this));
339 for (size_t i = 0; i < devices.size(); ++i) { 339 }
340 UsbDevice* const device = devices[i]; 340
341 void UsbFindDevicesFunction::OnCompleted() {
342 for (size_t i = 0; i < devices_.size(); ++i) {
343 UsbDevice* const device = devices_[i];
341 UsbDeviceResource* const resource = new UsbDeviceResource( 344 UsbDeviceResource* const resource = new UsbDeviceResource(
342 extension_->id(), device); 345 extension_->id(), device);
343 346
344 Device js_device; 347 Device js_device;
345 result->Append(PopulateDevice(manager_->Add(resource), 348 result_->Append(PopulateDevice(manager_->Add(resource),
346 vendor_id, 349 parameters_->options.vendor_id,
347 product_id)); 350 parameters_->options.product_id));
348 } 351 }
349 352
350 SetResult(result.release()); 353 SetResult(result_.release());
351 AsyncWorkCompleted(); 354 AsyncWorkCompleted();
352 } 355 }
353 356
354 UsbCloseDeviceFunction::UsbCloseDeviceFunction() {} 357 UsbCloseDeviceFunction::UsbCloseDeviceFunction() {}
355 358
356 UsbCloseDeviceFunction::~UsbCloseDeviceFunction() {} 359 UsbCloseDeviceFunction::~UsbCloseDeviceFunction() {}
357 360
358 bool UsbCloseDeviceFunction::Prepare() { 361 bool UsbCloseDeviceFunction::Prepare() {
359 parameters_ = CloseDevice::Params::Create(*args_); 362 parameters_ = CloseDevice::Params::Create(*args_);
360 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); 363 EXTENSION_FUNCTION_VALIDATE(parameters_.get());
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 CompleteWithError(kErrorMalformedParameters); 643 CompleteWithError(kErrorMalformedParameters);
641 return; 644 return;
642 } 645 }
643 646
644 device->device()->IsochronousTransfer(direction, generic_transfer.endpoint, 647 device->device()->IsochronousTransfer(direction, generic_transfer.endpoint,
645 buffer, size, transfer.packets, transfer.packet_length, 0, base::Bind( 648 buffer, size, transfer.packets, transfer.packet_length, 0, base::Bind(
646 &UsbIsochronousTransferFunction::OnCompleted, this)); 649 &UsbIsochronousTransferFunction::OnCompleted, this));
647 } 650 }
648 651
649 } // namespace extensions 652 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/usb/usb_api.h ('k') | chrome/browser/usb/usb_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698