| 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 #ifndef CHROME_COMMON_VISITEDLINK_COMMON_H__ | 5 #ifndef CHROME_COMMON_VISITEDLINK_COMMON_H__ | 
| 6 #define CHROME_COMMON_VISITEDLINK_COMMON_H__ | 6 #define CHROME_COMMON_VISITEDLINK_COMMON_H__ | 
| 7 | 7 | 
| 8 #include <string> | 8 #include <string> | 
| 9 | 9 | 
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 48   // A hash value of a fingerprint | 48   // A hash value of a fingerprint | 
| 49   typedef int32 Hash; | 49   typedef int32 Hash; | 
| 50 | 50 | 
| 51   // A fingerprint or hash value that does not exist | 51   // A fingerprint or hash value that does not exist | 
| 52   static const Fingerprint null_fingerprint_; | 52   static const Fingerprint null_fingerprint_; | 
| 53   static const Hash null_hash_; | 53   static const Hash null_hash_; | 
| 54 | 54 | 
| 55   VisitedLinkCommon(); | 55   VisitedLinkCommon(); | 
| 56   virtual ~VisitedLinkCommon(); | 56   virtual ~VisitedLinkCommon(); | 
| 57 | 57 | 
| 58   // Computes the fingerprint of the key and looks it up in the table. We | 58   // Returns the fingerprint for the given URL. | 
| 59   // return true if found. Does not modify the hastable. The input should be | 59   Fingerprint ComputeURLFingerprint(const char* canonical_url, | 
| 60   // the canonical 16-bit URL. | 60                                     size_t url_len) const { | 
|  | 61     return ComputeURLFingerprint(canonical_url, url_len, salt_); | 
|  | 62   } | 
|  | 63 | 
|  | 64   // Looks up the given key in the table. The fingerprint for the URL is | 
|  | 65   // computed if you call one with the string argument. Returns true if found. | 
|  | 66   // Does not modify the hastable. | 
| 61   bool IsVisited(const char* canonical_url, size_t url_len) const; | 67   bool IsVisited(const char* canonical_url, size_t url_len) const; | 
| 62   bool IsVisited(const GURL& url) const { | 68   bool IsVisited(const GURL& url) const { | 
| 63     return IsVisited(url.spec().data(), url.spec().size()); | 69     return IsVisited(url.spec().data(), url.spec().size()); | 
| 64   } | 70   } | 
|  | 71   bool IsVisited(Fingerprint fingerprint) const; | 
| 65 | 72 | 
| 66 #ifdef UNIT_TEST | 73 #ifdef UNIT_TEST | 
| 67   // Returns statistics about DB usage | 74   // Returns statistics about DB usage | 
| 68   void GetUsageStatistics(int32* table_size, | 75   void GetUsageStatistics(int32* table_size, | 
| 69                           VisitedLinkCommon::Fingerprint** fingerprints) { | 76                           VisitedLinkCommon::Fingerprint** fingerprints) { | 
| 70     *table_size = table_length_; | 77     *table_size = table_length_; | 
| 71     *fingerprints = hash_table_; | 78     *fingerprints = hash_table_; | 
| 72   } | 79   } | 
| 73 #endif | 80 #endif | 
| 74 | 81 | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 86   // Returns the fingerprint at the given index into the URL table. This | 93   // Returns the fingerprint at the given index into the URL table. This | 
| 87   // function should be called instead of accessing the table directly to contai
     n | 94   // function should be called instead of accessing the table directly to contai
     n | 
| 88   // endian issues. | 95   // endian issues. | 
| 89   Fingerprint FingerprintAt(int32 table_offset) const { | 96   Fingerprint FingerprintAt(int32 table_offset) const { | 
| 90     DCHECK(hash_table_); | 97     DCHECK(hash_table_); | 
| 91     if (!hash_table_) | 98     if (!hash_table_) | 
| 92       return 0; | 99       return 0; | 
| 93     return hash_table_[table_offset]; | 100     return hash_table_[table_offset]; | 
| 94   } | 101   } | 
| 95 | 102 | 
| 96   // Returns true if the given fingerprint is in the table. |  | 
| 97   bool IsVisited(Fingerprint fingerprint) const; |  | 
| 98 |  | 
| 99   // Computes the fingerprint of the given canonical URL. It is static so the | 103   // Computes the fingerprint of the given canonical URL. It is static so the | 
| 100   // same algorithm can be re-used by the table rebuilder, so you will have to | 104   // same algorithm can be re-used by the table rebuilder, so you will have to | 
| 101   // pass the salt as a parameter. | 105   // pass the salt as a parameter. See the non-static version above if you | 
|  | 106   // want to use the current class' salt. | 
| 102   static Fingerprint ComputeURLFingerprint(const char* canonical_url, | 107   static Fingerprint ComputeURLFingerprint(const char* canonical_url, | 
| 103                                            size_t url_len, | 108                                            size_t url_len, | 
| 104                                            const uint8 salt[LINK_SALT_LENGTH]); | 109                                            const uint8 salt[LINK_SALT_LENGTH]); | 
| 105 | 110 | 
| 106   // Computes the hash value of the given fingerprint, this is used as a lookup | 111   // Computes the hash value of the given fingerprint, this is used as a lookup | 
| 107   // into the hashtable. | 112   // into the hashtable. | 
| 108   static Hash HashFingerprint(Fingerprint fingerprint, int32 table_length) { | 113   static Hash HashFingerprint(Fingerprint fingerprint, int32 table_length) { | 
| 109     return static_cast<Hash>(fingerprint % table_length); | 114     return static_cast<Hash>(fingerprint % table_length); | 
| 110   } | 115   } | 
| 111   Hash HashFingerprint(Fingerprint fingerprint) const { // uses the current hash
     table | 116   Hash HashFingerprint(Fingerprint fingerprint) const { // uses the current hash
     table | 
| 112     return HashFingerprint(fingerprint, table_length_); | 117     return HashFingerprint(fingerprint, table_length_); | 
| 113   } | 118   } | 
| 114 | 119 | 
| 115   // pointer to the first item | 120   // pointer to the first item | 
| 116   VisitedLinkCommon::Fingerprint* hash_table_; | 121   VisitedLinkCommon::Fingerprint* hash_table_; | 
| 117 | 122 | 
| 118   // the number of items in the hash table | 123   // the number of items in the hash table | 
| 119   int32 table_length_; | 124   int32 table_length_; | 
| 120 | 125 | 
| 121   // salt used for each URL when computing the fingerprint | 126   // salt used for each URL when computing the fingerprint | 
| 122   uint8 salt_[LINK_SALT_LENGTH]; | 127   uint8 salt_[LINK_SALT_LENGTH]; | 
| 123 | 128 | 
| 124  private: | 129  private: | 
| 125   DISALLOW_EVIL_CONSTRUCTORS(VisitedLinkCommon); | 130   DISALLOW_EVIL_CONSTRUCTORS(VisitedLinkCommon); | 
| 126 }; | 131 }; | 
| 127 | 132 | 
| 128 #endif // WIN_COMMON_VISITEDLINK_COMMON_H__ | 133 #endif // WIN_COMMON_VISITEDLINK_COMMON_H__ | 
| 129 | 134 | 
| OLD | NEW | 
|---|