gn: Fix definition of |enable_plugins|.
[chromium-blink-merge.git] / device / hid / hid_service.cc
blob0e2f0d4c7716b4cda9ac777657487bb1204cc15f
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
3 // found in the LICENSE file.
5 #include "device/hid/hid_service.h"
7 #include "base/lazy_instance.h"
8 #include "base/logging.h"
9 #include "base/memory/scoped_vector.h"
10 #include "base/stl_util.h"
11 #include "base/threading/thread_restrictions.h"
13 #if defined(OS_LINUX) && defined(USE_UDEV)
14 #include "device/hid/hid_service_linux.h"
15 #elif defined(OS_MACOSX)
16 #include "device/hid/hid_service_mac.h"
17 #else
18 #include "device/hid/hid_service_win.h"
19 #endif
21 namespace device {
23 HidService* HidService::Create(
24 scoped_refptr<base::MessageLoopProxy> ui_message_loop) {
25 #if defined(OS_LINUX) && defined(USE_UDEV)
26 return new HidServiceLinux(ui_message_loop);
27 #elif defined(OS_MACOSX)
28 return new HidServiceMac();
29 #elif defined(OS_WIN)
30 return new HidServiceWin();
31 #else
32 return NULL;
33 #endif
36 HidService::~HidService() {
37 DCHECK(thread_checker_.CalledOnValidThread());
40 void HidService::GetDevices(std::vector<HidDeviceInfo>* devices) {
41 DCHECK(thread_checker_.CalledOnValidThread());
42 STLClearObject(devices);
43 for (DeviceMap::iterator it = devices_.begin();
44 it != devices_.end();
45 ++it) {
46 devices->push_back(it->second);
50 // Fills in the device info struct of the given device_id.
51 bool HidService::GetDeviceInfo(const HidDeviceId& device_id,
52 HidDeviceInfo* info) const {
53 DeviceMap::const_iterator it = devices_.find(device_id);
54 if (it == devices_.end())
55 return false;
56 *info = it->second;
57 return true;
60 HidService::HidService() {
61 base::ThreadRestrictions::AssertIOAllowed();
62 DCHECK(thread_checker_.CalledOnValidThread());
65 void HidService::AddDevice(const HidDeviceInfo& info) {
66 DCHECK(thread_checker_.CalledOnValidThread());
67 if (!ContainsKey(devices_, info.device_id)) {
68 devices_[info.device_id] = info;
72 void HidService::RemoveDevice(const HidDeviceId& device_id) {
73 DCHECK(thread_checker_.CalledOnValidThread());
74 DeviceMap::iterator it = devices_.find(device_id);
75 if (it != devices_.end())
76 devices_.erase(it);
79 const HidService::DeviceMap& HidService::GetDevicesNoEnumerate() const {
80 return devices_;
83 } // namespace device