OLD | NEW |
| (Empty) |
1 // Copyright 2014 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. | |
4 | |
5 #ifndef DeviceEventControllerBase_h | |
6 #define DeviceEventControllerBase_h | |
7 | |
8 #include "core/page/PageLifecycleObserver.h" | |
9 #include "platform/Timer.h" | |
10 | |
11 namespace WebCore { | |
12 | |
13 // Base controller class for registering controllers with a dispatcher. | |
14 // It watches page visibility and calls stopUpdating when page is not visible. | |
15 // It provides a didUpdateData() callback method which is called when new data | |
16 // it available. | |
17 class DeviceEventControllerBase : public PageLifecycleObserver { | |
18 public: | |
19 void startUpdating(); | |
20 void stopUpdating(); | |
21 | |
22 // This is called when new data becomes available. | |
23 virtual void didUpdateData() = 0; | |
24 | |
25 protected: | |
26 explicit DeviceEventControllerBase(Page*); | |
27 virtual ~DeviceEventControllerBase(); | |
28 | |
29 virtual void registerWithDispatcher() = 0; | |
30 virtual void unregisterWithDispatcher() = 0; | |
31 | |
32 // When true initiates a one-shot didUpdateData() when startUpdating() is ca
lled. | |
33 virtual bool hasLastData() = 0; | |
34 | |
35 bool m_hasEventListener; | |
36 | |
37 private: | |
38 // Inherited from PageLifecycleObserver. | |
39 virtual void pageVisibilityChanged() OVERRIDE FINAL; | |
40 | |
41 void oneShotCallback(Timer<DeviceEventControllerBase>*); | |
42 | |
43 bool m_isActive; | |
44 Timer<DeviceEventControllerBase> m_timer; | |
45 }; | |
46 | |
47 } // namespace WebCore | |
48 | |
49 #endif // DeviceEventControllerBase_h | |
OLD | NEW |