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

Unified Diff: base/memory/discardable_memory.h

Issue 24988003: Refactor DiscardableMemory for the upcoming DiscardableMemoryAllocator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix linux clang build Created 7 years, 2 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') | no next file with comments »
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..c6a8d82da72363d3dc2cecbb01547eeb64c226eb 100644
--- a/base/memory/discardable_memory.h
+++ b/base/memory/discardable_memory.h
@@ -8,6 +8,7 @@
#include "base/base_export.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
+#include "base/memory/scoped_ptr.h"
namespace base {
@@ -45,36 +46,28 @@ enum LockDiscardableMemoryStatus {
// http://www.opensource.apple.com/source/xnu/xnu-792.13.8/osfmk/vm/vm_object.c
class BASE_EXPORT DiscardableMemory {
public:
- DiscardableMemory();
+ virtual ~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.
+ // Returns 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
- // should stop using the DiscardableMemory afterwards.
- bool InitializeAndLock(size_t size);
+ static scoped_ptr<DiscardableMemory> CreateLockedMemory(size_t size);
- // Lock the memory so that it will not be purged by the system. Returns
+ // Locks the memory so that it will not be purged by the system. Returns
// DISCARDABLE_MEMORY_SUCCESS on success. If the return value is
// DISCARDABLE_MEMORY_FAILED then this object should be discarded and
// 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
+ // Unlocks 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
+ // Returns 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;
+ virtual void* Memory() const = 0;
// Testing utility calls.
@@ -85,32 +78,6 @@ class BASE_EXPORT DiscardableMemory {
// 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);
};
} // namespace base
« no previous file with comments | « no previous file | base/memory/discardable_memory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698