Index: chrome/browser/autocomplete/zero_suggest_provider.cc |
diff --git a/chrome/browser/autocomplete/zero_suggest_provider.cc b/chrome/browser/autocomplete/zero_suggest_provider.cc |
index 4a09c4a541c7f06ff29420760e90218d09c41e67..f9143aec506ceb7be54b93b80b6139d0ea28404a 100644 |
--- a/chrome/browser/autocomplete/zero_suggest_provider.cc |
+++ b/chrome/browser/autocomplete/zero_suggest_provider.cc |
@@ -21,7 +21,6 @@ |
#include "chrome/browser/autocomplete/history_url_provider.h" |
#include "chrome/browser/autocomplete/search_provider.h" |
#include "chrome/browser/autocomplete/url_prefix.h" |
-#include "chrome/browser/google/google_util.h" |
#include "chrome/browser/history/history_types.h" |
#include "chrome/browser/history/top_sites.h" |
#include "chrome/browser/metrics/variations/variations_http_header_provider.h" |
@@ -30,8 +29,6 @@ |
#include "chrome/browser/search/search.h" |
#include "chrome/browser/search_engines/template_url_service.h" |
#include "chrome/browser/search_engines/template_url_service_factory.h" |
-#include "chrome/browser/sync/profile_sync_service.h" |
-#include "chrome/browser/sync/profile_sync_service_factory.h" |
#include "chrome/common/net/url_fixer_upper.h" |
#include "chrome/common/pref_names.h" |
#include "chrome/common/url_constants.h" |
@@ -156,7 +153,9 @@ void ZeroSuggestProvider::StartZeroSuggest( |
Stop(true); |
field_trial_triggered_ = false; |
field_trial_triggered_in_session_ = false; |
- if (!ShouldRunZeroSuggest(url)) |
+ if (!SearchProvider::CanSendURL( |
+ url, template_url_service_->GetDefaultSearchProvider(), profile_) || |
+ !OmniboxFieldTrial::InZeroSuggestFieldTrial()) |
return; |
verbatim_relevance_ = kDefaultVerbatimZeroSuggestRelevance; |
done_ = false; |
@@ -186,52 +185,6 @@ ZeroSuggestProvider::ZeroSuggestProvider( |
ZeroSuggestProvider::~ZeroSuggestProvider() { |
} |
-bool ZeroSuggestProvider::ShouldRunZeroSuggest(const GURL& url) const { |
- if (!ShouldSendURL(url)) |
- return false; |
- |
- // Don't run if there's no profile or in incognito mode. |
- if (profile_ == NULL || profile_->IsOffTheRecord()) |
- return false; |
- |
- // Don't run if we can't get preferences or search suggest is not enabled. |
- PrefService* prefs = profile_->GetPrefs(); |
- if (prefs == NULL || !prefs->GetBoolean(prefs::kSearchSuggestEnabled)) |
- return false; |
- |
- ProfileSyncService* service = |
- ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); |
- browser_sync::SyncPrefs sync_prefs(prefs); |
- |
- // ZeroSuggest requires sending the current URL to the suggest provider, so we |
- // only want to enable it if the user is willing to have this data sent. |
- // Because tab sync involves sending the same data, we currently use |
- // "tab sync is enabled and tab sync data is unencrypted" as a proxy for |
- // "the user is OK with sending this data". We might someday want to change |
- // this to a standalone setting or part of some other explicit general opt-in. |
- if (!OmniboxFieldTrial::InZeroSuggestFieldTrial() || |
- service == NULL || |
- !service->IsSyncEnabledAndLoggedIn() || |
- !sync_prefs.GetPreferredDataTypes(syncer::UserTypes()).Has( |
- syncer::PROXY_TABS) || |
- service->GetEncryptedDataTypes().Has(syncer::SESSIONS)) { |
- return false; |
- } |
- return true; |
-} |
- |
-bool ZeroSuggestProvider::ShouldSendURL(const GURL& url) const { |
- if (!url.is_valid()) |
- return false; |
- |
- // Only allow HTTP URLs or Google HTTPS URLs (including Google search |
- // result pages). For the latter case, Google was already sent the HTTPS |
- // URLs when requesting the page, so the information is just re-sent. |
- return (url.scheme() == content::kHttpScheme) || |
- google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN, |
- google_util::ALLOW_NON_STANDARD_PORTS); |
-} |
- |
void ZeroSuggestProvider::FillResults( |
const Value& root_val, |
int* verbatim_relevance, |
@@ -382,17 +335,9 @@ void ZeroSuggestProvider::Run() { |
const TemplateURL* default_provider = |
template_url_service_->GetDefaultSearchProvider(); |
- // TODO(hfung): Generalize if the default provider supports zero suggest. |
- // Only make the request if we know that the provider supports zero suggest |
- // (currently only the prepopulated Google provider). |
- if (default_provider == NULL || !default_provider->SupportsReplacement() || |
- default_provider->prepopulate_id() != 1) { |
- Stop(true); |
- return; |
- } |
string16 prefix; |
TemplateURLRef::SearchTermsArgs search_term_args(prefix); |
- search_term_args.zero_prefix_url = current_query_; |
+ search_term_args.current_page_url = current_query_; |
std::string req_url = default_provider->suggestions_url_ref(). |
ReplaceSearchTerms(search_term_args); |
GURL suggest_url(req_url); |