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/disk_cache/simple/simple_index.h" | |
19 | |
20 namespace base { | |
21 class TaskRunner; | |
22 } | |
23 | |
24 namespace disk_cache { | |
25 | |
26 const uint64 kSimpleIndexMagicNumber = GG_UINT64_C(0x656e74657220796f); | |
rvargas (doing something else)
2013/04/16 03:24:19
Now that we're here, can somebody tell me what's t
| |
27 | |
28 // Simple Index File format is a pickle serialized data of IndexMetadata and | |
rvargas (doing something else)
2013/04/16 03:24:19
I'm torn with this direction. Don't get me wrong,
| |
29 // EntryMetadata objects. The file format is as follows: one instance of | |
30 // serialized |IndexMetadata| followed serialized |EntryMetadata| entries | |
31 // repeated |number_of_entries| amount of times. To know more about the format, | |
32 // see SimpleIndexFile::Serialize() and SeeSimpleIndexFile::LoadFromDisk() | |
33 // methods. | |
34 class SimpleIndexFile { | |
35 public: | |
36 class IndexMetadata { | |
37 public: | |
38 IndexMetadata(); | |
39 IndexMetadata(uint64 number_of_entries, uint64 cache_size); | |
40 | |
41 void Serialize(Pickle* pickle) const; | |
42 bool Deserialize(PickleIterator* it); | |
43 | |
44 bool CheckIndexMetadata(); | |
45 | |
46 uint64 GetNumberOfEntries() { return number_of_entries_; } | |
47 | |
48 private: | |
49 FRIEND_TEST_ALL_PREFIXES(IndexMetadataTest, Basics); | |
50 FRIEND_TEST_ALL_PREFIXES(IndexMetadataTest, Serialize); | |
51 | |
52 uint64 magic_number_; | |
53 uint32 version_; | |
54 uint64 number_of_entries_; | |
55 uint64 cache_size_; // Total cache storage size in bytes. | |
56 }; | |
57 | |
58 // Load the index file from disk, deserializing it and returning the | |
59 // corresponding EntrySet in a scoped_ptr<>, if successful. | |
60 // Uppon failure, the scoped_ptr<> will contain NULL. | |
61 static scoped_ptr<SimpleIndex::EntrySet> LoadFromDisk( | |
62 const base::FilePath& index_filename); | |
63 | |
64 // Returns a scoped_ptr for a newly allocated Pickle containing the serialized | |
65 // data to be written to a file. | |
66 static scoped_ptr<Pickle> Serialize( | |
67 const SimpleIndexFile::IndexMetadata& index_metadata, | |
68 const SimpleIndex::EntrySet& entries); | |
69 | |
70 // Write the serialized data from |pickle| into the index file. | |
71 static void WriteToDisk(const base::FilePath& index_filename, | |
72 const Pickle& pickle); | |
73 | |
74 private: | |
75 FRIEND_TEST_ALL_PREFIXES(SimpleIndexFileTest, Serialize); | |
76 | |
77 // Deserialize() is separate from LoadFromDisk() for easier testing. | |
78 static scoped_ptr<SimpleIndex::EntrySet> Deserialize(const char* data, | |
79 int data_len); | |
80 | |
81 struct PickleHeader : public Pickle::Header { | |
82 uint32 crc; | |
83 }; | |
84 | |
85 DISALLOW_COPY_AND_ASSIGN(SimpleIndexFile); | |
86 }; | |
87 | |
88 | |
89 } // namespace disk_cache | |
90 | |
91 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ | |
OLD | NEW |