Index: base/memory/discardable_memory.h |
diff --git a/base/memory/discardable_memory.h b/base/memory/discardable_memory.h |
index d6e91b979d5a46fdd50e6ef07ab4f52a904bc042..9370885dbdcc43ecd56a56e47447311618b3fff6 100644 |
--- a/base/memory/discardable_memory.h |
+++ b/base/memory/discardable_memory.h |
@@ -17,6 +17,15 @@ enum LockDiscardableMemoryStatus { |
DISCARDABLE_MEMORY_SUCCESS = 1 |
}; |
+#if defined(OS_MACOSX) || defined(OS_ANDROID) |
+// This should only be defined on platforms that guarantee that |
+// DiscardableMemoryProvider::GetInstance will not return NULL. If your |
+// platform's support cannot provide this guarantee (e.g., can only return a |
+// non-NULL value in certain circumstances), do not process this define. |
+#define DISCARDABLE_MEMORY_SUPPORTED_NATIVELY |
avi_google.com
2013/06/14 11:09:33
BTW it's likely that we will need to turn this int
|
+class DiscardableMemoryProvider; |
Avi (use Gerrit)
2013/06/12 14:56:49
Why is this class forward declared here? It's only
|
+#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,9 +60,6 @@ class BASE_EXPORT DiscardableMemory { |
// The opened file will also be closed after this. |
~DiscardableMemory(); |
- // Check whether the system supports discardable memory. |
- static bool Supported(); |
- |
// Initialize the DiscardableMemory object. On success, this function returns |
// true and the memory is locked. This should only be called once. |
// This call could fail because of platform-specific limitations and the user |
@@ -72,6 +78,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; |
@@ -86,7 +94,21 @@ class BASE_EXPORT DiscardableMemory { |
// across all running processes, so it should only be used for testing! |
static void PurgeForTesting(); |
+#if !defined(DISCARDABLE_MEMORY_SUPPORTED_NATIVELY) |
+ // Platforms without native support for discardable memory may use this |
+ // to force discardable memory to be purged as they see fit. |
+ static void Purge(); |
+#endif |
Avi (use Gerrit)
2013/06/12 14:56:49
I would re-order this up two functions, so it does
|
+ |
private: |
+#if !defined(DISCARDABLE_MEMORY_SUPPORTED_NATIVELY) |
+ friend class DiscardableMemoryProvider; |
+ |
+ // 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. |