summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authordglazkov@chromium.org <dglazkov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-04 17:22:08 +0000
committerdglazkov@chromium.org <dglazkov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-04 17:22:08 +0000
commitf8c42c90784b19c7ec17538b7977a4c2e5ece629 (patch)
tree6a241a57ddcf610e88d3abd48898530a521aca27 /chrome
parent17c4f3c7c289c840f8b285f7834ab7007f85e35e (diff)
downloadchromium_src-f8c42c90784b19c7ec17538b7977a4c2e5ece629.zip
chromium_src-f8c42c90784b19c7ec17538b7977a4c2e5ece629.tar.gz
chromium_src-f8c42c90784b19c7ec17538b7977a4c2e5ece629.tar.bz2
Ensure that VisitedLink listener Add event only fires when new fingerprint is added, and not during resizing/rebuilding or deleting fingerprints.
R=brettw TEST=VisitedLinkTest.Listener BUG=15926 Review URL: http://codereview.chromium.org/149185 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19931 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/visitedlink_master.cc18
-rw-r--r--chrome/browser/visitedlink_master.h9
-rw-r--r--chrome/browser/visitedlink_unittest.cc10
3 files changed, 20 insertions, 17 deletions
diff --git a/chrome/browser/visitedlink_master.cc b/chrome/browser/visitedlink_master.cc
index 41a97a1..3f2f3c0 100644
--- a/chrome/browser/visitedlink_master.cc
+++ b/chrome/browser/visitedlink_master.cc
@@ -311,7 +311,7 @@ VisitedLinkMaster::Hash VisitedLinkMaster::TryToAddURL(const GURL& url) {
if (used_items_ / 8 > table_length_ / 10)
return null_hash_; // Table is more than 80% full.
- return AddFingerprint(fingerprint);
+ return AddFingerprint(fingerprint, true);
}
void VisitedLinkMaster::AddURL(const GURL& url) {
@@ -400,7 +400,8 @@ void VisitedLinkMaster::DeleteURLs(const std::set<GURL>& urls) {
// See VisitedLinkCommon::IsVisited which should be in sync with this algorithm
VisitedLinkMaster::Hash VisitedLinkMaster::AddFingerprint(
- Fingerprint fingerprint) {
+ Fingerprint fingerprint,
+ bool send_notifications) {
if (!hash_table_ || table_length_ == 0) {
NOTREACHED(); // Not initialized.
return null_hash_;
@@ -417,8 +418,9 @@ VisitedLinkMaster::Hash VisitedLinkMaster::AddFingerprint(
// End of probe sequence found, insert here.
hash_table_[cur_hash] = fingerprint;
used_items_++;
- // Notify listener that a new visited link was added.
- listener_->Add(fingerprint);
+ // If allowed, notify listener that a new visited link was added.
+ if (send_notifications)
+ listener_->Add(fingerprint);
return cur_hash;
}
@@ -503,7 +505,7 @@ bool VisitedLinkMaster::DeleteFingerprint(Fingerprint fingerprint,
if (!shuffled_fingerprints->empty()) {
// Need to add the new items back.
for (size_t i = 0; i < shuffled_fingerprints->size(); i++)
- AddFingerprint(shuffled_fingerprints[i]);
+ AddFingerprint(shuffled_fingerprints[i], false);
}
// Write the affected range to disk [deleted_hash, end_range].
@@ -804,7 +806,7 @@ void VisitedLinkMaster::ResizeTable(int32 new_size) {
for (int32 i = 0; i < old_table_length; i++) {
Fingerprint cur = old_hash_table[i];
if (cur)
- AddFingerprint(cur);
+ AddFingerprint(cur, false);
}
// On error unmapping, just forget about it since we can't do anything
@@ -902,13 +904,13 @@ void VisitedLinkMaster::OnTableRebuildComplete(
// Add the stored fingerprints to the hash table.
for (size_t i = 0; i < fingerprints.size(); i++)
- AddFingerprint(fingerprints[i]);
+ AddFingerprint(fingerprints[i], false);
// Also add anything that was added while we were asynchronously
// generating the new table.
for (std::set<Fingerprint>::iterator i = added_since_rebuild_.begin();
i != added_since_rebuild_.end(); ++i)
- AddFingerprint(*i);
+ AddFingerprint(*i, false);
added_since_rebuild_.clear();
// Now handle deletions.
diff --git a/chrome/browser/visitedlink_master.h b/chrome/browser/visitedlink_master.h
index ad7be42..a07a1f7 100644
--- a/chrome/browser/visitedlink_master.h
+++ b/chrome/browser/visitedlink_master.h
@@ -220,10 +220,11 @@ class VisitedLinkMaster : public VisitedLinkCommon {
// General table handling
// ----------------------
- // Called to add a fingerprint to the table. Returns the index of the
- // inserted fingerprint or null_hash_ if there was a duplicate and this item
- // was skippped.
- Hash AddFingerprint(Fingerprint fingerprint);
+ // Called to add a fingerprint to the table. If |send_notifications| is true
+ // and the item is added successfully, Listener::Add will be invoked.
+ // Returns the index of the inserted fingerprint or null_hash_ if there was a
+ // duplicate and this item was skippped.
+ Hash AddFingerprint(Fingerprint fingerprint, bool send_notifications);
// Deletes all fingerprints from the given vector from the current hash table
// and syncs it to disk if there are changes. This does not update the
diff --git a/chrome/browser/visitedlink_unittest.cc b/chrome/browser/visitedlink_unittest.cc
index 45e620a..43be8e8 100644
--- a/chrome/browser/visitedlink_unittest.cc
+++ b/chrome/browser/visitedlink_unittest.cc
@@ -206,11 +206,11 @@ TEST_F(VisitedLinkTest, Delete) {
const VisitedLinkCommon::Fingerprint kFingerprint2 = kInitialSize * 2 + 14;
const VisitedLinkCommon::Fingerprint kFingerprint3 = kInitialSize * 3 + 14;
const VisitedLinkCommon::Fingerprint kFingerprint4 = kInitialSize * 4 + 14;
- master_->AddFingerprint(kFingerprint0); // @14
- master_->AddFingerprint(kFingerprint1); // @15
- master_->AddFingerprint(kFingerprint2); // @16
- master_->AddFingerprint(kFingerprint3); // @0
- master_->AddFingerprint(kFingerprint4); // @1
+ master_->AddFingerprint(kFingerprint0, false); // @14
+ master_->AddFingerprint(kFingerprint1, false); // @15
+ master_->AddFingerprint(kFingerprint2, false); // @16
+ master_->AddFingerprint(kFingerprint3, false); // @0
+ master_->AddFingerprint(kFingerprint4, false); // @1
// Deleting 14 should move the next value up one slot (we do not specify an
// order).