OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 MemoryPurgeController_h |
| 6 #define MemoryPurgeController_h |
| 7 |
| 8 #include "platform/PlatformExport.h" |
| 9 #include "platform/heap/Handle.h" |
| 10 #include "wtf/MainThread.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 enum class MemoryPurgeMode { |
| 15 // The tab contains the webview went to background |
| 16 InactiveTab, |
| 17 // TODO(bashi): Add more modes as needed. |
| 18 }; |
| 19 |
| 20 enum class DeviceKind { |
| 21 NotSpecified, |
| 22 LowEnd, |
| 23 }; |
| 24 |
| 25 // Classes which have discardable/reducible memory can implement this |
| 26 // interface to be informed when they should reduce memory consumption. |
| 27 // MemoryPurgeController assumes that subclasses of MemoryPurgeClient are |
| 28 // WillBes. |
| 29 class MemoryPurgeClient : public WillBeGarbageCollectedMixin { |
| 30 public: |
| 31 virtual ~MemoryPurgeClient() { } |
| 32 |
| 33 // MemoryPurgeController invokes this callback when a memory purge event |
| 34 // has occurred. |
| 35 virtual void purgeMemory(MemoryPurgeMode, DeviceKind) = 0; |
| 36 |
| 37 DECLARE_TRACE(); |
| 38 }; |
| 39 |
| 40 // MemoryPurgeController listens to some events which could be opportunities |
| 41 // for reducing memory consumption and notifies its clients. |
| 42 // Since we want to control memory per tab, MemoryPurgeController is owned by |
| 43 // Page. |
| 44 class PLATFORM_EXPORT MemoryPurgeController { |
| 45 public: |
| 46 MemoryPurgeController(); |
| 47 |
| 48 void registerClient(MemoryPurgeClient* client) |
| 49 { |
| 50 ASSERT(isMainThread()); |
| 51 ASSERT(client); |
| 52 ASSERT(!m_clients.contains(client)); |
| 53 m_clients.add(client); |
| 54 } |
| 55 |
| 56 void unregisterClient(MemoryPurgeClient* client) |
| 57 { |
| 58 ASSERT(isMainThread()); |
| 59 ASSERT(m_clients.contains(client)); |
| 60 m_clients.remove(client); |
| 61 } |
| 62 |
| 63 DECLARE_TRACE(); |
| 64 |
| 65 private: |
| 66 void purgeMemory(MemoryPurgeMode); |
| 67 |
| 68 WillBeHeapHashSet<RawPtrWillBeWeakMember<MemoryPurgeClient>> m_clients; |
| 69 DeviceKind m_deviceKind; |
| 70 }; |
| 71 |
| 72 } // namespace blink |
| 73 |
| 74 #endif // MemoryPurgeController_h |
OLD | NEW |