Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / platform / MemoryPurgeController.h
blob561c0cc2bb8e2ab68591db5e2655dffa5f523073
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.
5 #ifndef MemoryPurgeController_h
6 #define MemoryPurgeController_h
8 #include "platform/PlatformExport.h"
9 #include "platform/heap/Handle.h"
10 #include "wtf/MainThread.h"
12 namespace blink {
14 enum class MemoryPurgeMode {
15 // The tab contains the webview went to background
16 InactiveTab,
17 // TODO(bashi): Add more modes as needed.
20 enum class DeviceKind {
21 NotSpecified,
22 LowEnd,
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() { }
33 // MemoryPurgeController invokes this callback when a memory purge event
34 // has occurred.
35 virtual void purgeMemory(MemoryPurgeMode, DeviceKind) = 0;
37 DECLARE_TRACE();
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 final : public NoBaseWillBeGarbageCollected<MemoryPurgeController> {
45 DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(MemoryPurgeController);
46 public:
47 static PassOwnPtrWillBeRawPtr<MemoryPurgeController> create()
49 return adoptPtrWillBeNoop(new MemoryPurgeController);
52 void registerClient(MemoryPurgeClient* client)
54 ASSERT(isMainThread());
55 ASSERT(client);
56 ASSERT(!m_clients.contains(client));
57 m_clients.add(client);
60 void unregisterClient(MemoryPurgeClient* client)
62 ASSERT(isMainThread());
63 ASSERT(m_clients.contains(client));
64 m_clients.remove(client);
67 DECLARE_TRACE();
69 private:
70 MemoryPurgeController();
72 void purgeMemory(MemoryPurgeMode);
74 WillBeHeapHashSet<RawPtrWillBeWeakMember<MemoryPurgeClient>> m_clients;
75 DeviceKind m_deviceKind;
78 } // namespace blink
80 #endif // MemoryPurgeController_h