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

Side by Side 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: egors 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/files/file_path.h"
12 #include "base/hash_tables.h"
13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.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. The file format is as follows: one instance of
28 // serialized |IndexMetadata| followed serialized |EntryMetadata| entries
29 // repeated |number_of_entries| amount of times. To know more about the format,
30 // see SimpleIndexFile::Serialize() and SeeSimpleIndexFile::LoadFromDisk()
31 // methods.
32 class SimpleIndexFile {
33 public:
34 class IndexMetadata {
35 public:
36 IndexMetadata();
37 IndexMetadata(uint64 number_of_entries, uint64 cache_size);
38
39 void Serialize(Pickle* pickle) const;
40 bool DeSerialize(PickleIterator* it);
41
42 bool CheckIndexMetadata();
43
44 uint64 GetNumberOfEntries() { return number_of_entries_; }
45
46 private:
47 uint64 initial_magic_number_;
48 uint32 version_;
49 uint64 number_of_entries_;
50 uint64 cache_size_; // Total cache storage size in bytes.
51 };
52
53 static scoped_ptr<EntrySet> LoadFromDisk(
54 const base::FilePath& index_filename);
55
56 // Returns a scoped_ptr for a newly allocated Pickle containing the serialized
57 // data to be written to a file.
58 static scoped_ptr<Pickle> Serialize(
59 const SimpleIndexFile::IndexMetadata& index_metadata,
60 const EntrySet& entries);
61
62 // Write the serialized data from |pickle| into the index file.
63 static void WriteToDisk(const base::FilePath& index_filename,
64 const Pickle& pickle);
65
66 private:
67 struct PickleHeader : public Pickle::Header {
68 uint32 crc;
69 };
70
71 DISALLOW_COPY_AND_ASSIGN(SimpleIndexFile);
72 };
73
74
75 } // namespace disk_cache
76
77 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698