Stop depending on TemplateURLServiceFactory from SearchProvider

BUG=388515

Review URL: https://codereview.chromium.org/439243004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287487 0039d316-1c4b-4281-b951-d872f2087c98
parent b3ffb4c6
...@@ -200,13 +200,14 @@ AutocompleteController::AutocompleteController( ...@@ -200,13 +200,14 @@ AutocompleteController::AutocompleteController(
} }
#endif #endif
if (provider_types & AutocompleteProvider::TYPE_SEARCH) { if (provider_types & AutocompleteProvider::TYPE_SEARCH) {
search_provider_ = new SearchProvider(this, profile); search_provider_ = new SearchProvider(this, template_url_service, profile);
providers_.push_back(search_provider_); providers_.push_back(search_provider_);
} }
if (provider_types & AutocompleteProvider::TYPE_SHORTCUTS) if (provider_types & AutocompleteProvider::TYPE_SHORTCUTS)
providers_.push_back(new ShortcutsProvider(profile)); providers_.push_back(new ShortcutsProvider(profile));
if (provider_types & AutocompleteProvider::TYPE_ZERO_SUGGEST) { if (provider_types & AutocompleteProvider::TYPE_ZERO_SUGGEST) {
zero_suggest_provider_ = ZeroSuggestProvider::Create(this, profile); zero_suggest_provider_ = ZeroSuggestProvider::Create(
this, template_url_service, profile);
if (zero_suggest_provider_) if (zero_suggest_provider_)
providers_.push_back(zero_suggest_provider_); providers_.push_back(zero_suggest_provider_);
} }
......
...@@ -16,9 +16,6 @@ ...@@ -16,9 +16,6 @@
#include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/omnibox/omnibox_field_trial.h" #include "chrome/browser/omnibox/omnibox_field_trial.h"
#include "chrome/browser/profiles/profile.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/search_engines/ui_thread_search_terms_data.h"
#include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
...@@ -29,7 +26,6 @@ ...@@ -29,7 +26,6 @@
#include "components/search_engines/template_url_prepopulate_data.h" #include "components/search_engines/template_url_prepopulate_data.h"
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
#include "components/sync_driver/sync_prefs.h" #include "components/sync_driver/sync_prefs.h"
#include "content/public/common/url_constants.h"
#include "net/base/escape.h" #include "net/base/escape.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h" #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "net/url_request/url_fetcher.h" #include "net/url_request/url_fetcher.h"
...@@ -99,10 +95,12 @@ const int BaseSearchProvider::kKeywordProviderURLFetcherID = 2; ...@@ -99,10 +95,12 @@ const int BaseSearchProvider::kKeywordProviderURLFetcherID = 2;
const int BaseSearchProvider::kDeletionURLFetcherID = 3; const int BaseSearchProvider::kDeletionURLFetcherID = 3;
BaseSearchProvider::BaseSearchProvider(AutocompleteProviderListener* listener, BaseSearchProvider::BaseSearchProvider(AutocompleteProviderListener* listener,
TemplateURLService* template_url_service,
Profile* profile, Profile* profile,
AutocompleteProvider::Type type) AutocompleteProvider::Type type)
: AutocompleteProvider(type), : AutocompleteProvider(type),
listener_(listener), listener_(listener),
template_url_service_(template_url_service),
profile_(profile), profile_(profile),
field_trial_triggered_(false), field_trial_triggered_(false),
field_trial_triggered_in_session_(false), field_trial_triggered_in_session_(false),
...@@ -149,9 +147,8 @@ void BaseSearchProvider::DeleteMatch(const AutocompleteMatch& match) { ...@@ -149,9 +147,8 @@ void BaseSearchProvider::DeleteMatch(const AutocompleteMatch& match) {
HistoryService* const history_service = HistoryService* const history_service =
HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
TemplateURLService* template_url_service = TemplateURL* template_url =
TemplateURLServiceFactory::GetForProfile(profile_); match.GetTemplateURL(template_url_service_, false);
TemplateURL* template_url = match.GetTemplateURL(template_url_service, false);
// This may be NULL if the template corresponding to the keyword has been // This may be NULL if the template corresponding to the keyword has been
// deleted or there is no keyword set. // deleted or there is no keyword set.
if (template_url != NULL) { if (template_url != NULL) {
...@@ -197,12 +194,11 @@ void BaseSearchProvider::SetDeletionURL(const std::string& deletion_url, ...@@ -197,12 +194,11 @@ void BaseSearchProvider::SetDeletionURL(const std::string& deletion_url,
AutocompleteMatch* match) { AutocompleteMatch* match) {
if (deletion_url.empty()) if (deletion_url.empty())
return; return;
TemplateURLService* template_service = if (!template_url_service_)
TemplateURLServiceFactory::GetForProfile(profile_);
if (!template_service)
return; return;
GURL url = template_service->GetDefaultSearchProvider()->GenerateSearchURL( GURL url =
template_service->search_terms_data()); template_url_service_->GetDefaultSearchProvider()->GenerateSearchURL(
template_url_service_->search_terms_data());
url = url.GetOrigin().Resolve(deletion_url); url = url.GetOrigin().Resolve(deletion_url);
if (url.is_valid()) { if (url.is_valid()) {
match->RecordAdditionalInfo(BaseSearchProvider::kDeletionUrlKey, match->RecordAdditionalInfo(BaseSearchProvider::kDeletionUrlKey,
...@@ -295,6 +291,7 @@ bool BaseSearchProvider::ZeroSuggestEnabled( ...@@ -295,6 +291,7 @@ bool BaseSearchProvider::ZeroSuggestEnabled(
const GURL& suggest_url, const GURL& suggest_url,
const TemplateURL* template_url, const TemplateURL* template_url,
OmniboxEventProto::PageClassification page_classification, OmniboxEventProto::PageClassification page_classification,
const SearchTermsData& search_terms_data,
Profile* profile) { Profile* profile) {
if (!OmniboxFieldTrial::InZeroSuggestFieldTrial()) if (!OmniboxFieldTrial::InZeroSuggestFieldTrial())
return false; return false;
...@@ -324,7 +321,6 @@ bool BaseSearchProvider::ZeroSuggestEnabled( ...@@ -324,7 +321,6 @@ bool BaseSearchProvider::ZeroSuggestEnabled(
// Only make the request if we know that the provider supports zero suggest // Only make the request if we know that the provider supports zero suggest
// (currently only the prepopulated Google provider). // (currently only the prepopulated Google provider).
UIThreadSearchTermsData search_terms_data(profile);
if (template_url == NULL || if (template_url == NULL ||
!template_url->SupportsReplacement(search_terms_data) || !template_url->SupportsReplacement(search_terms_data) ||
TemplateURLPrepopulateData::GetEngineType( TemplateURLPrepopulateData::GetEngineType(
...@@ -340,9 +336,10 @@ bool BaseSearchProvider::CanSendURL( ...@@ -340,9 +336,10 @@ bool BaseSearchProvider::CanSendURL(
const GURL& suggest_url, const GURL& suggest_url,
const TemplateURL* template_url, const TemplateURL* template_url,
OmniboxEventProto::PageClassification page_classification, OmniboxEventProto::PageClassification page_classification,
const SearchTermsData& search_terms_data,
Profile* profile) { Profile* profile) {
if (!ZeroSuggestEnabled(suggest_url, template_url, page_classification, if (!ZeroSuggestEnabled(suggest_url, template_url, page_classification,
profile)) search_terms_data, profile))
return false; return false;
if (!current_page_url.is_valid()) if (!current_page_url.is_valid())
...@@ -412,7 +409,7 @@ void BaseSearchProvider::AddMatchToMap( ...@@ -412,7 +409,7 @@ void BaseSearchProvider::AddMatchToMap(
AutocompleteMatch match = CreateSearchSuggestion( AutocompleteMatch match = CreateSearchSuggestion(
this, GetInput(result.from_keyword_provider()), result, this, GetInput(result.from_keyword_provider()), result,
GetTemplateURL(result.from_keyword_provider()), GetTemplateURL(result.from_keyword_provider()),
UIThreadSearchTermsData(profile_), accepted_suggestion, template_url_service_->search_terms_data(), accepted_suggestion,
ShouldAppendExtraParams(result)); ShouldAppendExtraParams(result));
if (!match.destination_url.is_valid()) if (!match.destination_url.is_valid())
return; return;
......
...@@ -26,8 +26,10 @@ ...@@ -26,8 +26,10 @@
class AutocompleteProviderListener; class AutocompleteProviderListener;
class GURL; class GURL;
class Profile; class Profile;
class SearchTermsData;
class SuggestionDeletionHandler; class SuggestionDeletionHandler;
class TemplateURL; class TemplateURL;
class TemplateURLService;
namespace base { namespace base {
class DictionaryValue; class DictionaryValue;
...@@ -51,6 +53,7 @@ class BaseSearchProvider : public AutocompleteProvider, ...@@ -51,6 +53,7 @@ class BaseSearchProvider : public AutocompleteProvider,
static const int kDeletionURLFetcherID; static const int kDeletionURLFetcherID;
BaseSearchProvider(AutocompleteProviderListener* listener, BaseSearchProvider(AutocompleteProviderListener* listener,
TemplateURLService* template_url_service,
Profile* profile, Profile* profile,
AutocompleteProvider::Type type); AutocompleteProvider::Type type);
...@@ -142,6 +145,7 @@ class BaseSearchProvider : public AutocompleteProvider, ...@@ -142,6 +145,7 @@ class BaseSearchProvider : public AutocompleteProvider,
const GURL& suggest_url, const GURL& suggest_url,
const TemplateURL* template_url, const TemplateURL* template_url,
metrics::OmniboxEventProto::PageClassification page_classification, metrics::OmniboxEventProto::PageClassification page_classification,
const SearchTermsData& search_terms_data,
Profile* profile); Profile* profile);
// Returns whether we can send the URL of the current page in any suggest // Returns whether we can send the URL of the current page in any suggest
...@@ -165,6 +169,7 @@ class BaseSearchProvider : public AutocompleteProvider, ...@@ -165,6 +169,7 @@ class BaseSearchProvider : public AutocompleteProvider,
const GURL& suggest_url, const GURL& suggest_url,
const TemplateURL* template_url, const TemplateURL* template_url,
metrics::OmniboxEventProto::PageClassification page_classification, metrics::OmniboxEventProto::PageClassification page_classification,
const SearchTermsData& search_terms_data,
Profile* profile); Profile* profile);
// net::URLFetcherDelegate: // net::URLFetcherDelegate:
...@@ -252,6 +257,7 @@ class BaseSearchProvider : public AutocompleteProvider, ...@@ -252,6 +257,7 @@ class BaseSearchProvider : public AutocompleteProvider,
virtual void UpdateMatches() = 0; virtual void UpdateMatches() = 0;
AutocompleteProviderListener* listener_; AutocompleteProviderListener* listener_;
TemplateURLService* template_url_service_;
Profile* profile_; Profile* profile_;
// Whether a field trial, if any, has triggered in the most recent // Whether a field trial, if any, has triggered in the most recent
......
...@@ -28,9 +28,6 @@ ...@@ -28,9 +28,6 @@
#include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/omnibox/omnibox_field_trial.h" #include "chrome/browser/omnibox/omnibox_field_trial.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/search/instant_controller.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/autocomplete/autocomplete_provider_listener.h" #include "components/autocomplete/autocomplete_provider_listener.h"
#include "components/autocomplete/url_prefix.h" #include "components/autocomplete/url_prefix.h"
...@@ -133,9 +130,11 @@ class SearchProvider::CompareScoredResults { ...@@ -133,9 +130,11 @@ class SearchProvider::CompareScoredResults {
int SearchProvider::kMinimumTimeBetweenSuggestQueriesMs = 100; int SearchProvider::kMinimumTimeBetweenSuggestQueriesMs = 100;
SearchProvider::SearchProvider(AutocompleteProviderListener* listener, SearchProvider::SearchProvider(AutocompleteProviderListener* listener,
TemplateURLService* template_url_service,
Profile* profile) Profile* profile)
: BaseSearchProvider(listener, profile, AutocompleteProvider::TYPE_SEARCH), : BaseSearchProvider(listener, template_url_service, profile,
providers_(TemplateURLServiceFactory::GetForProfile(profile)) { AutocompleteProvider::TYPE_SEARCH),
providers_(template_url_service) {
} }
// static // static
...@@ -667,7 +666,8 @@ net::URLFetcher* SearchProvider::CreateSuggestFetcher( ...@@ -667,7 +666,8 @@ net::URLFetcher* SearchProvider::CreateSuggestFetcher(
// Send the current page URL if user setting and URL requirements are met and // Send the current page URL if user setting and URL requirements are met and
// the user is in the field trial. // the user is in the field trial.
if (CanSendURL(current_page_url_, suggest_url, template_url, if (CanSendURL(current_page_url_, suggest_url, template_url,
input.current_page_classification(), profile_) && input.current_page_classification(),
template_url_service_->search_terms_data(), profile_) &&
OmniboxFieldTrial::InZeroSuggestAfterTypingFieldTrial()) { OmniboxFieldTrial::InZeroSuggestAfterTypingFieldTrial()) {
search_term_args.current_page_url = current_page_url_.spec(); search_term_args.current_page_url = current_page_url_.spec();
// Create the suggest URL again with the current page URL. // Create the suggest URL again with the current page URL.
......
...@@ -45,7 +45,9 @@ class URLFetcher; ...@@ -45,7 +45,9 @@ class URLFetcher;
// suggestions. // suggestions.
class SearchProvider : public BaseSearchProvider { class SearchProvider : public BaseSearchProvider {
public: public:
SearchProvider(AutocompleteProviderListener* listener, Profile* profile); SearchProvider(AutocompleteProviderListener* listener,
TemplateURLService* template_url_service,
Profile* profile);
// Extracts the suggest response metadata which SearchProvider previously // Extracts the suggest response metadata which SearchProvider previously
// stored for |match|. // stored for |match|.
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "components/metrics/proto/omnibox_event.pb.h" #include "components/metrics/proto/omnibox_event.pb.h"
#include "components/search_engines/search_engine_type.h" #include "components/search_engines/search_engine_type.h"
#include "components/search_engines/search_engines_switches.h" #include "components/search_engines/search_engines_switches.h"
#include "components/search_engines/search_terms_data.h"
#include "components/search_engines/template_url.h" #include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
#include "components/signin/core/browser/signin_manager.h" #include "components/signin/core/browser/signin_manager.h"
...@@ -66,9 +67,9 @@ ACMatches::const_iterator FindDefaultMatch(const ACMatches& matches) { ...@@ -66,9 +67,9 @@ ACMatches::const_iterator FindDefaultMatch(const ACMatches& matches) {
class SuggestionDeletionHandler; class SuggestionDeletionHandler;
class SearchProviderForTest : public SearchProvider { class SearchProviderForTest : public SearchProvider {
public: public:
SearchProviderForTest( SearchProviderForTest(AutocompleteProviderListener* listener,
AutocompleteProviderListener* listener, TemplateURLService* template_url_service,
Profile* profile); Profile* profile);
bool is_success() { return is_success_; }; bool is_success() { return is_success_; };
protected: protected:
...@@ -82,8 +83,10 @@ class SearchProviderForTest : public SearchProvider { ...@@ -82,8 +83,10 @@ class SearchProviderForTest : public SearchProvider {
SearchProviderForTest::SearchProviderForTest( SearchProviderForTest::SearchProviderForTest(
AutocompleteProviderListener* listener, AutocompleteProviderListener* listener,
TemplateURLService* template_url_service,
Profile* profile) Profile* profile)
: SearchProvider(listener, profile), is_success_(false) { : SearchProvider(listener, template_url_service, profile),
is_success_(false) {
} }
SearchProviderForTest::~SearchProviderForTest() { SearchProviderForTest::~SearchProviderForTest() {
...@@ -285,7 +288,7 @@ void SearchProviderTest::SetUp() { ...@@ -285,7 +288,7 @@ void SearchProviderTest::SetUp() {
// requests to ensure the InMemoryDatabase is the state we expect it. // requests to ensure the InMemoryDatabase is the state we expect it.
profile_.BlockUntilHistoryProcessesPendingRequests(); profile_.BlockUntilHistoryProcessesPendingRequests();
provider_ = new SearchProviderForTest(this, &profile_); provider_ = new SearchProviderForTest(this, turl_model, &profile_);
provider_->kMinimumTimeBetweenSuggestQueriesMs = 0; provider_->kMinimumTimeBetweenSuggestQueriesMs = 0;
} }
...@@ -2945,7 +2948,7 @@ TEST_F(SearchProviderTest, CanSendURL) { ...@@ -2945,7 +2948,7 @@ TEST_F(SearchProviderTest, CanSendURL) {
EXPECT_FALSE(SearchProvider::CanSendURL( EXPECT_FALSE(SearchProvider::CanSendURL(
GURL("http://www.google.com/search"), GURL("http://www.google.com/search"),
GURL("https://www.google.com/complete/search"), &google_template_url, GURL("https://www.google.com/complete/search"), &google_template_url,
metrics::OmniboxEventProto::OTHER, &profile_)); metrics::OmniboxEventProto::OTHER, SearchTermsData(), &profile_));
SigninManagerBase* signin = SigninManagerFactory::GetForProfile(&profile_); SigninManagerBase* signin = SigninManagerFactory::GetForProfile(&profile_);
signin->SetAuthenticatedUsername("test"); signin->SetAuthenticatedUsername("test");
...@@ -2953,7 +2956,7 @@ TEST_F(SearchProviderTest, CanSendURL) { ...@@ -2953,7 +2956,7 @@ TEST_F(SearchProviderTest, CanSendURL) {
EXPECT_TRUE(SearchProvider::CanSendURL( EXPECT_TRUE(SearchProvider::CanSendURL(
GURL("http://www.google.com/search"), GURL("http://www.google.com/search"),
GURL("https://www.google.com/complete/search"), &google_template_url, GURL("https://www.google.com/complete/search"), &google_template_url,
metrics::OmniboxEventProto::OTHER, &profile_)); metrics::OmniboxEventProto::OTHER, SearchTermsData(), &profile_));
// Not in field trial. // Not in field trial.
ResetFieldTrialList(); ResetFieldTrialList();
...@@ -2961,7 +2964,7 @@ TEST_F(SearchProviderTest, CanSendURL) { ...@@ -2961,7 +2964,7 @@ TEST_F(SearchProviderTest, CanSendURL) {
EXPECT_FALSE(SearchProvider::CanSendURL( EXPECT_FALSE(SearchProvider::CanSendURL(
GURL("http://www.google.com/search"), GURL("http://www.google.com/search"),
GURL("https://www.google.com/complete/search"), &google_template_url, GURL("https://www.google.com/complete/search"), &google_template_url,
metrics::OmniboxEventProto::OTHER, &profile_)); metrics::OmniboxEventProto::OTHER, SearchTermsData(), &profile_));
ResetFieldTrialList(); ResetFieldTrialList();
CreateZeroSuggestFieldTrial(true); CreateZeroSuggestFieldTrial(true);
...@@ -2969,59 +2972,61 @@ TEST_F(SearchProviderTest, CanSendURL) { ...@@ -2969,59 +2972,61 @@ TEST_F(SearchProviderTest, CanSendURL) {
EXPECT_FALSE(SearchProvider::CanSendURL( EXPECT_FALSE(SearchProvider::CanSendURL(
GURL("badpageurl"), GURL("badpageurl"),
GURL("https://www.google.com/complete/search"), &google_template_url, GURL("https://www.google.com/complete/search"), &google_template_url,
metrics::OmniboxEventProto::OTHER, &profile_)); metrics::OmniboxEventProto::OTHER, SearchTermsData(), &profile_));
// Invalid page classification. // Invalid page classification.
EXPECT_FALSE(SearchProvider::CanSendURL( EXPECT_FALSE(SearchProvider::CanSendURL(
GURL("http://www.google.com/search"), GURL("http://www.google.com/search"),
GURL("https://www.google.com/complete/search"), &google_template_url, GURL("https://www.google.com/complete/search"), &google_template_url,
metrics::OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, metrics::OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS,
&profile_)); SearchTermsData(), &profile_));
// Invalid page classification. // Invalid page classification.
EXPECT_FALSE(SearchProvider::CanSendURL( EXPECT_FALSE(SearchProvider::CanSendURL(
GURL("http://www.google.com/search"), GURL("http://www.google.com/search"),
GURL("https://www.google.com/complete/search"), &google_template_url, GURL("https://www.google.com/complete/search"), &google_template_url,
metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS,
&profile_)); SearchTermsData(), &profile_));
// HTTPS page URL on same domain as provider. // HTTPS page URL on same domain as provider.
EXPECT_TRUE(SearchProvider::CanSendURL( EXPECT_TRUE(SearchProvider::CanSendURL(
GURL("https://www.google.com/search"), GURL("https://www.google.com/search"),
GURL("https://www.google.com/complete/search"), GURL("https://www.google.com/complete/search"),
&google_template_url, metrics::OmniboxEventProto::OTHER, &profile_)); &google_template_url, metrics::OmniboxEventProto::OTHER,
SearchTermsData(), &profile_));
// Non-HTTP[S] page URL on same domain as provider. // Non-HTTP[S] page URL on same domain as provider.
EXPECT_FALSE(SearchProvider::CanSendURL( EXPECT_FALSE(SearchProvider::CanSendURL(
GURL("ftp://www.google.com/search"), GURL("ftp://www.google.com/search"),
GURL("https://www.google.com/complete/search"), &google_template_url, GURL("https://www.google.com/complete/search"), &google_template_url,
metrics::OmniboxEventProto::OTHER, &profile_)); metrics::OmniboxEventProto::OTHER, SearchTermsData(), &profile_));
// Non-HTTP page URL on different domain. // Non-HTTP page URL on different domain.
EXPECT_FALSE(SearchProvider::CanSendURL( EXPECT_FALSE(SearchProvider::CanSendURL(
GURL("https://www.notgoogle.com/search"), GURL("https://www.notgoogle.com/search"),
GURL("https://www.google.com/complete/search"), &google_template_url, GURL("https://www.google.com/complete/search"), &google_template_url,
metrics::OmniboxEventProto::OTHER, &profile_)); metrics::OmniboxEventProto::OTHER, SearchTermsData(), &profile_));
// Non-HTTPS provider. // Non-HTTPS provider.
EXPECT_FALSE(SearchProvider::CanSendURL( EXPECT_FALSE(SearchProvider::CanSendURL(
GURL("http://www.google.com/search"), GURL("http://www.google.com/search"),
GURL("http://www.google.com/complete/search"), &google_template_url, GURL("http://www.google.com/complete/search"), &google_template_url,
metrics::OmniboxEventProto::OTHER, &profile_)); metrics::OmniboxEventProto::OTHER, SearchTermsData(), &profile_));
// Suggest disabled. // Suggest disabled.
profile_.GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false); profile_.GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false);
EXPECT_FALSE(SearchProvider::CanSendURL( EXPECT_FALSE(SearchProvider::CanSendURL(
GURL("http://www.google.com/search"), GURL("http://www.google.com/search"),
GURL("https://www.google.com/complete/search"), &google_template_url, GURL("https://www.google.com/complete/search"), &google_template_url,
metrics::OmniboxEventProto::OTHER, &profile_)); metrics::OmniboxEventProto::OTHER, SearchTermsData(), &profile_));
profile_.GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); profile_.GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true);
// Incognito. // Incognito.
EXPECT_FALSE(SearchProvider::CanSendURL( EXPECT_FALSE(SearchProvider::CanSendURL(
GURL("http://www.google.com/search"), GURL("http://www.google.com/search"),
GURL("https://www.google.com/complete/search"), &google_template_url, GURL("https://www.google.com/complete/search"), &google_template_url,
metrics::OmniboxEventProto::OTHER, profile_.GetOffTheRecordProfile())); metrics::OmniboxEventProto::OTHER, SearchTermsData(),
profile_.GetOffTheRecordProfile()));
// Tab sync not enabled. // Tab sync not enabled.
profile_.GetPrefs()->SetBoolean(sync_driver::prefs::kSyncKeepEverythingSynced, profile_.GetPrefs()->SetBoolean(sync_driver::prefs::kSyncKeepEverythingSynced,
...@@ -3030,7 +3035,7 @@ TEST_F(SearchProviderTest, CanSendURL) { ...@@ -3030,7 +3035,7 @@ TEST_F(SearchProviderTest, CanSendURL) {
EXPECT_FALSE(SearchProvider::CanSendURL( EXPECT_FALSE(SearchProvider::CanSendURL(
GURL("http://www.google.com/search"), GURL("http://www.google.com/search"),
GURL("https://www.google.com/complete/search"), &google_template_url, GURL("https://www.google.com/complete/search"), &google_template_url,
metrics::OmniboxEventProto::OTHER, &profile_)); metrics::OmniboxEventProto::OTHER, SearchTermsData(), &profile_));
profile_.GetPrefs()->SetBoolean(sync_driver::prefs::kSyncTabs, true); profile_.GetPrefs()->SetBoolean(sync_driver::prefs::kSyncTabs, true);
// Tab sync is encrypted. // Tab sync is encrypted.
...@@ -3042,7 +3047,7 @@ TEST_F(SearchProviderTest, CanSendURL) { ...@@ -3042,7 +3047,7 @@ TEST_F(SearchProviderTest, CanSendURL) {
EXPECT_FALSE(SearchProvider::CanSendURL( EXPECT_FALSE(SearchProvider::CanSendURL(
GURL("http://www.google.com/search"), GURL("http://www.google.com/search"),
GURL("https://www.google.com/complete/search"), &google_template_url, GURL("https://www.google.com/complete/search"), &google_template_url,
metrics::OmniboxEventProto::OTHER, &profile_)); metrics::OmniboxEventProto::OTHER, SearchTermsData(), &profile_));
encrypted_types.Remove(syncer::SESSIONS); encrypted_types.Remove(syncer::SESSIONS);
service->OnEncryptedTypesChanged(encrypted_types, false); service->OnEncryptedTypesChanged(encrypted_types, false);
...@@ -3050,7 +3055,7 @@ TEST_F(SearchProviderTest, CanSendURL) { ...@@ -3050,7 +3055,7 @@ TEST_F(SearchProviderTest, CanSendURL) {
EXPECT_TRUE(SearchProvider::CanSendURL( EXPECT_TRUE(SearchProvider::CanSendURL(
GURL("http://www.google.com/search"), GURL("http://www.google.com/search"),
GURL("https://www.google.com/complete/search"), &google_template_url, GURL("https://www.google.com/complete/search"), &google_template_url,
metrics::OmniboxEventProto::OTHER, &profile_)); metrics::OmniboxEventProto::OTHER, SearchTermsData(), &profile_));
} }
TEST_F(SearchProviderTest, TestDeleteMatch) { TEST_F(SearchProviderTest, TestDeleteMatch) {
......
...@@ -22,9 +22,7 @@ ...@@ -22,9 +22,7 @@
#include "chrome/browser/history/top_sites.h" #include "chrome/browser/history/top_sites.h"
#include "chrome/browser/omnibox/omnibox_field_trial.h" #include "chrome/browser/omnibox/omnibox_field_trial.h"
#include "chrome/browser/profiles/profile.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/pref_names.h"
#include "chrome/common/url_constants.h"
#include "components/autocomplete/autocomplete_input.h" #include "components/autocomplete/autocomplete_input.h"
#include "components/autocomplete/autocomplete_match.h" #include "components/autocomplete/autocomplete_match.h"
#include "components/autocomplete/autocomplete_provider_listener.h" #include "components/autocomplete/autocomplete_provider_listener.h"
...@@ -76,8 +74,9 @@ const int kDefaultZeroSuggestRelevance = 100; ...@@ -76,8 +74,9 @@ const int kDefaultZeroSuggestRelevance = 100;
// static // static
ZeroSuggestProvider* ZeroSuggestProvider::Create( ZeroSuggestProvider* ZeroSuggestProvider::Create(
AutocompleteProviderListener* listener, AutocompleteProviderListener* listener,
TemplateURLService* template_url_service,
Profile* profile) { Profile* profile) {
return new ZeroSuggestProvider(listener, profile); return new ZeroSuggestProvider(listener, template_url_service, profile);
} }
// static // static
...@@ -118,7 +117,8 @@ void ZeroSuggestProvider::Start(const AutocompleteInput& input, ...@@ -118,7 +117,8 @@ void ZeroSuggestProvider::Start(const AutocompleteInput& input,
// No need to send the current page URL in personalized suggest field trial. // No need to send the current page URL in personalized suggest field trial.
if (CanSendURL(input.current_url(), suggest_url, default_provider, if (CanSendURL(input.current_url(), suggest_url, default_provider,
current_page_classification_, profile_) && current_page_classification_,
template_url_service_->search_terms_data(), profile_) &&
!OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial()) { !OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial()) {
// Update suggest_url to include the current_page_url. // Update suggest_url to include the current_page_url.
search_term_args.current_page_url = current_query_; search_term_args.current_page_url = current_query_;
...@@ -164,10 +164,10 @@ void ZeroSuggestProvider::ModifyProviderInfo( ...@@ -164,10 +164,10 @@ void ZeroSuggestProvider::ModifyProviderInfo(
ZeroSuggestProvider::ZeroSuggestProvider( ZeroSuggestProvider::ZeroSuggestProvider(
AutocompleteProviderListener* listener, AutocompleteProviderListener* listener,
TemplateURLService* template_url_service,
Profile* profile) Profile* profile)
: BaseSearchProvider(listener, profile, : BaseSearchProvider(listener, template_url_service, profile,
AutocompleteProvider::TYPE_ZERO_SUGGEST), AutocompleteProvider::TYPE_ZERO_SUGGEST),
template_url_service_(TemplateURLServiceFactory::GetForProfile(profile)),
results_from_cache_(false), results_from_cache_(false),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
} }
...@@ -428,7 +428,8 @@ bool ZeroSuggestProvider::CanShowZeroSuggestWithoutSendingURL( ...@@ -428,7 +428,8 @@ bool ZeroSuggestProvider::CanShowZeroSuggestWithoutSendingURL(
const GURL& current_page_url) const { const GURL& current_page_url) const {
if (!ZeroSuggestEnabled(suggest_url, if (!ZeroSuggestEnabled(suggest_url,
template_url_service_->GetDefaultSearchProvider(), template_url_service_->GetDefaultSearchProvider(),
current_page_classification_, profile_)) current_page_classification_,
template_url_service_->search_terms_data(), profile_))
return false; return false;
// If we cannot send URLs, then only the MostVisited and Personalized // If we cannot send URLs, then only the MostVisited and Personalized
......
...@@ -51,6 +51,7 @@ class ZeroSuggestProvider : public BaseSearchProvider { ...@@ -51,6 +51,7 @@ class ZeroSuggestProvider : public BaseSearchProvider {
public: public:
// Creates and returns an instance of this provider. // Creates and returns an instance of this provider.
static ZeroSuggestProvider* Create(AutocompleteProviderListener* listener, static ZeroSuggestProvider* Create(AutocompleteProviderListener* listener,
TemplateURLService* template_url_service,
Profile* profile); Profile* profile);
// Registers a preference used to cache zero suggest results. // Registers a preference used to cache zero suggest results.
...@@ -71,6 +72,7 @@ class ZeroSuggestProvider : public BaseSearchProvider { ...@@ -71,6 +72,7 @@ class ZeroSuggestProvider : public BaseSearchProvider {
private: private:
ZeroSuggestProvider(AutocompleteProviderListener* listener, ZeroSuggestProvider(AutocompleteProviderListener* listener,
TemplateURLService* template_url_service,
Profile* profile); Profile* profile);
virtual ~ZeroSuggestProvider(); virtual ~ZeroSuggestProvider();
...@@ -132,9 +134,6 @@ class ZeroSuggestProvider : public BaseSearchProvider { ...@@ -132,9 +134,6 @@ class ZeroSuggestProvider : public BaseSearchProvider {
// populates |matches_| with cached results. // populates |matches_| with cached results.
void MaybeUseCachedSuggestions(); void MaybeUseCachedSuggestions();
// Used to build default search engine URLs for suggested queries.
TemplateURLService* template_url_service_;
// The URL for which a suggestion fetch is pending. // The URL for which a suggestion fetch is pending.
std::string current_query_; std::string current_query_;
......
...@@ -86,7 +86,7 @@ void ZeroSuggestProviderTest::SetUp() { ...@@ -86,7 +86,7 @@ void ZeroSuggestProviderTest::SetUp() {
turl_model->Add(default_t_url_); turl_model->Add(default_t_url_);
turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_);
provider_ = ZeroSuggestProvider::Create(this, &profile_); provider_ = ZeroSuggestProvider::Create(this, turl_model, &profile_);
} }
void ZeroSuggestProviderTest::TearDown() { void ZeroSuggestProviderTest::TearDown() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment