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 #ifndef CHROME_BROWSER_CHROMEOS_DEVICE_INPUT_SERVICE_PROXY_H_
6 #define CHROME_BROWSER_CHROMEOS_DEVICE_INPUT_SERVICE_PROXY_H_
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h"
14 #include "base/task_runner.h"
15 #include "base/threading/thread_checker.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "device/hid/input_service_linux.h"
21 // Proxy to device::InputServiceLinux. Should be created and used on the UI
23 class InputServiceProxy
{
25 typedef device::InputServiceLinux::InputDeviceInfo InputDeviceInfo
;
29 virtual ~Observer() {}
30 virtual void OnInputDeviceAdded(const InputDeviceInfo
& info
) = 0;
31 virtual void OnInputDeviceRemoved(const std::string
& id
) = 0;
34 typedef base::Callback
<void(const std::vector
<InputDeviceInfo
>& devices
)>
36 typedef base::Callback
<void(bool success
, const InputDeviceInfo
& info
)>
37 GetDeviceInfoCallback
;
42 void AddObserver(Observer
* observer
);
43 void RemoveObserver(Observer
* observer
);
45 void GetDevices(const GetDevicesCallback
& callback
);
46 void GetDeviceInfo(const std::string
& id
,
47 const GetDeviceInfoCallback
& callback
);
49 // Should be called once before any InputServiceProxy instance is created.
50 static void SetThreadIdForTesting(content::BrowserThread::ID thread_id
);
53 static content::BrowserThread::ID thread_identifier_
;
55 class ServiceObserver
;
57 void OnDeviceAdded(const device::InputServiceLinux::InputDeviceInfo
& info
);
58 void OnDeviceRemoved(const std::string
& id
);
60 base::ObserverList
<Observer
> observers_
;
61 scoped_ptr
<ServiceObserver
> service_observer_
;
63 base::ThreadChecker thread_checker_
;
65 scoped_refptr
<base::TaskRunner
> task_runner_
;
67 base::WeakPtrFactory
<InputServiceProxy
> weak_factory_
;
69 DISALLOW_COPY_AND_ASSIGN(InputServiceProxy
);
72 } // namespace chromeos
74 #endif // CHROME_BROWSER_CHROMEOS_DEVICE_INPUT_SERVICE_PROXY_H_