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

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: 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 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/callback.h"
12 #include "base/files/file_path.h"
13 #include "base/hash_tables.h"
14 #include "base/logging.h"
15 #include "base/memory/ref_counted.h"
16 #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.
17 #include "net/disk_cache/simple/simple_index.h"
18
19 namespace base {
20 class TaskRunner;
21 }
22
23 namespace disk_cache {
24
25 const uint64 kSimpleIndexInitialMagicNumber = GG_UINT64_C(0x656e74657220796f);
26
27 // Simple Index File format is a pickle serialized data of IndexMetadata and
28 // EntryMetadata objects. To know more about the pickle format, see
29 // SimpleIndexFile::Serialize() and SeeSimpleIndexFile::LoadFromDisk() methods.
30 class SimpleIndexFile {
31 public:
32 class IndexMetadata {
33 public:
34 IndexMetadata();
35 IndexMetadata(uint64 number_of_entries, uint64 cache_size);
36
37 void Serialize(Pickle* pickle) const;
38 bool DeSerialize(PickleIterator* it);
39
40 bool CheckIndexMetadata();
41
42 uint64 GetNumberOfEntries() { return number_of_entries_; }
43
44 private:
45 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.
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);
71
72 private:
73 struct PickleHeader : public Pickle::Header {
74 uint32 crc;
75 };
76
77 DISALLOW_COPY_AND_ASSIGN(SimpleIndexFile);
78 };
79
80
81 } // namespace disk_cache
82
83 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698