Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: net/disk_cache/mapped_file_posix.cc

Issue 10454093: Disk cache: Pre-read file headers when opening files (posix). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/disk_cache/mapped_file_win.cc » ('j') | net/disk_cache/mapped_file_win.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "net/disk_cache/disk_cache.h" 12 #include "net/disk_cache/disk_cache.h"
13 13
14 namespace disk_cache { 14 namespace disk_cache {
15 15
16 void* MappedFile::Init(const FilePath& name, size_t size) { 16 void* MappedFile::Init(const FilePath& name, size_t size) {
17 DCHECK(!init_); 17 DCHECK(!init_);
18 if (init_ || !File::Init(name)) 18 if (init_ || !File::Init(name))
19 return NULL; 19 return NULL;
20 20
21 if (!size) 21 if (!size)
22 size = GetLength(); 22 size = GetLength();
gavinp 2012/05/31 20:51:32 Here's where size gets set. GetLength() returns z
23 23
24 buffer_ = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, 24 buffer_ = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,
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 // Make sure we detect hardware failures reading the headers.
32 size_t temp_len = size ? size : 4096 * 2;
gavinp 2012/05/31 19:59:50 Isn't it just an error if size is 0 here? How wou
rvargas (doing something else) 2012/05/31 20:07:05 Well... that's one of the details that I was hopin
gavinp 2012/05/31 20:50:34 If I missed a request to help earlier, I'm very so
33 scoped_array<char> temp(new char[temp_len]);
34 if (!Read(temp.get(), temp_len, 0))
35 return NULL;
36
31 view_size_ = size; 37 view_size_ = size;
32 return buffer_; 38 return buffer_;
33 } 39 }
34 40
35 bool MappedFile::Load(const FileBlock* block) { 41 bool MappedFile::Load(const FileBlock* block) {
36 size_t offset = block->offset() + view_size_; 42 size_t offset = block->offset() + view_size_;
37 return Read(block->buffer(), block->size(), offset); 43 return Read(block->buffer(), block->size(), offset);
38 } 44 }
39 45
40 bool MappedFile::Store(const FileBlock* block) { 46 bool MappedFile::Store(const FileBlock* block) {
41 size_t offset = block->offset() + view_size_; 47 size_t offset = block->offset() + view_size_;
42 return Write(block->buffer(), block->size(), offset); 48 return Write(block->buffer(), block->size(), offset);
43 } 49 }
44 50
45 MappedFile::~MappedFile() { 51 MappedFile::~MappedFile() {
46 if (!init_) 52 if (!init_)
47 return; 53 return;
48 54
49 if (buffer_) { 55 if (buffer_) {
50 int ret = munmap(buffer_, view_size_); 56 int ret = munmap(buffer_, view_size_);
51 DCHECK_EQ(0, ret); 57 DCHECK_EQ(0, ret);
52 } 58 }
53 } 59 }
54 60
55 } // namespace disk_cache 61 } // namespace disk_cache
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/mapped_file_win.cc » ('j') | net/disk_cache/mapped_file_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698