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

Unified Diff: base/memory/discardable_memory.h

Issue 15650016: [Not for review] Discardable memory emulation (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
« no previous file with comments | « no previous file | base/memory/discardable_memory.cc » ('j') | base/memory/discardable_memory_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/discardable_memory.h
diff --git a/base/memory/discardable_memory.h b/base/memory/discardable_memory.h
index d6e91b979d5a46fdd50e6ef07ab4f52a904bc042..95abb22511a9057db71d45be422d96249be901fb 100644
--- a/base/memory/discardable_memory.h
+++ b/base/memory/discardable_memory.h
@@ -17,6 +17,35 @@ enum LockDiscardableMemoryStatus {
DISCARDABLE_MEMORY_SUCCESS = 1
};
+#if defined(OS_MACOSX) || defined(OS_ANDROID)
+#define DISCARDABLE_MEMORY_SUPPORTED_NATIVELY
+#endif
+
+class DiscardableMemory;
+
+class BASE_EXPORT DiscardableMemoryProvider {
+ public:
+ // Returns the instance set via SetInstance, if one exists. Otherwise, it
+ // will attempt to create an instance via CreateInstance(). It is possible
Avi (use Gerrit) 2013/06/07 14:46:53 What is CreateInstance()?
+ // that this can return NULL.
Avi (use Gerrit) 2013/06/07 14:46:53 "Can" return NULL is not helpful. In what scenario
+ static DiscardableMemoryProvider* GetInstance();
+
+#if !defined(DISCARDABLE_MEMORY_SUPPORTED_NATIVELY)
+ // The caller retains ownership of the factory.
+ static void SetInstance(DiscardableMemoryProvider* provider);
+#endif
+
+ virtual DiscardableMemory* CreateDiscardableMemory() = 0;
+
+ // Check whether a purge of all discardable memory in the system is supported.
+ // Use only for testing!
+ virtual bool PurgeForTestingSupported() const = 0;
+
+ // Purge all discardable memory in the system. This call has global effects
+ // across all running processes, so it should only be used for testing!
+ virtual void PurgeForTesting() = 0;
+};
+
// 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
@@ -45,20 +74,15 @@ enum LockDiscardableMemoryStatus {
// http://www.opensource.apple.com/source/xnu/xnu-792.13.8/osfmk/vm/vm_object.c
class BASE_EXPORT DiscardableMemory {
public:
- DiscardableMemory();
-
// If the discardable memory is locked, the destructor will unlock it.
// The opened file will also be closed after this.
- ~DiscardableMemory();
-
- // Check whether the system supports discardable memory.
- static bool Supported();
+ virtual ~DiscardableMemory();
// 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
// should stop using the DiscardableMemory afterwards.
- bool InitializeAndLock(size_t size);
+ virtual bool InitializeAndLock(size_t size) = 0;
// Lock the memory so that it will not be purged by the system. Returns
// DISCARDABLE_MEMORY_SUCCESS on success. If the return value is
@@ -66,51 +90,15 @@ class BASE_EXPORT DiscardableMemory {
// a new one should be created. If the return value is
// DISCARDABLE_MEMORY_PURGED then the memory is present but any data that
// was in it is gone.
- LockDiscardableMemoryStatus Lock() WARN_UNUSED_RESULT;
+ virtual LockDiscardableMemoryStatus Lock() WARN_UNUSED_RESULT = 0;
// Unlock the memory so that it can be purged by the system. Must be called
// after every successful lock call.
- void Unlock();
+ virtual void Unlock() = 0;
// 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;
-
- // Testing utility calls.
-
- // Check whether a purge of all discardable memory in the system is supported.
- // Use only for testing!
- static bool PurgeForTestingSupported();
-
- // Purge all discardable memory in the system. This call has global effects
- // across all running processes, so it should only be used for testing!
- static void PurgeForTesting();
-
- private:
-#if defined(OS_ANDROID)
- // Maps the discardable memory into the caller's address space.
- // Returns true on success, false otherwise.
- bool Map();
-
- // Unmaps the discardable memory from the caller's address space.
- void Unmap();
-
- // Reserve a file descriptor. When reaching the fd limit, this call returns
- // false and initialization should fail.
- bool ReserveFileDescriptor();
-
- // Release a file descriptor so that others can reserve it.
- void ReleaseFileDescriptor();
-#endif // OS_ANDROID
-
- void* memory_;
- size_t size_;
- bool is_locked_;
-#if defined(OS_ANDROID)
- int fd_;
-#endif // OS_ANDROID
-
- DISALLOW_COPY_AND_ASSIGN(DiscardableMemory);
+ virtual void* Memory() const = 0;
};
} // namespace base
« no previous file with comments | « no previous file | base/memory/discardable_memory.cc » ('j') | base/memory/discardable_memory_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698