Chromium Code Reviews| 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_ |