Index: net/disk_cache/simple/simple_index_file.h |
diff --git a/net/disk_cache/simple/simple_index_file.h b/net/disk_cache/simple/simple_index_file.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..27fad7f5b8df9c97efe99fc70fad2d6ebc89991d |
--- /dev/null |
+++ b/net/disk_cache/simple/simple_index_file.h |
@@ -0,0 +1,77 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ |
+#define NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ |
+ |
+#include <string> |
+ |
+#include "base/basictypes.h" |
+#include "base/files/file_path.h" |
+#include "base/hash_tables.h" |
+#include "base/logging.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/pickle.h" |
+#include "net/disk_cache/simple/simple_index.h" |
+ |
+namespace base { |
+class TaskRunner; |
+} |
+ |
+namespace disk_cache { |
+ |
+const uint64 kSimpleIndexInitialMagicNumber = GG_UINT64_C(0x656e74657220796f); |
+ |
+// Simple Index File format is a pickle serialized data of IndexMetadata and |
+// EntryMetadata objects. The file format is as follows: one instance of |
+// serialized |IndexMetadata| followed serialized |EntryMetadata| entries |
+// repeated |number_of_entries| amount of times. To know more about the format, |
+// see SimpleIndexFile::Serialize() and SeeSimpleIndexFile::LoadFromDisk() |
+// methods. |
+class SimpleIndexFile { |
+ public: |
+ class IndexMetadata { |
+ public: |
+ IndexMetadata(); |
+ IndexMetadata(uint64 number_of_entries, uint64 cache_size); |
+ |
+ void Serialize(Pickle* pickle) const; |
+ bool DeSerialize(PickleIterator* it); |
+ |
+ bool CheckIndexMetadata(); |
+ |
+ uint64 GetNumberOfEntries() { return number_of_entries_; } |
+ |
+ private: |
+ uint64 initial_magic_number_; |
+ uint32 version_; |
+ uint64 number_of_entries_; |
+ uint64 cache_size_; // Total cache storage size in bytes. |
+ }; |
+ |
+ static scoped_ptr<EntrySet> LoadFromDisk( |
+ const base::FilePath& index_filename); |
+ |
+ // Returns a scoped_ptr for a newly allocated Pickle containing the serialized |
+ // data to be written to a file. |
+ static scoped_ptr<Pickle> Serialize( |
+ const SimpleIndexFile::IndexMetadata& index_metadata, |
+ const EntrySet& entries); |
+ |
+ // Write the serialized data from |pickle| into the index file. |
+ static void WriteToDisk(const base::FilePath& index_filename, |
+ const Pickle& pickle); |
+ |
+ private: |
+ struct PickleHeader : public Pickle::Header { |
+ uint32 crc; |
+ }; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SimpleIndexFile); |
+}; |
+ |
+ |
+} // namespace disk_cache |
+ |
+#endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ |