Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Unified Diff: net/disk_cache/simple/simple_index_file.h

Issue 14263005: Refactor our SimpleIndex file format and serialization to use Pickle instead of the previously bugg… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Philippe's comments Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..1ad9c376b0515122f82492994148da9dede20122
--- /dev/null
+++ b/net/disk_cache/simple/simple_index_file.h
@@ -0,0 +1,83 @@
+// 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/memory/ref_counted.h"
+#include "base/pickle.h"
gavinp 2013/04/15 15:40:54 Missing base/port.h. Need base/memory/scoped_ptr.
felipeg 2013/04/15 15:56:09 Done.
+#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;
+ bool DeSerialize(PickleIterator* it);
+
+ bool CheckIndexMetadata();
+
+ uint64 GetNumberOfEntries() { return number_of_entries_; }
+
+ private:
+ uint64 initial_magic_number_;
gavinp 2013/04/15 15:40:54 This may not be "initial" any more.
felipeg 2013/04/15 15:56:09 Done.
+ 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);
+
+ 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_

Powered by Google App Engine
This is Rietveld 408576698