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..8b0de84bbe6ce6b9d1cc27a8835f131324d77939 |
--- /dev/null |
+++ b/net/disk_cache/simple/simple_index_file.h |
@@ -0,0 +1,86 @@ |
+// 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/callback.h" |
+#include "base/files/file_path.h" |
+#include "base/hash_tables.h" |
+#include "base/logging.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. To know more about the pickle 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; |
+ static bool DeSerialize(PickleIterator* it, |
+ IndexMetadata* out); |
+ |
+ 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 void LoadFromDisk( |
+ const base::FilePath& index_filename, |
+ const scoped_refptr<base::TaskRunner>& callback_runner, |
+ const IndexCompletionCallback& completion_callback); |
+ |
+ // Enumerates all entries' files on disk and regenerates the index. |
+ static void RestoreFromDisk( |
+ const base::FilePath& index_filename, |
+ const scoped_refptr<base::TaskRunner>& callback_runner, |
+ const IndexCompletionCallback& completion_callback); |
+ |
+ // 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, |
+ scoped_ptr<Pickle> pickle); |
Philippe
2013/04/15 13:57:57
It's not clear to me why this method is taking own
felipeg
2013/04/15 14:39:07
This is used in a callback.
Discussed offline.
|
+ |
+ private: |
+ struct PickleHeader : public Pickle::Header { |
Philippe
2013/04/15 13:57:57
Nit: I don't think you need to expose this in this
felipeg
2013/04/15 14:39:07
Yes, but I think it is more readable this way.
Pic
|
+ uint32 crc; |
+ }; |
+ |
+ static uint32 CalculatePickleCRC(const Pickle& pickle); |
Philippe
2013/04/15 13:57:57
Nit: I would move this to an anonymous namespace i
felipeg
2013/04/15 14:39:07
Done.
|
+ |
+ SimpleIndexFile() {} |
Philippe
2013/04/15 13:57:57
I would replace this constructor and destructor wi
felipeg
2013/04/15 14:39:07
Done.
|
+ ~SimpleIndexFile() {} |
+}; |
+ |
Philippe
2013/04/15 13:57:57
Nit: extra blank line.
felipeg
2013/04/15 14:39:07
Done.
|
+ |
+} // namespace disk_cache |
+ |
+#endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ |