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

Side by Side Diff: net/disk_cache/simple/simple_disk_format.h

Issue 13839011: Asynchronous initialization in Simple Index. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_DISK_FORMAT_H_ 5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_DISK_FORMAT_H_
6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_DISK_FORMAT_H_ 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_DISK_FORMAT_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 // ------------------------- 52 // -------------------------
53 namespace SimpleIndexFile { 53 namespace SimpleIndexFile {
54 // Simple Index File metadata is defined here. 54 // Simple Index File metadata is defined here.
55 struct Header { 55 struct Header {
56 uint64 initial_magic_number; 56 uint64 initial_magic_number;
57 uint32 version; 57 uint32 version;
58 uint64 number_of_entries; 58 uint64 number_of_entries;
59 uint64 cache_size; // Total cache storage size in bytes. 59 uint64 cache_size; // Total cache storage size in bytes.
60 }; 60 };
61 61
62 // TODO(felipeg): At some point we should consider using a protobuffer. See
63 // that we are re-implementing most of protobuffer's functionality such as
64 // Serialize and Merge.
62 // We must keep this struct a POD. 65 // We must keep this struct a POD.
63 struct EntryMetadata { 66 struct EntryMetadata {
64 EntryMetadata(); 67 EntryMetadata();
65 EntryMetadata(const std::string& hash_key_p, 68 EntryMetadata(const std::string& hash_key_p,
66 base::Time last_used_time_p, 69 base::Time last_used_time_p,
67 uint64 entry_size_p); 70 uint64 entry_size_p);
68 71
69 base::Time GetLastUsedTime() const; 72 base::Time GetLastUsedTime() const;
70 std::string GetHashKey() const; 73 std::string GetHashKey() const;
71 void SetLastUsedTime(const base::Time& last_used_time_p); 74 void SetLastUsedTime(const base::Time& last_used_time_p);
72 75
76 // Serialize the data from |in_entry_metadata| and appends the bytes in
77 // |out_buffer|. The serialization is platform dependent since it simply
78 // writes the whole struct from memory into the given buffer.
73 static void Serialize(const EntryMetadata& in_entry_metadata, 79 static void Serialize(const EntryMetadata& in_entry_metadata,
74 std::string* out_buffer); 80 std::string* out_buffer);
75 81
76 static void DeSerialize(const char* in_buffer, 82 static void DeSerialize(const char* in_buffer,
77 EntryMetadata* out_entry_metadata); 83 EntryMetadata* out_entry_metadata);
78 84
85 // Merge two EntryMetadata instances.
86 // The existing valid data in |out_entry_metadata| will prevail.
87 static void Merge(const EntryMetadata& entry_metadata,
88 EntryMetadata* out_entry_metadata);
89
79 char hash_key[kEntryHashKeySize]; // Not a c_string, not null terminated. 90 char hash_key[kEntryHashKeySize]; // Not a c_string, not null terminated.
80 91
81 // This is the serialized format from Time::ToInternalValue(). 92 // This is the serialized format from Time::ToInternalValue().
82 // If you want to make calculations/comparisons, you should use the 93 // If you want to make calculations/comparisons, you should use the
83 // base::Time() class. Use the GetLastUsedTime() method above. 94 // base::Time() class. Use the GetLastUsedTime() method above.
84 int64 last_used_time; 95 int64 last_used_time;
85 96
86 uint64 entry_size; // Storage size in bytes. 97 uint64 entry_size; // Storage size in bytes.
87 }; 98 };
88 99
89 const size_t kEntryMetadataSize = sizeof(EntryMetadata); 100 const size_t kEntryMetadataSize = sizeof(EntryMetadata);
90 101
91 struct Footer { 102 struct Footer {
92 uint32 crc; 103 uint32 crc;
93 }; 104 };
94 105
95 } // namespace SimpleIndexFile 106 } // namespace SimpleIndexFile
96 107
97 } // namespace disk_cache 108 } // namespace disk_cache
98 109
99 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_DISK_FORMAT_H_ 110 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_DISK_FORMAT_H_
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_backend_impl.cc ('k') | net/disk_cache/simple/simple_disk_format.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698