| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 DCHECK(thread_checker_.CalledOnValidThread()); | 52 DCHECK(thread_checker_.CalledOnValidThread()); |
| 53 STLClearObject(devices); | 53 STLClearObject(devices); |
| 54 for (DeviceMap::iterator it = devices_.begin(); | 54 for (DeviceMap::iterator it = devices_.begin(); |
| 55 it != devices_.end(); | 55 it != devices_.end(); |
| 56 ++it) { | 56 ++it) { |
| 57 devices->push_back(it->second); | 57 devices->push_back(it->second); |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 // Fills in the device info struct of the given device_id. | 61 // Fills in the device info struct of the given device_id. |
| 62 bool HidService::GetInfo(std::string device_id, HidDeviceInfo* info) const { | 62 bool HidService::GetInfo(const std::string& device_id, |
| 63 HidDeviceInfo* info) const { |
| 63 DeviceMap::const_iterator it = devices_.find(device_id); | 64 DeviceMap::const_iterator it = devices_.find(device_id); |
| 64 if (it == devices_.end()) | 65 if (it == devices_.end()) |
| 65 return false; | 66 return false; |
| 66 *info = it->second; | 67 *info = it->second; |
| 67 return true; | 68 return true; |
| 68 } | 69 } |
| 69 | 70 |
| 70 void HidService::AddDevice(HidDeviceInfo info) { | 71 void HidService::AddDevice(HidDeviceInfo info) { |
| 71 if (!ContainsKey(devices_, info.device_id)) { | 72 if (!ContainsKey(devices_, info.device_id)) { |
| 72 DCHECK(thread_checker_.CalledOnValidThread()); | 73 DCHECK(thread_checker_.CalledOnValidThread()); |
| 73 devices_[info.device_id] = info; | 74 devices_[info.device_id] = info; |
| 74 } | 75 } |
| 75 } | 76 } |
| 76 | 77 |
| 77 void HidService::RemoveDevice(std::string device_id) { | 78 void HidService::RemoveDevice(const std::string& device_id) { |
| 78 if (ContainsKey(devices_, device_id)) { | 79 if (ContainsKey(devices_, device_id)) { |
| 79 DCHECK(thread_checker_.CalledOnValidThread()); | 80 DCHECK(thread_checker_.CalledOnValidThread()); |
| 80 devices_.erase(device_id); | 81 devices_.erase(device_id); |
| 81 } | 82 } |
| 82 } | 83 } |
| 83 | 84 |
| 84 HidService* HidService::CreateInstance() { | 85 HidService* HidService::CreateInstance() { |
| 85 #if defined(OS_LINUX) | 86 #if defined(OS_LINUX) |
| 86 return new HidServiceLinux(); | 87 return new HidServiceLinux(); |
| 87 #elif defined(OS_MACOSX) | 88 #elif defined(OS_MACOSX) |
| 88 return new HidServiceMac(); | 89 return new HidServiceMac(); |
| 89 #elif defined(OS_WIN) | 90 #elif defined(OS_WIN) |
| 90 return new HidServiceWin(); | 91 return new HidServiceWin(); |
| 91 #else | 92 #else |
| 92 return NULL; | 93 return NULL; |
| 93 #endif | 94 #endif |
| 94 } | 95 } |
| 95 | 96 |
| 96 HidService* HidService::GetInstance() { | 97 HidService* HidService::GetInstance() { |
| 97 if (!g_hid_service_ptr.Get().get()){ | 98 if (!g_hid_service_ptr.Get().get()){ |
| 98 scoped_ptr<HidService> service(CreateInstance()); | 99 scoped_ptr<HidService> service(CreateInstance()); |
| 99 | 100 |
| 100 if (service && service->initialized()) | 101 if (service && service->initialized()) |
| 101 g_hid_service_ptr.Get().reset(service.release()); | 102 g_hid_service_ptr.Get().reset(service.release()); |
| 102 } | 103 } |
| 103 return g_hid_service_ptr.Get().get(); | 104 return g_hid_service_ptr.Get().get(); |
| 104 } | 105 } |
| 105 | 106 |
| 106 } // namespace device | 107 } // namespace device |
| OLD | NEW |