diff options
author | michaelbai@google.com <michaelbai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-21 22:34:50 +0000 |
---|---|---|
committer | michaelbai@google.com <michaelbai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-21 22:34:50 +0000 |
commit | f7d6997f6253e4c7645859757bc824c4164a9a7e (patch) | |
tree | 3183103533b527bb8b436aed5412b7bf00207e94 /base/shared_memory_posix.cc | |
parent | 559c4e3eee40f9f3a127ba792a2ef0bcd217b543 (diff) | |
download | chromium_src-f7d6997f6253e4c7645859757bc824c4164a9a7e.zip chromium_src-f7d6997f6253e4c7645859757bc824c4164a9a7e.tar.gz chromium_src-f7d6997f6253e4c7645859757bc824c4164a9a7e.tar.bz2 |
Upstream android file related code.
Implemented file related features
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/7184032
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89914 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/shared_memory_posix.cc')
-rw-r--r-- | base/shared_memory_posix.cc | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/base/shared_memory_posix.cc b/base/shared_memory_posix.cc index 7a238ed..1580487 100644 --- a/base/shared_memory_posix.cc +++ b/base/shared_memory_posix.cc @@ -21,12 +21,19 @@ #include "base/mac/foundation_util.h" #endif // OS_MACOSX +#if defined(OS_ANDROID) +#include "base/os_compat_android.h" +#include "third_party/ashmem/ashmem.h" +#endif + 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"; + } SharedMemory::SharedMemory() @@ -95,6 +102,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 +209,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 = ashmem_get_size_region(); + if (ashmem_bytes < 0) + return false; + + DCHECK_GE(static_cast<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 ashmem_get_size_region() + // in transport_dib_android.cc. + created_size_ = bytes; + } +#endif + memory_ = mmap(NULL, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE), MAP_SHARED, mapped_file_, 0); @@ -248,6 +274,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 +303,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 |