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

Unified Diff: device/hid/hid_service.cc

Issue 161823002: Clean up HID backend and API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/hid/hid_service.h ('k') | device/hid/hid_service_linux.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/hid/hid_service.cc
diff --git a/device/hid/hid_service.cc b/device/hid/hid_service.cc
index 973e901a82b8a77b12388c906954ee5ea2eeac27..2d0569bef069d2ad3759bfade98e573a2b3a3752 100644
--- a/device/hid/hid_service.cc
+++ b/device/hid/hid_service.cc
@@ -1,18 +1,14 @@
-// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "device/hid/hid_service.h"
-#include <vector>
-
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/memory/scoped_vector.h"
-#include "base/message_loop/message_loop.h"
+#include "base/stl_util.h"
#include "base/threading/thread_restrictions.h"
-#include "build/build_config.h"
-#include "device/hid/hid_device_info.h"
#if defined(OS_LINUX)
#include "device/hid/hid_service_linux.h"
@@ -32,22 +28,6 @@ base::LazyInstance<scoped_ptr<HidService> >::Leaky g_hid_service_ptr =
} // namespace
-HidService::HidService() : initialized_(false) {
- base::ThreadRestrictions::AssertIOAllowed();
- DCHECK(thread_checker_.CalledOnValidThread());
- base::MessageLoop::current()->AddDestructionObserver(this);
-}
-
-HidService::~HidService() {
- DCHECK(thread_checker_.CalledOnValidThread());
- base::MessageLoop::current()->RemoveDestructionObserver(this);
-}
-
-void HidService::WillDestroyCurrentMessageLoop() {
- DCHECK(thread_checker_.CalledOnValidThread());
- g_hid_service_ptr.Get().reset(NULL);
-}
-
void HidService::GetDevices(std::vector<HidDeviceInfo>* devices) {
DCHECK(thread_checker_.CalledOnValidThread());
STLClearObject(devices);
@@ -59,7 +39,8 @@ void HidService::GetDevices(std::vector<HidDeviceInfo>* devices) {
}
// Fills in the device info struct of the given device_id.
-bool HidService::GetInfo(std::string device_id, HidDeviceInfo* info) const {
+bool HidService::GetDeviceInfo(const HidDeviceId& device_id,
+ HidDeviceInfo* info) const {
DeviceMap::const_iterator it = devices_.find(device_id);
if (it == devices_.end())
return false;
@@ -67,18 +48,20 @@ bool HidService::GetInfo(std::string device_id, HidDeviceInfo* info) const {
return true;
}
-void HidService::AddDevice(HidDeviceInfo info) {
- if (!ContainsKey(devices_, info.device_id)) {
- DCHECK(thread_checker_.CalledOnValidThread());
- devices_[info.device_id] = info;
- }
+void HidService::WillDestroyCurrentMessageLoop() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ g_hid_service_ptr.Get().reset(NULL);
}
-void HidService::RemoveDevice(std::string device_id) {
- if (ContainsKey(devices_, device_id)) {
- DCHECK(thread_checker_.CalledOnValidThread());
- devices_.erase(device_id);
- }
+HidService::HidService() {
+ base::ThreadRestrictions::AssertIOAllowed();
+ DCHECK(thread_checker_.CalledOnValidThread());
+ base::MessageLoop::current()->AddDestructionObserver(this);
+}
+
+HidService::~HidService() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ base::MessageLoop::current()->RemoveDestructionObserver(this);
}
HidService* HidService::CreateInstance() {
@@ -93,13 +76,23 @@ HidService* HidService::CreateInstance() {
#endif
}
-HidService* HidService::GetInstance() {
- if (!g_hid_service_ptr.Get().get()){
- scoped_ptr<HidService> service(CreateInstance());
-
- if (service && service->initialized())
- g_hid_service_ptr.Get().reset(service.release());
+void HidService::AddDevice(const HidDeviceInfo& info) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (!ContainsKey(devices_, info.device_id)) {
+ devices_[info.device_id] = info;
}
+}
+
+void HidService::RemoveDevice(const HidDeviceId& device_id) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DeviceMap::iterator it = devices_.find(device_id);
+ if (it != devices_.end())
+ devices_.erase(it);
+}
+
+HidService* HidService::GetInstance() {
+ if (!g_hid_service_ptr.Get().get())
+ g_hid_service_ptr.Get().reset(CreateInstance());
return g_hid_service_ptr.Get().get();
}
« no previous file with comments | « device/hid/hid_service.h ('k') | device/hid/hid_service_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698