diff --git a/DEPS b/DEPS index 88720f9..56d6eb3 100644 --- a/DEPS +++ b/DEPS
@@ -39,7 +39,7 @@ # Three lines of non-changing comments so that # the commit queue can handle CLs rolling Skia # and whatever else without interference from each other. - 'skia_revision': 'f15246320cf69cd7bcd8882601c67eddc655d9ba', + 'skia_revision': '09f8e1b14e5096741bc1c28145acdb352d66ef58', # Three lines of non-changing comments so that # the commit queue can handle CLs rolling V8 # and whatever else without interference from each other.
diff --git a/chrome/browser/autocomplete/history_quick_provider_unittest.cc b/chrome/browser/autocomplete/history_quick_provider_unittest.cc index e554276..8fcc210 100644 --- a/chrome/browser/autocomplete/history_quick_provider_unittest.cc +++ b/chrome/browser/autocomplete/history_quick_provider_unittest.cc
@@ -21,8 +21,6 @@ #include "chrome/browser/autocomplete/in_memory_url_index_factory.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/history/history_service_factory.h" -#include "chrome/browser/search_engines/chrome_template_url_service_client.h" -#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile.h" #include "components/bookmarks/test/bookmark_test_helpers.h" @@ -38,8 +36,6 @@ #include "components/omnibox/browser/in_memory_url_index.h" #include "components/omnibox/browser/url_index_private_data.h" #include "components/search_engines/search_terms_data.h" -#include "components/search_engines/template_url.h" -#include "components/search_engines/template_url_service.h" #include "content/public/test/test_browser_thread.h" #include "content/public/test/test_utils.h" #include "sql/transaction.h" @@ -202,17 +198,6 @@ std::set<std::string> matches_; }; - static scoped_ptr<KeyedService> CreateTemplateURLService( - content::BrowserContext* context) { - Profile* profile = static_cast<Profile*>(context); - return make_scoped_ptr(new TemplateURLService( - profile->GetPrefs(), make_scoped_ptr(new SearchTermsData), NULL, - scoped_ptr<TemplateURLServiceClient>(new ChromeTemplateURLServiceClient( - HistoryServiceFactory::GetForProfile( - profile, ServiceAccessType::EXPLICIT_ACCESS))), - NULL, NULL, base::Closure())); - } - void SetUp() override; void TearDown() override; @@ -281,8 +266,6 @@ profile_.get(), ServiceAccessType::EXPLICIT_ACCESS); EXPECT_TRUE(history_service_); provider_ = new HistoryQuickProvider(client_.get()); - TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( - profile_.get(), &HistoryQuickProviderTest::CreateTemplateURLService); FillData(); InMemoryURLIndex* index = InMemoryURLIndexFactory::GetForProfile(profile_.get()); @@ -787,32 +770,6 @@ ASCIIToUTF16("popularsitewithroot.com"), base::string16()); } -TEST_F(HistoryQuickProviderTest, CullSearchResults) { - // Set up a default search engine. - TemplateURLData data; - data.SetShortName(ASCIIToUTF16("TestEngine")); - data.SetKeyword(ASCIIToUTF16("TestEngine")); - data.SetURL("http://testsearch.com/?q={searchTerms}"); - TemplateURLService* template_url_service = - TemplateURLServiceFactory::GetForProfile(profile_.get()); - TemplateURL* template_url = new TemplateURL(data); - template_url_service->Add(template_url); - template_url_service->SetUserSelectedDefaultSearchProvider(template_url); - template_url_service->Load(); - - // A search results page should not be returned when typing a query. - std::vector<std::string> expected_urls; - RunTest(ASCIIToUTF16("thequery"), false, expected_urls, false, - ASCIIToUTF16("anotherengine.com/?q=thequery"), base::string16()); - - // A search results page should not be returned when typing the engine URL. - expected_urls.clear(); - expected_urls.push_back("http://testsearch.com/"); - RunTest(ASCIIToUTF16("testsearch"), false, expected_urls, true, - ASCIIToUTF16("testsearch.com"), - ASCIIToUTF16(".com")); -} - TEST_F(HistoryQuickProviderTest, DoesNotProvideMatchesOnFocus) { AutocompleteInput input( ASCIIToUTF16("popularsite"), base::string16::npos, std::string(), GURL(),
diff --git a/chrome/browser/autocomplete/in_memory_url_index_factory.cc b/chrome/browser/autocomplete/in_memory_url_index_factory.cc index 25d3a2a..efb39392 100644 --- a/chrome/browser/autocomplete/in_memory_url_index_factory.cc +++ b/chrome/browser/autocomplete/in_memory_url_index_factory.cc
@@ -10,6 +10,7 @@ #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/profiles/incognito_helpers.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/common/pref_names.h" #include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/core/service_access_type.h" @@ -34,6 +35,7 @@ BrowserContextDependencyManager::GetInstance()) { DependsOn(BookmarkModelFactory::GetInstance()); DependsOn(HistoryServiceFactory::GetInstance()); + DependsOn(TemplateURLServiceFactory::GetInstance()); } InMemoryURLIndexFactory::~InMemoryURLIndexFactory() { @@ -49,6 +51,7 @@ BookmarkModelFactory::GetForProfile(profile), HistoryServiceFactory::GetForProfile(profile, ServiceAccessType::IMPLICIT_ACCESS), + TemplateURLServiceFactory::GetForProfile(profile), content::BrowserThread::GetBlockingPool(), profile->GetPath(), profile->GetPrefs()->GetString(prefs::kAcceptLanguages), chrome_schemes_to_whitelist);
diff --git a/chrome/browser/autocomplete/in_memory_url_index_unittest.cc b/chrome/browser/autocomplete/in_memory_url_index_unittest.cc index f68fbdc..f350b44 100644 --- a/chrome/browser/autocomplete/in_memory_url_index_unittest.cc +++ b/chrome/browser/autocomplete/in_memory_url_index_unittest.cc
@@ -331,7 +331,8 @@ SchemeSet client_schemes_to_whitelist; client_schemes_to_whitelist.insert(kClientWhitelistedScheme); url_index_.reset(new InMemoryURLIndex( - nullptr, history_service_, content::BrowserThread::GetBlockingPool(), + nullptr, history_service_, nullptr, + content::BrowserThread::GetBlockingPool(), base::FilePath(), kTestLanguages, client_schemes_to_whitelist)); url_index_->Init(); url_index_->RebuildFromHistory(history_database_); @@ -1266,7 +1267,8 @@ String16Vector lower_terms; StringToTerms(test_cases[i].search_string, test_cases[i].cursor_position, &lower_string, &lower_terms); - URLIndexPrivateData::AddHistoryMatch match(nullptr, *GetPrivateData(), + URLIndexPrivateData::AddHistoryMatch match(nullptr, nullptr, + *GetPrivateData(), kTestLanguages, lower_string, lower_terms, base::Time::Now()); @@ -1302,8 +1304,8 @@ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); base::FilePath path(temp_dir_.path()); url_index_.reset(new InMemoryURLIndex( - nullptr, nullptr, content::BrowserThread::GetBlockingPool(), path, - kTestLanguages, SchemeSet())); + nullptr, nullptr, nullptr, content::BrowserThread::GetBlockingPool(), + path, kTestLanguages, SchemeSet())); } void InMemoryURLIndexCacheTest::TearDown() {
diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc index 2bef2be8..0d32bda 100644 --- a/chrome/test/base/testing_profile.cc +++ b/chrome/test/base/testing_profile.cc
@@ -38,6 +38,7 @@ #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/storage_partition_descriptor.h" #include "chrome/browser/search_engines/template_url_fetcher_factory.h" +#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/sync/glue/sync_start_util.h" #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" #include "chrome/browser/web_data_service_factory.h" @@ -200,6 +201,7 @@ BookmarkModelFactory::GetForProfile(profile), HistoryServiceFactory::GetForProfile(profile, ServiceAccessType::IMPLICIT_ACCESS), + TemplateURLServiceFactory::GetForProfile(profile), content::BrowserThread::GetBlockingPool(), profile->GetPath(), profile->GetPrefs()->GetString(prefs::kAcceptLanguages), SchemeSet()));
diff --git a/chromeos/CHROMEOS_LKGM b/chromeos/CHROMEOS_LKGM index 23be71e..3e4992be 100644 --- a/chromeos/CHROMEOS_LKGM +++ b/chromeos/CHROMEOS_LKGM
@@ -1 +1 @@ -7683.0.0 \ No newline at end of file +7686.0.0 \ No newline at end of file
diff --git a/components/omnibox/browser/history_quick_provider.cc b/components/omnibox/browser/history_quick_provider.cc index 4975b72..8dba7a9 100644 --- a/components/omnibox/browser/history_quick_provider.cc +++ b/components/omnibox/browser/history_quick_provider.cc
@@ -27,8 +27,6 @@ #include "components/omnibox/browser/in_memory_url_index.h" #include "components/omnibox/browser/in_memory_url_index_types.h" #include "components/omnibox/browser/omnibox_field_trial.h" -#include "components/search_engines/template_url.h" -#include "components/search_engines/template_url_service.h" #include "components/url_formatter/url_formatter.h" #include "net/base/escape.h" #include "net/base/registry_controlled_domains/registry_controlled_domain.h" @@ -171,10 +169,6 @@ // they're visited.) The strength of this reduction depends on the // likely score for the URL-what-you-typed result. - // |template_url_service| or |template_url| can be NULL in unit tests. - TemplateURLService* template_url_service = client()->GetTemplateURLService(); - TemplateURL* template_url = template_url_service ? - template_url_service->GetDefaultSearchProvider() : NULL; int max_match_score = matches.begin()->raw_score; if (will_have_url_what_you_typed_match_first) { max_match_score = std::min(max_match_score, @@ -183,18 +177,11 @@ for (ScoredHistoryMatches::const_iterator match_iter = matches.begin(); match_iter != matches.end(); ++match_iter) { const ScoredHistoryMatch& history_match(*match_iter); - // Culls results corresponding to queries from the default search engine. - // These are low-quality, difficult-to-understand matches for users, and the - // SearchProvider should surface past queries in a better way anyway. - if (!template_url || - !template_url->IsSearchURL(history_match.url_info.url(), - template_url_service->search_terms_data())) { - // Set max_match_score to the score we'll assign this result: - max_match_score = std::min(max_match_score, history_match.raw_score); - matches_.push_back(QuickMatchToACMatch(history_match, max_match_score)); - // Mark this max_match_score as being used: - max_match_score--; - } + // Set max_match_score to the score we'll assign this result. + max_match_score = std::min(max_match_score, history_match.raw_score); + matches_.push_back(QuickMatchToACMatch(history_match, max_match_score)); + // Mark this max_match_score as being used. + max_match_score--; } }
diff --git a/components/omnibox/browser/in_memory_url_index.cc b/components/omnibox/browser/in_memory_url_index.cc index 9920013..c027301 100644 --- a/components/omnibox/browser/in_memory_url_index.cc +++ b/components/omnibox/browser/in_memory_url_index.cc
@@ -78,12 +78,14 @@ InMemoryURLIndex::InMemoryURLIndex( bookmarks::BookmarkModel* bookmark_model, history::HistoryService* history_service, + TemplateURLService* template_url_service, base::SequencedWorkerPool* worker_pool, const base::FilePath& history_dir, const std::string& languages, const SchemeSet& client_schemes_to_whitelist) : bookmark_model_(bookmark_model), history_service_(history_service), + template_url_service_(template_url_service), history_dir_(history_dir), languages_(languages), private_data_(new URLIndexPrivateData), @@ -131,7 +133,8 @@ size_t cursor_position, size_t max_matches) { return private_data_->HistoryItemsForTerms( - term_string, cursor_position, max_matches, languages_, bookmark_model_); + term_string, cursor_position, max_matches, languages_, bookmark_model_, + template_url_service_); } // Updating --------------------------------------------------------------------
diff --git a/components/omnibox/browser/in_memory_url_index.h b/components/omnibox/browser/in_memory_url_index.h index 868d88b..e13aabf 100644 --- a/components/omnibox/browser/in_memory_url_index.h +++ b/components/omnibox/browser/in_memory_url_index.h
@@ -25,6 +25,7 @@ #include "components/history/core/browser/history_types.h" #include "components/keyed_service/core/keyed_service.h" #include "components/omnibox/browser/scored_history_match.h" +#include "components/search_engines/template_url_service.h" class HistoryQuickProviderTest; @@ -105,6 +106,7 @@ // characters. InMemoryURLIndex(bookmarks::BookmarkModel* bookmark_model, history::HistoryService* history_service, + TemplateURLService* template_url_service, base::SequencedWorkerPool* worker_pool, const base::FilePath& history_dir, const std::string& languages, @@ -276,6 +278,10 @@ // The HistoryService; may be null when testing. history::HistoryService* history_service_; + // The TemplateURLService; may be null when testing. Used to identify URLs + // that are from the default search provider. + TemplateURLService* template_url_service_; + // Directory where cache file resides. This is, except when unit testing, // the same directory in which the history database is found. It should never // be empty.
diff --git a/components/omnibox/browser/scored_history_match.cc b/components/omnibox/browser/scored_history_match.cc index 2ae28b38..936d912 100644 --- a/components/omnibox/browser/scored_history_match.cc +++ b/components/omnibox/browser/scored_history_match.cc
@@ -20,6 +20,7 @@ #include "components/omnibox/browser/history_url_provider.h" #include "components/omnibox/browser/omnibox_field_trial.h" #include "components/omnibox/browser/url_prefix.h" +#include "components/search_engines/template_url_service.h" namespace { @@ -129,6 +130,7 @@ WordStarts(), RowWordStarts(), false, + nullptr, base::Time::Max()) { } @@ -141,6 +143,7 @@ const WordStarts& terms_to_word_starts_offsets, const RowWordStarts& word_starts, bool is_url_bookmarked, + TemplateURLService* template_url_service, base::Time now) : HistoryMatch(row, 0, false, false), raw_score(0), can_inline(false) { // NOTE: Call Init() before doing any validity checking to ensure that the @@ -153,6 +156,16 @@ if (!gurl.is_valid()) return; + // Skip results corresponding to queries from the default search engine. + // These are low-quality, difficult-to-understand matches for users. + // SearchProvider should surface past queries in a better way. + TemplateURL* template_url = template_url_service ? + template_url_service->GetDefaultSearchProvider() : nullptr; + if (template_url && + template_url->IsSearchURL(gurl, + template_url_service->search_terms_data())) + return; + // Figure out where each search term appears in the URL and/or page title // so that we can score as well as provide autocomplete highlighting. base::OffsetAdjuster::Adjustments adjustments;
diff --git a/components/omnibox/browser/scored_history_match.h b/components/omnibox/browser/scored_history_match.h index 9011bc3..d1e275d3 100644 --- a/components/omnibox/browser/scored_history_match.h +++ b/components/omnibox/browser/scored_history_match.h
@@ -16,6 +16,7 @@ #include "components/omnibox/browser/in_memory_url_index_types.h" class ScoredHistoryMatchTest; +class TemplateURLService; // An HistoryMatch that has a score as well as metrics defining where in the // history item's URL and/or page title matches have occurred. @@ -32,12 +33,14 @@ // Initializes the ScoredHistoryMatch with a raw score calculated for the // history item given in |row| with recent visits as indicated in |visits|. It // first determines if the row qualifies by seeing if all of the terms in - // |terms_vector| occur in |row|. If so, calculates a raw score. This raw - // score is in part determined by whether the matches occur at word - // boundaries, the locations of which are stored in |word_starts|. For some - // terms, it's appropriate to look for the word boundary within the term. For - // instance, the term ".net" should look for a word boundary at the "n". These - // offsets (".net" should have an offset of 1) come from + // |terms_vector| occur in |row| and checking if the URL does not come from + // the default search provider (obtained from |template_url_service|). If + // both those constraints are true, calculates a raw score. This raw score + // is in part determined by whether the matches occur at word boundaries, the + // locations of which are stored in |word_starts|. For some terms, it's + // appropriate to look for the word boundary within the term. For instance, + // the term ".net" should look for a word boundary at the "n". These offsets + // (".net" should have an offset of 1) come from // |terms_to_word_starts_offsets|. |is_url_bookmarked| indicates whether the // match's URL is referenced by any bookmarks, which can also affect the raw // score. The raw score allows the matches to be ordered and can be used to @@ -52,6 +55,7 @@ const WordStarts& terms_to_word_starts_offsets, const RowWordStarts& word_starts, bool is_url_bookmarked, + TemplateURLService* template_url_service, base::Time now); ~ScoredHistoryMatch();
diff --git a/components/omnibox/browser/scored_history_match_unittest.cc b/components/omnibox/browser/scored_history_match_unittest.cc index 12c85068..1271bbc2 100644 --- a/components/omnibox/browser/scored_history_match_unittest.cc +++ b/components/omnibox/browser/scored_history_match_unittest.cc
@@ -11,6 +11,10 @@ #include "base/memory/scoped_ptr.h" #include "base/strings/string16.h" #include "base/strings/utf_string_conversions.h" +#include "components/search_engines/search_terms_data.h" +#include "components/search_engines/template_url.h" +#include "components/search_engines/template_url_service.h" +#include "components/search_engines/template_url_service_client.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -133,7 +137,8 @@ visits_a[0].second = ui::PAGE_TRANSITION_TYPED; ScoredHistoryMatch scored_a(row_a, visits_a, std::string(), ASCIIToUTF16("abc"), Make1Term("abc"), - one_word_no_offset, word_starts_a, false, now); + one_word_no_offset, word_starts_a, false, nullptr, + now); // Test scores based on visit_count. history::URLRow row_b(MakeURLRow("http://abcdef", "abcd bcd", 10, 30, 1)); @@ -143,7 +148,8 @@ visits_b[0].second = ui::PAGE_TRANSITION_TYPED; ScoredHistoryMatch scored_b(row_b, visits_b, std::string(), ASCIIToUTF16("abc"), Make1Term("abc"), - one_word_no_offset, word_starts_b, false, now); + one_word_no_offset, word_starts_b, false, nullptr, + now); EXPECT_GT(scored_b.raw_score, scored_a.raw_score); // Test scores based on last_visit. @@ -154,7 +160,8 @@ visits_c[0].second = ui::PAGE_TRANSITION_TYPED; ScoredHistoryMatch scored_c(row_c, visits_c, std::string(), ASCIIToUTF16("abc"), Make1Term("abc"), - one_word_no_offset, word_starts_c, false, now); + one_word_no_offset, word_starts_c, false, nullptr, + now); EXPECT_GT(scored_c.raw_score, scored_a.raw_score); // Test scores based on typed_count. @@ -167,7 +174,8 @@ visits_d[2].second = ui::PAGE_TRANSITION_TYPED; ScoredHistoryMatch scored_d(row_d, visits_d, std::string(), ASCIIToUTF16("abc"), Make1Term("abc"), - one_word_no_offset, word_starts_d, false, now); + one_word_no_offset, word_starts_d, false, nullptr, + now); EXPECT_GT(scored_d.raw_score, scored_a.raw_score); // Test scores based on a terms appearing multiple times. @@ -179,14 +187,16 @@ const VisitInfoVector visits_e = visits_d; ScoredHistoryMatch scored_e(row_e, visits_e, std::string(), ASCIIToUTF16("csi"), Make1Term("csi"), - one_word_no_offset, word_starts_e, false, now); + one_word_no_offset, word_starts_e, false, nullptr, + now); EXPECT_LT(scored_e.raw_score, 1400); // Test that a result with only a mid-term match (i.e., not at a word // boundary) scores 0. ScoredHistoryMatch scored_f(row_a, visits_a, std::string(), ASCIIToUTF16("cd"), Make1Term("cd"), - one_word_no_offset, word_starts_a, false, now); + one_word_no_offset, word_starts_a, false, nullptr, + now); EXPECT_EQ(scored_f.raw_score, 0); } @@ -204,12 +214,12 @@ VisitInfoVector visits = CreateVisitInfoVector(8, 3, now); ScoredHistoryMatch scored(row, visits, std::string(), ASCIIToUTF16("abc"), Make1Term("abc"), one_word_no_offset, word_starts, - false, now); + false, nullptr, now); // Now check that if URL is bookmarked then its score increases. base::AutoReset<int> reset(&ScoredHistoryMatch::bookmark_value_, 5); ScoredHistoryMatch scored_with_bookmark( row, visits, std::string(), ASCIIToUTF16("abc"), Make1Term("abc"), - one_word_no_offset, word_starts, true, now); + one_word_no_offset, word_starts, true, nullptr, now); EXPECT_GT(scored_with_bookmark.raw_score, scored.raw_score); } @@ -228,14 +238,15 @@ VisitInfoVector visits = CreateVisitInfoVector(8, 3, now); ScoredHistoryMatch scored(row, visits, std::string(), ASCIIToUTF16("fed com"), Make2Terms("fed", "com"), two_words_no_offsets, - word_starts, false, now); + word_starts, false, nullptr, now); EXPECT_EQ(0, scored.raw_score); // Now allow credit for the match in the TLD. base::AutoReset<bool> reset(&ScoredHistoryMatch::allow_tld_matches_, true); ScoredHistoryMatch scored_with_tld( row, visits, std::string(), ASCIIToUTF16("fed com"), - Make2Terms("fed", "com"), two_words_no_offsets, word_starts, false, now); + Make2Terms("fed", "com"), two_words_no_offsets, word_starts, false, + nullptr, now); EXPECT_GT(scored_with_tld.raw_score, 0); } @@ -254,17 +265,83 @@ VisitInfoVector visits = CreateVisitInfoVector(8, 3, now); ScoredHistoryMatch scored(row, visits, std::string(), ASCIIToUTF16("fed http"), Make2Terms("fed", "http"), - two_words_no_offsets, word_starts, false, now); + two_words_no_offsets, word_starts, false, nullptr, + now); EXPECT_EQ(0, scored.raw_score); // Now allow credit for the match in the scheme. base::AutoReset<bool> reset(&ScoredHistoryMatch::allow_scheme_matches_, true); ScoredHistoryMatch scored_with_scheme( row, visits, std::string(), ASCIIToUTF16("fed http"), - Make2Terms("fed", "http"), two_words_no_offsets, word_starts, false, now); + Make2Terms("fed", "http"), two_words_no_offsets, word_starts, false, + nullptr, now); EXPECT_GT(scored_with_scheme.raw_score, 0); } +TEST_F(ScoredHistoryMatchTest, CullSearchResults) { + scoped_ptr<TemplateURLService> template_url_service = + make_scoped_ptr(new TemplateURLService( + nullptr, make_scoped_ptr(new SearchTermsData), nullptr, + scoped_ptr<TemplateURLServiceClient>(), nullptr, nullptr, + base::Closure())); + + // We use NowFromSystemTime() because MakeURLRow uses the same function + // to calculate last visit time when building a row. + base::Time now = base::Time::NowFromSystemTime(); + + // Pretend we've visited a search engine query URL, but that it's not + // associated with the default search engine. + history::URLRow row(MakeURLRow( + "http://testsearch.com/thequery", "Test Search Engine", 3, 30, 1)); + RowWordStarts word_starts; + PopulateWordStarts(row, &word_starts); + WordStarts one_word_no_offset(1, 0u); + VisitInfoVector visits = CreateVisitInfoVector(3, 30, now); + // Mark one visit as typed. + visits[0].second = ui::PAGE_TRANSITION_TYPED; + + // This page should be returned if it's associated with the default search + // engine. + ScoredHistoryMatch scored_a(row, visits, std::string(), + ASCIIToUTF16("thequery"), Make1Term("thequery"), + one_word_no_offset, word_starts, false, + template_url_service.get(), now); + EXPECT_GT(scored_a.raw_score, 0); + + // Likewise, it should be returned when typing the engine URL. + ScoredHistoryMatch scored_b(row, visits, std::string(), + ASCIIToUTF16("testsearch"), + Make1Term("testsearch"), one_word_no_offset, + word_starts, false, template_url_service.get(), + now); + EXPECT_GT(scored_b.raw_score, 0); + + // Set up a default search engine associated with this URL. + TemplateURLData data; + data.SetShortName(ASCIIToUTF16("TestEngine")); + data.SetKeyword(ASCIIToUTF16("TestEngine")); + data.SetURL("http://testsearch.com/{searchTerms}"); + TemplateURL* template_url = new TemplateURL(data); + template_url_service->Add(template_url); + template_url_service->SetUserSelectedDefaultSearchProvider(template_url); + template_url_service->Load(); + + // The search results page should not be returned when typing a query. + ScoredHistoryMatch scored_c(row, visits, std::string(), + ASCIIToUTF16("thequery"), Make1Term("thequery"), + one_word_no_offset, word_starts, false, + template_url_service.get(), now); + EXPECT_EQ(0, scored_c.raw_score); + + // Likewise, it shouldn't be returned when typing the engine URL. + ScoredHistoryMatch scored_d(row, visits, std::string(), + ASCIIToUTF16("testsearch"), + Make1Term("testsearch"), one_word_no_offset, + word_starts, false, template_url_service.get(), + now); + EXPECT_EQ(0, scored_d.raw_score); +} + TEST_F(ScoredHistoryMatchTest, Inlining) { // We use NowFromSystemTime() because MakeURLRow uses the same function // to calculate last visit time when building a row. @@ -279,22 +356,22 @@ PopulateWordStarts(row, &word_starts); ScoredHistoryMatch scored_a(row, visits, std::string(), ASCIIToUTF16("g"), Make1Term("g"), one_word_no_offset, word_starts, - false, now); + false, nullptr, now); EXPECT_TRUE(scored_a.can_inline); EXPECT_FALSE(scored_a.match_in_scheme); ScoredHistoryMatch scored_b(row, visits, std::string(), ASCIIToUTF16("w"), Make1Term("w"), one_word_no_offset, word_starts, - false, now); + false, nullptr, now); EXPECT_TRUE(scored_b.can_inline); EXPECT_FALSE(scored_b.match_in_scheme); ScoredHistoryMatch scored_c(row, visits, std::string(), ASCIIToUTF16("h"), Make1Term("h"), one_word_no_offset, word_starts, - false, now); + false, nullptr, now); EXPECT_TRUE(scored_c.can_inline); EXPECT_TRUE(scored_c.match_in_scheme); ScoredHistoryMatch scored_d(row, visits, std::string(), ASCIIToUTF16("o"), Make1Term("o"), one_word_no_offset, word_starts, - false, now); + false, nullptr, now); EXPECT_FALSE(scored_d.can_inline); EXPECT_FALSE(scored_d.match_in_scheme); } @@ -304,17 +381,17 @@ PopulateWordStarts(row, &word_starts); ScoredHistoryMatch scored_a(row, visits, std::string(), ASCIIToUTF16("t"), Make1Term("t"), one_word_no_offset, word_starts, - false, now); + false, nullptr, now); EXPECT_TRUE(scored_a.can_inline); EXPECT_FALSE(scored_a.match_in_scheme); ScoredHistoryMatch scored_b(row, visits, std::string(), ASCIIToUTF16("f"), Make1Term("f"), one_word_no_offset, word_starts, - false, now); + false, nullptr, now); EXPECT_FALSE(scored_b.can_inline); EXPECT_FALSE(scored_b.match_in_scheme); ScoredHistoryMatch scored_c(row, visits, std::string(), ASCIIToUTF16("o"), Make1Term("o"), one_word_no_offset, word_starts, - false, now); + false, nullptr, now); EXPECT_FALSE(scored_c.can_inline); EXPECT_FALSE(scored_c.match_in_scheme); } @@ -325,17 +402,17 @@ PopulateWordStarts(row, &word_starts); ScoredHistoryMatch scored_a(row, visits, std::string(), ASCIIToUTF16("t"), Make1Term("t"), one_word_no_offset, word_starts, - false, now); + false, nullptr, now); EXPECT_TRUE(scored_a.can_inline); EXPECT_FALSE(scored_a.match_in_scheme); ScoredHistoryMatch scored_b(row, visits, std::string(), ASCIIToUTF16("h"), Make1Term("h"), one_word_no_offset, word_starts, - false, now); + false, nullptr, now); EXPECT_TRUE(scored_b.can_inline); EXPECT_TRUE(scored_b.match_in_scheme); ScoredHistoryMatch scored_c(row, visits, std::string(), ASCIIToUTF16("w"), Make1Term("w"), one_word_no_offset, word_starts, - false, now); + false, nullptr, now); EXPECT_TRUE(scored_c.can_inline); EXPECT_FALSE(scored_c.match_in_scheme); } @@ -346,17 +423,17 @@ PopulateWordStarts(row, &word_starts); ScoredHistoryMatch scored_a(row, visits, "zh-CN", ASCIIToUTF16("x"), Make1Term("x"), one_word_no_offset, word_starts, - false, now); + false, nullptr, now); EXPECT_FALSE(scored_a.can_inline); EXPECT_FALSE(scored_a.match_in_scheme); ScoredHistoryMatch scored_b(row, visits, "zh-CN", ASCIIToUTF16("xn"), Make1Term("xn"), one_word_no_offset, - word_starts, false, now); + word_starts, false, nullptr, now); EXPECT_FALSE(scored_b.can_inline); EXPECT_FALSE(scored_b.match_in_scheme); ScoredHistoryMatch scored_c(row, visits, "zh-CN", ASCIIToUTF16("w"), Make1Term("w"), one_word_no_offset, - word_starts, false, now); + word_starts, false, nullptr, now); EXPECT_TRUE(scored_c.can_inline); EXPECT_FALSE(scored_c.match_in_scheme); }
diff --git a/components/omnibox/browser/url_index_private_data.cc b/components/omnibox/browser/url_index_private_data.cc index a468d2b..77ddb9f 100644 --- a/components/omnibox/browser/url_index_private_data.cc +++ b/components/omnibox/browser/url_index_private_data.cc
@@ -26,6 +26,7 @@ #include "components/history/core/browser/history_db_task.h" #include "components/history/core/browser/history_service.h" #include "components/omnibox/browser/in_memory_url_index.h" +#include "components/search_engines/template_url_service.h" #include "components/url_formatter/url_formatter.h" #if defined(USE_SYSTEM_PROTOBUF) @@ -154,7 +155,8 @@ size_t cursor_position, size_t max_matches, const std::string& languages, - bookmarks::BookmarkModel* bookmark_model) { + bookmarks::BookmarkModel* bookmark_model, + TemplateURLService* template_url_service) { // If cursor position is set and useful (not at either end of the // string), allow the search string to be broken at cursor position. // We do this by pretending there's a space where the cursor is. @@ -249,8 +251,9 @@ scored_items = std::for_each( history_id_set.begin(), history_id_set.end(), - AddHistoryMatch(bookmark_model, *this, languages, lower_raw_string, - lower_raw_terms, base::Time::Now())).ScoredMatches(); + AddHistoryMatch(bookmark_model, template_url_service, *this, + languages, lower_raw_string, lower_raw_terms, + base::Time::Now())).ScoredMatches(); // Select and sort only the top |max_matches| results. if (scored_items.size() > max_matches) { @@ -1272,12 +1275,14 @@ URLIndexPrivateData::AddHistoryMatch::AddHistoryMatch( bookmarks::BookmarkModel* bookmark_model, + TemplateURLService* template_url_service, const URLIndexPrivateData& private_data, const std::string& languages, const base::string16& lower_string, const String16Vector& lower_terms, const base::Time now) : bookmark_model_(bookmark_model), + template_url_service_(template_url_service), private_data_(private_data), languages_(languages), lower_string_(lower_string), @@ -1319,7 +1324,7 @@ hist_item, visits, languages_, lower_string_, lower_terms_, lower_terms_to_word_starts_offsets_, starts_pos->second, bookmark_model_ && bookmark_model_->IsBookmarked(hist_item.url()), - now_); + template_url_service_, now_); if (match.raw_score > 0) scored_matches_.push_back(match); }
diff --git a/components/omnibox/browser/url_index_private_data.h b/components/omnibox/browser/url_index_private_data.h index 13a80bc1..c772f29 100644 --- a/components/omnibox/browser/url_index_private_data.h +++ b/components/omnibox/browser/url_index_private_data.h
@@ -17,6 +17,7 @@ #include "components/omnibox/browser/scored_history_match.h" class HistoryQuickProviderTest; +class TemplateURLService; namespace bookmarks { class BookmarkModel; @@ -71,7 +72,8 @@ size_t cursor_position, size_t max_matches, const std::string& languages, - bookmarks::BookmarkModel* bookmark_model); + bookmarks::BookmarkModel* bookmark_model, + TemplateURLService* template_url_service); // Adds the history item in |row| to the index if it does not already already // exist and it meets the minimum 'quick' criteria. If the row already exists @@ -196,6 +198,7 @@ class AddHistoryMatch : public std::unary_function<HistoryID, void> { public: AddHistoryMatch(bookmarks::BookmarkModel* bookmark_model, + TemplateURLService* template_url_service, const URLIndexPrivateData& private_data, const std::string& languages, const base::string16& lower_string, @@ -211,6 +214,7 @@ friend class InMemoryURLIndexTest; FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, AddHistoryMatch); bookmarks::BookmarkModel* bookmark_model_; + TemplateURLService* template_url_service_; const URLIndexPrivateData& private_data_; const std::string& languages_; ScoredHistoryMatches scored_matches_;
diff --git a/ios/chrome/browser/autocomplete/in_memory_url_index_factory.cc b/ios/chrome/browser/autocomplete/in_memory_url_index_factory.cc index 232f9d0..63995a2 100644 --- a/ios/chrome/browser/autocomplete/in_memory_url_index_factory.cc +++ b/ios/chrome/browser/autocomplete/in_memory_url_index_factory.cc
@@ -14,6 +14,7 @@ #include "ios/chrome/browser/chrome_url_constants.h" #include "ios/chrome/browser/history/history_service_factory.h" #include "ios/chrome/browser/pref_names.h" +#include "ios/chrome/browser/search_engines/template_url_service_factory.h" #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/web/public/web_thread.h" @@ -33,6 +34,7 @@ ios::BookmarkModelFactory::GetForBrowserState(browser_state), ios::HistoryServiceFactory::GetForBrowserState( browser_state, ServiceAccessType::IMPLICIT_ACCESS), + ios::TemplateURLServiceFactory::GetForBrowserState(browser_state), web::WebThread::GetBlockingPool(), browser_state->GetStatePath(), browser_state->GetPrefs()->GetString(ios::prefs::kAcceptLanguages), schemes_to_whilelist));