Chromium Code Reviews| Index: chrome/browser/ui/search/search.cc |
| diff --git a/chrome/browser/ui/search/search.cc b/chrome/browser/ui/search/search.cc |
| index fae8bb0ae34d232d76e93cd1750a3f084285f47e..c58bc56642992c6a8da5f45d96c23fba53253850 100644 |
| --- a/chrome/browser/ui/search/search.cc |
| +++ b/chrome/browser/ui/search/search.cc |
| @@ -10,8 +10,11 @@ |
| #include "base/string_split.h" |
| #include "base/string_util.h" |
| #include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/search_engines/template_url_service.h" |
| +#include "chrome/browser/search_engines/template_url_service_factory.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/chrome_version_info.h" |
| +#include "googleurl/src/gurl.h" |
| #if !defined(OS_ANDROID) |
| #include "chrome/browser/themes/theme_service.h" |
| @@ -20,6 +23,20 @@ |
| namespace chrome { |
| namespace search { |
| +namespace { |
| +// Returns whether |template_url| supports the parameter necessary to enable |
| +// InstantExtended. |
| +bool SupportsInstantExtended(const TemplateURL* template_url) { |
| + if (!template_url) |
| + return false; |
| + const TemplateURLRef& instant_url_ref = template_url->instant_url_ref(); |
| + if (!instant_url_ref.IsValid()) |
| + return false; |
| + const std::string search_url = instant_url_ref.ReplaceSearchTerms( |
| + TemplateURLRef::SearchTermsArgs(string16())); |
| + return template_url->HasSearchTermsReplacementKey(GURL(search_url)); |
|
beaudoin
2013/01/16 14:52:27
Couldn't we assume that any TemplateURL that has a
Jered
2013/01/16 21:27:04
Oops sorry missed this. Your assumption was correc
|
| +} |
| +} // namespace |
| // Configuration options for Embedded Search. |
| // InstantExtended field trials are named in such a way that we can parse out |
| @@ -114,6 +131,15 @@ uint64 EmbeddedSearchPageVersion(Profile* profile) { |
| if (!profile || profile->IsOffTheRecord()) |
| return 0; |
| + // Some users may have their search provider TemplateURL pinned to an |
| + // obsolete value which does not support enabling InstantExtended on the |
| + // server side. Bail out of InstantExtended if we detect that. |
| + const TemplateURL* template_url = |
| + TemplateURLServiceFactory::GetForProfile(profile)-> |
| + GetDefaultSearchProvider(); |
| + if (!SupportsInstantExtended(template_url)) |
| + return 0; |
| + |
| // Check Finch field trials. |
| FieldTrialFlags flags; |
| uint64 group_number = 0; |
| @@ -151,6 +177,7 @@ uint64 EmbeddedSearchPageVersion(Profile* profile) { |
| // UI version. |
| return kEmbeddedPageVersionDefault; |
| } |
| + |
| return 0; |
| } |