Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1403)

Side by Side Diff: chrome/common/visitedlink_common.cc

Issue 42114: Don't leak visited site information from original profile to OTR profile.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/visitedlink_common.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
11 const VisitedLinkCommon::Hash VisitedLinkCommon::null_hash_ = -1; 11 const VisitedLinkCommon::Hash VisitedLinkCommon::null_hash_ = -1;
12 12
13 VisitedLinkCommon::VisitedLinkCommon() : 13 VisitedLinkCommon::VisitedLinkCommon() :
14 hash_table_(NULL), 14 hash_table_(NULL),
15 table_length_(0) { 15 table_length_(0) {
16 } 16 }
17 17
18 VisitedLinkCommon::~VisitedLinkCommon() { 18 VisitedLinkCommon::~VisitedLinkCommon() {
19 } 19 }
20 20
21 // FIXME: this uses linear probing, it should be replaced with quadratic 21 // FIXME: this uses linear probing, it should be replaced with quadratic
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
29 NOTREACHED();
30 return false; 28 return false;
31 }
32 return IsVisited(ComputeURLFingerprint(canonical_url, url_len)); 29 return IsVisited(ComputeURLFingerprint(canonical_url, url_len));
33 } 30 }
34 31
35 bool VisitedLinkCommon::IsVisited(Fingerprint fingerprint) const { 32 bool VisitedLinkCommon::IsVisited(Fingerprint fingerprint) const {
36 // Go through the table until we find the item or an empty spot (meaning it 33 // 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, 34 // wasn't found). This loop will terminate as long as the table isn't full,
38 // which should be enforced by AddFingerprint. 35 // which should be enforced by AddFingerprint.
39 Hash first_hash = HashFingerprint(fingerprint); 36 Hash first_hash = HashFingerprint(fingerprint);
40 Hash cur_hash = first_hash; 37 Hash cur_hash = first_hash;
41 while (true) { 38 while (true) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 MD5Final(&digest, &ctx); 80 MD5Final(&digest, &ctx);
84 81
85 // This is the same as "return *(Fingerprint*)&digest.a;" but if we do that 82 // 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 83 // 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 84 // 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 85 // 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. 86 // bit cast, which amounts to a memcpy. This does not handle endian issues.
90 return bit_cast<Fingerprint, uint8[8]>( 87 return bit_cast<Fingerprint, uint8[8]>(
91 *reinterpret_cast<uint8(*)[8]>(&digest.a)); 88 *reinterpret_cast<uint8(*)[8]>(&digest.a));
92 } 89 }
OLDNEW
« no previous file with comments | « chrome/common/visitedlink_common.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698