| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/common/visitedlink_common.h" | 5 #include "chrome/common/visitedlink_common.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/md5.h" | 8 #include "base/md5.h" |
| 9 | 9 |
| 10 const VisitedLinkCommon::Fingerprint VisitedLinkCommon::null_fingerprint_ = 0; | 10 const VisitedLinkCommon::Fingerprint VisitedLinkCommon::null_fingerprint_ = 0; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // probing or something better. See VisitedLinkMaster::AddFingerprint | 22 // probing or something better. See VisitedLinkMaster::AddFingerprint |
| 23 bool VisitedLinkCommon::IsVisited(const char* canonical_url, | 23 bool VisitedLinkCommon::IsVisited(const char* canonical_url, |
| 24 size_t url_len) const { | 24 size_t url_len) const { |
| 25 if (url_len == 0) | 25 if (url_len == 0) |
| 26 return false; | 26 return false; |
| 27 if (!hash_table_ || table_length_ == 0) { | 27 if (!hash_table_ || table_length_ == 0) { |
| 28 // Init() will always create a table, this means somebody forgot | 28 // Init() will always create a table, this means somebody forgot |
| 29 NOTREACHED(); | 29 NOTREACHED(); |
| 30 return false; | 30 return false; |
| 31 } | 31 } |
| 32 return IsVisited(ComputeURLFingerprint(canonical_url, url_len, salt_)); | 32 return IsVisited(ComputeURLFingerprint(canonical_url, url_len)); |
| 33 } | 33 } |
| 34 | 34 |
| 35 bool VisitedLinkCommon::IsVisited(Fingerprint fingerprint) const { | 35 bool VisitedLinkCommon::IsVisited(Fingerprint fingerprint) const { |
| 36 // Go through the table until we find the item or an empty spot (meaning it | 36 // Go through the table until we find the item or an empty spot (meaning it |
| 37 // wasn't found). This loop will terminate as long as the table isn't full, | 37 // wasn't found). This loop will terminate as long as the table isn't full, |
| 38 // which should be enforced by AddFingerprint. | 38 // which should be enforced by AddFingerprint. |
| 39 Hash first_hash = HashFingerprint(fingerprint); | 39 Hash first_hash = HashFingerprint(fingerprint); |
| 40 Hash cur_hash = first_hash; | 40 Hash cur_hash = first_hash; |
| 41 while (true) { | 41 while (true) { |
| 42 Fingerprint cur_fingerprint = FingerprintAt(cur_hash); | 42 Fingerprint cur_fingerprint = FingerprintAt(cur_hash); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 MD5Final(&digest, &ctx); | 83 MD5Final(&digest, &ctx); |
| 84 | 84 |
| 85 // This is the same as "return *(Fingerprint*)&digest.a;" but if we do that | 85 // This is the same as "return *(Fingerprint*)&digest.a;" but if we do that |
| 86 // direct cast the alignment could be wrong, and we can't access a 64-bit int | 86 // direct cast the alignment could be wrong, and we can't access a 64-bit int |
| 87 // on arbitrary alignment on some processors. This reinterpret_casts it | 87 // on arbitrary alignment on some processors. This reinterpret_casts it |
| 88 // down to a char array of the same size as fingerprint, and then does the | 88 // down to a char array of the same size as fingerprint, and then does the |
| 89 // bit cast, which amounts to a memcpy. This does not handle endian issues. | 89 // bit cast, which amounts to a memcpy. This does not handle endian issues. |
| 90 return bit_cast<Fingerprint, uint8[8]>( | 90 return bit_cast<Fingerprint, uint8[8]>( |
| 91 *reinterpret_cast<uint8(*)[8]>(&digest.a)); | 91 *reinterpret_cast<uint8(*)[8]>(&digest.a)); |
| 92 } | 92 } |
| OLD | NEW |