Chromium Code Reviews| 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 COMPONENTS_VISITEDLINK_BROWSER_VISITEDLINK_MASTER_H_ | 5 #ifndef COMPONENTS_VISITEDLINK_BROWSER_VISITEDLINK_MASTER_H_ |
| 6 #define COMPONENTS_VISITEDLINK_BROWSER_VISITEDLINK_MASTER_H_ | 6 #define COMPONENTS_VISITEDLINK_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 |
| 11 #include <set> | 11 #include <set> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/callback_forward.h" | 15 #include "base/callback_forward.h" |
| 16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 18 #include "base/memory/ref_counted.h" | |
| 18 #include "base/memory/shared_memory.h" | 19 #include "base/memory/shared_memory.h" |
| 20 #include "base/memory/weak_ptr.h" | |
| 19 #include "base/threading/sequenced_worker_pool.h" | 21 #include "base/threading/sequenced_worker_pool.h" |
| 20 #include "components/visitedlink/common/visitedlink_common.h" | 22 #include "components/visitedlink/common/visitedlink_common.h" |
| 21 | 23 |
| 22 #if defined(UNIT_TEST) || defined(PERF_TEST) || !defined(NDEBUG) | 24 #if defined(UNIT_TEST) || defined(PERF_TEST) || !defined(NDEBUG) |
| 23 #include "base/logging.h" | 25 #include "base/logging.h" |
| 24 #endif | 26 #endif |
| 25 | 27 |
| 26 class GURL; | 28 class GURL; |
| 27 | 29 |
| 28 namespace content { | 30 namespace content { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 49 | 51 |
| 50 // Called when link coloring database has been created or replaced. The | 52 // Called when link coloring database has been created or replaced. The |
| 51 // argument is the new table handle. | 53 // argument is the new table handle. |
| 52 virtual void NewTable(base::SharedMemory*) = 0; | 54 virtual void NewTable(base::SharedMemory*) = 0; |
| 53 | 55 |
| 54 // Called when new link has been added. The argument is the fingerprint | 56 // Called when new link has been added. The argument is the fingerprint |
| 55 // (hash) of the link. | 57 // (hash) of the link. |
| 56 virtual void Add(Fingerprint fingerprint) = 0; | 58 virtual void Add(Fingerprint fingerprint) = 0; |
| 57 | 59 |
| 58 // Called when link coloring state has been reset. This may occur when | 60 // Called when link coloring state has been reset. This may occur when |
| 59 // entire or parts of history were deleted. | 61 // entire or parts of history were deleted. Also this may occur when |
| 60 virtual void Reset() = 0; | 62 // the table was rebuilt or loaded. |
|
brettw
2015/12/08 00:54:42
Can this comment explain at a higher-level explici
| |
| 63 virtual void Reset(bool invalidate_hashes) = 0; | |
| 61 }; | 64 }; |
| 62 | 65 |
| 63 VisitedLinkMaster(content::BrowserContext* browser_context, | 66 VisitedLinkMaster(content::BrowserContext* browser_context, |
| 64 VisitedLinkDelegate* delegate, | 67 VisitedLinkDelegate* delegate, |
| 65 bool persist_to_disk); | 68 bool persist_to_disk); |
| 66 | 69 |
| 67 // In unit test mode, we allow the caller to optionally specify the database | 70 // In unit test mode, we allow the caller to optionally specify the database |
| 68 // filename so that it can be run from a unit test. The directory where this | 71 // filename so that it can be run from a unit test. The directory where this |
| 69 // file resides must exist in this mode. You can also specify the default | 72 // file resides must exist in this mode. You can also specify the default |
| 70 // table size to test table resizing. If this parameter is 0, we will use the | 73 // table size to test table resizing. If this parameter is 0, we will use the |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 91 // until this is called. Returns true on success, false means that this | 94 // until this is called. Returns true on success, false means that this |
| 92 // object won't work. | 95 // object won't work. |
| 93 bool Init(); | 96 bool Init(); |
| 94 | 97 |
| 95 base::SharedMemory* shared_memory() { return shared_memory_; } | 98 base::SharedMemory* shared_memory() { return shared_memory_; } |
| 96 | 99 |
| 97 // Adds a URL to the table. | 100 // Adds a URL to the table. |
| 98 void AddURL(const GURL& url); | 101 void AddURL(const GURL& url); |
| 99 | 102 |
| 100 // Adds a set of URLs to the table. | 103 // Adds a set of URLs to the table. |
| 101 void AddURLs(const std::vector<GURL>& url); | 104 void AddURLs(const std::vector<GURL>& urls); |
| 102 | 105 |
| 103 // See DeleteURLs. | 106 // See DeleteURLs. |
| 104 class URLIterator { | 107 class URLIterator { |
| 105 public: | 108 public: |
| 106 // HasNextURL must return true when this is called. Returns the next URL | 109 // HasNextURL must return true when this is called. Returns the next URL |
| 107 // then advances the iterator. Note that the returned reference is only | 110 // then advances the iterator. Note that the returned reference is only |
| 108 // valid until the next call of NextURL. | 111 // valid until the next call of NextURL. |
| 109 virtual const GURL& NextURL() = 0; | 112 virtual const GURL& NextURL() = 0; |
| 110 | 113 |
| 111 // Returns true if still has URLs to be iterated. | 114 // Returns true if still has URLs to be iterated. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 void RewriteFile() { | 156 void RewriteFile() { |
| 154 WriteFullTable(); | 157 WriteFullTable(); |
| 155 } | 158 } |
| 156 #endif | 159 #endif |
| 157 | 160 |
| 158 private: | 161 private: |
| 159 FRIEND_TEST_ALL_PREFIXES(VisitedLinkTest, Delete); | 162 FRIEND_TEST_ALL_PREFIXES(VisitedLinkTest, Delete); |
| 160 FRIEND_TEST_ALL_PREFIXES(VisitedLinkTest, BigDelete); | 163 FRIEND_TEST_ALL_PREFIXES(VisitedLinkTest, BigDelete); |
| 161 FRIEND_TEST_ALL_PREFIXES(VisitedLinkTest, BigImport); | 164 FRIEND_TEST_ALL_PREFIXES(VisitedLinkTest, BigImport); |
| 162 | 165 |
| 166 // Keeps the result of loading the table from the database file to the UI | |
| 167 // thread. | |
| 168 struct LoadFromFileResult; | |
| 169 | |
| 170 using TableLoadCompleteCallback = base::Callback<void( | |
| 171 bool success, | |
| 172 scoped_refptr<LoadFromFileResult> load_from_file_result)>; | |
| 173 | |
| 163 // Object to rebuild the table on the history thread (see the .cc file). | 174 // Object to rebuild the table on the history thread (see the .cc file). |
| 164 class TableBuilder; | 175 class TableBuilder; |
| 165 | 176 |
| 166 // Byte offsets of values in the header. | 177 // Byte offsets of values in the header. |
| 167 static const int32 kFileHeaderSignatureOffset; | 178 static const int32 kFileHeaderSignatureOffset; |
| 168 static const int32 kFileHeaderVersionOffset; | 179 static const int32 kFileHeaderVersionOffset; |
| 169 static const int32 kFileHeaderLengthOffset; | 180 static const int32 kFileHeaderLengthOffset; |
| 170 static const int32 kFileHeaderUsedOffset; | 181 static const int32 kFileHeaderUsedOffset; |
| 171 static const int32 kFileHeaderSaltOffset; | 182 static const int32 kFileHeaderSaltOffset; |
| 172 | 183 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 200 // These functions are only called if |persist_to_disk_| is true. | 211 // These functions are only called if |persist_to_disk_| is true. |
| 201 | 212 |
| 202 // Posts the given task to the blocking worker pool with our options. | 213 // Posts the given task to the blocking worker pool with our options. |
| 203 void PostIOTask(const tracked_objects::Location& from_here, | 214 void PostIOTask(const tracked_objects::Location& from_here, |
| 204 const base::Closure& task); | 215 const base::Closure& task); |
| 205 | 216 |
| 206 // Writes the entire table to disk. It will leave the table file open and | 217 // Writes the entire table to disk. It will leave the table file open and |
| 207 // the handle to it will be stored in file_. | 218 // the handle to it will be stored in file_. |
| 208 void WriteFullTable(); | 219 void WriteFullTable(); |
| 209 | 220 |
| 210 // Try to load the table from the database file. If the file doesn't exist or | 221 // Tries to load asynchronously the table from the database file. |
| 211 // is corrupt, this will return failure. | |
| 212 bool InitFromFile(); | 222 bool InitFromFile(); |
| 213 | 223 |
| 224 // Load the table from the database file. Calls |callback| when completed. It | |
| 225 // is called from the background thread. It must be first in the sequence of | |
| 226 // background operations with the database file. | |
| 227 static void LoadFromFile(const base::FilePath& filename, | |
| 228 const TableLoadCompleteCallback& callback); | |
| 229 | |
| 230 // Load the table from the database file. Returns true on success. | |
| 231 // Fills parameter |load_from_file_result| on success. It is called from | |
| 232 // the background thread. | |
| 233 static bool LoadApartFromFile( | |
| 234 const base::FilePath& filename, | |
| 235 scoped_refptr<LoadFromFileResult>* load_from_file_result); | |
| 236 | |
| 237 // It is called from the background thread and executed on the UI | |
| 238 // thread. | |
| 239 void OnTableLoadComplete( | |
| 240 bool success, | |
| 241 scoped_refptr<LoadFromFileResult> load_from_file_result); | |
| 242 | |
| 214 // Reads the header of the link coloring database from disk. Assumes the | 243 // Reads the header of the link coloring database from disk. Assumes the |
| 215 // file pointer is at the beginning of the file and that there are no pending | 244 // file pointer is at the beginning of the file and that it is the first |
| 216 // asynchronous I/O operations. | 245 // asynchronous I/O operation on the background thread. |
| 217 // | 246 // |
| 218 // Returns true on success and places the size of the table in num_entries | 247 // Returns true on success and places the size of the table in num_entries |
| 219 // and the number of nonzero fingerprints in used_count. This will fail if | 248 // and the number of nonzero fingerprints in used_count. This will fail if |
| 220 // the version of the file is not the current version of the database. | 249 // the version of the file is not the current version of the database. |
| 221 bool ReadFileHeader(FILE* hfile, int32* num_entries, int32* used_count, | 250 static bool ReadFileHeader(FILE* hfile, |
| 222 uint8 salt[LINK_SALT_LENGTH]); | 251 int32* num_entries, |
| 252 int32* used_count, | |
| 253 uint8 salt[LINK_SALT_LENGTH]); | |
| 223 | 254 |
| 224 // Fills *filename with the name of the link database filename | 255 // Fills *filename with the name of the link database filename |
| 225 bool GetDatabaseFileName(base::FilePath* filename); | 256 bool GetDatabaseFileName(base::FilePath* filename); |
| 226 | 257 |
| 227 // Wrapper around Window's WriteFile using asynchronous I/O. This will proxy | 258 // Wrapper around Window's WriteFile using asynchronous I/O. This will proxy |
| 228 // the write to a background thread. | 259 // the write to a background thread. |
| 229 void WriteToFile(FILE** hfile, off_t offset, void* data, int32 data_size); | 260 void WriteToFile(FILE** hfile, off_t offset, void* data, int32 data_size); |
| 230 | 261 |
| 231 // Helper function to schedule and asynchronous write of the used count to | 262 // Helper function to schedule and asynchronous write of the used count to |
| 232 // disk (this is a common operation). | 263 // disk (this is a common operation). |
| 233 void WriteUsedItemCountToFile(); | 264 void WriteUsedItemCountToFile(); |
| 234 | 265 |
| 235 // Helper function to schedule an asynchronous write of the given range of | 266 // Helper function to schedule an asynchronous write of the given range of |
| 236 // hash functions to disk. The range is inclusive on both ends. The range can | 267 // hash functions to disk. The range is inclusive on both ends. The range can |
| 237 // wrap around at 0 and this function will handle it. | 268 // wrap around at 0 and this function will handle it. |
| 238 void WriteHashRangeToFile(Hash first_hash, Hash last_hash); | 269 void WriteHashRangeToFile(Hash first_hash, Hash last_hash); |
| 239 | 270 |
| 240 // Synchronous read from the file. Assumes there are no pending asynchronous | 271 // Synchronous read from the file. Assumes that it is the first asynchronous |
| 241 // I/O functions. Returns true if the entire buffer was successfully filled. | 272 // I/O operation in the background thread. Returns true if the entire buffer |
| 242 bool ReadFromFile(FILE* hfile, off_t offset, void* data, size_t data_size); | 273 // was successfully filled. |
| 274 static bool ReadFromFile(FILE* hfile, | |
| 275 off_t offset, | |
| 276 void* data, | |
| 277 size_t data_size); | |
| 243 | 278 |
| 244 // General table handling | 279 // General table handling |
| 245 // ---------------------- | 280 // ---------------------- |
| 246 | 281 |
| 247 // Called to add a fingerprint to the table. If |send_notifications| is true | 282 // Called to add a fingerprint to the table. If |send_notifications| is true |
| 248 // and the item is added successfully, Listener::Add will be invoked. | 283 // and the item is added successfully, Listener::Add will be invoked. |
| 249 // Returns the index of the inserted fingerprint or null_hash_ if there was a | 284 // Returns the index of the inserted fingerprint or null_hash_ if there was a |
| 250 // duplicate and this item was skippped. | 285 // duplicate and this item was skippped. |
| 251 Hash AddFingerprint(Fingerprint fingerprint, bool send_notifications); | 286 Hash AddFingerprint(Fingerprint fingerprint, bool send_notifications); |
| 252 | 287 |
| 253 // Deletes all fingerprints from the given vector from the current hash table | 288 // Deletes all fingerprints from the given vector from the current hash table |
| 254 // and syncs it to disk if there are changes. This does not update the | 289 // and syncs it to disk if there are changes. This does not update the |
| 255 // deleted_since_rebuild_ list, the caller must update this itself if there | 290 // deleted_since_rebuild_ list, the caller must update this itself if there |
| 256 // is an update pending. | 291 // is an update pending. |
| 257 void DeleteFingerprintsFromCurrentTable( | 292 void DeleteFingerprintsFromCurrentTable( |
| 258 const std::set<Fingerprint>& fingerprints); | 293 const std::set<Fingerprint>& fingerprints); |
| 259 | 294 |
| 260 // Removes the indicated fingerprint from the table. If the update_file flag | 295 // Removes the indicated fingerprint from the table. If the update_file flag |
| 261 // is set, the changes will also be written to disk. Returns true if the | 296 // is set, the changes will also be written to disk. Returns true if the |
| 262 // fingerprint was deleted, false if it was not in the table to delete. | 297 // fingerprint was deleted, false if it was not in the table to delete. |
| 263 bool DeleteFingerprint(Fingerprint fingerprint, bool update_file); | 298 bool DeleteFingerprint(Fingerprint fingerprint, bool update_file); |
| 264 | 299 |
| 265 // Creates a new empty table, call if InitFromFile() fails. Normally, when | 300 // Creates a new empty table, call if InitFromFile() fails. Normally, when |
| 266 // |suppress_rebuild| is false, the table will be rebuilt from history, | 301 // |suppress_rebuild| is false, the table will be rebuilt from history, |
| 267 // keeping us in sync. When |suppress_rebuild| is true, the new table will be | 302 // keeping us in sync. When |suppress_rebuild| is true, the new table will be |
| 268 // empty and we will not consult history. This is used when clearing the | 303 // empty and we will not consult history. This is used when clearing the |
| 269 // database and for unit tests. | 304 // database and for unit tests. |
| 270 bool InitFromScratch(bool suppress_rebuild); | 305 bool InitFromScratch(bool suppress_rebuild); |
| 271 | 306 |
| 272 // Allocates the Fingerprint structure and length. When init_to_empty is set, | 307 // Allocates the Fingerprint structure and length. Structure is filled with 0s |
| 273 // the table will be filled with 0s and used_items_ will be set to 0 as well. | 308 // and shared header with salt and used_items_ is set to 0. |
| 274 // If the flag is not set, these things are untouched and it is the | 309 bool CreateURLTable(int32 num_entries); |
| 275 // responsibility of the caller to fill them (like when we are reading from | 310 |
| 276 // a file). | 311 // Allocates the Fingerprint structure and length. Returns true on success. |
| 277 bool CreateURLTable(int32 num_entries, bool init_to_empty); | 312 // Structure is filled with 0s and shared header with salt. |
| 313 static bool CreateApartURLTable(int32 num_entries, | |
| 314 const uint8 salt[LINK_SALT_LENGTH], | |
| 315 scoped_ptr<base::SharedMemory>* shared_memory, | |
| 316 VisitedLinkCommon::Fingerprint** hash_table); | |
|
brettw
2015/12/08 00:54:42
In the comment above, can you make more explicit h
| |
| 278 | 317 |
| 279 // A wrapper for CreateURLTable, this will allocate a new table, initialized | 318 // A wrapper for CreateURLTable, this will allocate a new table, initialized |
| 280 // to empty. The caller is responsible for saving the shared memory pointer | 319 // to empty. The caller is responsible for saving the shared memory pointer |
| 281 // and handles before this call (they will be replaced with new ones) and | 320 // and handles before this call (they will be replaced with new ones) and |
| 282 // releasing them later. This is designed for callers that make a new table | 321 // releasing them later. This is designed for callers that make a new table |
| 283 // and then copy values from the old table to the new one, then release the | 322 // and then copy values from the old table to the new one, then release the |
| 284 // old table. | 323 // old table. |
| 285 // | 324 // |
| 286 // Returns true on success. On failure, the old table will be restored. The | 325 // Returns true on success. On failure, the old table will be restored. The |
| 287 // caller should not attemp to release the pointer/handle in this case. | 326 // caller should not attemp to release the pointer/handle in this case. |
| 288 bool BeginReplaceURLTable(int32 num_entries); | 327 bool BeginReplaceURLTable(int32 num_entries); |
| 289 | 328 |
| 290 // unallocates the Fingerprint table | 329 // unallocates the Fingerprint table |
| 291 void FreeURLTable(); | 330 void FreeURLTable(); |
| 292 | 331 |
| 293 // For growing the table. ResizeTableIfNecessary will check to see if the | 332 // For growing the table. ResizeTableIfNecessary will check to see if the |
| 294 // table should be resized and calls ResizeTable if needed. Returns true if | 333 // table should be resized and calls ResizeTable if needed. Returns true if |
| 295 // we decided to resize the table. | 334 // we decided to resize the table. |
| 296 bool ResizeTableIfNecessary(); | 335 bool ResizeTableIfNecessary(); |
| 297 | 336 |
| 298 // Resizes the table (growing or shrinking) as necessary to accomodate the | 337 // Resizes the table (growing or shrinking) as necessary to accomodate the |
| 299 // current count. | 338 // current count. |
| 300 void ResizeTable(int32 new_size); | 339 void ResizeTable(int32 new_size); |
| 301 | 340 |
| 341 // Returns the default table size. It can be overrided in unit tests. | |
| 342 uint32 DefaultTableSize() const; | |
| 343 | |
| 302 // Returns the desired table size for |item_count| URLs. | 344 // Returns the desired table size for |item_count| URLs. |
| 303 uint32 NewTableSizeForCount(int32 item_count) const; | 345 uint32 NewTableSizeForCount(int32 item_count) const; |
| 304 | 346 |
| 305 // Computes the table load as fraction. For example, if 1/4 of the entries are | 347 // Computes the table load as fraction. For example, if 1/4 of the entries are |
| 306 // full, this value will be 0.25 | 348 // full, this value will be 0.25 |
| 307 float ComputeTableLoad() const { | 349 float ComputeTableLoad() const { |
| 308 return static_cast<float>(used_items_) / static_cast<float>(table_length_); | 350 return static_cast<float>(used_items_) / static_cast<float>(table_length_); |
| 309 } | 351 } |
| 310 | 352 |
| 311 // Initializes a rebuild of the visited link database based on the browser | 353 // Initializes a rebuild of the visited link database based on the browser |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 330 if (hash >= table_length_ - 1) | 372 if (hash >= table_length_ - 1) |
| 331 return 0; // Wrap around. | 373 return 0; // Wrap around. |
| 332 return hash + 1; | 374 return hash + 1; |
| 333 } | 375 } |
| 334 inline Hash DecrementHash(Hash hash) { | 376 inline Hash DecrementHash(Hash hash) { |
| 335 if (hash <= 0) | 377 if (hash <= 0) |
| 336 return table_length_ - 1; // Wrap around. | 378 return table_length_ - 1; // Wrap around. |
| 337 return hash - 1; | 379 return hash - 1; |
| 338 } | 380 } |
| 339 | 381 |
| 340 #ifndef NDEBUG | |
| 341 // Indicates whether any asynchronous operation has ever been completed. | |
| 342 // We do some synchronous reads that require that no asynchronous operations | |
| 343 // are pending, yet we don't track whether they have been completed. This | |
| 344 // flag is a sanity check that these reads only happen before any | |
| 345 // asynchronous writes have been fired. | |
| 346 bool posted_asynchronous_operation_; | |
| 347 #endif | |
| 348 | |
| 349 // Reference to the browser context that this object belongs to | 382 // Reference to the browser context that this object belongs to |
| 350 // (it knows the path to where the data is stored) | 383 // (it knows the path to where the data is stored) |
| 351 content::BrowserContext* browser_context_; | 384 content::BrowserContext* browser_context_; |
| 352 | 385 |
| 353 // Client owns the delegate and is responsible for it being valid through | 386 // Client owns the delegate and is responsible for it being valid through |
| 354 // the life time this VisitedLinkMaster. | 387 // the life time this VisitedLinkMaster. |
| 355 VisitedLinkDelegate* delegate_; | 388 VisitedLinkDelegate* delegate_; |
| 356 | 389 |
| 357 // VisitedLinkEventListener to handle incoming events. | 390 // VisitedLinkEventListener to handle incoming events. |
| 358 scoped_ptr<Listener> listener_; | 391 scoped_ptr<Listener> listener_; |
| 359 | 392 |
| 360 // Lazily initialized sequence token for posting file tasks. | 393 // Lazily initialized sequence token for posting file tasks. |
| 361 base::SequencedWorkerPool::SequenceToken sequence_token_; | 394 base::SequencedWorkerPool::SequenceToken sequence_token_; |
| 362 | 395 |
| 363 // When non-NULL, indicates we are in database rebuild mode and points to | 396 // When non-NULL, indicates we are in database rebuild mode and points to |
| 364 // the class collecting fingerprint information from the history system. | 397 // the class collecting fingerprint information from the history system. |
| 365 // The pointer is owned by this class, but it must remain valid while the | 398 // The pointer is owned by this class, but it must remain valid while the |
| 366 // history query is running. We must only delete it when the query is done. | 399 // history query is running. We must only delete it when the query is done. |
| 367 scoped_refptr<TableBuilder> table_builder_; | 400 scoped_refptr<TableBuilder> table_builder_; |
| 368 | 401 |
| 369 // Indicates URLs added and deleted since we started rebuilding the table. | 402 // Indicates URLs added and deleted since we started rebuilding the table. |
| 370 std::set<Fingerprint> added_since_rebuild_; | 403 std::set<Fingerprint> added_since_rebuild_; |
| 371 std::set<Fingerprint> deleted_since_rebuild_; | 404 std::set<Fingerprint> deleted_since_rebuild_; |
| 372 | 405 |
| 373 // TODO(brettw) Support deletion, we need to track whether anything was | 406 // Indicates URLs added and deleted since we started loading the table. |
| 374 // deleted during the rebuild here. Then we should delete any of these | 407 // It can be only url because after loading table the salt will be changed. |
| 375 // entries from the complete table later. | 408 std::set<GURL> added_since_load_; |
| 376 // std::vector<Fingerprint> removed_since_rebuild_; | 409 std::set<GURL> deleted_since_load_; |
| 377 | 410 |
| 378 // The currently open file with the table in it. This may be NULL if we're | 411 // The currently open file with the table in it. This may be NULL if we're |
| 379 // rebuilding and haven't written a new version yet or if |persist_to_disk_| | 412 // rebuilding and haven't written a new version yet or if |persist_to_disk_| |
| 380 // is false. Writing to the file may be safely ignored in this case. Also | 413 // is false. Writing to the file may be safely ignored in this case. Also |
| 381 // |file_| may be non-NULL but point to a NULL pointer. That would mean that | 414 // |file_| may be non-NULL but point to a NULL pointer. That would mean that |
| 382 // opening of the file is already scheduled in a background thread and any | 415 // opening of the file is already scheduled in a background thread and any |
| 383 // writing to the file can also be scheduled to the background thread as it's | 416 // writing to the file can also be scheduled to the background thread as it's |
| 384 // guaranteed to be executed after the opening. | 417 // guaranteed to be executed after the opening. |
| 385 // The class owns both the |file_| pointer and the pointer pointed | 418 // The class owns both the |file_| pointer and the pointer pointed |
| 386 // by |*file_|. | 419 // by |*file_|. |
| 387 FILE** file_; | 420 FILE** file_; |
| 388 | 421 |
| 389 // If true, will try to persist the hash table to disk. Will rebuild from | 422 // If true, will try to persist the hash table to disk. Will rebuild from |
| 390 // VisitedLinkDelegate::RebuildTable if there are disk corruptions. | 423 // VisitedLinkDelegate::RebuildTable if there are disk corruptions. |
| 391 bool persist_to_disk_; | 424 bool persist_to_disk_; |
| 392 | 425 |
| 393 // Shared memory consists of a SharedHeader followed by the table. | 426 // Shared memory consists of a SharedHeader followed by the table. |
| 394 base::SharedMemory *shared_memory_; | 427 base::SharedMemory *shared_memory_; |
| 395 | 428 |
| 396 // When we generate new tables, we increment the serial number of the | 429 // When we generate new tables, we increment the serial number of the |
| 397 // shared memory object. | 430 // shared memory object. |
| 398 int32 shared_memory_serial_; | 431 int32 shared_memory_serial_; |
| 399 | 432 |
| 400 // Number of non-empty items in the table, used to compute fullness. | 433 // Number of non-empty items in the table, used to compute fullness. |
| 401 int32 used_items_; | 434 int32 used_items_; |
| 402 | 435 |
| 436 // We set this to true to avoid writing to the database file. | |
| 437 bool table_is_loading_from_file_; | |
| 438 | |
| 403 // Testing values ----------------------------------------------------------- | 439 // Testing values ----------------------------------------------------------- |
| 404 // | 440 // |
| 405 // The following fields exist for testing purposes. They are not used in | 441 // The following fields exist for testing purposes. They are not used in |
| 406 // release builds. It'd be nice to eliminate them in release builds, but we | 442 // release builds. It'd be nice to eliminate them in release builds, but we |
| 407 // don't want to change the signature of the object between the unit test and | 443 // don't want to change the signature of the object between the unit test and |
| 408 // regular builds. Instead, we just have "default" values that these take | 444 // regular builds. Instead, we just have "default" values that these take |
| 409 // in release builds that give "regular" behavior. | 445 // in release builds that give "regular" behavior. |
| 410 | 446 |
| 411 // Overridden database file name for testing | 447 // Overridden database file name for testing |
| 412 base::FilePath database_name_override_; | 448 base::FilePath database_name_override_; |
| 413 | 449 |
| 414 // When nonzero, overrides the table size for new databases for testing | 450 // When nonzero, overrides the table size for new databases for testing |
| 415 int32 table_size_override_; | 451 int32 table_size_override_; |
| 416 | 452 |
| 417 // When set, indicates the task that should be run after the next rebuild from | 453 // When set, indicates the task that should be run after the next rebuild from |
| 418 // history is complete. | 454 // history is complete. |
| 419 base::Closure rebuild_complete_task_; | 455 base::Closure rebuild_complete_task_; |
| 420 | 456 |
| 421 // Set to prevent us from attempting to rebuild the database from global | 457 // Set to prevent us from attempting to rebuild the database from global |
| 422 // history if we have an error opening the file. This is used for testing, | 458 // history if we have an error opening the file. This is used for testing, |
| 423 // will be false in production. | 459 // will be false in production. |
| 424 bool suppress_rebuild_; | 460 bool suppress_rebuild_; |
| 425 | 461 |
| 462 base::WeakPtrFactory<VisitedLinkMaster> weak_ptr_factory_; | |
| 463 | |
| 426 DISALLOW_COPY_AND_ASSIGN(VisitedLinkMaster); | 464 DISALLOW_COPY_AND_ASSIGN(VisitedLinkMaster); |
| 427 }; | 465 }; |
| 428 | 466 |
| 429 // NOTE: These methods are defined inline here, so we can share the compilation | 467 // NOTE: These methods are defined inline here, so we can share the compilation |
| 430 // of visitedlink_master.cc between the browser and the unit/perf tests. | 468 // of visitedlink_master.cc between the browser and the unit/perf tests. |
| 431 | 469 |
| 432 #if defined(UNIT_TEST) || defined(PERF_TEST) || !defined(NDEBUG) | 470 #if defined(UNIT_TEST) || defined(PERF_TEST) || !defined(NDEBUG) |
| 433 inline void VisitedLinkMaster::DebugValidate() { | 471 inline void VisitedLinkMaster::DebugValidate() { |
| 434 int32 used_count = 0; | 472 int32 used_count = 0; |
| 435 for (int32 i = 0; i < table_length_; i++) { | 473 for (int32 i = 0; i < table_length_; i++) { |
| 436 if (hash_table_[i]) | 474 if (hash_table_[i]) |
| 437 used_count++; | 475 used_count++; |
| 438 } | 476 } |
| 439 DCHECK_EQ(used_count, used_items_); | 477 DCHECK_EQ(used_count, used_items_); |
| 440 } | 478 } |
| 441 #endif | 479 #endif |
| 442 | 480 |
| 443 } // namespace visitedlink | 481 } // namespace visitedlink |
| 444 | 482 |
| 445 #endif // COMPONENTS_VISITEDLINK_BROWSER_VISITEDLINK_MASTER_H_ | 483 #endif // COMPONENTS_VISITEDLINK_BROWSER_VISITEDLINK_MASTER_H_ |
| OLD | NEW |