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

Unified Diff: base/shared_memory_posix.cc

Issue 7184032: Upstream android file related code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 9 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
Index: base/shared_memory_posix.cc
diff --git a/base/shared_memory_posix.cc b/base/shared_memory_posix.cc
index 7a238ed880b12a641b7461fc01285b7d169d9cc2..37bb89a3bb806639c6f0a1aa7df4474bdb855aa8 100644
--- a/base/shared_memory_posix.cc
+++ b/base/shared_memory_posix.cc
@@ -21,13 +21,19 @@
#include "base/mac/foundation_util.h"
#endif // OS_MACOSX
+#if defined(OS_ANDROID)
+#include "base/os_compat_android.h"
+#endif // defined(OS_ANDROID)
+
namespace base {
namespace {
+
// Paranoia. Semaphores and shared memory segments should live in different
// namespaces, but who knows what's out there.
const char kSemaphoreSuffix[] = "-sem";
-}
+
+} // namespace.
darin (slow to review) 2011/06/21 18:44:02 nit: no trailing comment
michaelbai 2011/06/21 20:17:31 Done.
SharedMemory::SharedMemory()
: mapped_file_(-1),
@@ -95,6 +101,7 @@ bool SharedMemory::CreateAnonymous(uint32 size) {
return CreateNamed("", false, size);
}
+#if !defined(OS_ANDROID)
// Chromium mostly only uses the unique/private shmem as specified by
// "name == L"". The exception is in the StatsTable.
// TODO(jrg): there is no way to "clean up" all unused named shmem if
@@ -201,10 +208,28 @@ bool SharedMemory::Open(const std::string& name, bool read_only) {
return PrepareMapFile(fp);
}
+#endif // !defined(OS_ANDROID)
+
bool SharedMemory::Map(uint32 bytes) {
if (mapped_file_ == -1)
return false;
+#if defined(OS_ANDROID)
+ if (bytes == 0) {
+ int ashmem_bytes = GetAshmenSizeRegion();
+ if (ashmem_bytes < 0)
+ return false;
+
+ DCHECK_GE((uint32)ashmem_bytes, bytes);
+ // The caller wants to determine the map region size from ashmem.
+ bytes = ashmem_bytes;
+ // TODO(port): we set the created size here so that it is available in
+ // transport_dib_android.cc. We should use
+ // SharedMemory::GetAshmenSizeRegion() in TransportDIB::Map().
+ created_size_ = bytes;
+ }
+#endif
+
memory_ = mmap(NULL, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE),
MAP_SHARED, mapped_file_, 0);
@@ -248,6 +273,7 @@ void SharedMemory::Unlock() {
LockOrUnlockCommon(F_ULOCK);
}
+#if !defined(OS_ANDROID)
bool SharedMemory::PrepareMapFile(FILE *fp) {
DCHECK_EQ(-1, mapped_file_);
if (fp == NULL) return false;
@@ -276,6 +302,7 @@ bool SharedMemory::PrepareMapFile(FILE *fp) {
return true;
}
+#endif
// For the given shmem named |mem_name|, return a filename to mmap()
// (and possibly create). Modifies |filename|. Return false on

Powered by Google App Engine
This is Rietveld 408576698