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/callback.h" | |
12 #include "base/files/file_path.h" | |
13 #include "base/hash_tables.h" | |
14 #include "base/logging.h" | |
Philippe
2013/04/15 13:57:57
ref_counted.h is missing.
felipeg
2013/04/15 14:39:07
Done.
| |
15 #include "base/pickle.h" | |
16 #include "net/disk_cache/simple/simple_index.h" | |
17 | |
18 namespace base { | |
19 class TaskRunner; | |
20 } | |
21 | |
22 namespace disk_cache { | |
23 | |
24 const uint64 kSimpleIndexInitialMagicNumber = GG_UINT64_C(0x656e74657220796f); | |
25 | |
26 // Simple Index File format is a pickle serialized data of IndexMetadata and | |
pasko-google - do not use
2013/04/15 14:23:55
makes sense to expand this a little:
The file form
felipeg
2013/04/15 15:37:04
Done.
| |
27 // EntryMetadata objects. To know more about the pickle format, see | |
pasko-google - do not use
2013/04/15 14:23:55
there is no need to reference what a pickled forma
felipeg
2013/04/15 15:37:04
Done.
| |
28 // SimpleIndexFile::Serialize() and SeeSimpleIndexFile::LoadFromDisk() methods. | |
29 class SimpleIndexFile { | |
30 public: | |
31 class IndexMetadata { | |
32 public: | |
33 IndexMetadata(); | |
34 IndexMetadata(uint64 number_of_entries, uint64 cache_size); | |
35 | |
36 void Serialize(Pickle* pickle) const; | |
37 static bool DeSerialize(PickleIterator* it, | |
38 IndexMetadata* out); | |
Philippe
2013/04/15 13:57:57
Nit: I believe this fits on the line above.
felipeg
2013/04/15 14:39:07
Done.
| |
39 | |
40 bool CheckIndexMetadata(); | |
41 | |
42 uint64 GetNumberOfEntries() { return number_of_entries_; } | |
43 | |
44 private: | |
45 uint64 initial_magic_number_; | |
46 uint32 version_; | |
Philippe
2013/04/15 13:57:57
FWIW, I believe you might be able to save 32 bits
felipeg
2013/04/15 14:39:07
early optimization
| |
47 uint64 number_of_entries_; | |
48 uint64 cache_size_; // Total cache storage size in bytes. | |
49 }; | |
50 | |
51 static void LoadFromDisk( | |
52 const base::FilePath& index_filename, | |
53 const scoped_refptr<base::TaskRunner>& callback_runner, | |
54 const IndexCompletionCallback& completion_callback); | |
55 | |
56 // Enumerates all entries' files on disk and regenerates the index. | |
57 static void RestoreFromDisk( | |
pasko-google - do not use
2013/04/15 14:23:55
why is this in SimpleIndexFile? Logically it belon
felipeg
2013/04/15 15:37:04
Done.
| |
58 const base::FilePath& index_filename, | |
59 const scoped_refptr<base::TaskRunner>& callback_runner, | |
60 const IndexCompletionCallback& completion_callback); | |
61 | |
62 // Returns a scoped_ptr for a newly allocated Pickle containing the serialized | |
63 // data to be written to a file. | |
64 static scoped_ptr<Pickle> Serialize( | |
65 const SimpleIndexFile::IndexMetadata& index_metadata, | |
66 const EntrySet& entries); | |
67 | |
68 // Write the serialized data from |pickle| into the index file. | |
69 static void WriteToDisk(const base::FilePath& index_filename, | |
70 scoped_ptr<Pickle> pickle); | |
71 | |
72 private: | |
73 struct PickleHeader : public Pickle::Header { | |
74 uint32 crc; | |
75 }; | |
76 | |
77 static uint32 CalculatePickleCRC(const Pickle& pickle); | |
78 | |
79 SimpleIndexFile() {} | |
80 ~SimpleIndexFile() {} | |
81 }; | |
82 | |
83 | |
84 } // namespace disk_cache | |
85 | |
86 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ | |
OLD | NEW |