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

Side by Side Diff: chrome/browser/visitedlink_master.cc

Issue 149185: Ensure that VisitedLink listener Add event only fires when new fingerprint is... (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/trunk/src/
Patch Set: Fixed the comment. Created 11 years, 5 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
« no previous file with comments | « chrome/browser/visitedlink_master.h ('k') | chrome/browser/visitedlink_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/browser/visitedlink_master.h" 5 #include "chrome/browser/visitedlink_master.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <io.h> 9 #include <io.h>
10 #include <shlobj.h> 10 #include <shlobj.h>
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 added_since_rebuild_.insert(fingerprint); 304 added_since_rebuild_.insert(fingerprint);
305 } 305 }
306 306
307 // If the table is "full", we don't add URLs and just drop them on the floor. 307 // If the table is "full", we don't add URLs and just drop them on the floor.
308 // This can happen if we get thousands of new URLs and something causes 308 // This can happen if we get thousands of new URLs and something causes
309 // the table resizing to fail. This check prevents a hang in that case. Note 309 // the table resizing to fail. This check prevents a hang in that case. Note
310 // that this is *not* the resize limit, this is just a sanity check. 310 // that this is *not* the resize limit, this is just a sanity check.
311 if (used_items_ / 8 > table_length_ / 10) 311 if (used_items_ / 8 > table_length_ / 10)
312 return null_hash_; // Table is more than 80% full. 312 return null_hash_; // Table is more than 80% full.
313 313
314 return AddFingerprint(fingerprint); 314 return AddFingerprint(fingerprint, true);
315 } 315 }
316 316
317 void VisitedLinkMaster::AddURL(const GURL& url) { 317 void VisitedLinkMaster::AddURL(const GURL& url) {
318 Hash index = TryToAddURL(url); 318 Hash index = TryToAddURL(url);
319 if (!table_builder_ && index != null_hash_) { 319 if (!table_builder_ && index != null_hash_) {
320 // Not rebuilding, so we want to keep the file on disk up-to-date. 320 // Not rebuilding, so we want to keep the file on disk up-to-date.
321 WriteUsedItemCountToFile(); 321 WriteUsedItemCountToFile();
322 WriteHashRangeToFile(index, index); 322 WriteHashRangeToFile(index, index);
323 ResizeTableIfNecessary(); 323 ResizeTableIfNecessary();
324 } 324 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 if (!i->is_valid()) 393 if (!i->is_valid())
394 continue; 394 continue;
395 deleted_fingerprints.insert( 395 deleted_fingerprints.insert(
396 ComputeURLFingerprint(i->spec().data(), i->spec().size(), salt_)); 396 ComputeURLFingerprint(i->spec().data(), i->spec().size(), salt_));
397 } 397 }
398 DeleteFingerprintsFromCurrentTable(deleted_fingerprints); 398 DeleteFingerprintsFromCurrentTable(deleted_fingerprints);
399 } 399 }
400 400
401 // See VisitedLinkCommon::IsVisited which should be in sync with this algorithm 401 // See VisitedLinkCommon::IsVisited which should be in sync with this algorithm
402 VisitedLinkMaster::Hash VisitedLinkMaster::AddFingerprint( 402 VisitedLinkMaster::Hash VisitedLinkMaster::AddFingerprint(
403 Fingerprint fingerprint) { 403 Fingerprint fingerprint,
404 bool send_notifications) {
404 if (!hash_table_ || table_length_ == 0) { 405 if (!hash_table_ || table_length_ == 0) {
405 NOTREACHED(); // Not initialized. 406 NOTREACHED(); // Not initialized.
406 return null_hash_; 407 return null_hash_;
407 } 408 }
408 409
409 Hash cur_hash = HashFingerprint(fingerprint); 410 Hash cur_hash = HashFingerprint(fingerprint);
410 Hash first_hash = cur_hash; 411 Hash first_hash = cur_hash;
411 while (true) { 412 while (true) {
412 Fingerprint cur_fingerprint = FingerprintAt(cur_hash); 413 Fingerprint cur_fingerprint = FingerprintAt(cur_hash);
413 if (cur_fingerprint == fingerprint) 414 if (cur_fingerprint == fingerprint)
414 return null_hash_; // This fingerprint is already in there, do nothing. 415 return null_hash_; // This fingerprint is already in there, do nothing.
415 416
416 if (cur_fingerprint == null_fingerprint_) { 417 if (cur_fingerprint == null_fingerprint_) {
417 // End of probe sequence found, insert here. 418 // End of probe sequence found, insert here.
418 hash_table_[cur_hash] = fingerprint; 419 hash_table_[cur_hash] = fingerprint;
419 used_items_++; 420 used_items_++;
420 // Notify listener that a new visited link was added. 421 // If allowed, notify listener that a new visited link was added.
421 listener_->Add(fingerprint); 422 if (send_notifications)
423 listener_->Add(fingerprint);
422 return cur_hash; 424 return cur_hash;
423 } 425 }
424 426
425 // Advance in the probe sequence. 427 // Advance in the probe sequence.
426 cur_hash = IncrementHash(cur_hash); 428 cur_hash = IncrementHash(cur_hash);
427 if (cur_hash == first_hash) { 429 if (cur_hash == first_hash) {
428 // This means that we've wrapped around and are about to go into an 430 // This means that we've wrapped around and are about to go into an
429 // infinite loop. Something was wrong with the hashtable resizing 431 // infinite loop. Something was wrong with the hashtable resizing
430 // logic, so stop here. 432 // logic, so stop here.
431 NOTREACHED(); 433 NOTREACHED();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 // This will balance the increment of this value in AddFingerprint below 498 // This will balance the increment of this value in AddFingerprint below
497 // so there is no net change. 499 // so there is no net change.
498 used_items_--; 500 used_items_--;
499 } 501 }
500 hash_table_[i] = null_fingerprint_; 502 hash_table_[i] = null_fingerprint_;
501 } 503 }
502 504
503 if (!shuffled_fingerprints->empty()) { 505 if (!shuffled_fingerprints->empty()) {
504 // Need to add the new items back. 506 // Need to add the new items back.
505 for (size_t i = 0; i < shuffled_fingerprints->size(); i++) 507 for (size_t i = 0; i < shuffled_fingerprints->size(); i++)
506 AddFingerprint(shuffled_fingerprints[i]); 508 AddFingerprint(shuffled_fingerprints[i], false);
507 } 509 }
508 510
509 // Write the affected range to disk [deleted_hash, end_range]. 511 // Write the affected range to disk [deleted_hash, end_range].
510 if (update_file) 512 if (update_file)
511 WriteHashRangeToFile(deleted_hash, end_range); 513 WriteHashRangeToFile(deleted_hash, end_range);
512 514
513 return true; 515 return true;
514 } 516 }
515 517
516 bool VisitedLinkMaster::WriteFullTable() { 518 bool VisitedLinkMaster::WriteFullTable() {
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 Fingerprint* old_hash_table = hash_table_; 799 Fingerprint* old_hash_table = hash_table_;
798 int32 old_table_length = table_length_; 800 int32 old_table_length = table_length_;
799 if (!BeginReplaceURLTable(new_size)) 801 if (!BeginReplaceURLTable(new_size))
800 return; 802 return;
801 803
802 // Now we have two tables, our local copy which is the old one, and the new 804 // Now we have two tables, our local copy which is the old one, and the new
803 // one loaded into this object where we need to copy the data. 805 // one loaded into this object where we need to copy the data.
804 for (int32 i = 0; i < old_table_length; i++) { 806 for (int32 i = 0; i < old_table_length; i++) {
805 Fingerprint cur = old_hash_table[i]; 807 Fingerprint cur = old_hash_table[i];
806 if (cur) 808 if (cur)
807 AddFingerprint(cur); 809 AddFingerprint(cur, false);
808 } 810 }
809 811
810 // On error unmapping, just forget about it since we can't do anything 812 // On error unmapping, just forget about it since we can't do anything
811 // else to release it. 813 // else to release it.
812 delete old_shared_memory; 814 delete old_shared_memory;
813 815
814 // Send an update notification to all child processes so they read the new 816 // Send an update notification to all child processes so they read the new
815 // table. 817 // table.
816 listener_->NewTable(shared_memory_); 818 listener_->NewTable(shared_memory_);
817 819
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 base::SharedMemory* old_shared_memory = shared_memory_; 897 base::SharedMemory* old_shared_memory = shared_memory_;
896 898
897 int new_table_size = NewTableSizeForCount( 899 int new_table_size = NewTableSizeForCount(
898 static_cast<int>(fingerprints.size())); 900 static_cast<int>(fingerprints.size()));
899 if (BeginReplaceURLTable(new_table_size)) { 901 if (BeginReplaceURLTable(new_table_size)) {
900 // Free the old table. 902 // Free the old table.
901 delete old_shared_memory; 903 delete old_shared_memory;
902 904
903 // Add the stored fingerprints to the hash table. 905 // Add the stored fingerprints to the hash table.
904 for (size_t i = 0; i < fingerprints.size(); i++) 906 for (size_t i = 0; i < fingerprints.size(); i++)
905 AddFingerprint(fingerprints[i]); 907 AddFingerprint(fingerprints[i], false);
906 908
907 // Also add anything that was added while we were asynchronously 909 // Also add anything that was added while we were asynchronously
908 // generating the new table. 910 // generating the new table.
909 for (std::set<Fingerprint>::iterator i = added_since_rebuild_.begin(); 911 for (std::set<Fingerprint>::iterator i = added_since_rebuild_.begin();
910 i != added_since_rebuild_.end(); ++i) 912 i != added_since_rebuild_.end(); ++i)
911 AddFingerprint(*i); 913 AddFingerprint(*i, false);
912 added_since_rebuild_.clear(); 914 added_since_rebuild_.clear();
913 915
914 // Now handle deletions. 916 // Now handle deletions.
915 DeleteFingerprintsFromCurrentTable(deleted_since_rebuild_); 917 DeleteFingerprintsFromCurrentTable(deleted_since_rebuild_);
916 deleted_since_rebuild_.clear(); 918 deleted_since_rebuild_.clear();
917 919
918 // Send an update notification to all child processes. 920 // Send an update notification to all child processes.
919 listener_->NewTable(shared_memory_); 921 listener_->NewTable(shared_memory_);
920 922
921 WriteFullTable(); 923 WriteFullTable();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 } 1029 }
1028 1030
1029 void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() { 1031 void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() {
1030 if (master_) 1032 if (master_)
1031 master_->OnTableRebuildComplete(success_, fingerprints_); 1033 master_->OnTableRebuildComplete(success_, fingerprints_);
1032 1034
1033 // WILL (generally) DELETE THIS! This balances the AddRef in 1035 // WILL (generally) DELETE THIS! This balances the AddRef in
1034 // VisitedLinkMaster::RebuildTableFromHistory. 1036 // VisitedLinkMaster::RebuildTableFromHistory.
1035 Release(); 1037 Release();
1036 } 1038 }
OLDNEW
« no previous file with comments | « chrome/browser/visitedlink_master.h ('k') | chrome/browser/visitedlink_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698