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

Unified Diff: base/memory/discardable_memory.h

Issue 17106004: Add discardable memory emulation for non-android/mac platforms (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 6 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
Index: base/memory/discardable_memory.h
diff --git a/base/memory/discardable_memory.h b/base/memory/discardable_memory.h
index d6e91b979d5a46fdd50e6ef07ab4f52a904bc042..c173dfe1cde5a2076b655aa52306d814e7196e4c 100644
--- a/base/memory/discardable_memory.h
+++ b/base/memory/discardable_memory.h
@@ -17,6 +17,10 @@ enum LockDiscardableMemoryStatus {
DISCARDABLE_MEMORY_SUCCESS = 1
};
+#if defined(OS_MACOSX) || defined(OS_ANDROID)
+#define DISCARDABLE_MEMORY_SUPPORTED_NATIVELY
Avi (use Gerrit) 2013/06/20 21:16:41 If there is now a runtime call, do we need this #d
Ian Vollick 2013/06/20 23:27:09 Yup, but it needs a better name. We need to condit
Avi (use Gerrit) 2013/06/20 23:29:56 Meh. I'm not thrilled, but I don't care that much.
+#endif
+
// Platform abstraction for discardable memory. DiscardableMemory is used to
// cache large objects without worrying about blowing out memory, both on mobile
// devices where there is no swap, and desktop devices where unused free memory
@@ -51,8 +55,9 @@ class BASE_EXPORT DiscardableMemory {
// The opened file will also be closed after this.
~DiscardableMemory();
- // Check whether the system supports discardable memory.
- static bool Supported();
+ // Check whether the system supports discardable memory natively. Returns
+ // false if the support is emulated.
+ static bool SupportedNatively();
// Initialize the DiscardableMemory object. On success, this function returns
// true and the memory is locked. This should only be called once.
@@ -72,6 +77,8 @@ class BASE_EXPORT DiscardableMemory {
// after every successful lock call.
void Unlock();
+ bool is_locked() const { return is_locked_; }
+
// Return the memory address held by this object. The object must be locked
// before calling this. Otherwise, this will cause a DCHECK error.
void* Memory() const;
@@ -87,6 +94,15 @@ class BASE_EXPORT DiscardableMemory {
static void PurgeForTesting();
private:
+#if !defined(DISCARDABLE_MEMORY_SUPPORTED_NATIVELY)
+ friend class DiscardableMemoryProvider;
+ friend class DiscardableMemoryProviderTest;
+
+ // Used by the DiscardableMemoryProvider to allocate and free memory.
+ bool Allocate();
+ void Deallocate();
+#endif
+
#if defined(OS_ANDROID)
// Maps the discardable memory into the caller's address space.
// Returns true on success, false otherwise.

Powered by Google App Engine
This is Rietveld 408576698