Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ | |
| 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/files/file_path.h" | |
| 12 #include "base/gtest_prod_util.h" | |
| 13 #include "base/hash_tables.h" | |
| 14 #include "base/logging.h" | |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "base/pickle.h" | |
| 17 #include "base/port.h" | |
| 18 #include "net/base/net_export.h" | |
| 19 #include "net/disk_cache/simple/simple_index.h" | |
| 20 | |
| 21 namespace base { | |
| 22 class TaskRunner; | |
| 23 } | |
| 24 | |
| 25 namespace disk_cache { | |
| 26 | |
| 27 const uint64 kSimpleIndexMagicNumber = GG_UINT64_C(0x656e74657220796f); | |
| 28 | |
| 29 // Simple Index File format is a pickle serialized data of IndexMetadata and | |
| 30 // EntryMetadata objects. The file format is as follows: one instance of | |
| 31 // serialized |IndexMetadata| followed serialized |EntryMetadata| entries | |
| 32 // repeated |number_of_entries| amount of times. To know more about the format, | |
| 33 // see SimpleIndexFile::Serialize() and SeeSimpleIndexFile::LoadFromDisk() | |
| 34 // methods. | |
| 35 class NET_EXPORT_PRIVATE SimpleIndexFile { | |
| 36 public: | |
| 37 class NET_EXPORT_PRIVATE IndexMetadata { | |
| 38 public: | |
| 39 IndexMetadata(); | |
| 40 IndexMetadata(uint64 number_of_entries, uint64 cache_size); | |
| 41 | |
| 42 void Serialize(Pickle* pickle) const; | |
| 43 bool Deserialize(PickleIterator* it); | |
| 44 | |
| 45 bool CheckIndexMetadata(); | |
| 46 | |
| 47 uint64 GetNumberOfEntries() { return number_of_entries_; } | |
| 48 | |
| 49 private: | |
| 50 FRIEND_TEST_ALL_PREFIXES(IndexMetadataTest, Basics); | |
| 51 FRIEND_TEST_ALL_PREFIXES(IndexMetadataTest, Serialize); | |
| 52 | |
| 53 uint64 magic_number_; | |
| 54 uint32 version_; | |
| 55 uint64 number_of_entries_; | |
| 56 uint64 cache_size_; // Total cache storage size in bytes. | |
| 57 }; | |
| 58 | |
| 59 // Load the index file from disk, deserializing it and returning the | |
| 60 // corresponding EntrySet in a scoped_ptr<>, if successful. | |
| 61 // Uppon failure, the scoped_ptr<> will contain NULL. | |
| 62 static scoped_ptr<SimpleIndex::EntrySet> LoadFromDisk( | |
| 63 const base::FilePath& index_filename); | |
| 64 | |
| 65 // Returns a scoped_ptr for a newly allocated Pickle containing the serialized | |
| 66 // data to be written to a file. | |
| 67 static scoped_ptr<Pickle> Serialize( | |
| 68 const SimpleIndexFile::IndexMetadata& index_metadata, | |
| 69 const SimpleIndex::EntrySet& entries); | |
| 70 | |
| 71 // Write the serialized data from |pickle| into the index file. | |
| 72 static void WriteToDisk(const base::FilePath& index_filename, | |
| 73 const Pickle& pickle); | |
| 74 | |
| 75 private: | |
| 76 FRIEND_TEST_ALL_PREFIXES(SimpleIndexFileTest, Serialize); | |
| 77 | |
| 78 // Deserialize() is separate from LoadFromDisk() for easier testing. | |
| 79 static scoped_ptr<SimpleIndex::EntrySet> Deserialize(const char* data, | |
| 80 int data_len); | |
| 81 | |
| 82 struct PickleHeader : public Pickle::Header { | |
| 83 uint32 crc; | |
| 84 }; | |
| 85 | |
| 86 DISALLOW_COPY_AND_ASSIGN(SimpleIndexFile); | |
| 87 }; | |
| 88 | |
| 89 | |
|
Philippe
2013/04/16 11:58:47
Nit: extra blank line.
| |
| 90 } // namespace disk_cache | |
| 91 | |
| 92 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ | |
| OLD | NEW |