Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / system / pointer_device_observer.cc
blob125e3afa572e7bf7e0257e4997940e1d8e68fb5c
1 // Copyright (c) 2012 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 "chrome/browser/chromeos/system/pointer_device_observer.h"
7 #include "base/basictypes.h"
8 #include "base/bind.h"
9 #include "base/bind_helpers.h"
10 #include "chrome/browser/chromeos/system/input_device_settings.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "ui/events/devices/device_data_manager.h"
14 using content::BrowserThread;
16 namespace chromeos {
17 namespace system {
19 PointerDeviceObserver::PointerDeviceObserver()
20 : weak_factory_(this) {
23 PointerDeviceObserver::~PointerDeviceObserver() {
24 ui::DeviceDataManager::GetInstance()->RemoveObserver(this);
27 void PointerDeviceObserver::Init() {
28 ui::DeviceDataManager::GetInstance()->AddObserver(this);
31 void PointerDeviceObserver::CheckDevices() {
32 CheckMouseExists();
33 CheckTouchpadExists();
36 void PointerDeviceObserver::AddObserver(Observer* observer) {
37 observers_.AddObserver(observer);
40 void PointerDeviceObserver::RemoveObserver(Observer* observer) {
41 observers_.RemoveObserver(observer);
44 void PointerDeviceObserver::OnMouseDeviceConfigurationChanged() {
45 CheckDevices();
48 void PointerDeviceObserver::OnTouchpadDeviceConfigurationChanged() {
49 CheckDevices();
52 void PointerDeviceObserver::CheckTouchpadExists() {
53 InputDeviceSettings::Get()->TouchpadExists(
54 base::Bind(&PointerDeviceObserver::OnTouchpadExists,
55 weak_factory_.GetWeakPtr()));
58 void PointerDeviceObserver::CheckMouseExists() {
59 InputDeviceSettings::Get()->MouseExists(
60 base::Bind(&PointerDeviceObserver::OnMouseExists,
61 weak_factory_.GetWeakPtr()));
64 void PointerDeviceObserver::OnTouchpadExists(bool exists) {
65 FOR_EACH_OBSERVER(Observer, observers_, TouchpadExists(exists));
68 void PointerDeviceObserver::OnMouseExists(bool exists) {
69 FOR_EACH_OBSERVER(Observer, observers_, MouseExists(exists));
72 PointerDeviceObserver::Observer::~Observer() {
75 } // namespace system
76 } // namespace chromeos