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

Side by Side Diff: content/browser/device_orientation/provider.h

Issue 10755002: Refactors DeviceOrientation to make it more extensible (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Moves construction of DeviceData objects out of ProviderImpl Created 8 years, 5 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
OLDNEW
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/browser/device_orientation/device_data.h"
9 #include "content/common/content_export.h" 10 #include "content/common/content_export.h"
10 11
11 namespace device_orientation { 12 namespace device_orientation {
12 13
13 class Orientation;
14
15 class CONTENT_EXPORT Provider : public base::RefCountedThreadSafe<Provider> { 14 class CONTENT_EXPORT Provider : public base::RefCountedThreadSafe<Provider> {
16 public: 15 public:
17 class Observer { 16 class Observer {
18 public: 17 public:
19 // Called when the orientation changes. 18 // Called when device data changes.
20 // An Observer must not synchronously call Provider::RemoveObserver 19 // An Observer must not synchronously call Provider::RemoveObserver
21 // or Provider::AddObserver when this is called. 20 // or Provider::AddObserver when this is called.
22 virtual void OnOrientationUpdate(const Orientation& orientation) = 0; 21 virtual void OnDeviceDataUpdate(const DeviceData* device_data) = 0;
22 DeviceData::DeviceDataType device_data_type() { return device_data_type_; }
23 23
24 protected: 24 protected:
25 virtual ~Observer() {} 25 virtual ~Observer() {}
26 // Each Observer observes exactly one type of DeviceData
bulach 2012/07/12 10:43:27 nit: members must be private... please, add a cons
aousterh 2012/07/12 17:13:57 Done (regarding the private members).
27 DeviceData::DeviceDataType device_data_type_;
26 }; 28 };
27 29
28 // Returns a pointer to the singleton instance of this class. 30 // Returns a pointer to the singleton instance of this class.
29 // The caller should store the returned pointer in a scoped_refptr. 31 // The caller should store the returned pointer in a scoped_refptr.
30 // The Provider instance is lazily constructed when GetInstance() is called, 32 // The Provider instance is lazily constructed when GetInstance() is called,
31 // and destructed when the last scoped_refptr referring to it is destructed. 33 // and destructed when the last scoped_refptr referring to it is destructed.
32 static Provider* GetInstance(); 34 static Provider* GetInstance();
33 35
34 // Inject a mock Provider for testing. Only a weak pointer to the injected 36 // 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 37 // object will be held by Provider, i.e. it does not itself contribute to the
36 // injected object's reference count. 38 // injected object's reference count.
37 static void SetInstanceForTests(Provider* provider); 39 static void SetInstanceForTests(Provider* provider);
38 40
39 // Get the current instance. Used for testing. 41 // Get the current instance. Used for testing.
40 static Provider* GetInstanceForTests(); 42 static Provider* GetInstanceForTests();
41 43
42 // Note: AddObserver may call back synchronously to the observer with 44 // Note: AddObserver may call back synchronously to the observer with data.
43 // orientation data.
44 virtual void AddObserver(Observer* observer) = 0; 45 virtual void AddObserver(Observer* observer) = 0;
45 virtual void RemoveObserver(Observer* observer) = 0; 46 virtual void RemoveObserver(Observer* observer) = 0;
46 47
47 protected: 48 protected:
48 Provider(); 49 Provider();
49 virtual ~Provider(); 50 virtual ~Provider();
50 51
51 private: 52 private:
52 friend class base::RefCountedThreadSafe<Provider>; 53 friend class base::RefCountedThreadSafe<Provider>;
53 static Provider* instance_; 54 static Provider* instance_;
54 55
55 DISALLOW_COPY_AND_ASSIGN(Provider); 56 DISALLOW_COPY_AND_ASSIGN(Provider);
56 }; 57 };
57 58
58 } // namespace device_orientation 59 } // namespace device_orientation
59 60
60 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_H_ 61 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698