| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_ | 5 #ifndef CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_ |
| 6 #define CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_ | 6 #define CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| 11 #include "chromeos/chromeos_export.h" | 11 #include "chromeos/chromeos_export.h" |
| 12 #include "ui/accelerometer/accelerometer_types.h" | 12 #include "ui/accelerometer/accelerometer_types.h" |
| 13 | 13 |
| 14 template <typename T> |
| 15 struct DefaultSingletonTraits; |
| 16 |
| 14 namespace base { | 17 namespace base { |
| 15 class TaskRunner; | 18 class TaskRunner; |
| 16 } | 19 } |
| 17 | 20 |
| 18 namespace chromeos { | 21 namespace chromeos { |
| 19 | 22 |
| 20 // Reads an accelerometer device and reports data back to an | 23 // Reads an accelerometer device and reports data back to an |
| 21 // AccelerometerDelegate. | 24 // AccelerometerDelegate. |
| 22 class CHROMEOS_EXPORT AccelerometerReader { | 25 class CHROMEOS_EXPORT AccelerometerReader { |
| 23 public: | 26 public: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 47 // An interface to receive data from the AccelerometerReader. | 50 // An interface to receive data from the AccelerometerReader. |
| 48 class Observer { | 51 class Observer { |
| 49 public: | 52 public: |
| 50 virtual void OnAccelerometerUpdated( | 53 virtual void OnAccelerometerUpdated( |
| 51 const ui::AccelerometerUpdate& update) = 0; | 54 const ui::AccelerometerUpdate& update) = 0; |
| 52 | 55 |
| 53 protected: | 56 protected: |
| 54 virtual ~Observer() {} | 57 virtual ~Observer() {} |
| 55 }; | 58 }; |
| 56 | 59 |
| 57 AccelerometerReader(); | 60 static AccelerometerReader* GetInstance(); |
| 58 ~AccelerometerReader(); | |
| 59 | 61 |
| 60 void Initialize(scoped_refptr<base::TaskRunner> blocking_task_runner); | 62 void Initialize(scoped_refptr<base::TaskRunner> blocking_task_runner); |
| 61 | 63 |
| 62 // Add/Remove observers. | 64 // Add/Remove observers. |
| 63 void AddObserver(Observer* observer); | 65 void AddObserver(Observer* observer); |
| 64 void RemoveObserver(Observer* observer); | 66 void RemoveObserver(Observer* observer); |
| 65 | 67 |
| 68 protected: |
| 69 AccelerometerReader(); |
| 70 virtual ~AccelerometerReader(); |
| 71 |
| 66 private: | 72 private: |
| 73 friend struct DefaultSingletonTraits<AccelerometerReader>; |
| 74 |
| 67 // Dispatched when initialization is complete. If |success|, |configuration| | 75 // Dispatched when initialization is complete. If |success|, |configuration| |
| 68 // provides the details of the detected accelerometer. | 76 // provides the details of the detected accelerometer. |
| 69 void OnInitialized(scoped_refptr<Configuration> configuration, bool success); | 77 void OnInitialized(scoped_refptr<Configuration> configuration, bool success); |
| 70 | 78 |
| 71 // Triggers an asynchronous read from the accelerometer, signalling | 79 // Triggers an asynchronous read from the accelerometer, signalling |
| 72 // OnDataRead with the result. | 80 // OnDataRead with the result. |
| 73 void TriggerRead(); | 81 void TriggerRead(); |
| 74 | 82 |
| 75 // If |success|, converts the raw reading to an AccelerometerUpdate | 83 // If |success|, converts the raw reading to an AccelerometerUpdate |
| 76 // message and notifies the |delegate_| with the new readings. | 84 // message and notifies the |delegate_| with the new readings. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 89 ObserverList<Observer, true> observers_; | 97 ObserverList<Observer, true> observers_; |
| 90 | 98 |
| 91 base::WeakPtrFactory<AccelerometerReader> weak_factory_; | 99 base::WeakPtrFactory<AccelerometerReader> weak_factory_; |
| 92 | 100 |
| 93 DISALLOW_COPY_AND_ASSIGN(AccelerometerReader); | 101 DISALLOW_COPY_AND_ASSIGN(AccelerometerReader); |
| 94 }; | 102 }; |
| 95 | 103 |
| 96 } // namespace chromeos | 104 } // namespace chromeos |
| 97 | 105 |
| 98 #endif // CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_ | 106 #endif // CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_ |
| OLD | NEW |