diff options
26 files changed, 154 insertions, 98 deletions
diff --git a/chrome/browser/android/omnibox/autocomplete_controller_android.cc b/chrome/browser/android/omnibox/autocomplete_controller_android.cc index 2ff97d5..8bb2fc6 100644 --- a/chrome/browser/android/omnibox/autocomplete_controller_android.cc +++ b/chrome/browser/android/omnibox/autocomplete_controller_android.cc @@ -82,7 +82,8 @@ class ZeroSuggestPrefetcher : public AutocompleteControllerDelegate { ZeroSuggestPrefetcher::ZeroSuggestPrefetcher(Profile* profile) : controller_(new AutocompleteController( - profile, this, AutocompleteProvider::TYPE_ZERO_SUGGEST)) { + profile, TemplateURLServiceFactory::GetForProfile(profile), this, + AutocompleteProvider::TYPE_ZERO_SUGGEST)) { // Creating an arbitrary fake_request_source to avoid passing in an invalid // AutocompleteInput object. base::string16 fake_request_source(base::ASCIIToUTF16( @@ -115,7 +116,8 @@ void ZeroSuggestPrefetcher::OnResultChanged(bool default_match_changed) { AutocompleteControllerAndroid::AutocompleteControllerAndroid(Profile* profile) : autocomplete_controller_(new AutocompleteController( - profile, this, kAndroidAutocompleteProviders)), + profile, TemplateURLServiceFactory::GetForProfile(profile), this, + kAndroidAutocompleteProviders)), inside_synchronous_start_(false), profile_(profile) { } diff --git a/chrome/browser/autocomplete/autocomplete_classifier_factory.cc b/chrome/browser/autocomplete/autocomplete_classifier_factory.cc index 1d5972b..aae29a7 100644 --- a/chrome/browser/autocomplete/autocomplete_classifier_factory.cc +++ b/chrome/browser/autocomplete/autocomplete_classifier_factory.cc @@ -33,7 +33,8 @@ KeyedService* AutocompleteClassifierFactory::BuildInstanceFor( Profile* profile = static_cast<Profile*>(context); return new AutocompleteClassifier( make_scoped_ptr(new AutocompleteController( - profile, NULL, AutocompleteClassifier::kDefaultOmniboxProviders)), + profile, TemplateURLServiceFactory::GetForProfile(profile), NULL, + AutocompleteClassifier::kDefaultOmniboxProviders)), scoped_ptr<AutocompleteSchemeClassifier>( new ChromeAutocompleteSchemeClassifier(profile))); } diff --git a/chrome/browser/autocomplete/autocomplete_controller.cc b/chrome/browser/autocomplete/autocomplete_controller.cc index 8cdccbd9..062b9c1 100644 --- a/chrome/browser/autocomplete/autocomplete_controller.cc +++ b/chrome/browser/autocomplete/autocomplete_controller.cc @@ -24,8 +24,7 @@ #include "chrome/browser/autocomplete/zero_suggest_provider.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/omnibox/omnibox_field_trial.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/search_engines/ui_thread_search_terms_data.h" +#include "chrome/browser/search_engines/template_url_service.h" #include "components/search_engines/template_url.h" #include "content/public/browser/notification_service.h" #include "grit/generated_resources.h" @@ -170,6 +169,7 @@ bool AutocompleteMatchHasCustomDescription(const AutocompleteMatch& match) { AutocompleteController::AutocompleteController( Profile* profile, + TemplateURLService* template_url_service, AutocompleteControllerDelegate* delegate, int provider_types) : delegate_(delegate), @@ -180,7 +180,7 @@ AutocompleteController::AutocompleteController( stop_timer_duration_(OmniboxFieldTrial::StopTimerFieldTrialDuration()), done_(true), in_start_(false), - profile_(profile) { + template_url_service_(template_url_service) { provider_types &= ~OmniboxFieldTrial::GetDisabledProviderTypes(); if (provider_types & AutocompleteProvider::TYPE_BOOKMARK) providers_.push_back(new BookmarkProvider(this, profile)); @@ -402,7 +402,8 @@ void AutocompleteController::ResetSession() { void AutocompleteController::UpdateMatchDestinationURL( base::TimeDelta query_formulation_time, AutocompleteMatch* match) const { - TemplateURL* template_url = match->GetTemplateURL(profile_, false); + TemplateURL* template_url = match->GetTemplateURL( + template_url_service_, false); if (!template_url || !match->search_terms_args.get() || match->search_terms_args->assisted_query_stats.empty()) return; @@ -420,7 +421,7 @@ void AutocompleteController::UpdateMatchDestinationURL( zero_suggest_provider_->field_trial_triggered_in_session()), input_.current_page_classification()); match->destination_url = GURL(template_url->url_ref().ReplaceSearchTerms( - search_terms_args, UIThreadSearchTermsData(profile_))); + search_terms_args, template_url_service_->search_terms_data())); } void AutocompleteController::UpdateResult( @@ -450,7 +451,7 @@ void AutocompleteController::UpdateResult( result_.AppendMatches((*i)->matches()); // Sort the matches and trim to a small number of "best" matches. - result_.SortAndCull(input_, profile_); + result_.SortAndCull(input_, template_url_service_); // Need to validate before invoking CopyOldMatches as the old matches are not // valid against the current input. @@ -461,7 +462,7 @@ void AutocompleteController::UpdateResult( if (!done_) { // This conditional needs to match the conditional in Start that invokes // StartExpireTimer. - result_.CopyOldMatches(input_, last_result, profile_); + result_.CopyOldMatches(input_, last_result, template_url_service_); } UpdateKeywordDescriptions(&result_); @@ -506,7 +507,7 @@ void AutocompleteController::UpdateAssociatedKeywords( for (ACMatches::iterator match(result->begin()); match != result->end(); ++match) { base::string16 keyword( - match->GetSubstitutingExplicitlyInvokedKeyword(profile_)); + match->GetSubstitutingExplicitlyInvokedKeyword(template_url_service_)); if (!keyword.empty()) { keywords.insert(keyword); continue; @@ -542,7 +543,8 @@ void AutocompleteController::UpdateKeywordDescriptions( i->description_class.clear(); DCHECK(!i->keyword.empty()); if (i->keyword != last_keyword) { - const TemplateURL* template_url = i->GetTemplateURL(profile_, false); + const TemplateURL* template_url = + i->GetTemplateURL(template_url_service_, false); if (template_url) { // For extension keywords, just make the description the extension // name -- don't assume that the normal search keyword description is @@ -595,7 +597,8 @@ void AutocompleteController::UpdateAssistedQueryStats( // Go over all matches and set AQS if the match supports it. for (size_t index = 0; index < result->size(); ++index) { AutocompleteMatch* match = result->match_at(index); - const TemplateURL* template_url = match->GetTemplateURL(profile_, false); + const TemplateURL* template_url = + match->GetTemplateURL(template_url_service_, false); if (!template_url || !match->search_terms_args.get()) continue; std::string selected_index; @@ -607,7 +610,7 @@ void AutocompleteController::UpdateAssistedQueryStats( selected_index.c_str(), autocompletions.c_str()); match->destination_url = GURL(template_url->url_ref().ReplaceSearchTerms( - *match->search_terms_args, UIThreadSearchTermsData(profile_))); + *match->search_terms_args, template_url_service_->search_terms_data())); } } diff --git a/chrome/browser/autocomplete/autocomplete_controller.h b/chrome/browser/autocomplete/autocomplete_controller.h index ed38d41..51794ce 100644 --- a/chrome/browser/autocomplete/autocomplete_controller.h +++ b/chrome/browser/autocomplete/autocomplete_controller.h @@ -21,6 +21,7 @@ class HistoryURLProvider; class KeywordProvider; class Profile; class SearchProvider; +class TemplateURLService; class ZeroSuggestProvider; // The AutocompleteController is the center of the autocomplete system. A @@ -47,8 +48,10 @@ class AutocompleteController : public AutocompleteProviderListener { public: // |provider_types| is a bitmap containing AutocompleteProvider::Type values // that will (potentially, depending on platform, flags, etc.) be - // instantiated. + // instantiated. |template_url_service| is used to create URLs from the + // autocomplete results. AutocompleteController(Profile* profile, + TemplateURLService* template_url_service, AutocompleteControllerDelegate* delegate, int provider_types); ~AutocompleteController(); @@ -237,7 +240,7 @@ class AutocompleteController : public AutocompleteProviderListener { // notifications until Start() has been invoked on all providers. bool in_start_; - Profile* profile_; + TemplateURLService* template_url_service_; DISALLOW_COPY_AND_ASSIGN(AutocompleteController); }; diff --git a/chrome/browser/autocomplete/autocomplete_match.cc b/chrome/browser/autocomplete/autocomplete_match.cc index 37dfca0..9a3d13c 100644 --- a/chrome/browser/autocomplete/autocomplete_match.cc +++ b/chrome/browser/autocomplete/autocomplete_match.cc @@ -13,10 +13,7 @@ #include "base/time/time.h" #include "chrome/browser/autocomplete/autocomplete_provider.h" #include "chrome/browser/search_engines/template_url_service.h" -#include "chrome/browser/search_engines/template_url_service_factory.h" -#include "chrome/browser/search_engines/ui_thread_search_terms_data.h" #include "components/search_engines/template_url.h" -#include "content/public/common/url_constants.h" #include "grit/theme_resources.h" namespace { @@ -345,7 +342,8 @@ bool AutocompleteMatch::IsSpecializedSearchType(Type type) { type == AutocompleteMatchType::SEARCH_SUGGEST_ANSWER; } -void AutocompleteMatch::ComputeStrippedDestinationURL(Profile* profile) { +void AutocompleteMatch::ComputeStrippedDestinationURL( + TemplateURLService* template_url_service) { stripped_destination_url = destination_url; if (!stripped_destination_url.is_valid()) return; @@ -355,18 +353,19 @@ void AutocompleteMatch::ComputeStrippedDestinationURL(Profile* profile) { // to eliminate cases like past search URLs from history that differ only // by some obscure query param from each other or from the search/keyword // provider matches. - TemplateURL* template_url = GetTemplateURL(profile, true); - UIThreadSearchTermsData search_terms_data(profile); + TemplateURL* template_url = GetTemplateURL(template_url_service, true); if (template_url != NULL && - template_url->SupportsReplacement(search_terms_data)) { + template_url->SupportsReplacement( + template_url_service->search_terms_data())) { base::string16 search_terms; - if (template_url->ExtractSearchTermsFromURL(stripped_destination_url, - search_terms_data, - &search_terms)) { + if (template_url->ExtractSearchTermsFromURL( + stripped_destination_url, + template_url_service->search_terms_data(), + &search_terms)) { stripped_destination_url = GURL(template_url->url_ref().ReplaceSearchTerms( TemplateURLRef::SearchTermsArgs(search_terms), - search_terms_data)); + template_url_service->search_terms_data())); } } @@ -399,29 +398,32 @@ void AutocompleteMatch::ComputeStrippedDestinationURL(Profile* profile) { replacements); } -void AutocompleteMatch::GetKeywordUIState(Profile* profile, - base::string16* keyword, - bool* is_keyword_hint) const { +void AutocompleteMatch::GetKeywordUIState( + TemplateURLService* template_url_service, + base::string16* keyword, + bool* is_keyword_hint) const { *is_keyword_hint = associated_keyword.get() != NULL; keyword->assign(*is_keyword_hint ? associated_keyword->keyword : - GetSubstitutingExplicitlyInvokedKeyword(profile)); + GetSubstitutingExplicitlyInvokedKeyword(template_url_service)); } base::string16 AutocompleteMatch::GetSubstitutingExplicitlyInvokedKeyword( - Profile* profile) const { - if (transition != content::PAGE_TRANSITION_KEYWORD) + TemplateURLService* template_url_service) const { + if (transition != content::PAGE_TRANSITION_KEYWORD || + template_url_service == NULL) { return base::string16(); - const TemplateURL* t_url = GetTemplateURL(profile, false); + } + + const TemplateURL* t_url = GetTemplateURL(template_url_service, false); return (t_url && - t_url->SupportsReplacement(UIThreadSearchTermsData(profile))) ? + t_url->SupportsReplacement( + template_url_service->search_terms_data())) ? keyword : base::string16(); } TemplateURL* AutocompleteMatch::GetTemplateURL( - Profile* profile, bool allow_fallback_to_destination_host) const { - DCHECK(profile); - TemplateURLService* template_url_service = - TemplateURLServiceFactory::GetForProfile(profile); + TemplateURLService* template_url_service, + bool allow_fallback_to_destination_host) const { if (template_url_service == NULL) return NULL; TemplateURL* template_url = keyword.empty() ? NULL : diff --git a/chrome/browser/autocomplete/autocomplete_match.h b/chrome/browser/autocomplete/autocomplete_match.h index e92766a..fed5206 100644 --- a/chrome/browser/autocomplete/autocomplete_match.h +++ b/chrome/browser/autocomplete/autocomplete_match.h @@ -16,8 +16,8 @@ #include "url/gurl.h" class AutocompleteProvider; -class Profile; class TemplateURL; +class TemplateURLService; namespace base { class Time; @@ -174,11 +174,11 @@ struct AutocompleteMatch { // remove likely duplicates; these URLs are not used as actual // destination URLs. This method is invoked internally by the // AutocompleteResult and does not normally need to be invoked. - // If |profile| is not NULL, it is used to get a template URL corresponding - // to this match. The template is used to strip off query args other than - // the search terms themselves that would otherwise prevent from proper - // deduping. - void ComputeStrippedDestinationURL(Profile* profile); + // If |template_url_service| is not NULL, it is used to get a template URL + // corresponding to this match. The template is used to strip off query args + // other than the search terms themselves that would otherwise prevent from + // proper deduping. + void ComputeStrippedDestinationURL(TemplateURLService* template_url_service); // Gets data relevant to whether there should be any special keyword-related // UI shown for this match. If this match represents a selected keyword, i.e. @@ -192,7 +192,7 @@ struct AutocompleteMatch { // is non-empty -- such as with non-substituting keywords or matches that // represent searches using the default search engine. See also // GetSubstitutingExplicitlyInvokedKeyword(). - void GetKeywordUIState(Profile* profile, + void GetKeywordUIState(TemplateURLService* template_url_service, base::string16* keyword, bool* is_keyword_hint) const; @@ -203,7 +203,7 @@ struct AutocompleteMatch { // this function returns a non-empty string in the same cases as when the UI // should show up as being "in keyword mode". base::string16 GetSubstitutingExplicitlyInvokedKeyword( - Profile* profile) const; + TemplateURLService* template_url_service) const; // Returns the TemplateURL associated with this match. This may be NULL if // the match has no keyword OR if the keyword no longer corresponds to a valid @@ -211,7 +211,7 @@ struct AutocompleteMatch { // If |allow_fallback_to_destination_host| is true and the keyword does // not map to a valid TemplateURL, we'll then check for a TemplateURL that // corresponds to the destination_url's hostname. - TemplateURL* GetTemplateURL(Profile* profile, + TemplateURL* GetTemplateURL(TemplateURLService* template_url_service, bool allow_fallback_to_destination_host) const; // Adds optional information to the |additional_info| dictionary. diff --git a/chrome/browser/autocomplete/autocomplete_provider_unittest.cc b/chrome/browser/autocomplete/autocomplete_provider_unittest.cc index 504b1b3..fde091c 100644 --- a/chrome/browser/autocomplete/autocomplete_provider_unittest.cc +++ b/chrome/browser/autocomplete/autocomplete_provider_unittest.cc @@ -143,7 +143,9 @@ void TestProvider::AddResultsWithSearchTermsArgs( new TemplateURLRef::SearchTermsArgs(search_terms_args)); if (!match_keyword_.empty()) { match.keyword = match_keyword_; - ASSERT_TRUE(match.GetTemplateURL(profile_, false) != NULL); + TemplateURLService* service = + TemplateURLServiceFactory::GetForProfile(profile_); + ASSERT_TRUE(match.GetTemplateURL(service, false) != NULL); } matches_.push_back(match); @@ -268,7 +270,8 @@ void AutocompleteProviderTest::ResetControllerWithTestProviders( providers.push_back(provider2); // Reset the controller to contain our new providers. - controller_.reset(new AutocompleteController(&profile_, NULL, 0)); + controller_.reset(new AutocompleteController( + &profile_, TemplateURLServiceFactory::GetForProfile(&profile_), NULL, 0)); // We're going to swap the providers vector, but the old vector should be // empty so no elements need to be freed at this point. EXPECT_TRUE(controller_->providers_.empty()); @@ -314,7 +317,7 @@ void AutocompleteProviderTest:: ASSERT_NE(0, keyword_t_url->id()); controller_.reset(new AutocompleteController( - &profile_, NULL, + &profile_, TemplateURLServiceFactory::GetForProfile(&profile_), NULL, AutocompleteProvider::TYPE_KEYWORD | AutocompleteProvider::TYPE_SEARCH)); } @@ -343,7 +346,8 @@ void AutocompleteProviderTest::ResetControllerWithKeywordProvider() { ASSERT_NE(0, keyword_t_url->id()); controller_.reset(new AutocompleteController( - &profile_, NULL, AutocompleteProvider::TYPE_KEYWORD)); + &profile_, TemplateURLServiceFactory::GetForProfile(&profile_), NULL, + AutocompleteProvider::TYPE_KEYWORD)); } void AutocompleteProviderTest::RunTest() { diff --git a/chrome/browser/autocomplete/autocomplete_result.cc b/chrome/browser/autocomplete/autocomplete_result.cc index 7c817a0..664384b 100644 --- a/chrome/browser/autocomplete/autocomplete_result.cc +++ b/chrome/browser/autocomplete/autocomplete_result.cc @@ -132,9 +132,10 @@ AutocompleteResult::AutocompleteResult() { AutocompleteResult::~AutocompleteResult() {} -void AutocompleteResult::CopyOldMatches(const AutocompleteInput& input, - const AutocompleteResult& old_matches, - Profile* profile) { +void AutocompleteResult::CopyOldMatches( + const AutocompleteInput& input, + const AutocompleteResult& old_matches, + TemplateURLService* template_url_service) { if (old_matches.empty()) return; @@ -170,7 +171,7 @@ void AutocompleteResult::CopyOldMatches(const AutocompleteInput& input, i->second, matches_per_provider[i->first]); } - SortAndCull(input, profile); + SortAndCull(input, template_url_service); } void AutocompleteResult::AppendMatches(const ACMatches& matches) { @@ -186,10 +187,11 @@ void AutocompleteResult::AppendMatches(const ACMatches& matches) { alternate_nav_url_ = GURL(); } -void AutocompleteResult::SortAndCull(const AutocompleteInput& input, - Profile* profile) { +void AutocompleteResult::SortAndCull( + const AutocompleteInput& input, + TemplateURLService* template_url_service) { for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) - i->ComputeStrippedDestinationURL(profile); + i->ComputeStrippedDestinationURL(template_url_service); DedupMatchesByDestination(input.current_page_classification(), true, &matches_); diff --git a/chrome/browser/autocomplete/autocomplete_result.h b/chrome/browser/autocomplete/autocomplete_result.h index 39447c7..c4c7999 100644 --- a/chrome/browser/autocomplete/autocomplete_result.h +++ b/chrome/browser/autocomplete/autocomplete_result.h @@ -16,7 +16,7 @@ class AutocompleteInput; class AutocompleteProvider; -class Profile; +class TemplateURLService; // All matches from all providers for a particular query. This also tracks // what the default match should be if the user doesn't manually select another @@ -67,7 +67,7 @@ class AutocompleteResult { // comments in code for specifics. void CopyOldMatches(const AutocompleteInput& input, const AutocompleteResult& old_matches, - Profile* profile); + TemplateURLService* template_url_service); // Adds a new set of matches to the result set. Does not re-sort. void AppendMatches(const ACMatches& matches); @@ -75,7 +75,8 @@ class AutocompleteResult { // Removes duplicates, puts the list in sorted order and culls to leave only // the best kMaxMatches matches. Sets the default match to the best match // and updates the alternate nav URL. - void SortAndCull(const AutocompleteInput& input, Profile* profile); + void SortAndCull(const AutocompleteInput& input, + TemplateURLService* template_url_service); // Returns true if at least one match was copied from the last result. bool HasCopiedMatches() const; diff --git a/chrome/browser/autocomplete/autocomplete_result_unittest.cc b/chrome/browser/autocomplete/autocomplete_result_unittest.cc index 6dd6e62..312a890 100644 --- a/chrome/browser/autocomplete/autocomplete_result_unittest.cc +++ b/chrome/browser/autocomplete/autocomplete_result_unittest.cc @@ -189,14 +189,14 @@ void AutocompleteResultTest::RunCopyOldMatchesTest( PopulateAutocompleteMatches(last, last_size, &last_matches); AutocompleteResult last_result; last_result.AppendMatches(last_matches); - last_result.SortAndCull(input, test_util_.profile()); + last_result.SortAndCull(input, test_util_.model()); ACMatches current_matches; PopulateAutocompleteMatches(current, current_size, ¤t_matches); AutocompleteResult current_result; current_result.AppendMatches(current_matches); - current_result.SortAndCull(input, test_util_.profile()); - current_result.CopyOldMatches(input, last_result, test_util_.profile()); + current_result.SortAndCull(input, test_util_.model()); + current_result.CopyOldMatches(input, last_result, test_util_.model()); AssertResultMatches(current_result, expected, expected_size); } @@ -223,7 +223,7 @@ TEST_F(AutocompleteResultTest, Swap) { test_util_.profile())); matches.push_back(match); r1.AppendMatches(matches); - r1.SortAndCull(input, test_util_.profile()); + r1.SortAndCull(input, test_util_.model()); EXPECT_EQ(r1.begin(), r1.default_match()); EXPECT_EQ("http://a/", r1.alternate_nav_url().spec()); r1.Swap(&r2); @@ -306,7 +306,7 @@ TEST_F(AutocompleteResultTest, SortAndCullEmptyDestinationURLs) { true, ChromeAutocompleteSchemeClassifier( test_util_.profile())); - result.SortAndCull(input, test_util_.profile()); + result.SortAndCull(input, test_util_.model()); // Of the two results with the same non-empty destination URL, the // lower-relevance one should be dropped. All of the results with empty URLs @@ -354,7 +354,7 @@ TEST_F(AutocompleteResultTest, SortAndCullDuplicateSearchURLs) { true, ChromeAutocompleteSchemeClassifier( test_util_.profile())); - result.SortAndCull(input, test_util_.profile()); + result.SortAndCull(input, test_util_.model()); // We expect the 3rd and 4th results to be removed. ASSERT_EQ(3U, result.size()); @@ -408,7 +408,7 @@ TEST_F(AutocompleteResultTest, SortAndCullWithMatchDups) { true, ChromeAutocompleteSchemeClassifier( test_util_.profile())); - result.SortAndCull(input, test_util_.profile()); + result.SortAndCull(input, test_util_.model()); // Expect 3 unique results after SortAndCull(). ASSERT_EQ(3U, result.size()); @@ -464,7 +464,7 @@ TEST_F(AutocompleteResultTest, SortAndCullWithDemotionsByType) { true, ChromeAutocompleteSchemeClassifier( test_util_.profile())); - result.SortAndCull(input, test_util_.profile()); + result.SortAndCull(input, test_util_.model()); // Check the new ordering. The history-title results should be omitted. // We cannot check relevance scores because the matches are sorted by @@ -510,7 +510,7 @@ TEST_F(AutocompleteResultTest, SortAndCullWithMatchDupsAndDemotionsByType) { OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, false, false, false, true, ChromeAutocompleteSchemeClassifier(test_util_.profile())); - result.SortAndCull(input, test_util_.profile()); + result.SortAndCull(input, test_util_.model()); // The NAVSUGGEST dup-url stay above search-url since the navsuggest // variant should not be demoted. @@ -550,7 +550,7 @@ TEST_F(AutocompleteResultTest, SortAndCullReorderForDefaultMatch) { true, ChromeAutocompleteSchemeClassifier( test_util_.profile())); - result.SortAndCull(input, test_util_.profile()); + result.SortAndCull(input, test_util_.model()); AssertResultMatches(result, data, 4); } @@ -568,7 +568,7 @@ TEST_F(AutocompleteResultTest, SortAndCullReorderForDefaultMatch) { true, ChromeAutocompleteSchemeClassifier( test_util_.profile())); - result.SortAndCull(input, test_util_.profile()); + result.SortAndCull(input, test_util_.model()); ASSERT_EQ(4U, result.size()); EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); @@ -601,7 +601,7 @@ TEST_F(AutocompleteResultTest, SortAndCullWithDisableInlining) { true, ChromeAutocompleteSchemeClassifier( test_util_.profile())); - result.SortAndCull(input, test_util_.profile()); + result.SortAndCull(input, test_util_.model()); AssertResultMatches(result, data, 4); } @@ -628,7 +628,7 @@ TEST_F(AutocompleteResultTest, SortAndCullWithDisableInlining) { true, ChromeAutocompleteSchemeClassifier( test_util_.profile())); - result.SortAndCull(input, test_util_.profile()); + result.SortAndCull(input, test_util_.model()); ASSERT_EQ(4U, result.size()); EXPECT_EQ("http://b/", result.match_at(0)->destination_url.spec()); EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); @@ -651,7 +651,7 @@ TEST_F(AutocompleteResultTest, SortAndCullWithDisableInlining) { true, ChromeAutocompleteSchemeClassifier( test_util_.profile())); - result.SortAndCull(input, test_util_.profile()); + result.SortAndCull(input, test_util_.model()); AssertResultMatches(result, data, 4); } @@ -669,7 +669,7 @@ TEST_F(AutocompleteResultTest, SortAndCullWithDisableInlining) { true, ChromeAutocompleteSchemeClassifier( test_util_.profile())); - result.SortAndCull(input, test_util_.profile()); + result.SortAndCull(input, test_util_.model()); ASSERT_EQ(4U, result.size()); EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); @@ -691,7 +691,7 @@ TEST_F(AutocompleteResultTest, SortAndCullWithDisableInlining) { true, ChromeAutocompleteSchemeClassifier( test_util_.profile())); - result.SortAndCull(input, test_util_.profile()); + result.SortAndCull(input, test_util_.model()); ASSERT_EQ(4U, result.size()); EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); @@ -718,7 +718,7 @@ TEST_F(AutocompleteResultTest, SortAndCullWithDisableInlining) { true, ChromeAutocompleteSchemeClassifier( test_util_.profile())); - result.SortAndCull(input, test_util_.profile()); + result.SortAndCull(input, test_util_.model()); AssertResultMatches(result, data, 4); } @@ -741,7 +741,7 @@ TEST_F(AutocompleteResultTest, SortAndCullWithDisableInlining) { true, ChromeAutocompleteSchemeClassifier( test_util_.profile())); - result.SortAndCull(input, test_util_.profile()); + result.SortAndCull(input, test_util_.model()); ASSERT_EQ(4U, result.size()); EXPECT_EQ("http://b/", result.match_at(0)->destination_url.spec()); EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); diff --git a/chrome/browser/autocomplete/base_search_provider.cc b/chrome/browser/autocomplete/base_search_provider.cc index a01043e..22eb27f 100644 --- a/chrome/browser/autocomplete/base_search_provider.cc +++ b/chrome/browser/autocomplete/base_search_provider.cc @@ -177,7 +177,9 @@ void BaseSearchProvider::DeleteMatch(const AutocompleteMatch& match) { HistoryService* const history_service = HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); - TemplateURL* template_url = match.GetTemplateURL(profile_, false); + TemplateURLService* template_url_service = + TemplateURLServiceFactory::GetForProfile(profile_); + TemplateURL* template_url = match.GetTemplateURL(template_url_service, false); // This may be NULL if the template corresponding to the keyword has been // deleted or there is no keyword set. if (template_url != NULL) { diff --git a/chrome/browser/autocomplete/history_url_provider_unittest.cc b/chrome/browser/autocomplete/history_url_provider_unittest.cc index 8cc98c6..daefd65 100644 --- a/chrome/browser/autocomplete/history_url_provider_unittest.cc +++ b/chrome/browser/autocomplete/history_url_provider_unittest.cc @@ -294,8 +294,10 @@ void HistoryURLProviderTest::RunTest( matches_ = autocomplete_->matches(); if (sort_matches_) { + TemplateURLService* service = + TemplateURLServiceFactory::GetForProfile(profile_.get()); for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) - i->ComputeStrippedDestinationURL(profile_.get()); + i->ComputeStrippedDestinationURL(service); AutocompleteResult::DedupMatchesByDestination( input.current_page_classification(), false, &matches_); std::sort(matches_.begin(), matches_.end(), diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc index 9f4163e..e68286b 100644 --- a/chrome/browser/autocomplete/search_provider_unittest.cc +++ b/chrome/browser/autocomplete/search_provider_unittest.cc @@ -896,8 +896,9 @@ TEST_F(SearchProviderTest, KeywordOrderingAndDescriptions) { AddSearchToHistory(keyword_t_url_, ASCIIToUTF16("term2"), 1); profile_.BlockUntilHistoryProcessesPendingRequests(); - AutocompleteController controller(&profile_, NULL, - AutocompleteProvider::TYPE_SEARCH); + AutocompleteController controller(&profile_, + TemplateURLServiceFactory::GetForProfile(&profile_), + NULL, AutocompleteProvider::TYPE_SEARCH); controller.Start(AutocompleteInput( ASCIIToUTF16("k t"), base::string16::npos, base::string16(), GURL(), metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, diff --git a/chrome/browser/autocomplete/shortcuts_backend.cc b/chrome/browser/autocomplete/shortcuts_backend.cc index 71254aa..fd0916c 100644 --- a/chrome/browser/autocomplete/shortcuts_backend.cc +++ b/chrome/browser/autocomplete/shortcuts_backend.cc @@ -22,6 +22,7 @@ #include "chrome/browser/history/shortcuts_database.h" #include "chrome/browser/omnibox/omnibox_log.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" #include "chrome/common/autocomplete_match_type.h" #include "chrome/common/chrome_constants.h" @@ -143,12 +144,14 @@ history::ShortcutsDatabase::Shortcut::MatchCore ShortcutsBackend::MatchToMatchCore(const AutocompleteMatch& match, Profile* profile) { const AutocompleteMatch::Type match_type = GetTypeForShortcut(match.type); + TemplateURLService* service = + TemplateURLServiceFactory::GetForProfile(profile); const AutocompleteMatch& normalized_match = AutocompleteMatch::IsSpecializedSearchType(match.type) ? BaseSearchProvider::CreateSearchSuggestion( match.search_terms_args->search_terms, match_type, (match.transition == content::PAGE_TRANSITION_KEYWORD), - match.GetTemplateURL(profile, false), + match.GetTemplateURL(service, false), UIThreadSearchTermsData(profile)) : match; return history::ShortcutsDatabase::Shortcut::MatchCore( diff --git a/chrome/browser/autocomplete/shortcuts_provider.cc b/chrome/browser/autocomplete/shortcuts_provider.cc index 7d5b02a..42c58ab 100644 --- a/chrome/browser/autocomplete/shortcuts_provider.cc +++ b/chrome/browser/autocomplete/shortcuts_provider.cc @@ -28,6 +28,7 @@ #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/omnibox/omnibox_field_trial.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "components/autocomplete/autocomplete_input.h" @@ -158,7 +159,8 @@ void ShortcutsProvider::GetMatches(const AutocompleteInput& input) { if (relevance) { matches_.push_back(ShortcutToACMatch(it->second, relevance, input, fixed_up_input, input_as_gurl)); - matches_.back().ComputeStrippedDestinationURL(profile_); + matches_.back().ComputeStrippedDestinationURL( + TemplateURLServiceFactory::GetForProfile(profile_)); } } // Remove duplicates. Duplicates don't need to be preserved in the matches diff --git a/chrome/browser/ui/app_list/search/omnibox_provider.cc b/chrome/browser/ui/app_list/search/omnibox_provider.cc index e6fd051..eeda768 100644 --- a/chrome/browser/ui/app_list/search/omnibox_provider.cc +++ b/chrome/browser/ui/app_list/search/omnibox_provider.cc @@ -9,6 +9,7 @@ #include "chrome/browser/autocomplete/autocomplete_match.h" #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" #include "chrome/browser/autocomplete/search_provider.h" +#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/ui/app_list/search/chrome_search_result.h" #include "chrome/browser/ui/browser_navigator.h" #include "components/autocomplete/autocomplete_input.h" @@ -136,6 +137,7 @@ OmniboxProvider::OmniboxProvider(Profile* profile) : profile_(profile), controller_(new AutocompleteController( profile, + TemplateURLServiceFactory::GetForProfile(profile), this, AutocompleteClassifier::kDefaultOmniboxProviders & ~AutocompleteProvider::TYPE_ZERO_SUGGEST)) { diff --git a/chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.h b/chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.h index e15ba90..48ea1d9 100644 --- a/chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.h +++ b/chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.h @@ -9,6 +9,8 @@ #include "chrome/browser/autocomplete/autocomplete_match.h" #include "components/infobars/core/infobar_delegate.h" +class Profile; + namespace content { class WebContents; } diff --git a/chrome/browser/ui/omnibox/omnibox_controller.cc b/chrome/browser/ui/omnibox/omnibox_controller.cc index 0917ebb..7c63988 100644 --- a/chrome/browser/ui/omnibox/omnibox_controller.cc +++ b/chrome/browser/ui/omnibox/omnibox_controller.cc @@ -15,6 +15,7 @@ #include "chrome/browser/prerender/prerender_manager_factory.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search/search.h" +#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" @@ -73,7 +74,8 @@ OmniboxController::OmniboxController(OmniboxEditModel* omnibox_edit_model, : omnibox_edit_model_(omnibox_edit_model), profile_(profile), popup_(NULL), - autocomplete_controller_(new AutocompleteController(profile, this, + autocomplete_controller_(new AutocompleteController(profile, + TemplateURLServiceFactory::GetForProfile(profile), this, AutocompleteClassifier::kDefaultOmniboxProviders)) { } diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.cc b/chrome/browser/ui/omnibox/omnibox_edit_model.cc index 0d81e3c..9cc2394 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_model.cc +++ b/chrome/browser/ui/omnibox/omnibox_edit_model.cc @@ -687,7 +687,9 @@ void OmniboxEditModel::AcceptInput(WindowOpenDisposition disposition, match.transition = content::PAGE_TRANSITION_LINK; } - const TemplateURL* template_url = match.GetTemplateURL(profile_, false); + TemplateURLService* service = + TemplateURLServiceFactory::GetForProfile(profile_); + const TemplateURL* template_url = match.GetTemplateURL(service, false); if (template_url && template_url->url_ref().HasGoogleBaseURLs( UIThreadSearchTermsData(profile_))) { GoogleURLTracker* tracker = @@ -784,7 +786,9 @@ void OmniboxEditModel::OpenMatch(AutocompleteMatch match, << "An omnibox focus should have occurred before opening a match."; UMA_HISTOGRAM_TIMES(kFocusToOpenTimeHistogram, now - last_omnibox_focus_); - TemplateURL* template_url = match.GetTemplateURL(profile_, false); + TemplateURLService* service = + TemplateURLServiceFactory::GetForProfile(profile_); + TemplateURL* template_url = match.GetTemplateURL(service, false); if (template_url) { if (match.transition == content::PAGE_TRANSITION_KEYWORD) { // The user is using a non-substituting keyword or is explicitly in @@ -1265,7 +1269,9 @@ void OmniboxEditModel::OnCurrentMatchChanged() { // OnPopupDataChanged use their previous state to detect changes. base::string16 keyword; bool is_keyword_hint; - match.GetKeywordUIState(profile_, &keyword, &is_keyword_hint); + TemplateURLService* service = + TemplateURLServiceFactory::GetForProfile(profile_); + match.GetKeywordUIState(service, &keyword, &is_keyword_hint); if (popup_model()) popup_model()->OnResultChanged(); // OnPopupDataChanged() resets OmniboxController's |current_match_| early diff --git a/chrome/browser/ui/omnibox/omnibox_navigation_observer.h b/chrome/browser/ui/omnibox/omnibox_navigation_observer.h index 0b80411..e180100 100644 --- a/chrome/browser/ui/omnibox/omnibox_navigation_observer.h +++ b/chrome/browser/ui/omnibox/omnibox_navigation_observer.h @@ -15,6 +15,7 @@ #include "content/public/browser/web_contents_observer.h" #include "net/url_request/url_fetcher_delegate.h" +class Profile; class ShortcutsBackend; namespace net { diff --git a/chrome/browser/ui/omnibox/omnibox_popup_model.cc b/chrome/browser/ui/omnibox/omnibox_popup_model.cc index e237c28..9c6651e 100644 --- a/chrome/browser/ui/omnibox/omnibox_popup_model.cc +++ b/chrome/browser/ui/omnibox/omnibox_popup_model.cc @@ -159,7 +159,9 @@ void OmniboxPopupModel::SetSelectedLine(size_t line, // eliminated and just become a call to the observer on the edit. base::string16 keyword; bool is_keyword_hint; - match.GetKeywordUIState(edit_model_->profile(), &keyword, &is_keyword_hint); + TemplateURLService* service = + TemplateURLServiceFactory::GetForProfile(edit_model_->profile()); + match.GetKeywordUIState(service, &keyword, &is_keyword_hint); if (reset_to_default) { edit_model_->OnPopupDataChanged(match.inline_autocompletion, NULL, @@ -242,7 +244,9 @@ void OmniboxPopupModel::TryDeletingCurrentItem() { gfx::Image OmniboxPopupModel::GetIconIfExtensionMatch( const AutocompleteMatch& match) const { Profile* profile = edit_model_->profile(); - const TemplateURL* template_url = match.GetTemplateURL(profile, false); + TemplateURLService* service = + TemplateURLServiceFactory::GetForProfile(profile); + const TemplateURL* template_url = match.GetTemplateURL(service, false); if (template_url && (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) { return extensions::OmniboxAPI::Get(profile)->GetOmniboxPopupIcon( diff --git a/chrome/browser/ui/views/frame/test_with_browser_view.cc b/chrome/browser/ui/views/frame/test_with_browser_view.cc index a4b4d93..df53fdd 100644 --- a/chrome/browser/ui/views/frame/test_with_browser_view.cc +++ b/chrome/browser/ui/views/frame/test_with_browser_view.cc @@ -31,10 +31,11 @@ KeyedService* CreateTemplateURLService(content::BrowserContext* profile) { return new TemplateURLService(static_cast<Profile*>(profile), NULL); } -KeyedService* CreateAutocompleteClassifier(content::BrowserContext* profile) { +KeyedService* CreateAutocompleteClassifier(content::BrowserContext* context) { + Profile* profile = static_cast<Profile*>(context); return new AutocompleteClassifier( make_scoped_ptr(new AutocompleteController( - static_cast<Profile*>(profile), NULL, + profile, TemplateURLServiceFactory::GetForProfile(profile), NULL, AutocompleteClassifier::kDefaultOmniboxProviders)), scoped_ptr<AutocompleteSchemeClassifier>(new TestSchemeClassifier())); } diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc index 9a8ac60..6013d5a 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc +++ b/chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc @@ -5,6 +5,7 @@ #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" #include "base/command_line.h" +#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_window.h" @@ -270,7 +271,9 @@ IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, CloseOmniboxPopupOnTextDrag) { match.destination_url = GURL("http://autocomplete-result2/"); matches.push_back(match); results.AppendMatches(matches); - results.SortAndCull(AutocompleteInput(), browser()->profile()); + results.SortAndCull( + AutocompleteInput(), + TemplateURLServiceFactory::GetForProfile(browser()->profile())); // The omnibox popup should open with suggestions displayed. omnibox_view->model()->popup_model()->OnResultChanged(); diff --git a/chrome/browser/ui/webui/omnibox/omnibox_ui_handler.cc b/chrome/browser/ui/webui/omnibox/omnibox_ui_handler.cc index 9eab24c..ad142a4 100644 --- a/chrome/browser/ui/webui/omnibox/omnibox_ui_handler.cc +++ b/chrome/browser/ui/webui/omnibox/omnibox_ui_handler.cc @@ -21,6 +21,7 @@ #include "chrome/browser/history/history_service.h" #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/search/search.h" +#include "chrome/browser/search_engines/template_url_service_factory.h" #include "components/history/core/browser/url_database.h" #include "components/metrics/proto/omnibox_event.pb.h" #include "components/search_engines/template_url.h" @@ -180,6 +181,8 @@ void OmniboxUIHandler::StartOmniboxQuery(const mojo::String& input_string, } void OmniboxUIHandler::ResetController() { - controller_.reset(new AutocompleteController(profile_, this, + controller_.reset(new AutocompleteController(profile_, + TemplateURLServiceFactory::GetForProfile(profile_), + this, AutocompleteClassifier::kDefaultOmniboxProviders)); } diff --git a/chrome/browser/ui/webui/options/home_page_overlay_handler.cc b/chrome/browser/ui/webui/options/home_page_overlay_handler.cc index 56e912a..e6ae48f 100644 --- a/chrome/browser/ui/webui/options/home_page_overlay_handler.cc +++ b/chrome/browser/ui/webui/options/home_page_overlay_handler.cc @@ -12,6 +12,7 @@ #include "chrome/browser/autocomplete/autocomplete_result.h" #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search_engines/template_url_service_factory.h" #include "components/autocomplete/autocomplete_input.h" #include "components/metrics/proto/omnibox_event.pb.h" #include "content/public/browser/web_ui.h" @@ -35,7 +36,8 @@ void HomePageOverlayHandler::RegisterMessages() { void HomePageOverlayHandler::InitializeHandler() { Profile* profile = Profile::FromWebUI(web_ui()); - autocomplete_controller_.reset(new AutocompleteController(profile, this, + autocomplete_controller_.reset(new AutocompleteController(profile, + TemplateURLServiceFactory::GetForProfile(profile), this, AutocompleteClassifier::kDefaultOmniboxProviders)); } diff --git a/chrome/browser/ui/webui/options/startup_pages_handler.cc b/chrome/browser/ui/webui/options/startup_pages_handler.cc index ffd26ce4..5e2ab82 100644 --- a/chrome/browser/ui/webui/options/startup_pages_handler.cc +++ b/chrome/browser/ui/webui/options/startup_pages_handler.cc @@ -15,6 +15,7 @@ #include "chrome/browser/custom_home_pages_table_model.h" #include "chrome/browser/prefs/session_startup_pref.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/autocomplete/autocomplete_input.h" #include "components/metrics/proto/omnibox_event.pb.h" @@ -94,7 +95,8 @@ void StartupPagesHandler::InitializeHandler() { base::Bind(&StartupPagesHandler::UpdateStartupPages, base::Unretained(this))); - autocomplete_controller_.reset(new AutocompleteController(profile, this, + autocomplete_controller_.reset(new AutocompleteController(profile, + TemplateURLServiceFactory::GetForProfile(profile), this, AutocompleteClassifier::kDefaultOmniboxProviders)); } |