diff options
author | Patrick Scott <phanna@android.com> | 2010-02-04 10:37:17 -0500 |
---|---|---|
committer | Patrick Scott <phanna@android.com> | 2010-02-04 10:39:42 -0500 |
commit | c7f5f8508d98d5952d42ed7648c2a8f30a4da156 (patch) | |
tree | dd51dbfbf6670daa61279b3a19e7b1835b301dbf /net/disk_cache/mapped_file_posix.cc | |
parent | 139d8152182f9093f03d9089822b688e49fa7667 (diff) | |
download | chromium-c7f5f8508d98d5952d42ed7648c2a8f30a4da156.tar.gz |
Initial source checkin.
The source files were determined by building net_unittests in chromium's source
tree. Some of the obvious libraries were left out (v8, gmock, gtest).
The Android.mk file has all the sources (minus unittests and tools) that were
used during net_unittests compilation. Nothing builds yet because of STL but
that is the next task. The .cpp files will most likely not compile anyways
because of the LOCAL_CPP_EXTENSION mod. I will have to break this into multiple
projects to get around that limitation.
Diffstat (limited to 'net/disk_cache/mapped_file_posix.cc')
-rw-r--r-- | net/disk_cache/mapped_file_posix.cc | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/net/disk_cache/mapped_file_posix.cc b/net/disk_cache/mapped_file_posix.cc new file mode 100644 index 00000000..f9a361b7 --- /dev/null +++ b/net/disk_cache/mapped_file_posix.cc @@ -0,0 +1,55 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/disk_cache/mapped_file.h" + +#include <errno.h> +#include <sys/mman.h> + +#include "base/file_path.h" +#include "base/logging.h" +#include "net/disk_cache/disk_cache.h" + +namespace disk_cache { + +void* MappedFile::Init(const FilePath& name, size_t size) { + DCHECK(!init_); + if (init_ || !File::Init(name)) + return NULL; + + if (!size) + size = GetLength(); + + buffer_ = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, + platform_file(), 0); + init_ = true; + DCHECK(reinterpret_cast<intptr_t>(buffer_) != -1); + if (reinterpret_cast<intptr_t>(buffer_) == -1) + buffer_ = 0; + + view_size_ = size; + return buffer_; +} + +MappedFile::~MappedFile() { + if (!init_) + return; + + if (buffer_) { + int ret = munmap(buffer_, view_size_); + DCHECK(0 == ret); + } +} + +bool MappedFile::Load(const FileBlock* block) { + size_t offset = block->offset() + view_size_; + return Read(block->buffer(), block->size(), offset); +} + +bool MappedFile::Store(const FileBlock* block) { + size_t offset = block->offset() + view_size_; + return Write(block->buffer(), block->size(), offset); +} + +} // namespace disk_cache |