OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_VISITEDLINK_VISITEDLINK_MASTER_H_ | 5 #ifndef CHROME_BROWSER_VISITEDLINK_VISITEDLINK_MASTER_H_ |
6 #define CHROME_BROWSER_VISITEDLINK_VISITEDLINK_MASTER_H_ | 6 #define CHROME_BROWSER_VISITEDLINK_VISITEDLINK_MASTER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 rebuild_complete_task_ = task; | 110 rebuild_complete_task_ = task; |
111 } | 111 } |
112 | 112 |
113 // returns the number of items in the table for testing verification | 113 // returns the number of items in the table for testing verification |
114 int32 GetUsedCount() const { | 114 int32 GetUsedCount() const { |
115 return used_items_; | 115 return used_items_; |
116 } | 116 } |
117 | 117 |
118 // Call to cause the entire database file to be re-written from scratch | 118 // Call to cause the entire database file to be re-written from scratch |
119 // to disk. Used by the performance tester. | 119 // to disk. Used by the performance tester. |
120 bool RewriteFile() { | 120 void RewriteFile() { |
121 return WriteFullTable(); | 121 WriteFullTable(); |
122 } | 122 } |
123 #endif | 123 #endif |
124 | 124 |
125 private: | 125 private: |
126 FRIEND_TEST_ALL_PREFIXES(VisitedLinkTest, Delete); | 126 FRIEND_TEST_ALL_PREFIXES(VisitedLinkTest, Delete); |
127 FRIEND_TEST_ALL_PREFIXES(VisitedLinkTest, BigDelete); | 127 FRIEND_TEST_ALL_PREFIXES(VisitedLinkTest, BigDelete); |
128 FRIEND_TEST_ALL_PREFIXES(VisitedLinkTest, BigImport); | 128 FRIEND_TEST_ALL_PREFIXES(VisitedLinkTest, BigImport); |
129 | 129 |
130 // Object to rebuild the table on the history thread (see the .cc file). | 130 // Object to rebuild the table on the history thread (see the .cc file). |
131 class TableBuilder; | 131 class TableBuilder; |
132 | 132 |
133 typedef FILE* FilePtr; | |
brettw
2012/07/27 22:11:14
I think I prefer just seeing FILE** in the various
| |
134 | |
133 // Byte offsets of values in the header. | 135 // Byte offsets of values in the header. |
134 static const int32 kFileHeaderSignatureOffset; | 136 static const int32 kFileHeaderSignatureOffset; |
135 static const int32 kFileHeaderVersionOffset; | 137 static const int32 kFileHeaderVersionOffset; |
136 static const int32 kFileHeaderLengthOffset; | 138 static const int32 kFileHeaderLengthOffset; |
137 static const int32 kFileHeaderUsedOffset; | 139 static const int32 kFileHeaderUsedOffset; |
138 static const int32 kFileHeaderSaltOffset; | 140 static const int32 kFileHeaderSaltOffset; |
139 | 141 |
140 // The signature at the beginning of a file. | 142 // The signature at the beginning of a file. |
141 static const int32 kFileSignature; | 143 static const int32 kFileSignature; |
142 | 144 |
(...skipping 19 matching lines...) Expand all Loading... | |
162 // inserted fingerprint or null_hash_ on failure. | 164 // inserted fingerprint or null_hash_ on failure. |
163 Hash TryToAddURL(const GURL& url); | 165 Hash TryToAddURL(const GURL& url); |
164 | 166 |
165 // File I/O functions | 167 // File I/O functions |
166 // ------------------ | 168 // ------------------ |
167 | 169 |
168 // Posts the given task to the blocking worker pool with our options. | 170 // Posts the given task to the blocking worker pool with our options. |
169 void PostIOTask(const tracked_objects::Location& from_here, | 171 void PostIOTask(const tracked_objects::Location& from_here, |
170 const base::Closure& task); | 172 const base::Closure& task); |
171 | 173 |
172 // Writes the entire table to disk, returning true on success. It will leave | 174 // Writes the entire table to disk. It will leave the table file open and |
173 // the table file open and the handle to it in file_ | 175 // the handle to it will be stored in file_. |
174 bool WriteFullTable(); | 176 void WriteFullTable(); |
175 | 177 |
176 // Try to load the table from the database file. If the file doesn't exist or | 178 // Try to load the table from the database file. If the file doesn't exist or |
177 // is corrupt, this will return failure. | 179 // is corrupt, this will return failure. |
178 bool InitFromFile(); | 180 bool InitFromFile(); |
179 | 181 |
180 // Reads the header of the link coloring database from disk. Assumes the | 182 // Reads the header of the link coloring database from disk. Assumes the |
181 // file pointer is at the beginning of the file and that there are no pending | 183 // file pointer is at the beginning of the file and that there are no pending |
182 // asynchronous I/O operations. | 184 // asynchronous I/O operations. |
183 // | 185 // |
184 // Returns true on success and places the size of the table in num_entries | 186 // Returns true on success and places the size of the table in num_entries |
185 // and the number of nonzero fingerprints in used_count. This will fail if | 187 // and the number of nonzero fingerprints in used_count. This will fail if |
186 // the version of the file is not the current version of the database. | 188 // the version of the file is not the current version of the database. |
187 bool ReadFileHeader(FILE* hfile, int32* num_entries, int32* used_count, | 189 bool ReadFileHeader(FILE* hfile, int32* num_entries, int32* used_count, |
188 uint8 salt[LINK_SALT_LENGTH]); | 190 uint8 salt[LINK_SALT_LENGTH]); |
189 | 191 |
190 // Fills *filename with the name of the link database filename | 192 // Fills *filename with the name of the link database filename |
191 bool GetDatabaseFileName(FilePath* filename); | 193 bool GetDatabaseFileName(FilePath* filename); |
192 | 194 |
193 // Wrapper around Window's WriteFile using asynchronous I/O. This will proxy | 195 // Wrapper around Window's WriteFile using asynchronous I/O. This will proxy |
194 // the write to a background thread. | 196 // the write to a background thread. |
195 void WriteToFile(FILE* hfile, off_t offset, void* data, int32 data_size); | 197 void WriteToFile(FilePtr* hfile, off_t offset, void* data, int32 data_size); |
196 | 198 |
197 // Helper function to schedule and asynchronous write of the used count to | 199 // Helper function to schedule and asynchronous write of the used count to |
198 // disk (this is a common operation). | 200 // disk (this is a common operation). |
199 void WriteUsedItemCountToFile(); | 201 void WriteUsedItemCountToFile(); |
200 | 202 |
201 // Helper function to schedule an asynchronous write of the given range of | 203 // Helper function to schedule an asynchronous write of the given range of |
202 // hash functions to disk. The range is inclusive on both ends. The range can | 204 // hash functions to disk. The range is inclusive on both ends. The range can |
203 // wrap around at 0 and this function will handle it. | 205 // wrap around at 0 and this function will handle it. |
204 void WriteHashRangeToFile(Hash first_hash, Hash last_hash); | 206 void WriteHashRangeToFile(Hash first_hash, Hash last_hash); |
205 | 207 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 std::set<Fingerprint> deleted_since_rebuild_; | 334 std::set<Fingerprint> deleted_since_rebuild_; |
333 | 335 |
334 // TODO(brettw) Support deletion, we need to track whether anything was | 336 // TODO(brettw) Support deletion, we need to track whether anything was |
335 // deleted during the rebuild here. Then we should delete any of these | 337 // deleted during the rebuild here. Then we should delete any of these |
336 // entries from the complete table later. | 338 // entries from the complete table later. |
337 // std::vector<Fingerprint> removed_since_rebuild_; | 339 // std::vector<Fingerprint> removed_since_rebuild_; |
338 | 340 |
339 // The currently open file with the table in it. This may be NULL if we're | 341 // The currently open file with the table in it. This may be NULL if we're |
340 // rebuilding and haven't written a new version yet. Writing to the file may | 342 // rebuilding and haven't written a new version yet. Writing to the file may |
341 // be safely ignored in this case. | 343 // be safely ignored in this case. |
342 FILE* file_; | 344 FilePtr* file_; |
brettw
2012/07/27 22:11:14
Can you clarify the comment here? There are now th
| |
343 | 345 |
344 // Shared memory consists of a SharedHeader followed by the table. | 346 // Shared memory consists of a SharedHeader followed by the table. |
345 base::SharedMemory *shared_memory_; | 347 base::SharedMemory *shared_memory_; |
346 | 348 |
347 // When we generate new tables, we increment the serial number of the | 349 // When we generate new tables, we increment the serial number of the |
348 // shared memory object. | 350 // shared memory object. |
349 int32 shared_memory_serial_; | 351 int32 shared_memory_serial_; |
350 | 352 |
351 // Number of non-empty items in the table, used to compute fullness. | 353 // Number of non-empty items in the table, used to compute fullness. |
352 int32 used_items_; | 354 int32 used_items_; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
389 int32 used_count = 0; | 391 int32 used_count = 0; |
390 for (int32 i = 0; i < table_length_; i++) { | 392 for (int32 i = 0; i < table_length_; i++) { |
391 if (hash_table_[i]) | 393 if (hash_table_[i]) |
392 used_count++; | 394 used_count++; |
393 } | 395 } |
394 DCHECK_EQ(used_count, used_items_); | 396 DCHECK_EQ(used_count, used_items_); |
395 } | 397 } |
396 #endif | 398 #endif |
397 | 399 |
398 #endif // CHROME_BROWSER_VISITEDLINK_VISITEDLINK_MASTER_H_ | 400 #endif // CHROME_BROWSER_VISITEDLINK_VISITEDLINK_MASTER_H_ |
OLD | NEW |