Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: Source/platform/MemoryPurgeController.h

Issue 1303203002: Add MemoryPurgeController (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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
haraken 2015/08/25 03:46:08 control
bashi 2015/08/25 04:52:58 Done.
40 // Page.
41 class PLATFORM_EXPORT MemoryPurgeController {
42 public:
43 MemoryPurgeController();
44
45 void registerClient(MemoryPurgeClient* client)
tkent 2015/08/25 03:45:59 Is it ok to call registerClient/unregisterClient f
bashi 2015/08/25 04:52:58 Added ASSERT(isMainThead())
46 {
47 ASSERT(client);
haraken 2015/08/25 03:46:08 Add ASSERT(!m_clients.contains(client)).
bashi 2015/08/25 04:52:58 Done.
48 m_clients.add(client);
49 }
50
51 void unregisterClient(MemoryPurgeClient* client)
tkent 2015/08/25 03:45:59 How to call unregisterClient() for an object which
haraken 2015/08/25 03:47:03 This will be used only when we want to explicitly
tkent 2015/08/25 03:50:19 m_clients consists of raw pointers now (!ENABLE(OI
haraken 2015/08/25 03:52:35 Yes, I'm assuming the following use case. class X
tkent 2015/08/25 04:58:08 I'm asking about GarbageCollected(Finalized) cases
52 {
53 ASSERT(m_clients.contains(client));
54 m_clients.remove(client);
55 }
56
57 // Called when page visibility changed.
58 void pageBecameVisible();
59 void pageBecameHidden();
60
61 DECLARE_TRACE();
62
63 private:
64 void purgeMemory(MemoryPurgeMode);
65
66 WillBeHeapHashSet<RawPtrWillBeWeakMember<MemoryPurgeClient>> m_clients;
67 DeviceKind m_deviceKind;
68 };
69
70 } // namespace blink
71
72 #endif // MemoryPurgeController_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698