Chromium Code Reviews| 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" | |
| 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 | |
| 27 // EntryMetadata objects. To know more about the pickle format, see | |
| 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); | |
| 39 | |
| 40 bool CheckIndexMetadata(); | |
| 41 | |
| 42 uint64 GetNumberOfEntries() { return number_of_entries_; } | |
| 43 | |
| 44 private: | |
| 45 uint64 initial_magic_number_; | |
| 46 uint32 version_; | |
| 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( | |
| 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); | |
|
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.
| |
| 71 | |
| 72 private: | |
| 73 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
| |
| 74 uint32 crc; | |
| 75 }; | |
| 76 | |
| 77 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.
| |
| 78 | |
| 79 SimpleIndexFile() {} | |
|
Philippe
2013/04/15 13:57:57
I would replace this constructor and destructor wi
felipeg
2013/04/15 14:39:07
Done.
| |
| 80 ~SimpleIndexFile() {} | |
| 81 }; | |
| 82 | |
|
Philippe
2013/04/15 13:57:57
Nit: extra blank line.
felipeg
2013/04/15 14:39:07
Done.
| |
| 83 | |
| 84 } // namespace disk_cache | |
| 85 | |
| 86 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ | |
| OLD | NEW |