Index: chrome/browser/ui/title_prefix_matcher.cc |
=================================================================== |
--- chrome/browser/ui/title_prefix_matcher.cc (revision 79877) |
+++ chrome/browser/ui/title_prefix_matcher.cc (working copy) |
@@ -7,6 +7,7 @@ |
#include "base/hash_tables.h" |
#include "base/i18n/break_iterator.h" |
#include "base/logging.h" |
+#include "base/utf_string_conversions.h" |
namespace { |
// We use this value to identify that we have already seen the title associated |
@@ -14,9 +15,10 @@ |
const size_t kPreviouslySeenIndex = 0xFFFFFFFF; |
} |
-TitlePrefixMatcher::TitleInfo::TitleInfo(const string16* title, |
- int caller_value) |
+TitlePrefixMatcher::TitleInfo::TitleInfo( |
+ const string16* title, const GURL& url, int caller_value) |
: title(title), |
+ url(url), |
prefix_length(0), |
caller_value(caller_value) { |
DCHECK(title != NULL); |
@@ -64,7 +66,11 @@ |
// Duplicate titles are not to be included in this process. |
if (duplicate_titles.find(i) != duplicate_titles.end()) |
continue; |
- const string16* title = title_infos->at(i).title; |
+ const TitleInfo& title_info = title_infos->at(i); |
+ const string16* title = title_info.title; |
+ // We prefix the hostname at the beginning, so that we only group |
+ // titles that are from the same hostname. |
+ string16 hostname = ASCIIToUTF16(title_info.url.host()); |
// We only create prefixes at word boundaries. |
base::BreakIterator iter(title, base::BreakIterator::BREAK_WORD); |
// We ignore this title if we can't break it into words, or if it only |
@@ -76,7 +82,7 @@ |
// previous word and more easily ignore the last word while iterating. |
while (iter.Advance()) { |
if (iter.IsWord()) |
- prefixes[title->substr(0, iter.prev())].push_back(i); |
+ prefixes[hostname + title->substr(0, iter.prev())].push_back(i); |
} |
} |
@@ -86,8 +92,12 @@ |
prefixes.begin(); iter != prefixes.end(); ++iter) { |
// iter->first is the prefix string, iter->second is a vector of indices. |
if (iter->second.size() > 1) { |
- size_t prefix_length = iter->first.size(); |
+ // We need to subtract the hostname size since we added it to the prefix. |
+ size_t prefix_length = iter->first.size() - |
+ title_infos->at(iter->second[0]).url.host().size(); |
for (size_t i = 0; i < iter->second.size(); ++i){ |
+ DCHECK(title_infos->at(iter->second[i]).url.host() == |
Peter Kasting
2011/04/01 17:28:31
Nit: DCHECK_EQ()
MAD
2011/04/01 19:47:37
Done.
|
+ title_infos->at(iter->second[0]).url.host()); |
if (title_infos->at(iter->second[i]).prefix_length < prefix_length) |
title_infos->at(iter->second[i]).prefix_length = prefix_length; |
} |