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

Unified Diff: base/memory/discardable_shared_memory.cc

Issue 1146103002: content: Close in-process discardable memory segments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix comment typo Created 5 years, 7 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_shared_memory.h ('k') | base/memory/discardable_shared_memory_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/discardable_shared_memory.cc
diff --git a/base/memory/discardable_shared_memory.cc b/base/memory/discardable_shared_memory.cc
index 830d6b9d87fdde5438b2d1255c6dc07b62aabf93..f8248e942cbc69aa48a4ad32e073e746c5dac3c0 100644
--- a/base/memory/discardable_shared_memory.cc
+++ b/base/memory/discardable_shared_memory.cc
@@ -157,6 +157,14 @@ bool DiscardableSharedMemory::Map(size_t size) {
return true;
}
+bool DiscardableSharedMemory::Unmap() {
+ if (!shared_memory_.Unmap())
+ return false;
+
+ mapped_size_ = 0;
+ return true;
+}
+
DiscardableSharedMemory::LockResult DiscardableSharedMemory::Lock(
size_t offset, size_t length) {
DCHECK_EQ(AlignToPageSize(offset), offset);
@@ -212,10 +220,11 @@ DiscardableSharedMemory::LockResult DiscardableSharedMemory::Lock(
#if defined(OS_ANDROID)
SharedMemoryHandle handle = shared_memory_.handle();
- DCHECK(SharedMemory::IsHandleValid(handle));
- if (ashmem_pin_region(
- handle.fd, AlignToPageSize(sizeof(SharedState)) + offset, length)) {
- return PURGED;
+ if (SharedMemory::IsHandleValid(handle)) {
+ if (ashmem_pin_region(
+ handle.fd, AlignToPageSize(sizeof(SharedState)) + offset, length)) {
+ return PURGED;
+ }
}
#endif
@@ -237,10 +246,11 @@ void DiscardableSharedMemory::Unlock(size_t offset, size_t length) {
#if defined(OS_ANDROID)
SharedMemoryHandle handle = shared_memory_.handle();
- DCHECK(SharedMemory::IsHandleValid(handle));
- if (ashmem_unpin_region(
- handle.fd, AlignToPageSize(sizeof(SharedState)) + offset, length)) {
- DPLOG(ERROR) << "ashmem_unpin_region() failed";
+ if (SharedMemory::IsHandleValid(handle)) {
+ if (ashmem_unpin_region(
+ handle.fd, AlignToPageSize(sizeof(SharedState)) + offset, length)) {
+ DPLOG(ERROR) << "ashmem_unpin_region() failed";
+ }
}
#endif
@@ -336,9 +346,7 @@ bool DiscardableSharedMemory::IsMemoryResident() const {
}
void DiscardableSharedMemory::Close() {
- shared_memory_.Unmap();
shared_memory_.Close();
- mapped_size_ = 0;
}
#if defined(DISCARDABLE_SHARED_MEMORY_SHRINKING)
« no previous file with comments | « base/memory/discardable_shared_memory.h ('k') | base/memory/discardable_shared_memory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698