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

Unified Diff: Source/core/page/PageLifecycleNotifier.h

Issue 18777003: Extract simpler classes for observing context lifecycle and observe Page lifecycle inNavigatorVibra… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Use SimpleLifecycleObserver in addObserver / removeObserver. Created 7 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/page/PageLifecycleNotifier.h
diff --git a/Source/core/platform/PurgeableBuffer.h b/Source/core/page/PageLifecycleNotifier.h
similarity index 52%
copy from Source/core/platform/PurgeableBuffer.h
copy to Source/core/page/PageLifecycleNotifier.h
index 3ad0992e229b2623f6abee13794187735b90425e..8ad03ee6bc9b8d62755d591eaf76426c9d749099 100644
--- a/Source/core/platform/PurgeableBuffer.h
+++ b/Source/core/page/PageLifecycleNotifier.h
@@ -1,5 +1,5 @@
+
/*
- * Copyright (C) 2008, 2010 Apple Inc. All Rights Reserved.
* Copyright (C) 2013 Google Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -21,51 +21,49 @@
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef PurgeableBuffer_h
-#define PurgeableBuffer_h
+#ifndef PageLifecycleNotifier_h
+#define PageLifecycleNotifier_h
-#include "wtf/OwnPtr.h"
+#include "core/dom/SimpleLifecycleNotifier.h"
+#include "core/page/PageLifecycleObserver.h"
#include "wtf/PassOwnPtr.h"
-
-namespace WebKit {
-class WebDiscardableMemory;
-}
+#include "wtf/TemporaryChange.h"
namespace WebCore {
-class PurgeableBuffer {
- WTF_MAKE_NONCOPYABLE(PurgeableBuffer);
-public:
- static PassOwnPtr<PurgeableBuffer> create(const char* data, size_t);
- ~PurgeableBuffer();
+class Page;
- // Call lock and check the return value before accessing the data.
- const char* data() const;
- size_t size() const { return m_size; }
+class PageLifecycleNotifier : public SimpleLifecycleNotifier {
+public:
+ static PassOwnPtr<PageLifecycleNotifier> create(SimpleLifecycleContext*);
- bool isPurgeable() const { return m_state != Locked; }
- bool wasPurged() const;
+ void notifyPageVisibilityChanged();
- bool lock();
- void unlock();
+ virtual void addObserver(SimpleLifecycleObserver*, SimpleLifecycleObserver::Type) OVERRIDE;
+ virtual void removeObserver(SimpleLifecycleObserver*, SimpleLifecycleObserver::Type) OVERRIDE;
private:
- enum State {
- Locked,
- Unlocked,
- Purged
- };
+ explicit PageLifecycleNotifier(SimpleLifecycleContext*);
- PurgeableBuffer(PassOwnPtr<WebKit::WebDiscardableMemory>, const char* data, size_t);
-
- OwnPtr<WebKit::WebDiscardableMemory> m_memory;
- size_t m_size;
- State m_state;
+ typedef HashSet<PageLifecycleObserver*> PageObserverSet;
+ PageObserverSet m_pageObservers;
};
+inline PassOwnPtr<PageLifecycleNotifier> PageLifecycleNotifier::create(SimpleLifecycleContext* context)
+{
+ return adoptPtr(new PageLifecycleNotifier(context));
+}
+
+inline void PageLifecycleNotifier::notifyPageVisibilityChanged()
+{
+ TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverPageObservers);
+ for (PageObserverSet::iterator it = m_pageObservers.begin(); it != m_pageObservers.end(); ++it)
+ (*it)->pageVisibilityChanged();
}
-#endif
+} // namespace WebCore
+
+#endif // PageLifecycleNotifier_h

Powered by Google App Engine
This is Rietveld 408576698