| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/chromeos/system/pointer_device_observer.h" | 5 #include "chrome/browser/chromeos/system/pointer_device_observer.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "chrome/browser/chromeos/system/input_device_settings.h" | 10 #include "chrome/browser/chromeos/system/input_device_settings.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 *exists = touchpad_settings::TouchpadExists(); | 21 *exists = touchpad_settings::TouchpadExists(); |
| 22 } | 22 } |
| 23 | 23 |
| 24 void MouseExistsFileThread(bool* exists) { | 24 void MouseExistsFileThread(bool* exists) { |
| 25 *exists = mouse_settings::MouseExists(); | 25 *exists = mouse_settings::MouseExists(); |
| 26 } | 26 } |
| 27 | 27 |
| 28 } // namespace | 28 } // namespace |
| 29 | 29 |
| 30 PointerDeviceObserver::PointerDeviceObserver() | 30 PointerDeviceObserver::PointerDeviceObserver() |
| 31 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)){ | 31 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 32 } | 32 } |
| 33 | 33 |
| 34 PointerDeviceObserver::~PointerDeviceObserver() { | 34 PointerDeviceObserver::~PointerDeviceObserver() { |
| 35 XInputHierarchyChangedEventListener::GetInstance() | 35 XInputHierarchyChangedEventListener::GetInstance() |
| 36 ->RemoveObserver(this); | 36 ->RemoveObserver(this); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void PointerDeviceObserver::Init() { | 39 void PointerDeviceObserver::Init() { |
| 40 XInputHierarchyChangedEventListener::GetInstance() | 40 XInputHierarchyChangedEventListener::GetInstance() |
| 41 ->AddObserver(this); | 41 ->AddObserver(this); |
| 42 DeviceHierarchyChanged(); | 42 } |
| 43 |
| 44 void PointerDeviceObserver::CheckDevices() { |
| 45 CheckMouseExists(); |
| 46 CheckTouchpadExists(); |
| 43 } | 47 } |
| 44 | 48 |
| 45 void PointerDeviceObserver::AddObserver(Observer* observer) { | 49 void PointerDeviceObserver::AddObserver(Observer* observer) { |
| 46 observers_.AddObserver(observer); | 50 observers_.AddObserver(observer); |
| 47 } | 51 } |
| 48 | 52 |
| 49 void PointerDeviceObserver::RemoveObserver(Observer* observer) { | 53 void PointerDeviceObserver::RemoveObserver(Observer* observer) { |
| 50 observers_.RemoveObserver(observer); | 54 observers_.RemoveObserver(observer); |
| 51 } | 55 } |
| 52 | 56 |
| 53 void PointerDeviceObserver::DeviceHierarchyChanged() { | 57 void PointerDeviceObserver::DeviceHierarchyChanged() { |
| 54 CheckMouseExists(); | 58 CheckDevices(); |
| 55 CheckTouchpadExists(); | |
| 56 } | 59 } |
| 57 | 60 |
| 58 void PointerDeviceObserver::CheckTouchpadExists() { | 61 void PointerDeviceObserver::CheckTouchpadExists() { |
| 59 bool* exists = new bool; | 62 bool* exists = new bool; |
| 60 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, | 63 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, |
| 61 base::Bind(&TouchpadExistsFileThread, exists), | 64 base::Bind(&TouchpadExistsFileThread, exists), |
| 62 base::Bind(&PointerDeviceObserver::TouchpadExists, | 65 base::Bind(&PointerDeviceObserver::OnTouchpadExists, |
| 63 weak_factory_.GetWeakPtr(), | 66 weak_factory_.GetWeakPtr(), |
| 64 base::Owned(exists))); | 67 base::Owned(exists))); |
| 65 } | 68 } |
| 66 | 69 |
| 67 void PointerDeviceObserver::CheckMouseExists() { | 70 void PointerDeviceObserver::CheckMouseExists() { |
| 68 bool* exists = new bool; | 71 bool* exists = new bool; |
| 69 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, | 72 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, |
| 70 base::Bind(&MouseExistsFileThread, exists), | 73 base::Bind(&MouseExistsFileThread, exists), |
| 71 base::Bind(&PointerDeviceObserver::MouseExists, | 74 base::Bind(&PointerDeviceObserver::OnMouseExists, |
| 72 weak_factory_.GetWeakPtr(), | 75 weak_factory_.GetWeakPtr(), |
| 73 base::Owned(exists))); | 76 base::Owned(exists))); |
| 74 } | 77 } |
| 75 | 78 |
| 76 void PointerDeviceObserver::TouchpadExists(bool* exists) { | 79 void PointerDeviceObserver::OnTouchpadExists(bool* exists) { |
| 77 FOR_EACH_OBSERVER(Observer, observers_, TouchpadExists(*exists)); | 80 FOR_EACH_OBSERVER(Observer, observers_, TouchpadExists(*exists)); |
| 78 } | 81 } |
| 79 | 82 |
| 80 void PointerDeviceObserver::MouseExists(bool* exists) { | 83 void PointerDeviceObserver::OnMouseExists(bool* exists) { |
| 81 FOR_EACH_OBSERVER(Observer, observers_, MouseExists(*exists)); | 84 FOR_EACH_OBSERVER(Observer, observers_, MouseExists(*exists)); |
| 82 } | 85 } |
| 83 | 86 |
| 84 PointerDeviceObserver::Observer::~Observer() { | 87 PointerDeviceObserver::Observer::~Observer() { |
| 85 } | 88 } |
| 86 | 89 |
| 87 } // namespace system | 90 } // namespace system |
| 88 } // namespace chromeos | 91 } // namespace chromeos |
| OLD | NEW |