OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "net/disk_cache/disk_cache.h" | 10 #include "net/disk_cache/disk_cache.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 section_ = CreateFileMapping(platform_file(), NULL, PAGE_READWRITE, 0, | 21 section_ = CreateFileMapping(platform_file(), NULL, PAGE_READWRITE, 0, |
22 static_cast<DWORD>(size), NULL); | 22 static_cast<DWORD>(size), NULL); |
23 if (!section_) | 23 if (!section_) |
24 return NULL; | 24 return NULL; |
25 | 25 |
26 buffer_ = MapViewOfFile(section_, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, size); | 26 buffer_ = MapViewOfFile(section_, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, size); |
27 DCHECK(buffer_); | 27 DCHECK(buffer_); |
28 view_size_ = size; | 28 view_size_ = size; |
29 | 29 |
30 // Make sure we detect hardware failures reading the headers. | 30 // Make sure we detect hardware failures reading the headers. |
31 size_t temp_len = size ? size : 4096; | 31 /*size_t temp_len = size ? size : 4096; |
32 scoped_ptr<char[]> temp(new char[temp_len]); | 32 scoped_ptr<char[]> temp(new char[temp_len]); |
33 if (!Read(temp.get(), temp_len, 0)) | 33 if (!Read(temp.get(), temp_len, 0)) |
34 return NULL; | 34 return NULL;*/ |
35 | 35 |
36 return buffer_; | 36 return buffer_; |
37 } | 37 } |
38 | 38 |
| 39 bool MappedFile::InitNoMap(const base::FilePath& name) { |
| 40 DCHECK(!init_); |
| 41 if (init_ || !File::Init(name)) |
| 42 return false; |
| 43 |
| 44 buffer_ = NULL; |
| 45 section_ = NULL; |
| 46 view_size_ = 0; |
| 47 init_ = true; |
| 48 return true; |
| 49 } |
| 50 |
39 MappedFile::~MappedFile() { | 51 MappedFile::~MappedFile() { |
40 if (!init_) | 52 if (!init_) |
41 return; | 53 return; |
42 | 54 |
43 if (buffer_) { | 55 if (buffer_) { |
44 BOOL ret = UnmapViewOfFile(buffer_); | 56 BOOL ret = UnmapViewOfFile(buffer_); |
45 DCHECK(ret); | 57 DCHECK(ret); |
46 } | 58 } |
47 | 59 |
48 if (section_) | 60 if (section_) |
49 CloseHandle(section_); | 61 CloseHandle(section_); |
50 } | 62 } |
51 | 63 |
52 bool MappedFile::Load(const FileBlock* block) { | 64 bool MappedFile::Load(const FileBlock* block) { |
53 size_t offset = block->offset() + view_size_; | 65 size_t offset = block->offset() + view_size_; |
54 return Read(block->buffer(), block->size(), offset); | 66 return Read(block->buffer(), block->size(), offset); |
55 } | 67 } |
56 | 68 |
57 bool MappedFile::Store(const FileBlock* block) { | 69 bool MappedFile::Store(const FileBlock* block) { |
58 size_t offset = block->offset() + view_size_; | 70 size_t offset = block->offset() + view_size_; |
59 return Write(block->buffer(), block->size(), offset); | 71 return Write(block->buffer(), block->size(), offset); |
60 } | 72 } |
61 | 73 |
| 74 bool MappedFile::Load(const FileBlock* block, |
| 75 FileIOCallback* callback, |
| 76 bool* completed) { |
| 77 size_t offset = block->offset() + view_size_; |
| 78 return Read(block->buffer(), block->size(), offset, callback, completed); |
| 79 } |
| 80 |
| 81 bool MappedFile::Store(const FileBlock* block, |
| 82 FileIOCallback* callback, |
| 83 bool* completed) { |
| 84 size_t offset = block->offset() + view_size_; |
| 85 return Write(block->buffer(), block->size(), offset, callback, completed); |
| 86 } |
| 87 |
62 void MappedFile::Flush() { | 88 void MappedFile::Flush() { |
63 } | 89 } |
64 | 90 |
65 } // namespace disk_cache | 91 } // namespace disk_cache |
OLD | NEW |