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 "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/location.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
11 #include "base/message_loop/message_loop.h" | |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" |
13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
14 #include "components/device_event_log/device_event_log.h" | 15 #include "components/device_event_log/device_event_log.h" |
15 | 16 |
16 #if defined(OS_LINUX) && defined(USE_UDEV) | 17 #if defined(OS_LINUX) && defined(USE_UDEV) |
17 #include "device/hid/hid_service_linux.h" | 18 #include "device/hid/hid_service_linux.h" |
18 #elif defined(OS_MACOSX) | 19 #elif defined(OS_MACOSX) |
19 #include "device/hid/hid_service_mac.h" | 20 #include "device/hid/hid_service_mac.h" |
20 #elif defined(OS_WIN) | 21 #elif defined(OS_WIN) |
21 #include "device/hid/hid_service_win.h" | 22 #include "device/hid/hid_service_win.h" |
22 #endif | 23 #endif |
(...skipping 25 matching lines...) Expand all Loading... |
48 #endif | 49 #endif |
49 } | 50 } |
50 | 51 |
51 void HidService::GetDevices(const GetDevicesCallback& callback) { | 52 void HidService::GetDevices(const GetDevicesCallback& callback) { |
52 DCHECK(thread_checker_.CalledOnValidThread()); | 53 DCHECK(thread_checker_.CalledOnValidThread()); |
53 if (enumeration_ready_) { | 54 if (enumeration_ready_) { |
54 std::vector<scoped_refptr<HidDeviceInfo>> devices; | 55 std::vector<scoped_refptr<HidDeviceInfo>> devices; |
55 for (const auto& map_entry : devices_) { | 56 for (const auto& map_entry : devices_) { |
56 devices.push_back(map_entry.second); | 57 devices.push_back(map_entry.second); |
57 } | 58 } |
58 base::MessageLoop::current()->PostTask(FROM_HERE, | 59 base::ThreadTaskRunnerHandle::Get()->PostTask( |
59 base::Bind(callback, devices)); | 60 FROM_HERE, base::Bind(callback, devices)); |
60 } else { | 61 } else { |
61 pending_enumerations_.push_back(callback); | 62 pending_enumerations_.push_back(callback); |
62 } | 63 } |
63 } | 64 } |
64 | 65 |
65 void HidService::AddObserver(HidService::Observer* observer) { | 66 void HidService::AddObserver(HidService::Observer* observer) { |
66 observer_list_.AddObserver(observer); | 67 observer_list_.AddObserver(observer); |
67 } | 68 } |
68 | 69 |
69 void HidService::RemoveObserver(HidService::Observer* observer) { | 70 void HidService::RemoveObserver(HidService::Observer* observer) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 } | 136 } |
136 | 137 |
137 for (const GetDevicesCallback& callback : pending_enumerations_) { | 138 for (const GetDevicesCallback& callback : pending_enumerations_) { |
138 callback.Run(devices); | 139 callback.Run(devices); |
139 } | 140 } |
140 pending_enumerations_.clear(); | 141 pending_enumerations_.clear(); |
141 } | 142 } |
142 } | 143 } |
143 | 144 |
144 } // namespace device | 145 } // namespace device |
OLD | NEW |