| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/visitedlink_master.h" | 5 #include "chrome/browser/visitedlink/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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 memset(hash_table_, 0, this->table_length_ * sizeof(Fingerprint)); | 282 memset(hash_table_, 0, this->table_length_ * sizeof(Fingerprint)); |
| 283 | 283 |
| 284 // Resize it if it is now too empty. Resize may write the new table out for | 284 // Resize it if it is now too empty. Resize may write the new table out for |
| 285 // us, otherwise, schedule writing the new table to disk ourselves. | 285 // us, otherwise, schedule writing the new table to disk ourselves. |
| 286 if (!ResizeTableIfNecessary()) | 286 if (!ResizeTableIfNecessary()) |
| 287 WriteFullTable(); | 287 WriteFullTable(); |
| 288 | 288 |
| 289 listener_->Reset(); | 289 listener_->Reset(); |
| 290 } | 290 } |
| 291 | 291 |
| 292 void VisitedLinkMaster::DeleteURLs(const history::URLRows& rows) { | 292 void VisitedLinkMaster::DeleteURLs(const std::set<GURL>& urls) { |
| 293 typedef std::set<GURL>::const_iterator SetIterator; | 293 typedef std::set<GURL>::const_iterator SetIterator; |
| 294 | 294 |
| 295 if (rows.empty()) | 295 if (urls.empty()) |
| 296 return; | 296 return; |
| 297 | 297 |
| 298 listener_->Reset(); | 298 listener_->Reset(); |
| 299 | 299 |
| 300 if (table_builder_) { | 300 if (table_builder_) { |
| 301 // A rebuild is in progress, save this deletion in the temporary list so | 301 // A rebuild is in progress, save this deletion in the temporary list so |
| 302 // it can be added once rebuild is complete. | 302 // it can be added once rebuild is complete. |
| 303 for (history::URLRows::const_iterator i = rows.begin(); i != rows.end(); | 303 for (SetIterator i = urls.begin(); i != urls.end(); ++i) { |
| 304 ++i) { | 304 if (!i->is_valid()) |
| 305 const GURL& url(i->url()); | |
| 306 if (!url.is_valid()) | |
| 307 continue; | 305 continue; |
| 308 | 306 |
| 309 Fingerprint fingerprint = | 307 Fingerprint fingerprint = |
| 310 ComputeURLFingerprint(url.spec().data(), url.spec().size(), salt_); | 308 ComputeURLFingerprint(i->spec().data(), i->spec().size(), salt_); |
| 311 deleted_since_rebuild_.insert(fingerprint); | 309 deleted_since_rebuild_.insert(fingerprint); |
| 312 | 310 |
| 313 // If the URL was just added and now we're deleting it, it may be in the | 311 // If the URL was just added and now we're deleting it, it may be in the |
| 314 // list of things added since the last rebuild. Delete it from that list. | 312 // list of things added since the last rebuild. Delete it from that list. |
| 315 std::set<Fingerprint>::iterator found = | 313 std::set<Fingerprint>::iterator found = |
| 316 added_since_rebuild_.find(fingerprint); | 314 added_since_rebuild_.find(fingerprint); |
| 317 if (found != added_since_rebuild_.end()) | 315 if (found != added_since_rebuild_.end()) |
| 318 added_since_rebuild_.erase(found); | 316 added_since_rebuild_.erase(found); |
| 319 | 317 |
| 320 // Delete the URLs from the in-memory table, but don't bother writing | 318 // Delete the URLs from the in-memory table, but don't bother writing |
| 321 // to disk since it will be replaced soon. | 319 // to disk since it will be replaced soon. |
| 322 DeleteFingerprint(fingerprint, false); | 320 DeleteFingerprint(fingerprint, false); |
| 323 } | 321 } |
| 324 return; | 322 return; |
| 325 } | 323 } |
| 326 | 324 |
| 327 // Compute the deleted URLs' fingerprints and delete them | 325 // Compute the deleted URLs' fingerprints and delete them |
| 328 std::set<Fingerprint> deleted_fingerprints; | 326 std::set<Fingerprint> deleted_fingerprints; |
| 329 for (history::URLRows::const_iterator i = rows.begin(); i != rows.end(); | 327 for (SetIterator i = urls.begin(); i != urls.end(); ++i) { |
| 330 ++i) { | 328 if (!i->is_valid()) |
| 331 const GURL& url(i->url()); | |
| 332 if (!url.is_valid()) | |
| 333 continue; | 329 continue; |
| 334 deleted_fingerprints.insert( | 330 deleted_fingerprints.insert( |
| 335 ComputeURLFingerprint(url.spec().data(), url.spec().size(), salt_)); | 331 ComputeURLFingerprint(i->spec().data(), i->spec().size(), salt_)); |
| 336 } | 332 } |
| 337 DeleteFingerprintsFromCurrentTable(deleted_fingerprints); | 333 DeleteFingerprintsFromCurrentTable(deleted_fingerprints); |
| 338 } | 334 } |
| 339 | 335 |
| 340 // See VisitedLinkCommon::IsVisited which should be in sync with this algorithm | 336 // See VisitedLinkCommon::IsVisited which should be in sync with this algorithm |
| 341 VisitedLinkMaster::Hash VisitedLinkMaster::AddFingerprint( | 337 VisitedLinkMaster::Hash VisitedLinkMaster::AddFingerprint( |
| 342 Fingerprint fingerprint, | 338 Fingerprint fingerprint, |
| 343 bool send_notifications) { | 339 bool send_notifications) { |
| 344 if (!hash_table_ || table_length_ == 0) { | 340 if (!hash_table_ || table_length_ == 0) { |
| 345 NOTREACHED(); // Not initialized. | 341 NOTREACHED(); // Not initialized. |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 } | 944 } |
| 949 | 945 |
| 950 void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() { | 946 void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() { |
| 951 if (master_) | 947 if (master_) |
| 952 master_->OnTableRebuildComplete(success_, fingerprints_); | 948 master_->OnTableRebuildComplete(success_, fingerprints_); |
| 953 | 949 |
| 954 // WILL (generally) DELETE THIS! This balances the AddRef in | 950 // WILL (generally) DELETE THIS! This balances the AddRef in |
| 955 // VisitedLinkMaster::RebuildTableFromHistory. | 951 // VisitedLinkMaster::RebuildTableFromHistory. |
| 956 Release(); | 952 Release(); |
| 957 } | 953 } |
| OLD | NEW |