| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 18 matching lines...) Expand all Loading... |
| 29 using file_util::ScopedFILE; | 29 using file_util::ScopedFILE; |
| 30 using file_util::OpenFile; | 30 using file_util::OpenFile; |
| 31 using file_util::TruncateFile; | 31 using file_util::TruncateFile; |
| 32 | 32 |
| 33 const int32 VisitedLinkMaster::kFileHeaderSignatureOffset = 0; | 33 const int32 VisitedLinkMaster::kFileHeaderSignatureOffset = 0; |
| 34 const int32 VisitedLinkMaster::kFileHeaderVersionOffset = 4; | 34 const int32 VisitedLinkMaster::kFileHeaderVersionOffset = 4; |
| 35 const int32 VisitedLinkMaster::kFileHeaderLengthOffset = 8; | 35 const int32 VisitedLinkMaster::kFileHeaderLengthOffset = 8; |
| 36 const int32 VisitedLinkMaster::kFileHeaderUsedOffset = 12; | 36 const int32 VisitedLinkMaster::kFileHeaderUsedOffset = 12; |
| 37 const int32 VisitedLinkMaster::kFileHeaderSaltOffset = 16; | 37 const int32 VisitedLinkMaster::kFileHeaderSaltOffset = 16; |
| 38 | 38 |
| 39 const int32 VisitedLinkMaster::kFileCurrentVersion = 2; | 39 const int32 VisitedLinkMaster::kFileCurrentVersion = 3; |
| 40 | 40 |
| 41 // the signature at the beginning of the URL table = "VLnk" (visited links) | 41 // the signature at the beginning of the URL table = "VLnk" (visited links) |
| 42 const int32 VisitedLinkMaster::kFileSignature = 0x6b6e4c56; | 42 const int32 VisitedLinkMaster::kFileSignature = 0x6b6e4c56; |
| 43 const size_t VisitedLinkMaster::kFileHeaderSize = | 43 const size_t VisitedLinkMaster::kFileHeaderSize = |
| 44 kFileHeaderSaltOffset + LINK_SALT_LENGTH; | 44 kFileHeaderSaltOffset + LINK_SALT_LENGTH; |
| 45 | 45 |
| 46 // This value should also be the same as the smallest size in the lookup | 46 // This value should also be the same as the smallest size in the lookup |
| 47 // table in NewTableSizeForCount (prime number). | 47 // table in NewTableSizeForCount (prime number). |
| 48 const unsigned VisitedLinkMaster::kDefaultTableSize = 16381; | 48 const unsigned VisitedLinkMaster::kDefaultTableSize = 16381; |
| 49 | 49 |
| (...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 for (size_t i = 0; i < fingerprints.size(); i++) | 872 for (size_t i = 0; i < fingerprints.size(); i++) |
| 873 AddFingerprint(fingerprints[i], false); | 873 AddFingerprint(fingerprints[i], false); |
| 874 | 874 |
| 875 // Also add anything that was added while we were asynchronously | 875 // Also add anything that was added while we were asynchronously |
| 876 // generating the new table. | 876 // generating the new table. |
| 877 for (std::set<Fingerprint>::iterator i = added_since_rebuild_.begin(); | 877 for (std::set<Fingerprint>::iterator i = added_since_rebuild_.begin(); |
| 878 i != added_since_rebuild_.end(); ++i) | 878 i != added_since_rebuild_.end(); ++i) |
| 879 AddFingerprint(*i, false); | 879 AddFingerprint(*i, false); |
| 880 added_since_rebuild_.clear(); | 880 added_since_rebuild_.clear(); |
| 881 | 881 |
| 882 // We shouldn't be writing the table from the main thread! |
| 883 // http://code.google.com/p/chromium/issues/detail?id=24163 |
| 884 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 885 |
| 882 // Now handle deletions. | 886 // Now handle deletions. |
| 883 DeleteFingerprintsFromCurrentTable(deleted_since_rebuild_); | 887 DeleteFingerprintsFromCurrentTable(deleted_since_rebuild_); |
| 884 deleted_since_rebuild_.clear(); | 888 deleted_since_rebuild_.clear(); |
| 885 | 889 |
| 886 // Send an update notification to all child processes. | 890 // Send an update notification to all child processes. |
| 887 listener_->NewTable(shared_memory_); | 891 listener_->NewTable(shared_memory_); |
| 888 | 892 |
| 889 // We shouldn't be writing the table from the main thread! | |
| 890 // http://code.google.com/p/chromium/issues/detail?id=24163 | |
| 891 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
| 892 WriteFullTable(); | 893 WriteFullTable(); |
| 893 } | 894 } |
| 894 } | 895 } |
| 895 table_builder_ = NULL; // Will release our reference to the builder. | 896 table_builder_ = NULL; // Will release our reference to the builder. |
| 896 | 897 |
| 897 // Notify the unit test that the rebuild is complete (will be NULL in prod.) | 898 // Notify the unit test that the rebuild is complete (will be NULL in prod.) |
| 898 if (rebuild_complete_task_.get()) { | 899 if (rebuild_complete_task_.get()) { |
| 899 rebuild_complete_task_->Run(); | 900 rebuild_complete_task_->Run(); |
| 900 rebuild_complete_task_.reset(NULL); | 901 rebuild_complete_task_.reset(NULL); |
| 901 } | 902 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 } | 959 } |
| 959 | 960 |
| 960 // VisitedLinkTableBuilder ---------------------------------------------------- | 961 // VisitedLinkTableBuilder ---------------------------------------------------- |
| 961 | 962 |
| 962 VisitedLinkMaster::TableBuilder::TableBuilder( | 963 VisitedLinkMaster::TableBuilder::TableBuilder( |
| 963 VisitedLinkMaster* master, | 964 VisitedLinkMaster* master, |
| 964 const uint8 salt[LINK_SALT_LENGTH]) | 965 const uint8 salt[LINK_SALT_LENGTH]) |
| 965 : master_(master), | 966 : master_(master), |
| 966 success_(true) { | 967 success_(true) { |
| 967 fingerprints_.reserve(4096); | 968 fingerprints_.reserve(4096); |
| 968 memcpy(salt_, salt, sizeof(salt)); | 969 memcpy(salt_, salt, LINK_SALT_LENGTH * sizeof(uint8)); |
| 969 } | 970 } |
| 970 | 971 |
| 971 // TODO(brettw): Do we want to try to cancel the request if this happens? It | 972 // TODO(brettw): Do we want to try to cancel the request if this happens? It |
| 972 // could delay shutdown if there are a lot of URLs. | 973 // could delay shutdown if there are a lot of URLs. |
| 973 void VisitedLinkMaster::TableBuilder::DisownMaster() { | 974 void VisitedLinkMaster::TableBuilder::DisownMaster() { |
| 974 master_ = NULL; | 975 master_ = NULL; |
| 975 } | 976 } |
| 976 | 977 |
| 977 void VisitedLinkMaster::TableBuilder::OnURL(const GURL& url) { | 978 void VisitedLinkMaster::TableBuilder::OnURL(const GURL& url) { |
| 978 if (!url.is_empty()) { | 979 if (!url.is_empty()) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 993 } | 994 } |
| 994 | 995 |
| 995 void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() { | 996 void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() { |
| 996 if (master_) | 997 if (master_) |
| 997 master_->OnTableRebuildComplete(success_, fingerprints_); | 998 master_->OnTableRebuildComplete(success_, fingerprints_); |
| 998 | 999 |
| 999 // WILL (generally) DELETE THIS! This balances the AddRef in | 1000 // WILL (generally) DELETE THIS! This balances the AddRef in |
| 1000 // VisitedLinkMaster::RebuildTableFromHistory. | 1001 // VisitedLinkMaster::RebuildTableFromHistory. |
| 1001 Release(); | 1002 Release(); |
| 1002 } | 1003 } |
| OLD | NEW |