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

Side by Side Diff: device/usb/usb_service_linux.cc

Issue 2905153002: Move off of deprecated base::NonThreadSafe in device/ (Closed)
Patch Set: ThreadChecker => SequenceChecker Created 3 years, 6 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 | « device/usb/usb_service_impl.cc ('k') | device/usb/usb_service_win.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "device/usb/usb_service_linux.h" 5 #include "device/usb/usb_service_linux.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 blocking_task_runner()->PostTask( 186 blocking_task_runner()->PostTask(
187 FROM_HERE, 187 FROM_HERE,
188 base::Bind(&FileThreadHelper::Start, base::Unretained(helper_.get()))); 188 base::Bind(&FileThreadHelper::Start, base::Unretained(helper_.get())));
189 } 189 }
190 190
191 UsbServiceLinux::~UsbServiceLinux() { 191 UsbServiceLinux::~UsbServiceLinux() {
192 blocking_task_runner()->DeleteSoon(FROM_HERE, helper_.release()); 192 blocking_task_runner()->DeleteSoon(FROM_HERE, helper_.release());
193 } 193 }
194 194
195 void UsbServiceLinux::GetDevices(const GetDevicesCallback& callback) { 195 void UsbServiceLinux::GetDevices(const GetDevicesCallback& callback) {
196 DCHECK(CalledOnValidThread()); 196 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
197 if (enumeration_ready()) 197 if (enumeration_ready())
198 UsbService::GetDevices(callback); 198 UsbService::GetDevices(callback);
199 else 199 else
200 enumeration_callbacks_.push_back(callback); 200 enumeration_callbacks_.push_back(callback);
201 } 201 }
202 202
203 void UsbServiceLinux::OnDeviceAdded(const std::string& device_path, 203 void UsbServiceLinux::OnDeviceAdded(const std::string& device_path,
204 const UsbDeviceDescriptor& descriptor, 204 const UsbDeviceDescriptor& descriptor,
205 const std::string& manufacturer, 205 const std::string& manufacturer,
206 const std::string& product, 206 const std::string& product,
207 const std::string& serial_number, 207 const std::string& serial_number,
208 uint8_t active_configuration) { 208 uint8_t active_configuration) {
209 DCHECK(CalledOnValidThread()); 209 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
210 210
211 if (ContainsKey(devices_by_path_, device_path)) { 211 if (ContainsKey(devices_by_path_, device_path)) {
212 USB_LOG(ERROR) << "Got duplicate add event for path: " << device_path; 212 USB_LOG(ERROR) << "Got duplicate add event for path: " << device_path;
213 return; 213 return;
214 } 214 }
215 215
216 // Devices that appear during initial enumeration are gathered into the first 216 // Devices that appear during initial enumeration are gathered into the first
217 // result returned by GetDevices() and prevent device add/remove notifications 217 // result returned by GetDevices() and prevent device add/remove notifications
218 // from being sent. 218 // from being sent.
219 if (!enumeration_ready()) 219 if (!enumeration_ready())
220 ++first_enumeration_countdown_; 220 ++first_enumeration_countdown_;
221 221
222 scoped_refptr<UsbDeviceLinux> device( 222 scoped_refptr<UsbDeviceLinux> device(
223 new UsbDeviceLinux(device_path, descriptor, manufacturer, product, 223 new UsbDeviceLinux(device_path, descriptor, manufacturer, product,
224 serial_number, active_configuration)); 224 serial_number, active_configuration));
225 devices_by_path_[device->device_path()] = device; 225 devices_by_path_[device->device_path()] = device;
226 if (device->usb_version() >= kUsbVersion2_1) { 226 if (device->usb_version() >= kUsbVersion2_1) {
227 device->Open(base::Bind(&OnDeviceOpenedToReadDescriptors, 227 device->Open(base::Bind(&OnDeviceOpenedToReadDescriptors,
228 base::Bind(&UsbServiceLinux::DeviceReady, 228 base::Bind(&UsbServiceLinux::DeviceReady,
229 weak_factory_.GetWeakPtr(), device))); 229 weak_factory_.GetWeakPtr(), device)));
230 } else { 230 } else {
231 DeviceReady(device, true /* success */); 231 DeviceReady(device, true /* success */);
232 } 232 }
233 } 233 }
234 234
235 void UsbServiceLinux::DeviceReady(scoped_refptr<UsbDeviceLinux> device, 235 void UsbServiceLinux::DeviceReady(scoped_refptr<UsbDeviceLinux> device,
236 bool success) { 236 bool success) {
237 DCHECK(CalledOnValidThread()); 237 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
238 238
239 bool enumeration_became_ready = false; 239 bool enumeration_became_ready = false;
240 if (!enumeration_ready()) { 240 if (!enumeration_ready()) {
241 DCHECK_GT(first_enumeration_countdown_, 0u); 241 DCHECK_GT(first_enumeration_countdown_, 0u);
242 first_enumeration_countdown_--; 242 first_enumeration_countdown_--;
243 if (enumeration_ready()) 243 if (enumeration_ready())
244 enumeration_became_ready = true; 244 enumeration_became_ready = true;
245 } 245 }
246 246
247 // If |device| was disconnected while descriptors were being read then it 247 // If |device| was disconnected while descriptors were being read then it
(...skipping 22 matching lines...) Expand all
270 result.push_back(map_entry.second); 270 result.push_back(map_entry.second);
271 for (const auto& callback : enumeration_callbacks_) 271 for (const auto& callback : enumeration_callbacks_)
272 callback.Run(result); 272 callback.Run(result);
273 enumeration_callbacks_.clear(); 273 enumeration_callbacks_.clear();
274 } else if (success && enumeration_ready()) { 274 } else if (success && enumeration_ready()) {
275 NotifyDeviceAdded(device); 275 NotifyDeviceAdded(device);
276 } 276 }
277 } 277 }
278 278
279 void UsbServiceLinux::OnDeviceRemoved(const std::string& path) { 279 void UsbServiceLinux::OnDeviceRemoved(const std::string& path) {
280 DCHECK(CalledOnValidThread()); 280 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
281 auto by_path_it = devices_by_path_.find(path); 281 auto by_path_it = devices_by_path_.find(path);
282 if (by_path_it == devices_by_path_.end()) 282 if (by_path_it == devices_by_path_.end())
283 return; 283 return;
284 284
285 scoped_refptr<UsbDeviceLinux> device = by_path_it->second; 285 scoped_refptr<UsbDeviceLinux> device = by_path_it->second;
286 devices_by_path_.erase(by_path_it); 286 devices_by_path_.erase(by_path_it);
287 device->OnDisconnect(); 287 device->OnDisconnect();
288 288
289 auto by_guid_it = devices().find(device->guid()); 289 auto by_guid_it = devices().find(device->guid());
290 if (by_guid_it != devices().end() && enumeration_ready()) { 290 if (by_guid_it != devices().end() && enumeration_ready()) {
291 USB_LOG(USER) << "USB device removed: path=" << device->device_path() 291 USB_LOG(USER) << "USB device removed: path=" << device->device_path()
292 << " guid=" << device->guid(); 292 << " guid=" << device->guid();
293 293
294 devices().erase(by_guid_it); 294 devices().erase(by_guid_it);
295 NotifyDeviceRemoved(device); 295 NotifyDeviceRemoved(device);
296 } 296 }
297 } 297 }
298 298
299 void UsbServiceLinux::HelperStarted() { 299 void UsbServiceLinux::HelperStarted() {
300 DCHECK(CalledOnValidThread()); 300 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
301 helper_started_ = true; 301 helper_started_ = true;
302 if (enumeration_ready()) { 302 if (enumeration_ready()) {
303 std::vector<scoped_refptr<UsbDevice>> result; 303 std::vector<scoped_refptr<UsbDevice>> result;
304 result.reserve(devices().size()); 304 result.reserve(devices().size());
305 for (const auto& map_entry : devices()) 305 for (const auto& map_entry : devices())
306 result.push_back(map_entry.second); 306 result.push_back(map_entry.second);
307 for (const auto& callback : enumeration_callbacks_) 307 for (const auto& callback : enumeration_callbacks_)
308 callback.Run(result); 308 callback.Run(result);
309 enumeration_callbacks_.clear(); 309 enumeration_callbacks_.clear();
310 } 310 }
311 } 311 }
312 312
313 } // namespace device 313 } // namespace device
OLDNEW
« no previous file with comments | « device/usb/usb_service_impl.cc ('k') | device/usb/usb_service_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698