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 #ifndef CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_H_ | 5 #ifndef CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_H_ |
6 #define CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_H_ | 6 #define CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "content/common/content_export.h" | 9 #include "content/common/content_export.h" |
10 | 10 |
11 namespace device_orientation { | 11 namespace device_orientation { |
12 | 12 |
13 class Motion; | |
13 class Orientation; | 14 class Orientation; |
14 | 15 |
15 class CONTENT_EXPORT Provider : public base::RefCountedThreadSafe<Provider> { | 16 class CONTENT_EXPORT Provider : public base::RefCountedThreadSafe<Provider> { |
16 public: | 17 public: |
17 class Observer { | 18 // TODO(aousterh): refactor this so that there is only one type of observer |
19 // that can handle multiple types of data (motion, orientation, etc.) | |
20 class MotionObserver { | |
21 public: | |
22 virtual void OnMotionUpdate(const Motion& motion) = 0; | |
23 | |
24 protected: | |
25 virtual ~MotionObserver() {} | |
26 }; | |
27 | |
28 class OrientationObserver { | |
Steve Block
2012/07/04 13:58:24
You might want to do the Oberver -> OrientationObs
| |
18 public: | 29 public: |
19 // Called when the orientation changes. | 30 // Called when the orientation changes. |
20 // An Observer must not synchronously call Provider::RemoveObserver | 31 // An Observer must not synchronously call Provider::RemoveObserver |
21 // or Provider::AddObserver when this is called. | 32 // or Provider::AddObserver when this is called. |
22 virtual void OnOrientationUpdate(const Orientation& orientation) = 0; | 33 virtual void OnOrientationUpdate(const Orientation& orientation) = 0; |
23 | 34 |
24 protected: | 35 protected: |
25 virtual ~Observer() {} | 36 virtual ~OrientationObserver() {} |
26 }; | 37 }; |
27 | 38 |
28 // Returns a pointer to the singleton instance of this class. | 39 // Returns a pointer to the singleton instance of this class. |
29 // The caller should store the returned pointer in a scoped_refptr. | 40 // The caller should store the returned pointer in a scoped_refptr. |
30 // The Provider instance is lazily constructed when GetInstance() is called, | 41 // The Provider instance is lazily constructed when GetInstance() is called, |
31 // and destructed when the last scoped_refptr referring to it is destructed. | 42 // and destructed when the last scoped_refptr referring to it is destructed. |
32 static Provider* GetInstance(); | 43 static Provider* GetInstance(); |
33 | 44 |
34 // Inject a mock Provider for testing. Only a weak pointer to the injected | 45 // Inject a mock Provider for testing. Only a weak pointer to the injected |
35 // object will be held by Provider, i.e. it does not itself contribute to the | 46 // object will be held by Provider, i.e. it does not itself contribute to the |
36 // injected object's reference count. | 47 // injected object's reference count. |
37 static void SetInstanceForTests(Provider* provider); | 48 static void SetInstanceForTests(Provider* provider); |
38 | 49 |
39 // Get the current instance. Used for testing. | 50 // Get the current instance. Used for testing. |
40 static Provider* GetInstanceForTests(); | 51 static Provider* GetInstanceForTests(); |
41 | 52 |
42 // Note: AddObserver may call back synchronously to the observer with | 53 // Note: AddMotionObserver and AddOrientationObserver may call back |
43 // orientation data. | 54 // synchronously to the observer with data. |
44 virtual void AddObserver(Observer* observer) = 0; | 55 virtual void AddMotionObserver(MotionObserver* observer) = 0; |
45 virtual void RemoveObserver(Observer* observer) = 0; | 56 virtual void AddOrientationObserver(OrientationObserver* observer) = 0; |
57 | |
58 virtual void RemoveMotionObserver(MotionObserver* observer) = 0; | |
59 virtual void RemoveOrientationObserver(OrientationObserver* observer) = 0; | |
46 | 60 |
47 protected: | 61 protected: |
48 Provider(); | 62 Provider(); |
49 virtual ~Provider(); | 63 virtual ~Provider(); |
50 | 64 |
51 private: | 65 private: |
52 friend class base::RefCountedThreadSafe<Provider>; | 66 friend class base::RefCountedThreadSafe<Provider>; |
53 static Provider* instance_; | 67 static Provider* instance_; |
54 | 68 |
55 DISALLOW_COPY_AND_ASSIGN(Provider); | 69 DISALLOW_COPY_AND_ASSIGN(Provider); |
56 }; | 70 }; |
57 | 71 |
58 } // namespace device_orientation | 72 } // namespace device_orientation |
59 | 73 |
60 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_H_ | 74 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_H_ |
OLD | NEW |