1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // See net/disk_cache/disk_cache.h for the public interface of the cache. 6 7 #ifndef NET_DISK_CACHE_MAPPED_FILE_H_ 8 #define NET_DISK_CACHE_MAPPED_FILE_H_ 9 #pragma once 10 11 #include "net/disk_cache/disk_format.h" 12 #include "net/disk_cache/file.h" 13 #include "net/disk_cache/file_block.h" 14 15 class FilePath; 16 17 namespace disk_cache { 18 19 // This class implements a memory mapped file used to access block-files. The 20 // idea is that the header and bitmap will be memory mapped all the time, and 21 // the actual data for the blocks will be access asynchronously (most of the 22 // time). 23 class MappedFile : public File { 24 public: 25 MappedFile() : File(true), init_(false) {} 26 27 // Performs object initialization. name is the file to use, and size is the 28 // ammount of data to memory map from th efile. If size is 0, the whole file 29 // will be mapped in memory. 30 void* Init(const FilePath& name, size_t size); 31 32 void* buffer() const { 33 return buffer_; 34 } 35 36 // Loads or stores a given block from the backing file (synchronously). 37 bool Load(const FileBlock* block); 38 bool Store(const FileBlock* block); 39 40 private: 41 virtual ~MappedFile(); 42 43 bool init_; 44 #if defined(OS_WIN) 45 HANDLE section_; 46 #endif 47 void* buffer_; // Address of the memory mapped buffer. 48 size_t view_size_; // Size of the memory pointed by buffer_. 49 50 DISALLOW_COPY_AND_ASSIGN(MappedFile); 51 }; 52 53 } // namespace disk_cache 54 55 #endif // NET_DISK_CACHE_MAPPED_FILE_H_ 56