OLD | NEW |
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 #include "components/visitedlink/browser/visitedlink_master.h" | 5 #include "components/visitedlink/browser/visitedlink_master.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <utility> | 10 #include <utility> |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 DCHECK(persist_to_disk_); | 355 DCHECK(persist_to_disk_); |
356 BrowserThread::GetBlockingPool()->PostSequencedWorkerTask(sequence_token_, | 356 BrowserThread::GetBlockingPool()->PostSequencedWorkerTask(sequence_token_, |
357 from_here, task); | 357 from_here, task); |
358 } | 358 } |
359 | 359 |
360 void VisitedLinkMaster::AddURL(const GURL& url) { | 360 void VisitedLinkMaster::AddURL(const GURL& url) { |
361 Hash index = TryToAddURL(url); | 361 Hash index = TryToAddURL(url); |
362 if (!table_builder_.get() && | 362 if (!table_builder_.get() && |
363 !table_is_loading_from_file_ && | 363 !table_is_loading_from_file_ && |
364 index != null_hash_) { | 364 index != null_hash_) { |
365 // Not rebuilding, so we want to keep the file on disk up-to-date. | 365 // Not rebuilding, so we want to keep the file on disk up to date. |
366 if (persist_to_disk_) { | 366 if (persist_to_disk_) { |
367 WriteUsedItemCountToFile(); | 367 WriteUsedItemCountToFile(); |
368 WriteHashRangeToFile(index, index); | 368 WriteHashRangeToFile(index, index); |
369 } | 369 } |
370 ResizeTableIfNecessary(); | 370 ResizeTableIfNecessary(); |
371 } | 371 } |
372 } | 372 } |
373 | 373 |
374 void VisitedLinkMaster::AddURLs(const std::vector<GURL>& urls) { | 374 void VisitedLinkMaster::AddURLs(const std::vector<GURL>& urls) { |
375 for (const GURL& url : urls) { | 375 for (const GURL& url : urls) { |
376 Hash index = TryToAddURL(url); | 376 Hash index = TryToAddURL(url); |
377 if (!table_builder_.get() && | 377 if (!table_builder_.get() && |
378 !table_is_loading_from_file_ && | 378 !table_is_loading_from_file_ && |
379 index != null_hash_) | 379 index != null_hash_) |
380 ResizeTableIfNecessary(); | 380 ResizeTableIfNecessary(); |
381 } | 381 } |
382 | 382 |
383 // Keeps the file on disk up-to-date. | 383 // Keeps the file on disk up to date. |
384 if (!table_builder_.get() && | 384 if (!table_builder_.get() && |
385 !table_is_loading_from_file_ && | 385 !table_is_loading_from_file_ && |
386 persist_to_disk_) | 386 persist_to_disk_) |
387 WriteFullTable(); | 387 WriteFullTable(); |
388 } | 388 } |
389 | 389 |
390 void VisitedLinkMaster::DeleteAllURLs() { | 390 void VisitedLinkMaster::DeleteAllURLs() { |
391 // Any pending modifications are invalid. | 391 // Any pending modifications are invalid. |
392 added_since_rebuild_.clear(); | 392 added_since_rebuild_.clear(); |
393 deleted_since_rebuild_.clear(); | 393 deleted_since_rebuild_.clear(); |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 uint8_t header[kFileHeaderSize]; | 809 uint8_t header[kFileHeaderSize]; |
810 if (!ReadFromFile(file, 0, &header, kFileHeaderSize)) | 810 if (!ReadFromFile(file, 0, &header, kFileHeaderSize)) |
811 return false; | 811 return false; |
812 | 812 |
813 // Verify the signature. | 813 // Verify the signature. |
814 int32_t signature; | 814 int32_t signature; |
815 memcpy(&signature, &header[kFileHeaderSignatureOffset], sizeof(signature)); | 815 memcpy(&signature, &header[kFileHeaderSignatureOffset], sizeof(signature)); |
816 if (signature != kFileSignature) | 816 if (signature != kFileSignature) |
817 return false; | 817 return false; |
818 | 818 |
819 // Verify the version is up-to-date. As with other read errors, a version | 819 // Verify the version is up to date. As with other read errors, a version |
820 // mistmatch will trigger a rebuild of the database from history, which will | 820 // mistmatch will trigger a rebuild of the database from history, which will |
821 // have the effect of migrating the database. | 821 // have the effect of migrating the database. |
822 int32_t version; | 822 int32_t version; |
823 memcpy(&version, &header[kFileHeaderVersionOffset], sizeof(version)); | 823 memcpy(&version, &header[kFileHeaderVersionOffset], sizeof(version)); |
824 if (version != kFileCurrentVersion) | 824 if (version != kFileCurrentVersion) |
825 return false; // Bad version. | 825 return false; // Bad version. |
826 | 826 |
827 // Read the table size and make sure it matches the file size. | 827 // Read the table size and make sure it matches the file size. |
828 memcpy(num_entries, &header[kFileHeaderLengthOffset], sizeof(*num_entries)); | 828 memcpy(num_entries, &header[kFileHeaderLengthOffset], sizeof(*num_entries)); |
829 if (*num_entries * sizeof(Fingerprint) + kFileHeaderSize != file_size) | 829 if (*num_entries * sizeof(Fingerprint) + kFileHeaderSize != file_size) |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 BrowserThread::UI, FROM_HERE, | 1195 BrowserThread::UI, FROM_HERE, |
1196 base::Bind(&TableBuilder::OnCompleteMainThread, this)); | 1196 base::Bind(&TableBuilder::OnCompleteMainThread, this)); |
1197 } | 1197 } |
1198 | 1198 |
1199 void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() { | 1199 void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() { |
1200 if (master_) | 1200 if (master_) |
1201 master_->OnTableRebuildComplete(success_, fingerprints_); | 1201 master_->OnTableRebuildComplete(success_, fingerprints_); |
1202 } | 1202 } |
1203 | 1203 |
1204 } // namespace visitedlink | 1204 } // namespace visitedlink |
OLD | NEW |