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

Side by Side Diff: net/disk_cache/v3/index_table.h

Issue 15203004: Disk cache: Reference CL for the implementation of file format version 3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 6 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
« no previous file with comments | « net/disk_cache/v3/eviction_v3.cc ('k') | net/disk_cache/v3/index_table.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
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_V3_INDEX_TABLE_V3_H_
6 #define NET_DISK_CACHE_V3_INDEX_TABLE_V3_H_
7
8 #include <vector>
9
10
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/time.h"
14 #include "net/base/net_export.h"
15 #include "net/disk_cache/addr.h"
16 #include "net/disk_cache/bitmap.h"
17 #include "net/disk_cache/v3/disk_format_v3.h"
18
19 namespace base {
20 class FilePath;
21 }
22
23 namespace disk_cache {
24
25 class BackendImplV3;
26 struct InitResult;
27
28 class EntryCell {
29 public:
30 EntryCell();
31 EntryCell(int32 cell_id, uint32 hash, Addr address);
32 EntryCell(int32 cell_id, uint32 hash, const IndexCell& cell);
33 ~EntryCell();
34
35 int32 cell_id() const { return cell_id_; }
36 EntryState state() const { return static_cast<EntryState>(cell_.state); }
37 EntryGroup group() const { return static_cast<EntryGroup>(cell_.group); }
38 int reuse() const { return cell_.reuse; }
39 uint32 hash() const { return hash_; }
40 IndexCell cell() const { return cell_; }
41
42 Addr GetAddress() const;
43 int GetTimestamp() const;
44
45 void set_state(EntryState state) { cell_.state = state; }
46 void set_group(EntryGroup group) { cell_.group = group; }
47 void set_reuse(int count);
48 void set_timestamp(int timestamp);
49
50 static bool ValidAddress(Addr address);
51 static uint32 GetHash(const IndexCell& cell);
52 static int GetTimestamp(const IndexCell& cell);
53 static bool IsNormalState(const IndexCell& cell);
54
55 bool IsValid() const { return cell_.address != 0; }
56 void Clear() { cell_.Clear(); }
57 void FixSum();
58
59 private:
60 int32 cell_id_;
61 uint32 hash_;
62 IndexCell cell_;
63 };
64
65 struct EntrySet {
66 EntrySet();
67
68 int evicted_count;
69 size_t current;
70 std::vector<EntryCell> cells;
71 };
72
73 struct CellId { uint32 hash; Addr address; };
74 typedef std::vector<CellId> CellList;
75 struct IndexIterator {
76 CellList cells;
77 int timestamp;
78 bool forward;
79 };
80
81 class IndexTable {
82 public:
83 IndexTable(BackendImplV3* backend);
84
85 void Init(InitResult* params);
86 void Reset();
87
88 EntrySet LookupEntry(uint32 hash);
89 EntryCell CreateEntryCell(uint32 hash, Addr address);
90 bool SetSate(uint32 hash, Addr address, EntryState state);
91 bool SetGroup(uint32 hash, Addr address, EntryGroup group);
92 int GetTimestamp(base::Time time);
93 void UpdateTime(uint32 hash, Addr address);
94
95 EntryCell FindEntryCell(uint32 hash, Addr address);
96 void Save(EntryCell* cell);
97
98 void GetOldest(CellList* no_use, CellList* low_use, CellList* high_use);
99 bool GetNextCells(IndexIterator* iterator);
100
101 IndexHeaderV3* header() { return header_; }
102 const IndexHeaderV3* header() const { return header_; }
103
104 private:
105 EntryCell FindEntryCellImpl(uint32 hash, Addr address, bool allow_deleted);
106 void CheckState(IndexCell* cell, int32 cell_id);
107 void Write(const EntryCell& cell);
108 int NewExtraBucket();
109 void GetOldestFromBucket(IndexBucket* bucket, int bucket_hash,
110 CellList* no_use, int* no_use_time,
111 CellList* low_use, int* low_use_time,
112 CellList* high_use, int* high_use_time);
113 void MoveCells(IndexBucket* old_extra_table);
114 void MoveSingleCell(IndexCell* current_cell, int cell_id,
115 int main_table_index, bool growing);
116 void HandleMisplacedCell(IndexCell* current_cell, int cell_id,
117 int main_table_index);
118 void CheckBucketList(int bucket_id);
119
120 BackendImplV3* backend_;
121 IndexHeaderV3* header_;
122 scoped_ptr<Bitmap> bitmap_;
123 scoped_ptr<Bitmap> backup_bitmap_;
124 scoped_ptr<uint32[]> backup_bitmap_storage_;
125 scoped_ptr<IndexHeaderV3> backup_header_;
126 IndexBucket* main_table_;
127 IndexBucket* extra_table_;
128 uint32 mask_; // Binary mask to map a hash to the hash table.
129 int extra_bits_; // How many bits are in mask_ above the default value.
130
131 DISALLOW_COPY_AND_ASSIGN(IndexTable);
132 };
133
134 } // namespace disk_cache
135
136 #endif // NET_DISK_CACHE_V3_INDEX_TABLE_V3_H_
OLDNEW
« no previous file with comments | « net/disk_cache/v3/eviction_v3.cc ('k') | net/disk_cache/v3/index_table.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698