Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / core / frame / PlatformEventController.h
blobc55a544b58bb85c366590181912b0949997b4cf8
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.
5 #ifndef PlatformEventController_h
6 #define PlatformEventController_h
8 #include "core/CoreExport.h"
9 #include "core/page/PageLifecycleObserver.h"
10 #include "platform/Timer.h"
11 #include "platform/heap/Handle.h"
13 namespace blink {
15 // Base controller class for registering controllers with a dispatcher.
16 // It watches page visibility and calls stopUpdating when page is not visible.
17 // It provides a didUpdateData() callback method which is called when new data
18 // it available.
19 class CORE_EXPORT PlatformEventController : public PageLifecycleObserver {
20 public:
21 void startUpdating();
22 void stopUpdating();
24 // This is called when new data becomes available.
25 virtual void didUpdateData() = 0;
27 protected:
28 explicit PlatformEventController(Page*);
29 virtual ~PlatformEventController();
31 virtual void registerWithDispatcher() = 0;
32 virtual void unregisterWithDispatcher() = 0;
34 // When true initiates a one-shot didUpdateData() when startUpdating() is called.
35 virtual bool hasLastData() = 0;
37 bool m_hasEventListener;
39 private:
40 // Inherited from PageLifecycleObserver.
41 void pageVisibilityChanged() override;
43 void oneShotCallback(Timer<PlatformEventController>*);
45 bool m_isActive;
46 Timer<PlatformEventController> m_timer;
49 } // namespace blink
51 #endif // PlatformEventController_h