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. 4 5 #include "chrome/browser/chromeos/system/pointer_device_observer.h" 6 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 "chrome/browser/chromeos/xinput_hierarchy_changed_event_listener.h" 12 #include "content/public/browser/browser_thread.h" 13 14 using content::BrowserThread; 15 16 namespace chromeos { 17 namespace system { 18 19 PointerDeviceObserver::PointerDeviceObserver() 20 : weak_factory_(this) { 21 } 22 23 PointerDeviceObserver::~PointerDeviceObserver() { 24 XInputHierarchyChangedEventListener::GetInstance() 25 ->RemoveObserver(this); 26 } 27 28 void PointerDeviceObserver::Init() { 29 XInputHierarchyChangedEventListener::GetInstance() 30 ->AddObserver(this); 31 } 32 33 void PointerDeviceObserver::CheckDevices() { 34 CheckMouseExists(); 35 CheckTouchpadExists(); 36 } 37 38 void PointerDeviceObserver::AddObserver(Observer* observer) { 39 observers_.AddObserver(observer); 40 } 41 42 void PointerDeviceObserver::RemoveObserver(Observer* observer) { 43 observers_.RemoveObserver(observer); 44 } 45 46 void PointerDeviceObserver::DeviceHierarchyChanged() { 47 CheckDevices(); 48 } 49 50 void PointerDeviceObserver::CheckTouchpadExists() { 51 touchpad_settings::TouchpadExists( 52 base::Bind(&PointerDeviceObserver::OnTouchpadExists, 53 weak_factory_.GetWeakPtr())); 54 } 55 56 void PointerDeviceObserver::CheckMouseExists() { 57 mouse_settings::MouseExists( 58 base::Bind(&PointerDeviceObserver::OnMouseExists, 59 weak_factory_.GetWeakPtr())); 60 } 61 62 void PointerDeviceObserver::OnTouchpadExists(bool exists) { 63 FOR_EACH_OBSERVER(Observer, observers_, TouchpadExists(exists)); 64 } 65 66 void PointerDeviceObserver::OnMouseExists(bool exists) { 67 FOR_EACH_OBSERVER(Observer, observers_, MouseExists(exists)); 68 } 69 70 PointerDeviceObserver::Observer::~Observer() { 71 } 72 73 } // namespace system 74 } // namespace chromeos 75