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 class MotionObserver { |
| 19 public: |
| 20 virtual void OnMotionUpdate(const Motion& motion) = 0; |
| 21 |
| 22 protected: |
| 23 virtual ~MotionObserver() {} |
| 24 }; |
| 25 |
| 26 class OrientationObserver { |
18 public: | 27 public: |
19 // Called when the orientation changes. | 28 // Called when the orientation changes. |
20 // An Observer must not synchronously call Provider::RemoveObserver | 29 // An Observer must not synchronously call Provider::RemoveObserver |
21 // or Provider::AddObserver when this is called. | 30 // or Provider::AddObserver when this is called. |
22 virtual void OnOrientationUpdate(const Orientation& orientation) = 0; | 31 virtual void OnOrientationUpdate(const Orientation& orientation) = 0; |
23 | 32 |
24 protected: | 33 protected: |
25 virtual ~Observer() {} | 34 virtual ~OrientationObserver() {} |
26 }; | 35 }; |
27 | 36 |
28 // Returns a pointer to the singleton instance of this class. | 37 // Returns a pointer to the singleton instance of this class. |
29 // The caller should store the returned pointer in a scoped_refptr. | 38 // The caller should store the returned pointer in a scoped_refptr. |
30 // The Provider instance is lazily constructed when GetInstance() is called, | 39 // The Provider instance is lazily constructed when GetInstance() is called, |
31 // and destructed when the last scoped_refptr referring to it is destructed. | 40 // and destructed when the last scoped_refptr referring to it is destructed. |
32 static Provider* GetInstance(); | 41 static Provider* GetInstance(); |
33 | 42 |
34 // Inject a mock Provider for testing. Only a weak pointer to the injected | 43 // 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 | 44 // object will be held by Provider, i.e. it does not itself contribute to the |
36 // injected object's reference count. | 45 // injected object's reference count. |
37 static void SetInstanceForTests(Provider* provider); | 46 static void SetInstanceForTests(Provider* provider); |
38 | 47 |
39 // Get the current instance. Used for testing. | 48 // Get the current instance. Used for testing. |
40 static Provider* GetInstanceForTests(); | 49 static Provider* GetInstanceForTests(); |
41 | 50 |
42 // Note: AddObserver may call back synchronously to the observer with | 51 // Note: AddMotionObserver and AddOrientationObserver may call back |
43 // orientation data. | 52 // synchronously to the observer with data. |
44 virtual void AddObserver(Observer* observer) = 0; | 53 virtual void AddMotionObserver(MotionObserver* observer) = 0; |
45 virtual void RemoveObserver(Observer* observer) = 0; | 54 virtual void AddOrientationObserver(OrientationObserver* observer) = 0; |
| 55 |
| 56 virtual void RemoveMotionObserver(MotionObserver* observer) = 0; |
| 57 virtual void RemoveOrientationObserver(OrientationObserver* observer) = 0; |
46 | 58 |
47 protected: | 59 protected: |
48 Provider(); | 60 Provider(); |
49 virtual ~Provider(); | 61 virtual ~Provider(); |
50 | 62 |
51 private: | 63 private: |
52 friend class base::RefCountedThreadSafe<Provider>; | 64 friend class base::RefCountedThreadSafe<Provider>; |
53 static Provider* instance_; | 65 static Provider* instance_; |
54 | 66 |
55 DISALLOW_COPY_AND_ASSIGN(Provider); | 67 DISALLOW_COPY_AND_ASSIGN(Provider); |
56 }; | 68 }; |
57 | 69 |
58 } // namespace device_orientation | 70 } // namespace device_orientation |
59 | 71 |
60 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_H_ | 72 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_H_ |
OLD | NEW |