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

Side by Side Diff: chrome/browser/usb/usb_service.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/usb/usb_service.h ('k') | no next file » | 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/usb/usb_service.h" 5 #include "chrome/browser/usb/usb_service.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 UsbService::~UsbService() {} 64 UsbService::~UsbService() {}
65 65
66 void UsbService::Cleanup() { 66 void UsbService::Cleanup() {
67 event_handler_->Stop(); 67 event_handler_->Stop();
68 event_handler_ = NULL; 68 event_handler_ = NULL;
69 } 69 }
70 70
71 void UsbService::FindDevices(const uint16 vendor_id, 71 void UsbService::FindDevices(const uint16 vendor_id,
72 const uint16 product_id, 72 const uint16 product_id,
73 vector<scoped_refptr<UsbDevice> >* devices) { 73 vector<scoped_refptr<UsbDevice> >* devices,
74 const base::Callback<void()>& callback) {
74 DCHECK(event_handler_) << "FindDevices called after event handler stopped."; 75 DCHECK(event_handler_) << "FindDevices called after event handler stopped.";
75 #if defined(OS_CHROMEOS) 76 #if defined(OS_CHROMEOS)
76 chromeos::PermissionBrokerClient* client = 77 chromeos::PermissionBrokerClient* client =
77 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient(); 78 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient();
78 DCHECK(client) << "Could not get permission broker client."; 79 DCHECK(client) << "Could not get permission broker client.";
79 if (!client) 80 if (!client) {
81 callback.Run();
80 return; 82 return;
83 }
84
81 client->RequestUsbAccess(vendor_id, 85 client->RequestUsbAccess(vendor_id,
82 product_id, 86 product_id,
83 base::Bind(&UsbService::FindDevicesImpl, 87 base::Bind(&UsbService::FindDevicesImpl,
84 base::Unretained(this), 88 base::Unretained(this),
85 vendor_id, 89 vendor_id,
86 product_id, 90 product_id,
87 devices)); 91 devices,
92 callback));
88 #else 93 #else
89 FindDevicesImpl(vendor_id, product_id, devices, true); 94 FindDevicesImpl(vendor_id, product_id, devices, callback, true);
90 #endif // defined(OS_CHROMEOS) 95 #endif // defined(OS_CHROMEOS)
91 } 96 }
92 97
93 void UsbService::FindDevicesImpl(const uint16 vendor_id, 98 void UsbService::FindDevicesImpl(const uint16 vendor_id,
94 const uint16 product_id, 99 const uint16 product_id,
95 vector<scoped_refptr<UsbDevice> >* devices, 100 vector<scoped_refptr<UsbDevice> >* devices,
101 const base::Callback<void()>& callback,
96 bool success) { 102 bool success) {
103 base::ScopedClosureRunner run_callback(callback);
104
97 devices->clear(); 105 devices->clear();
98 106
99 // If the permission broker was unable to obtain permission for the specified 107 // If the permission broker was unable to obtain permission for the specified
100 // devices then there is no point in attempting to enumerate the devices. On 108 // devices then there is no point in attempting to enumerate the devices. On
101 // platforms without a permission broker, we assume permission is granted. 109 // platforms without a permission broker, we assume permission is granted.
102 if (!success) 110 if (!success)
103 return; 111 return;
104 112
105 DeviceVector enumerated_devices; 113 DeviceVector enumerated_devices;
106 EnumerateDevices(&enumerated_devices); 114 EnumerateDevices(&enumerated_devices);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 if (libusb_open(device, &handle)) { 188 if (libusb_open(device, &handle)) {
181 LOG(WARNING) << "Could not open device."; 189 LOG(WARNING) << "Could not open device.";
182 return NULL; 190 return NULL;
183 } 191 }
184 192
185 UsbDevice* wrapper = new UsbDevice(this, handle); 193 UsbDevice* wrapper = new UsbDevice(this, handle);
186 devices_[device] = wrapper; 194 devices_[device] = wrapper;
187 } 195 }
188 return devices_[device]; 196 return devices_[device];
189 } 197 }
OLDNEW
« no previous file with comments | « chrome/browser/usb/usb_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698