| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MemoryCoordinator_h | 5 #ifndef MemoryCoordinator_h |
| 6 #define MemoryCoordinator_h | 6 #define MemoryCoordinator_h |
| 7 | 7 |
| 8 #include "platform/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
| 9 #include "platform/heap/Handle.h" | 9 #include "platform/heap/Handle.h" |
| 10 #include "public/platform/WebMemoryPressureLevel.h" | 10 #include "public/platform/WebMemoryPressureLevel.h" |
| 11 #include "public/platform/WebMemoryState.h" |
| 11 #include "wtf/Noncopyable.h" | 12 #include "wtf/Noncopyable.h" |
| 12 | 13 |
| 13 namespace blink { | 14 namespace blink { |
| 14 | 15 |
| 15 class PLATFORM_EXPORT MemoryCoordinatorClient : public GarbageCollectedMixin { | 16 class PLATFORM_EXPORT MemoryCoordinatorClient : public GarbageCollectedMixin { |
| 16 public: | 17 public: |
| 17 virtual ~MemoryCoordinatorClient() {} | 18 virtual ~MemoryCoordinatorClient() {} |
| 18 | 19 |
| 19 // Called when MemoryCoordinator is asked to prepare for suspending | 20 // Called when MemoryCoordinator is asked to prepare for suspending |
| 20 // the renderer. Clients should purge discardable memory as much as | 21 // the renderer. Clients should purge discardable memory as much as |
| 21 // possible. | 22 // possible. |
| 22 virtual void prepareToSuspend() {} | 23 virtual void prepareToSuspend() {} |
| 23 | 24 |
| 24 // TODO(bashi): Deprecating. Remove this when MemoryPressureListener is | 25 // TODO(bashi): Deprecating. Remove this when MemoryPressureListener is |
| 25 // gone. | 26 // gone. |
| 26 virtual void onMemoryPressure(WebMemoryPressureLevel) {} | 27 virtual void onMemoryPressure(WebMemoryPressureLevel) {} |
| 28 |
| 29 virtual void onMemoryStateChange(MemoryState) {} |
| 27 }; | 30 }; |
| 28 | 31 |
| 29 // MemoryCoordinator listens to some events which could be opportunities | 32 // MemoryCoordinator listens to some events which could be opportunities |
| 30 // for reducing memory consumption and notifies its clients. | 33 // for reducing memory consumption and notifies its clients. |
| 31 class PLATFORM_EXPORT MemoryCoordinator final | 34 class PLATFORM_EXPORT MemoryCoordinator final |
| 32 : public GarbageCollected<MemoryCoordinator> { | 35 : public GarbageCollected<MemoryCoordinator> { |
| 33 WTF_MAKE_NONCOPYABLE(MemoryCoordinator); | 36 WTF_MAKE_NONCOPYABLE(MemoryCoordinator); |
| 34 | 37 |
| 35 public: | 38 public: |
| 36 static MemoryCoordinator& instance(); | 39 static MemoryCoordinator& instance(); |
| 37 | 40 |
| 38 void registerClient(MemoryCoordinatorClient*); | 41 void registerClient(MemoryCoordinatorClient*); |
| 39 void unregisterClient(MemoryCoordinatorClient*); | 42 void unregisterClient(MemoryCoordinatorClient*); |
| 40 | 43 |
| 41 void prepareToSuspend(); | 44 void prepareToSuspend(); |
| 42 | 45 |
| 43 // TODO(bashi): Deprecating. Remove this when MemoryPressureListener is | 46 // TODO(bashi): Deprecating. Remove this when MemoryPressureListener is |
| 44 // gone. | 47 // gone. |
| 45 void onMemoryPressure(WebMemoryPressureLevel); | 48 void onMemoryPressure(WebMemoryPressureLevel); |
| 46 | 49 |
| 50 void onMemoryStateChange(MemoryState); |
| 51 |
| 47 DECLARE_TRACE(); | 52 DECLARE_TRACE(); |
| 48 | 53 |
| 49 private: | 54 private: |
| 50 MemoryCoordinator(); | 55 MemoryCoordinator(); |
| 51 | 56 |
| 57 void clearMemory(); |
| 58 |
| 52 HeapHashSet<WeakMember<MemoryCoordinatorClient>> m_clients; | 59 HeapHashSet<WeakMember<MemoryCoordinatorClient>> m_clients; |
| 53 }; | 60 }; |
| 54 | 61 |
| 55 } // namespace blink | 62 } // namespace blink |
| 56 | 63 |
| 57 #endif // MemoryCoordinator_h | 64 #endif // MemoryCoordinator_h |
| OLD | NEW |