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

Unified 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 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..d618d1ad76601308ca5f9d9daa81ae3d4e21f1fd
--- /dev/null
+++ b/Source/platform/MemoryPurgeController.h
@@ -0,0 +1,51 @@
+// 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 "wtf/HashSet.h"
+
+namespace blink {
+
+enum MemoryPurgeMode {
+ // The tab contains the webview went to background
+ Inactive,
dcheng 2015/08/21 15:04:19 Suggestion: we should prefer enum class for both o
bashi 2015/08/25 02:34:23 Done.
+ // TODO(bashi): Add more modes as needed.
+};
+
+enum DeviceKind {
dcheng 2015/08/21 15:04:19 Ditto: NotSpecified is pretty generic.
bashi 2015/08/25 02:34:23 Done.
+ NotSpecified,
+ LowEnd,
+};
+
+// TODO(bashi): Make MemoryPurgeEventListener garbage collected.
+class MemoryPurgeEventListener {
+public:
+ // MemoryPurgeController invokes this callback when a memory purge event
+ // has occurred.
+ virtual void purgeMemory(MemoryPurgeMode, DeviceKind) = 0;
+};
+
+class MemoryPurgeController {
+public:
+ MemoryPurgeController();
+
+ void addListener(MemoryPurgeEventListener* listener) { m_listeners.add(listener); }
+ void removeListener(MemoryPurgeEventListener* listener) { m_listeners.remove(listener); }
+
+ // Called several seconds after the tab went to background.
+ void didBecomeInactive();
+
+private:
+ void purgeMemory(MemoryPurgeMode);
+
+ HashSet<MemoryPurgeEventListener*> m_listeners;
+ 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