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 | |
11 namespace blink { | |
12 | |
13 enum class MemoryPurgeMode { | |
14 // The tab contains the webview went to background | |
15 InactiveTab, | |
16 // TODO(bashi): Add more modes as needed. | |
17 }; | |
18 | |
19 enum class DeviceKind { | |
20 NotSpecified, | |
21 LowEnd, | |
22 }; | |
23 | |
24 // Classes which have discardable/reducible memory can implement this | |
25 // interface to be informed when they should reduce memory consumption. | |
26 class MemoryPurgeClient : public WillBeGarbageCollectedMixin { | |
27 public: | |
28 virtual ~MemoryPurgeClient() { } | |
29 | |
30 // MemoryPurgeController invokes this callback when a memory purge event | |
31 // has occurred. | |
32 virtual void purgeMemory(MemoryPurgeMode, DeviceKind) = 0; | |
33 | |
34 DECLARE_TRACE(); | |
35 }; | |
36 | |
37 // MemoryPurgeController listens to some events which could be opportunities | |
38 // for reducing memory consumption and notifies its clients. | |
39 // Since we want to controll memory per tab, MemoryPurgeController is owned by | |
40 // Page. | |
41 class PLATFORM_EXPORT MemoryPurgeController { | |
42 public: | |
43 MemoryPurgeController(); | |
44 | |
45 void registerClient(MemoryPurgeClient* client) { m_clients.add(client); } | |
tkent
2015/08/25 03:09:31
Do you allow null client?
bashi
2015/08/25 03:36:44
Added ASSERT().
| |
46 void unregisterClient(MemoryPurgeClient* client) { m_clients.remove(client); } | |
tkent
2015/08/25 03:09:31
Do you allow to call unregisterClient with not-reg
bashi
2015/08/25 03:36:44
Added ASSERT().
| |
47 | |
48 // Called when page visibility changed. | |
49 void pageBecameVisible(); | |
50 void pageBecameHidden(); | |
51 | |
52 DECLARE_TRACE(); | |
53 | |
54 private: | |
55 void purgeMemory(MemoryPurgeMode); | |
56 | |
57 WillBeHeapHashSet<RawPtrWillBeWeakMember<MemoryPurgeClient>> m_clients; | |
58 DeviceKind m_deviceKind; | |
59 }; | |
60 | |
61 } // namespace blink | |
62 | |
63 #endif // MemoryPurgeController_h | |
OLD | NEW |