Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: chromeos/accelerometer/accelerometer_reader.h

Issue 822503003: Change AccelerometerReader to a Singleton (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update new dependency Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/ash/ash_init.cc ('k') | chromeos/accelerometer/accelerometer_reader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
66 // A reading is considered stable if its deviation from gravity is small. This 68 // A reading is considered stable if its deviation from gravity is small. This
67 // returns false if the deviation is too higher, or if |source| is not present 69 // returns false if the deviation is too higher, or if |source| is not present
68 // in the update. 70 // in the update.
69 static bool IsReadingStable(const ui::AccelerometerUpdate& update, 71 static bool IsReadingStable(const ui::AccelerometerUpdate& update,
70 ui::AccelerometerSource source); 72 ui::AccelerometerSource source);
71 73
74 protected:
75 AccelerometerReader();
76 virtual ~AccelerometerReader();
77
72 private: 78 private:
79 friend struct DefaultSingletonTraits<AccelerometerReader>;
80
73 // Dispatched when initialization is complete. If |success|, |configuration| 81 // Dispatched when initialization is complete. If |success|, |configuration|
74 // provides the details of the detected accelerometer. 82 // provides the details of the detected accelerometer.
75 void OnInitialized(scoped_refptr<Configuration> configuration, bool success); 83 void OnInitialized(scoped_refptr<Configuration> configuration, bool success);
76 84
77 // Triggers an asynchronous read from the accelerometer, signalling 85 // Triggers an asynchronous read from the accelerometer, signalling
78 // OnDataRead with the result. 86 // OnDataRead with the result.
79 void TriggerRead(); 87 void TriggerRead();
80 88
81 // If |success|, converts the raw reading to an AccelerometerUpdate 89 // If |success|, converts the raw reading to an AccelerometerUpdate
82 // message and notifies the |delegate_| with the new readings. 90 // message and notifies the |delegate_| with the new readings.
(...skipping 12 matching lines...) Expand all
95 ObserverList<Observer, true> observers_; 103 ObserverList<Observer, true> observers_;
96 104
97 base::WeakPtrFactory<AccelerometerReader> weak_factory_; 105 base::WeakPtrFactory<AccelerometerReader> weak_factory_;
98 106
99 DISALLOW_COPY_AND_ASSIGN(AccelerometerReader); 107 DISALLOW_COPY_AND_ASSIGN(AccelerometerReader);
100 }; 108 };
101 109
102 } // namespace chromeos 110 } // namespace chromeos
103 111
104 #endif // CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_ 112 #endif // CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/ash_init.cc ('k') | chromeos/accelerometer/accelerometer_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698