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

Unified Diff: base/memory/discardable_memory_android.cc

Issue 114923005: base: Discardable memory types. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add switches::kUseDiscardableMemory to kForwardSwitches Created 6 years, 11 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 | « base/memory/discardable_memory_android.h ('k') | base/memory/discardable_memory_emulated.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/discardable_memory_android.cc
diff --git a/base/memory/discardable_memory_android.cc b/base/memory/discardable_memory_android.cc
index 9f4f159a6718f2ddcbf80c12805c523c0e20787b..b5168ee0fe81bb344f5f66b71d2b68dd7a6294fa 100644
--- a/base/memory/discardable_memory_android.cc
+++ b/base/memory/discardable_memory_android.cc
@@ -15,8 +15,8 @@
#include "base/file_util.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
-#include "base/memory/discardable_memory.h"
#include "base/memory/discardable_memory_allocator_android.h"
+#include "base/memory/discardable_memory_emulated.h"
#include "third_party/ashmem/ashmem.h"
namespace base {
@@ -100,14 +100,14 @@ bool CloseAshmemRegion(int fd, size_t size, void* address) {
return close(fd) == 0;
}
-LockDiscardableMemoryStatus LockAshmemRegion(int fd,
+DiscardableMemoryLockStatus LockAshmemRegion(int fd,
size_t off,
size_t size,
const void* address) {
const int result = ashmem_pin_region(fd, off, size);
DCHECK_EQ(0, mprotect(address, size, PROT_READ | PROT_WRITE));
- return result == ASHMEM_WAS_PURGED ?
- DISCARDABLE_MEMORY_PURGED : DISCARDABLE_MEMORY_SUCCESS;
+ return result == ASHMEM_WAS_PURGED ? DISCARDABLE_MEMORY_LOCK_STATUS_PURGED
+ : DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS;
}
bool UnlockAshmemRegion(int fd, size_t off, size_t size, const void* address) {
@@ -122,14 +122,37 @@ bool UnlockAshmemRegion(int fd, size_t off, size_t size, const void* address) {
} // namespace internal
// static
-bool DiscardableMemory::SupportedNatively() {
- return true;
+void DiscardableMemory::GetSupportedTypes(
+ std::vector<DiscardableMemoryType>* types) {
+ const DiscardableMemoryType supported_types[] = {
+ DISCARDABLE_MEMORY_TYPE_ANDROID,
+ DISCARDABLE_MEMORY_TYPE_EMULATED
+ };
+ types->assign(supported_types, supported_types + arraysize(supported_types));
}
// static
-scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemory(
- size_t size) {
- return g_context.Pointer()->allocator.Allocate(size);
+scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType(
+ DiscardableMemoryType type, size_t size) {
+ switch (type) {
+ case DISCARDABLE_MEMORY_TYPE_NONE:
+ case DISCARDABLE_MEMORY_TYPE_MAC:
+ return scoped_ptr<DiscardableMemory>();
+ case DISCARDABLE_MEMORY_TYPE_ANDROID: {
+ return g_context.Pointer()->allocator.Allocate(size);
+ }
+ case DISCARDABLE_MEMORY_TYPE_EMULATED: {
+ scoped_ptr<internal::DiscardableMemoryEmulated> memory(
+ new internal::DiscardableMemoryEmulated(size));
+ if (!memory->Initialize())
+ return scoped_ptr<DiscardableMemory>();
+
+ return memory.PassAs<DiscardableMemory>();
+ }
+ }
+
+ NOTREACHED();
+ return scoped_ptr<DiscardableMemory>();
}
// static
« no previous file with comments | « base/memory/discardable_memory_android.h ('k') | base/memory/discardable_memory_emulated.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698