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/page/PageLifecycleObserver.h"
9 #include "platform/Timer.h"
10 #include "platform/heap/Handle.h"
14 // Base controller class for registering controllers with a dispatcher.
15 // It watches page visibility and calls stopUpdating when page is not visible.
16 // It provides a didUpdateData() callback method which is called when new data
18 class PlatformEventController : public WillBeGarbageCollectedMixin, public PageLifecycleObserver {
23 // This is called when new data becomes available.
24 virtual void didUpdateData() = 0;
26 virtual void trace(Visitor*) { }
29 explicit PlatformEventController(Page*);
30 virtual ~PlatformEventController();
32 virtual void registerWithDispatcher() = 0;
33 virtual void unregisterWithDispatcher() = 0;
35 // When true initiates a one-shot didUpdateData() when startUpdating() is called.
36 virtual bool hasLastData() = 0;
38 bool m_hasEventListener;
41 // Inherited from PageLifecycleObserver.
42 virtual void pageVisibilityChanged() override;
44 void oneShotCallback(Timer<PlatformEventController>*);
47 Timer<PlatformEventController> m_timer;
52 #endif // PlatformEventController_h