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

Side by Side Diff: components/visitedlink/browser/visitedlink_master.h

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

Powered by Google App Engine
This is Rietveld 408576698