| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/disk_cache/mapped_file.h" | 5 #include "net/disk_cache/mapped_file.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <sys/mman.h> | 8 #include <sys/mman.h> |
| 9 | 9 |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 platform_file(), 0); | 25 platform_file(), 0); |
| 26 init_ = true; | 26 init_ = true; |
| 27 DCHECK(reinterpret_cast<intptr_t>(buffer_) != -1); | 27 DCHECK(reinterpret_cast<intptr_t>(buffer_) != -1); |
| 28 if (reinterpret_cast<intptr_t>(buffer_) == -1) | 28 if (reinterpret_cast<intptr_t>(buffer_) == -1) |
| 29 buffer_ = 0; | 29 buffer_ = 0; |
| 30 | 30 |
| 31 view_size_ = size; | 31 view_size_ = size; |
| 32 return buffer_; | 32 return buffer_; |
| 33 } | 33 } |
| 34 | 34 |
| 35 MappedFile::~MappedFile() { | |
| 36 if (!init_) | |
| 37 return; | |
| 38 | |
| 39 if (buffer_) { | |
| 40 int ret = munmap(buffer_, view_size_); | |
| 41 DCHECK(0 == ret); | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 bool MappedFile::Load(const FileBlock* block) { | 35 bool MappedFile::Load(const FileBlock* block) { |
| 46 size_t offset = block->offset() + view_size_; | 36 size_t offset = block->offset() + view_size_; |
| 47 return Read(block->buffer(), block->size(), offset); | 37 return Read(block->buffer(), block->size(), offset); |
| 48 } | 38 } |
| 49 | 39 |
| 50 bool MappedFile::Store(const FileBlock* block) { | 40 bool MappedFile::Store(const FileBlock* block) { |
| 51 size_t offset = block->offset() + view_size_; | 41 size_t offset = block->offset() + view_size_; |
| 52 return Write(block->buffer(), block->size(), offset); | 42 return Write(block->buffer(), block->size(), offset); |
| 53 } | 43 } |
| 54 | 44 |
| 45 MappedFile::~MappedFile() { |
| 46 if (!init_) |
| 47 return; |
| 48 |
| 49 if (buffer_) { |
| 50 int ret = munmap(buffer_, view_size_); |
| 51 DCHECK(0 == ret); |
| 52 } |
| 53 } |
| 54 |
| 55 } // namespace disk_cache | 55 } // namespace disk_cache |
| OLD | NEW |