Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: chrome/browser/ui/search/search.cc

Issue 11884037: InstantExtended: Bail on TemplateURLs with no espv. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/search/search.h" 5 #include "chrome/browser/ui/search/search.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/string_split.h" 10 #include "base/string_split.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/search_engines/template_url_service.h"
14 #include "chrome/browser/search_engines/template_url_service_factory.h"
13 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/chrome_version_info.h" 16 #include "chrome/common/chrome_version_info.h"
17 #include "googleurl/src/gurl.h"
15 18
16 #if !defined(OS_ANDROID) 19 #if !defined(OS_ANDROID)
17 #include "chrome/browser/themes/theme_service.h" 20 #include "chrome/browser/themes/theme_service.h"
18 #include "chrome/browser/themes/theme_service_factory.h" 21 #include "chrome/browser/themes/theme_service_factory.h"
19 #endif 22 #endif
20 23
21 namespace chrome { 24 namespace chrome {
22 namespace search { 25 namespace search {
26 namespace {
27 // Returns whether |template_url| supports the parameter necessary to enable
28 // InstantExtended.
29 bool SupportsInstantExtended(const TemplateURL* template_url) {
30 if (!template_url)
31 return false;
32 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref();
33 if (!instant_url_ref.IsValid())
34 return false;
35 const std::string search_url = instant_url_ref.ReplaceSearchTerms(
36 TemplateURLRef::SearchTermsArgs(string16()));
37 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
38 }
39 } // namespace
23 40
24 // Configuration options for Embedded Search. 41 // Configuration options for Embedded Search.
25 // InstantExtended field trials are named in such a way that we can parse out 42 // InstantExtended field trials are named in such a way that we can parse out
26 // the experiment configuration from the trial's group name in order to give 43 // the experiment configuration from the trial's group name in order to give
27 // us maximum flexability in running experiments. 44 // us maximum flexability in running experiments.
28 // Field trials should be named things like "Group7 espv:2 themes:0". 45 // Field trials should be named things like "Group7 espv:2 themes:0".
29 // The first token is always GroupN for some integer N, followed by a 46 // The first token is always GroupN for some integer N, followed by a
30 // space-delimited list of key:value pairs which correspond to these flags: 47 // space-delimited list of key:value pairs which correspond to these flags:
31 const char kEnableOnThemesFlagName[] = "themes"; 48 const char kEnableOnThemesFlagName[] = "themes";
32 const bool kEnableOnThemesDefault = false; 49 const bool kEnableOnThemesDefault = false;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // Determine what embedded search page version to request from the user's 124 // Determine what embedded search page version to request from the user's
108 // default search provider. If 0, the embedded search UI should not be enabled. 125 // default search provider. If 0, the embedded search UI should not be enabled.
109 // Note that the profile object here isn't const because we need to determine 126 // Note that the profile object here isn't const because we need to determine
110 // whether or not the user has a theme installed as part of this check, and 127 // whether or not the user has a theme installed as part of this check, and
111 // that logic requires a non-const profile for whatever reason. 128 // that logic requires a non-const profile for whatever reason.
112 uint64 EmbeddedSearchPageVersion(Profile* profile) { 129 uint64 EmbeddedSearchPageVersion(Profile* profile) {
113 // Incognito windows do not currently use the embedded search API. 130 // Incognito windows do not currently use the embedded search API.
114 if (!profile || profile->IsOffTheRecord()) 131 if (!profile || profile->IsOffTheRecord())
115 return 0; 132 return 0;
116 133
134 // Some users may have their search provider TemplateURL pinned to an
135 // obsolete value which does not support enabling InstantExtended on the
136 // server side. Bail out of InstantExtended if we detect that.
137 const TemplateURL* template_url =
138 TemplateURLServiceFactory::GetForProfile(profile)->
139 GetDefaultSearchProvider();
140 if (!SupportsInstantExtended(template_url))
141 return 0;
142
117 // Check Finch field trials. 143 // Check Finch field trials.
118 FieldTrialFlags flags; 144 FieldTrialFlags flags;
119 uint64 group_number = 0; 145 uint64 group_number = 0;
120 base::FieldTrial* trial = 146 base::FieldTrial* trial =
121 base::FieldTrialList::Find(kInstantExtendedFieldTrialName); 147 base::FieldTrialList::Find(kInstantExtendedFieldTrialName);
122 if (trial) { 148 if (trial) {
123 std::string group_name = trial->group_name(); 149 std::string group_name = trial->group_name();
124 GetFieldTrialInfo(group_name, &flags, &group_number); 150 GetFieldTrialInfo(group_name, &flags, &group_number);
125 } 151 }
126 152
(...skipping 17 matching lines...) Expand all
144 if (!has_theme || enable_for_themes) 170 if (!has_theme || enable_for_themes)
145 return espv; 171 return espv;
146 } 172 }
147 173
148 if (CommandLine::ForCurrentProcess()->HasSwitch( 174 if (CommandLine::ForCurrentProcess()->HasSwitch(
149 switches::kEnableInstantExtendedAPI)) { 175 switches::kEnableInstantExtendedAPI)) {
150 // The user has manually flipped the about:flags switch - give the default 176 // The user has manually flipped the about:flags switch - give the default
151 // UI version. 177 // UI version.
152 return kEmbeddedPageVersionDefault; 178 return kEmbeddedPageVersionDefault;
153 } 179 }
180
154 return 0; 181 return 0;
155 } 182 }
156 183
157 void EnableInstantExtendedAPIForTesting() { 184 void EnableInstantExtendedAPIForTesting() {
158 CommandLine::ForCurrentProcess()->AppendSwitch( 185 CommandLine::ForCurrentProcess()->AppendSwitch(
159 switches::kEnableInstantExtendedAPI); 186 switches::kEnableInstantExtendedAPI);
160 } 187 }
161 188
162 bool IsQueryExtractionEnabled(Profile* profile) { 189 bool IsQueryExtractionEnabled(Profile* profile) {
163 #if defined(OS_IOS) 190 #if defined(OS_IOS)
(...skipping 20 matching lines...) Expand all
184 #else 211 #else
185 // On desktop, query extraction is controlled by the instant-extended-api 212 // On desktop, query extraction is controlled by the instant-extended-api
186 // flag. 213 // flag.
187 CommandLine::ForCurrentProcess()->AppendSwitch( 214 CommandLine::ForCurrentProcess()->AppendSwitch(
188 switches::kEnableInstantExtendedAPI); 215 switches::kEnableInstantExtendedAPI);
189 #endif 216 #endif
190 } 217 }
191 218
192 } // namespace search 219 } // namespace search
193 } // namespace chrome 220 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698