OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_path.h" | 7 #include "base/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 * 2; |
gavinp
2012/05/31 19:59:50
This is twice as good! Could we ever have a file
rvargas (doing something else)
2012/05/31 20:07:05
Nope, the header size is 8k.
| |
32 scoped_array<char> temp(new char[temp_len]); | 32 scoped_array<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 MappedFile::~MappedFile() { | 39 MappedFile::~MappedFile() { |
40 if (!init_) | 40 if (!init_) |
41 return; | 41 return; |
(...skipping 11 matching lines...) Expand all Loading... | |
53 size_t offset = block->offset() + view_size_; | 53 size_t offset = block->offset() + view_size_; |
54 return Read(block->buffer(), block->size(), offset); | 54 return Read(block->buffer(), block->size(), offset); |
55 } | 55 } |
56 | 56 |
57 bool MappedFile::Store(const FileBlock* block) { | 57 bool MappedFile::Store(const FileBlock* block) { |
58 size_t offset = block->offset() + view_size_; | 58 size_t offset = block->offset() + view_size_; |
59 return Write(block->buffer(), block->size(), offset); | 59 return Write(block->buffer(), block->size(), offset); |
60 } | 60 } |
61 | 61 |
62 } // namespace disk_cache | 62 } // namespace disk_cache |
OLD | NEW |