OLD | NEW |
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/hid/hid_device_manager.h" | 5 #include "extensions/browser/api/hid/hid_device_manager.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 213 |
214 // Don't generate events during the initial enumeration. | 214 // Don't generate events during the initial enumeration. |
215 if (enumeration_ready_ && event_router_) { | 215 if (enumeration_ready_ && event_router_) { |
216 core_api::hid::HidDeviceInfo api_device_info; | 216 core_api::hid::HidDeviceInfo api_device_info; |
217 api_device_info.device_id = new_id; | 217 api_device_info.device_id = new_id; |
218 PopulateHidDeviceInfo(&api_device_info, device_info); | 218 PopulateHidDeviceInfo(&api_device_info, device_info); |
219 | 219 |
220 if (api_device_info.collections.size() > 0) { | 220 if (api_device_info.collections.size() > 0) { |
221 scoped_ptr<base::ListValue> args( | 221 scoped_ptr<base::ListValue> args( |
222 hid::OnDeviceAdded::Create(api_device_info)); | 222 hid::OnDeviceAdded::Create(api_device_info)); |
223 DispatchEvent(hid::OnDeviceAdded::kEventName, args.Pass(), device_info); | 223 DispatchEvent(events::HID_ON_DEVICE_ADDED, hid::OnDeviceAdded::kEventName, |
| 224 args.Pass(), device_info); |
224 } | 225 } |
225 } | 226 } |
226 } | 227 } |
227 | 228 |
228 void HidDeviceManager::OnDeviceRemoved( | 229 void HidDeviceManager::OnDeviceRemoved( |
229 scoped_refptr<HidDeviceInfo> device_info) { | 230 scoped_refptr<HidDeviceInfo> device_info) { |
230 DCHECK(thread_checker_.CalledOnValidThread()); | 231 DCHECK(thread_checker_.CalledOnValidThread()); |
231 const auto& resource_entry = resource_ids_.find(device_info->device_id()); | 232 const auto& resource_entry = resource_ids_.find(device_info->device_id()); |
232 DCHECK(resource_entry != resource_ids_.end()); | 233 DCHECK(resource_entry != resource_ids_.end()); |
233 int resource_id = resource_entry->second; | 234 int resource_id = resource_entry->second; |
234 const auto& device_entry = device_ids_.find(resource_id); | 235 const auto& device_entry = device_ids_.find(resource_id); |
235 DCHECK(device_entry != device_ids_.end()); | 236 DCHECK(device_entry != device_ids_.end()); |
236 resource_ids_.erase(resource_entry); | 237 resource_ids_.erase(resource_entry); |
237 device_ids_.erase(device_entry); | 238 device_ids_.erase(device_entry); |
238 | 239 |
239 if (event_router_) { | 240 if (event_router_) { |
240 DCHECK(enumeration_ready_); | 241 DCHECK(enumeration_ready_); |
241 scoped_ptr<base::ListValue> args(hid::OnDeviceRemoved::Create(resource_id)); | 242 scoped_ptr<base::ListValue> args(hid::OnDeviceRemoved::Create(resource_id)); |
242 DispatchEvent(hid::OnDeviceRemoved::kEventName, args.Pass(), device_info); | 243 DispatchEvent(events::HID_ON_DEVICE_REMOVED, |
| 244 hid::OnDeviceRemoved::kEventName, args.Pass(), device_info); |
243 } | 245 } |
244 } | 246 } |
245 | 247 |
246 void HidDeviceManager::LazyInitialize() { | 248 void HidDeviceManager::LazyInitialize() { |
247 DCHECK(thread_checker_.CalledOnValidThread()); | 249 DCHECK(thread_checker_.CalledOnValidThread()); |
248 | 250 |
249 if (initialized_) { | 251 if (initialized_) { |
250 return; | 252 return; |
251 } | 253 } |
252 | 254 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 enumeration_ready_ = true; | 310 enumeration_ready_ = true; |
309 | 311 |
310 for (const GetApiDevicesParams* params : pending_enumerations_) { | 312 for (const GetApiDevicesParams* params : pending_enumerations_) { |
311 scoped_ptr<base::ListValue> devices = | 313 scoped_ptr<base::ListValue> devices = |
312 CreateApiDeviceList(params->extension, params->filters); | 314 CreateApiDeviceList(params->extension, params->filters); |
313 params->callback.Run(devices.Pass()); | 315 params->callback.Run(devices.Pass()); |
314 } | 316 } |
315 pending_enumerations_.clear(); | 317 pending_enumerations_.clear(); |
316 } | 318 } |
317 | 319 |
318 void HidDeviceManager::DispatchEvent(const std::string& event_name, | 320 void HidDeviceManager::DispatchEvent(events::HistogramValue histogram_value, |
| 321 const std::string& event_name, |
319 scoped_ptr<base::ListValue> event_args, | 322 scoped_ptr<base::ListValue> event_args, |
320 scoped_refptr<HidDeviceInfo> device_info) { | 323 scoped_refptr<HidDeviceInfo> device_info) { |
321 scoped_ptr<Event> event( | 324 scoped_ptr<Event> event( |
322 new Event(events::UNKNOWN, event_name, event_args.Pass())); | 325 new Event(histogram_value, event_name, event_args.Pass())); |
323 event->will_dispatch_callback = base::Bind( | 326 event->will_dispatch_callback = base::Bind( |
324 &WillDispatchDeviceEvent, weak_factory_.GetWeakPtr(), device_info); | 327 &WillDispatchDeviceEvent, weak_factory_.GetWeakPtr(), device_info); |
325 event_router_->BroadcastEvent(event.Pass()); | 328 event_router_->BroadcastEvent(event.Pass()); |
326 } | 329 } |
327 | 330 |
328 } // namespace extensions | 331 } // namespace extensions |
OLD | NEW |