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

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: Removing unused function IsEmpty 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,
22 DeviceData::Type device_data_type) = 0;
23 DeviceData::Type device_data_type() { return device_data_type_; }
23 24
24 protected: 25 protected:
26 Observer(DeviceData::Type device_data_type)
27 : device_data_type_(device_data_type) {
28 }
25 virtual ~Observer() {} 29 virtual ~Observer() {}
30
31 private:
32 // Each Observer observes exactly one type of DeviceData
hans 2012/07/30 16:12:52 nit: period after end of sentence.
aousterh 2012/08/03 11:08:14 Done.
33 DeviceData::Type device_data_type_;
26 }; 34 };
27 35
28 // Returns a pointer to the singleton instance of this class. 36 // Returns a pointer to the singleton instance of this class.
29 // The caller should store the returned pointer in a scoped_refptr. 37 // The caller should store the returned pointer in a scoped_refptr.
30 // The Provider instance is lazily constructed when GetInstance() is called, 38 // The Provider instance is lazily constructed when GetInstance() is called,
31 // and destructed when the last scoped_refptr referring to it is destructed. 39 // and destructed when the last scoped_refptr referring to it is destructed.
32 static Provider* GetInstance(); 40 static Provider* GetInstance();
33 41
34 // Inject a mock Provider for testing. Only a weak pointer to the injected 42 // 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 43 // object will be held by Provider, i.e. it does not itself contribute to the
36 // injected object's reference count. 44 // injected object's reference count.
37 static void SetInstanceForTests(Provider* provider); 45 static void SetInstanceForTests(Provider* provider);
38 46
39 // Get the current instance. Used for testing. 47 // Get the current instance. Used for testing.
40 static Provider* GetInstanceForTests(); 48 static Provider* GetInstanceForTests();
41 49
42 // Note: AddObserver may call back synchronously to the observer with 50 // Note: AddObserver may call back synchronously to the observer with data.
43 // orientation data.
44 virtual void AddObserver(Observer* observer) = 0; 51 virtual void AddObserver(Observer* observer) = 0;
45 virtual void RemoveObserver(Observer* observer) = 0; 52 virtual void RemoveObserver(Observer* observer) = 0;
46 53
47 protected: 54 protected:
48 Provider(); 55 Provider();
49 virtual ~Provider(); 56 virtual ~Provider();
50 57
51 private: 58 private:
52 friend class base::RefCountedThreadSafe<Provider>; 59 friend class base::RefCountedThreadSafe<Provider>;
53 static Provider* instance_; 60 static Provider* instance_;
54 61
55 DISALLOW_COPY_AND_ASSIGN(Provider); 62 DISALLOW_COPY_AND_ASSIGN(Provider);
56 }; 63 };
57 64
58 } // namespace device_orientation 65 } // namespace device_orientation
59 66
60 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_H_ 67 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698