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 std::set<GURL>& urls) { | 292 void VisitedLinkMaster::DeleteURLs(const history::URLRows& rows) { |
293 typedef std::set<GURL>::const_iterator SetIterator; | 293 typedef std::set<GURL>::const_iterator SetIterator; |
294 | 294 |
295 if (urls.empty()) | 295 if (rows.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 (SetIterator i = urls.begin(); i != urls.end(); ++i) { | 303 for (history::URLRows::const_iterator i = rows.begin(); i != rows.end(); |
304 if (!i->is_valid()) | 304 ++i) { |
| 305 const GURL& url(i->url()); |
| 306 if (!url.is_valid()) |
305 continue; | 307 continue; |
306 | 308 |
307 Fingerprint fingerprint = | 309 Fingerprint fingerprint = |
308 ComputeURLFingerprint(i->spec().data(), i->spec().size(), salt_); | 310 ComputeURLFingerprint(url.spec().data(), url.spec().size(), salt_); |
309 deleted_since_rebuild_.insert(fingerprint); | 311 deleted_since_rebuild_.insert(fingerprint); |
310 | 312 |
311 // If the URL was just added and now we're deleting it, it may be in the | 313 // If the URL was just added and now we're deleting it, it may be in the |
312 // list of things added since the last rebuild. Delete it from that list. | 314 // list of things added since the last rebuild. Delete it from that list. |
313 std::set<Fingerprint>::iterator found = | 315 std::set<Fingerprint>::iterator found = |
314 added_since_rebuild_.find(fingerprint); | 316 added_since_rebuild_.find(fingerprint); |
315 if (found != added_since_rebuild_.end()) | 317 if (found != added_since_rebuild_.end()) |
316 added_since_rebuild_.erase(found); | 318 added_since_rebuild_.erase(found); |
317 | 319 |
318 // Delete the URLs from the in-memory table, but don't bother writing | 320 // Delete the URLs from the in-memory table, but don't bother writing |
319 // to disk since it will be replaced soon. | 321 // to disk since it will be replaced soon. |
320 DeleteFingerprint(fingerprint, false); | 322 DeleteFingerprint(fingerprint, false); |
321 } | 323 } |
322 return; | 324 return; |
323 } | 325 } |
324 | 326 |
325 // Compute the deleted URLs' fingerprints and delete them | 327 // Compute the deleted URLs' fingerprints and delete them |
326 std::set<Fingerprint> deleted_fingerprints; | 328 std::set<Fingerprint> deleted_fingerprints; |
327 for (SetIterator i = urls.begin(); i != urls.end(); ++i) { | 329 for (history::URLRows::const_iterator i = rows.begin(); i != rows.end(); |
328 if (!i->is_valid()) | 330 ++i) { |
| 331 const GURL& url(i->url()); |
| 332 if (!url.is_valid()) |
329 continue; | 333 continue; |
330 deleted_fingerprints.insert( | 334 deleted_fingerprints.insert( |
331 ComputeURLFingerprint(i->spec().data(), i->spec().size(), salt_)); | 335 ComputeURLFingerprint(url.spec().data(), url.spec().size(), salt_)); |
332 } | 336 } |
333 DeleteFingerprintsFromCurrentTable(deleted_fingerprints); | 337 DeleteFingerprintsFromCurrentTable(deleted_fingerprints); |
334 } | 338 } |
335 | 339 |
336 // See VisitedLinkCommon::IsVisited which should be in sync with this algorithm | 340 // See VisitedLinkCommon::IsVisited which should be in sync with this algorithm |
337 VisitedLinkMaster::Hash VisitedLinkMaster::AddFingerprint( | 341 VisitedLinkMaster::Hash VisitedLinkMaster::AddFingerprint( |
338 Fingerprint fingerprint, | 342 Fingerprint fingerprint, |
339 bool send_notifications) { | 343 bool send_notifications) { |
340 if (!hash_table_ || table_length_ == 0) { | 344 if (!hash_table_ || table_length_ == 0) { |
341 NOTREACHED(); // Not initialized. | 345 NOTREACHED(); // Not initialized. |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 } | 948 } |
945 | 949 |
946 void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() { | 950 void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() { |
947 if (master_) | 951 if (master_) |
948 master_->OnTableRebuildComplete(success_, fingerprints_); | 952 master_->OnTableRebuildComplete(success_, fingerprints_); |
949 | 953 |
950 // WILL (generally) DELETE THIS! This balances the AddRef in | 954 // WILL (generally) DELETE THIS! This balances the AddRef in |
951 // VisitedLinkMaster::RebuildTableFromHistory. | 955 // VisitedLinkMaster::RebuildTableFromHistory. |
952 Release(); | 956 Release(); |
953 } | 957 } |
OLD | NEW |