Index: Source/platform/MemoryPurgeController.h |
diff --git a/Source/platform/MemoryPurgeController.h b/Source/platform/MemoryPurgeController.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..86c7de3ba402252bfda812d156be63b906adec76 |
--- /dev/null |
+++ b/Source/platform/MemoryPurgeController.h |
@@ -0,0 +1,72 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef MemoryPurgeController_h |
+#define MemoryPurgeController_h |
+ |
+#include "platform/PlatformExport.h" |
+#include "platform/heap/Handle.h" |
+ |
+namespace blink { |
+ |
+enum class MemoryPurgeMode { |
+ // The tab contains the webview went to background |
+ InactiveTab, |
+ // TODO(bashi): Add more modes as needed. |
+}; |
+ |
+enum class DeviceKind { |
+ NotSpecified, |
+ LowEnd, |
+}; |
+ |
+// Classes which have discardable/reducible memory can implement this |
+// interface to be informed when they should reduce memory consumption. |
+class MemoryPurgeClient : public WillBeGarbageCollectedMixin { |
+public: |
+ virtual ~MemoryPurgeClient() { } |
+ |
+ // MemoryPurgeController invokes this callback when a memory purge event |
+ // has occurred. |
+ virtual void purgeMemory(MemoryPurgeMode, DeviceKind) = 0; |
+ |
+ DECLARE_TRACE(); |
+}; |
+ |
+// MemoryPurgeController listens to some events which could be opportunities |
+// for reducing memory consumption and notifies its clients. |
+// Since we want to controll memory per tab, MemoryPurgeController is owned by |
haraken
2015/08/25 03:46:08
control
bashi
2015/08/25 04:52:58
Done.
|
+// Page. |
+class PLATFORM_EXPORT MemoryPurgeController { |
+public: |
+ MemoryPurgeController(); |
+ |
+ void registerClient(MemoryPurgeClient* client) |
tkent
2015/08/25 03:45:59
Is it ok to call registerClient/unregisterClient f
bashi
2015/08/25 04:52:58
Added ASSERT(isMainThead())
|
+ { |
+ ASSERT(client); |
haraken
2015/08/25 03:46:08
Add ASSERT(!m_clients.contains(client)).
bashi
2015/08/25 04:52:58
Done.
|
+ m_clients.add(client); |
+ } |
+ |
+ void unregisterClient(MemoryPurgeClient* client) |
tkent
2015/08/25 03:45:59
How to call unregisterClient() for an object which
haraken
2015/08/25 03:47:03
This will be used only when we want to explicitly
tkent
2015/08/25 03:50:19
m_clients consists of raw pointers now (!ENABLE(OI
haraken
2015/08/25 03:52:35
Yes, I'm assuming the following use case.
class X
tkent
2015/08/25 04:58:08
I'm asking about GarbageCollected(Finalized) cases
|
+ { |
+ ASSERT(m_clients.contains(client)); |
+ m_clients.remove(client); |
+ } |
+ |
+ // Called when page visibility changed. |
+ void pageBecameVisible(); |
+ void pageBecameHidden(); |
+ |
+ DECLARE_TRACE(); |
+ |
+private: |
+ void purgeMemory(MemoryPurgeMode); |
+ |
+ WillBeHeapHashSet<RawPtrWillBeWeakMember<MemoryPurgeClient>> m_clients; |
+ DeviceKind m_deviceKind; |
+}; |
+ |
+} // namespace blink |
+ |
+#endif // MemoryPurgeController_h |