OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_MASTER_H__ | 5 #ifndef CHROME_BROWSER_VISITEDLINK_MASTER_H__ |
6 #define CHROME_BROWSER_VISITEDLINK_MASTER_H__ | 6 #define CHROME_BROWSER_VISITEDLINK_MASTER_H__ |
7 | 7 |
8 #if defined(OS_WIN) | 8 #if defined(OS_WIN) |
9 #include <windows.h> | 9 #include <windows.h> |
10 #endif | 10 #endif |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 // testing except when you want to test the rebuild process explicitly. | 70 // testing except when you want to test the rebuild process explicitly. |
71 VisitedLinkMaster(Listener* listener, | 71 VisitedLinkMaster(Listener* listener, |
72 HistoryService* history_service, | 72 HistoryService* history_service, |
73 bool suppress_rebuild, | 73 bool suppress_rebuild, |
74 const FilePath& filename, | 74 const FilePath& filename, |
75 int32 default_table_size); | 75 int32 default_table_size); |
76 virtual ~VisitedLinkMaster(); | 76 virtual ~VisitedLinkMaster(); |
77 | 77 |
78 // Must be called immediately after object creation. Nothing else will work | 78 // Must be called immediately after object creation. Nothing else will work |
79 // until this is called. Returns true on success, false means that this | 79 // until this is called. Returns true on success, false means that this |
80 // object won't work. | 80 // object won't work. You can also use InitFromFile() and InitFromScratch() |
| 81 // if you need more control over loading the visited link information. |
81 bool Init(); | 82 bool Init(); |
82 | 83 |
| 84 // Try to load the table from the database file. If the file doesn't exist or |
| 85 // is corrupt, this will return failure. |
| 86 bool InitFromFile(); |
| 87 |
| 88 // Creates a new empty table, call if InitFromFile() fails. Normally, when |
| 89 // |suppress_rebuild| is false, the table will be rebuilt from history, |
| 90 // keeping us in sync. |
| 91 bool InitFromScratch(); |
| 92 |
83 base::SharedMemory* shared_memory() { return shared_memory_; } | 93 base::SharedMemory* shared_memory() { return shared_memory_; } |
84 | 94 |
85 // Adds a URL to the table. | 95 // Adds a URL to the table. |
86 void AddURL(const GURL& url); | 96 void AddURL(const GURL& url); |
87 | 97 |
88 // Adds a set of URLs to the table. | 98 // Adds a set of URLs to the table. |
89 void AddURLs(const std::vector<GURL>& url); | 99 void AddURLs(const std::vector<GURL>& url); |
90 | 100 |
91 // Deletes the specified URLs from the table. | 101 // Deletes the specified URLs from the table. |
92 void DeleteURLs(const std::set<GURL>& urls); | 102 void DeleteURLs(const std::set<GURL>& urls); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 // inserted fingerprint or null_hash_ on failure. | 170 // inserted fingerprint or null_hash_ on failure. |
161 Hash TryToAddURL(const GURL& url); | 171 Hash TryToAddURL(const GURL& url); |
162 | 172 |
163 // File I/O functions | 173 // File I/O functions |
164 // ------------------ | 174 // ------------------ |
165 | 175 |
166 // Writes the entire table to disk, returning true on success. It will leave | 176 // Writes the entire table to disk, returning true on success. It will leave |
167 // the table file open and the handle to it in file_ | 177 // the table file open and the handle to it in file_ |
168 bool WriteFullTable(); | 178 bool WriteFullTable(); |
169 | 179 |
170 // Try to load the table from the database file. If the file doesn't exist or | |
171 // is corrupt, this will return failure. | |
172 bool InitFromFile(); | |
173 | |
174 // Reads the header of the link coloring database from disk. Assumes the | 180 // Reads the header of the link coloring database from disk. Assumes the |
175 // file pointer is at the beginning of the file and that there are no pending | 181 // file pointer is at the beginning of the file and that there are no pending |
176 // asynchronous I/O operations. | 182 // asynchronous I/O operations. |
177 // | 183 // |
178 // Returns true on success and places the size of the table in num_entries | 184 // Returns true on success and places the size of the table in num_entries |
179 // and the number of nonzero fingerprints in used_count. This will fail if | 185 // and the number of nonzero fingerprints in used_count. This will fail if |
180 // the version of the file is not the current version of the database. | 186 // the version of the file is not the current version of the database. |
181 bool ReadFileHeader(FILE* hfile, int32* num_entries, int32* used_count, | 187 bool ReadFileHeader(FILE* hfile, int32* num_entries, int32* used_count, |
182 uint8 salt[LINK_SALT_LENGTH]); | 188 uint8 salt[LINK_SALT_LENGTH]); |
183 | 189 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 // deleted_since_rebuild_ list, the caller must update this itself if there | 221 // deleted_since_rebuild_ list, the caller must update this itself if there |
216 // is an update pending. | 222 // is an update pending. |
217 void DeleteFingerprintsFromCurrentTable( | 223 void DeleteFingerprintsFromCurrentTable( |
218 const std::set<Fingerprint>& fingerprints); | 224 const std::set<Fingerprint>& fingerprints); |
219 | 225 |
220 // Removes the indicated fingerprint from the table. If the update_file flag | 226 // Removes the indicated fingerprint from the table. If the update_file flag |
221 // is set, the changes will also be written to disk. Returns true if the | 227 // is set, the changes will also be written to disk. Returns true if the |
222 // fingerprint was deleted, false if it was not in the table to delete. | 228 // fingerprint was deleted, false if it was not in the table to delete. |
223 bool DeleteFingerprint(Fingerprint fingerprint, bool update_file); | 229 bool DeleteFingerprint(Fingerprint fingerprint, bool update_file); |
224 | 230 |
225 // Creates a new empty table, call if InitFromFile() fails. Normally, when | |
226 // |suppress_rebuild| is false, the table will be rebuilt from history, | |
227 // keeping us in sync. When |suppress_rebuild| is true, the new table will be | |
228 // empty and we will not consult history. This is used when clearing the | |
229 // database and for unit tests. | |
230 bool InitFromScratch(bool suppress_rebuild); | |
231 | |
232 // Allocates the Fingerprint structure and length. When init_to_empty is set, | 231 // Allocates the Fingerprint structure and length. When init_to_empty is set, |
233 // the table will be filled with 0s and used_items_ will be set to 0 as well. | 232 // the table will be filled with 0s and used_items_ will be set to 0 as well. |
234 // If the flag is not set, these things are untouched and it is the | 233 // If the flag is not set, these things are untouched and it is the |
235 // responsibility of the caller to fill them (like when we are reading from | 234 // responsibility of the caller to fill them (like when we are reading from |
236 // a file). | 235 // a file). |
237 bool CreateURLTable(int32 num_entries, bool init_to_empty); | 236 bool CreateURLTable(int32 num_entries, bool init_to_empty); |
238 | 237 |
239 // A wrapper for CreateURLTable, this will allocate a new table, initialized | 238 // A wrapper for CreateURLTable, this will allocate a new table, initialized |
240 // to empty. The caller is responsible for saving the shared memory pointer | 239 // to empty. The caller is responsible for saving the shared memory pointer |
241 // and handles before this call (they will be replaced with new ones) and | 240 // and handles before this call (they will be replaced with new ones) and |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 int32 used_count = 0; | 379 int32 used_count = 0; |
381 for (int32 i = 0; i < table_length_; i++) { | 380 for (int32 i = 0; i < table_length_; i++) { |
382 if (hash_table_[i]) | 381 if (hash_table_[i]) |
383 used_count++; | 382 used_count++; |
384 } | 383 } |
385 DCHECK_EQ(used_count, used_items_); | 384 DCHECK_EQ(used_count, used_items_); |
386 } | 385 } |
387 #endif | 386 #endif |
388 | 387 |
389 #endif // CHROME_BROWSER_VISITEDLINK_MASTER_H__ | 388 #endif // CHROME_BROWSER_VISITEDLINK_MASTER_H__ |
OLD | NEW |