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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_H_
6 #define CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_H_
8 #include "base/memory/ref_counted.h"
9 #include "content/browser/device_orientation/device_data.h"
10 #include "content/common/content_export.h"
14 class CONTENT_EXPORT Provider
: public base::RefCountedThreadSafe
<Provider
> {
18 // Called when device data changes.
19 // An Observer must not synchronously call Provider::RemoveObserver
20 // or Provider::AddObserver when this is called.
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_
; }
26 Observer(DeviceData::Type device_data_type
)
27 : device_data_type_(device_data_type
) {
29 virtual ~Observer() {}
32 // Each Observer observes exactly one type of DeviceData.
33 DeviceData::Type device_data_type_
;
36 // Returns a pointer to the singleton instance of this class.
37 // The caller should store the returned pointer in a scoped_refptr.
38 // The Provider instance is lazily constructed when GetInstance() is called,
39 // and destructed when the last scoped_refptr referring to it is destructed.
40 static Provider
* GetInstance();
42 // Inject a mock Provider for testing. Only a weak pointer to the injected
43 // object will be held by Provider, i.e. it does not itself contribute to the
44 // injected object's reference count.
45 static void SetInstanceForTests(Provider
* provider
);
47 // Get the current instance. Used for testing.
48 static Provider
* GetInstanceForTests();
50 // Note: AddObserver may call back synchronously to the observer with data.
51 virtual void AddObserver(Observer
* observer
) = 0;
52 virtual void RemoveObserver(Observer
* observer
) = 0;
59 friend class base::RefCountedThreadSafe
<Provider
>;
60 static Provider
* instance_
;
62 DISALLOW_COPY_AND_ASSIGN(Provider
);
65 } // namespace content
67 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_H_