| 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/Timer.h" | |
| 10 #include "platform/heap/Handle.h" | |
| 11 #include "public/platform/WebMemoryPressureLevel.h" | |
| 12 | |
| 13 namespace blink { | |
| 14 | |
| 15 enum class DeviceKind { | |
| 16 NotSpecified, | |
| 17 LowEnd, | |
| 18 }; | |
| 19 | |
| 20 // Classes which have discardable/reducible memory can implement this | |
| 21 // interface to be informed when they should reduce memory consumption. | |
| 22 // MemoryPurgeController assumes that subclasses of MemoryPurgeClient are | |
| 23 // WillBes. | |
| 24 class PLATFORM_EXPORT MemoryPurgeClient : public GarbageCollectedMixin { | |
| 25 public: | |
| 26 virtual ~MemoryPurgeClient() { } | |
| 27 | |
| 28 // MemoryPurgeController invokes this callback when a memory purge event | |
| 29 // has occurred. | |
| 30 virtual void purgeMemory(DeviceKind) = 0; | |
| 31 | |
| 32 DECLARE_VIRTUAL_TRACE(); | |
| 33 }; | |
| 34 | |
| 35 // MemoryPurgeController listens to some events which could be opportunities | |
| 36 // for reducing memory consumption and notifies its clients. | |
| 37 // Since we want to control memory per tab, MemoryPurgeController is owned by | |
| 38 // Page. | |
| 39 class PLATFORM_EXPORT MemoryPurgeController final : public GarbageCollected<Memo
ryPurgeController> { | |
| 40 WTF_MAKE_NONCOPYABLE(MemoryPurgeController); | |
| 41 public: | |
| 42 static void onMemoryPressure(WebMemoryPressureLevel); | |
| 43 | |
| 44 static MemoryPurgeController* create() | |
| 45 { | |
| 46 return new MemoryPurgeController; | |
| 47 } | |
| 48 | |
| 49 void registerClient(MemoryPurgeClient* client) | |
| 50 { | |
| 51 ASSERT(isMainThread()); | |
| 52 ASSERT(client); | |
| 53 ASSERT(!m_clients.contains(client)); | |
| 54 m_clients.add(client); | |
| 55 } | |
| 56 | |
| 57 void unregisterClient(MemoryPurgeClient* client) | |
| 58 { | |
| 59 // Don't assert m_clients.contains() so that clients can unregister | |
| 60 // unconditionally. | |
| 61 ASSERT(isMainThread()); | |
| 62 m_clients.remove(client); | |
| 63 } | |
| 64 | |
| 65 void purgeMemory(); | |
| 66 | |
| 67 DECLARE_TRACE(); | |
| 68 | |
| 69 private: | |
| 70 MemoryPurgeController(); | |
| 71 | |
| 72 HeapHashSet<WeakMember<MemoryPurgeClient>> m_clients; | |
| 73 DeviceKind m_deviceKind; | |
| 74 }; | |
| 75 | |
| 76 } // namespace blink | |
| 77 | |
| 78 #endif // MemoryPurgeController_h | |
| OLD | NEW |