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

Unified Diff: Source/platform/MemoryPurgeController.h

Issue 1303203002: Add MemoryPurgeController (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: export 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/page/Page.cpp ('k') | Source/platform/MemoryPurgeController.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/MemoryPurgeController.h
diff --git a/Source/platform/MemoryPurgeController.h b/Source/platform/MemoryPurgeController.h
new file mode 100644
index 0000000000000000000000000000000000000000..232b78e25dc02c43d666b8aee21ecf0f1146200e
--- /dev/null
+++ b/Source/platform/MemoryPurgeController.h
@@ -0,0 +1,63 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MemoryPurgeController_h
+#define MemoryPurgeController_h
+
+#include "platform/PlatformExport.h"
+#include "platform/heap/Handle.h"
+
+namespace blink {
+
+enum class MemoryPurgeMode {
+ // The tab contains the webview went to background
+ InactiveTab,
+ // TODO(bashi): Add more modes as needed.
+};
+
+enum class DeviceKind {
+ NotSpecified,
+ LowEnd,
+};
+
+// Classes which have discardable/reducible memory can implement this
+// interface to be informed when they should reduce memory consumption.
+class MemoryPurgeClient : public WillBeGarbageCollectedMixin {
+public:
+ virtual ~MemoryPurgeClient() { }
+
+ // MemoryPurgeController invokes this callback when a memory purge event
+ // has occurred.
+ virtual void purgeMemory(MemoryPurgeMode, DeviceKind) = 0;
+
+ DECLARE_TRACE();
+};
+
+// MemoryPurgeController listens to some events which could be opportunities
+// for reducing memory consumption and notifies its clients.
+// Since we want to controll memory per tab, MemoryPurgeController is owned by
+// Page.
+class PLATFORM_EXPORT MemoryPurgeController {
+public:
+ MemoryPurgeController();
+
+ 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().
+ 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().
+
+ // Called when page visibility changed.
+ void pageBecameVisible();
+ void pageBecameHidden();
+
+ DECLARE_TRACE();
+
+private:
+ void purgeMemory(MemoryPurgeMode);
+
+ WillBeHeapHashSet<RawPtrWillBeWeakMember<MemoryPurgeClient>> m_clients;
+ DeviceKind m_deviceKind;
+};
+
+} // namespace blink
+
+#endif // MemoryPurgeController_h
« no previous file with comments | « Source/core/page/Page.cpp ('k') | Source/platform/MemoryPurgeController.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698