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

Side by Side Diff: device/hid/hid_service.cc

Issue 980023002: Move device/usb classes from the FILE thread to UI thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Allow USB transfer calls from any thread again. Created 5 years, 8 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
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 "device/hid/hid_service.h" 5 #include "device/hid/hid_service.h"
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 DCHECK(thread_checker_.CalledOnValidThread()); 99 DCHECK(thread_checker_.CalledOnValidThread());
100 } 100 }
101 101
102 void HidService::AddDevice(scoped_refptr<HidDeviceInfo> device_info) { 102 void HidService::AddDevice(scoped_refptr<HidDeviceInfo> device_info) {
103 DCHECK(thread_checker_.CalledOnValidThread()); 103 DCHECK(thread_checker_.CalledOnValidThread());
104 if (!ContainsKey(devices_, device_info->device_id())) { 104 if (!ContainsKey(devices_, device_info->device_id())) {
105 devices_[device_info->device_id()] = device_info; 105 devices_[device_info->device_id()] = device_info;
106 106
107 HID_LOG(USER) << "HID device " 107 HID_LOG(USER) << "HID device "
108 << (enumeration_ready_ ? "added" : "detected") 108 << (enumeration_ready_ ? "added" : "detected")
109 << ": vendorId = " << device_info->vendor_id() 109 << ": vendorId=" << device_info->vendor_id()
110 << ", productId = " << device_info->product_id() 110 << ", productId=" << device_info->product_id() << ", name='"
111 << ", deviceId = '" << device_info->device_id() << "'"; 111 << device_info->product_name() << "', serial='"
112 << device_info->serial_number() << "', deviceId='"
113 << device_info->device_id() << "'";
112 114
113 if (enumeration_ready_) { 115 if (enumeration_ready_) {
114 FOR_EACH_OBSERVER(Observer, observer_list_, OnDeviceAdded(device_info)); 116 FOR_EACH_OBSERVER(Observer, observer_list_, OnDeviceAdded(device_info));
115 } 117 }
116 } 118 }
117 } 119 }
118 120
119 void HidService::RemoveDevice(const HidDeviceId& device_id) { 121 void HidService::RemoveDevice(const HidDeviceId& device_id) {
120 DCHECK(thread_checker_.CalledOnValidThread()); 122 DCHECK(thread_checker_.CalledOnValidThread());
121 DeviceMap::iterator it = devices_.find(device_id); 123 DeviceMap::iterator it = devices_.find(device_id);
122 if (it != devices_.end()) { 124 if (it != devices_.end()) {
123 HID_LOG(USER) << "HID device removed: deviceId = '" << device_id << "'"; 125 HID_LOG(USER) << "HID device removed: deviceId='" << device_id << "'";
124 126
125 if (enumeration_ready_) { 127 if (enumeration_ready_) {
126 FOR_EACH_OBSERVER(Observer, observer_list_, OnDeviceRemoved(it->second)); 128 FOR_EACH_OBSERVER(Observer, observer_list_, OnDeviceRemoved(it->second));
127 } 129 }
128 devices_.erase(it); 130 devices_.erase(it);
129 } 131 }
130 } 132 }
131 133
132 void HidService::FirstEnumerationComplete() { 134 void HidService::FirstEnumerationComplete() {
133 enumeration_ready_ = true; 135 enumeration_ready_ = true;
134 136
135 if (!pending_enumerations_.empty()) { 137 if (!pending_enumerations_.empty()) {
136 std::vector<scoped_refptr<HidDeviceInfo>> devices; 138 std::vector<scoped_refptr<HidDeviceInfo>> devices;
137 for (const auto& map_entry : devices_) { 139 for (const auto& map_entry : devices_) {
138 devices.push_back(map_entry.second); 140 devices.push_back(map_entry.second);
139 } 141 }
140 142
141 for (const GetDevicesCallback& callback : pending_enumerations_) { 143 for (const GetDevicesCallback& callback : pending_enumerations_) {
142 callback.Run(devices); 144 callback.Run(devices);
143 } 145 }
144 pending_enumerations_.clear(); 146 pending_enumerations_.clear();
145 } 147 }
146 } 148 }
147 149
148 } // namespace device 150 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698