OLD | NEW |
---|---|
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/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 | 24 |
25 // Configuration options for Embedded Search. | 25 // Configuration options for Embedded Search. |
26 // InstantExtended field trials are named in such a way that we can parse out | 26 // InstantExtended field trials are named in such a way that we can parse out |
27 // the experiment configuration from the trial's group name in order to give | 27 // the experiment configuration from the trial's group name in order to give |
28 // us maximum flexability in running experiments. | 28 // us maximum flexability in running experiments. |
29 // Field trial groups should be named things like "Group7 espv:2 instant:1". | 29 // Field trial groups should be named things like "Group7 espv:2 instant:1". |
30 // The first token is always GroupN for some integer N, followed by a | 30 // The first token is always GroupN for some integer N, followed by a |
31 // space-delimited list of key:value pairs which correspond to these flags: | 31 // space-delimited list of key:value pairs which correspond to these flags: |
32 const char kEmbeddedPageVersionFlagName[] = "espv"; | 32 const char kEmbeddedPageVersionFlagName[] = "espv"; |
33 const uint64 kEmbeddedPageVersionDisabled = 0; | 33 const uint64 kEmbeddedPageVersionDisabled = 0; |
34 #if defined(OS_IOS) || defined(OS_ANDROID) | |
35 const uint64 kEmbeddedPageVersionDefault = 1; | |
36 #else | |
34 const uint64 kEmbeddedPageVersionDefault = 2; | 37 const uint64 kEmbeddedPageVersionDefault = 2; |
38 #endif | |
35 | 39 |
36 const char kInstantExtendedActivationName[] = "instant"; | 40 const char kInstantExtendedActivationName[] = "instant"; |
37 const chrome::search::InstantExtendedDefault kInstantExtendedActivationDefault = | 41 const chrome::search::InstantExtendedDefault kInstantExtendedActivationDefault = |
38 chrome::search::INSTANT_DEFAULT_ON; | 42 chrome::search::INSTANT_DEFAULT_ON; |
39 | 43 |
40 // Constants for the field trial name and group prefix. | 44 // Constants for the field trial name and group prefix. |
41 const char kInstantExtendedFieldTrialName[] = "InstantExtended"; | 45 const char kInstantExtendedFieldTrialName[] = "InstantExtended"; |
42 const char kGroupNumberPrefix[] = "Group"; | 46 const char kGroupNumberPrefix[] = "Group"; |
43 | 47 |
44 // If the field trial's group name ends with this string its configuration will | 48 // If the field trial's group name ends with this string its configuration will |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 kInstantExtendedActivationName, | 150 kInstantExtendedActivationName, |
147 kInstantExtendedActivationDefault, | 151 kInstantExtendedActivationDefault, |
148 flags); | 152 flags); |
149 return InstantExtendedDefaultFromInt64(trial_default); | 153 return InstantExtendedDefaultFromInt64(trial_default); |
150 } | 154 } |
151 | 155 |
152 return kInstantExtendedActivationDefault; | 156 return kInstantExtendedActivationDefault; |
153 } | 157 } |
154 | 158 |
155 bool IsInstantExtendedAPIEnabled(const Profile* profile) { | 159 bool IsInstantExtendedAPIEnabled(const Profile* profile) { |
156 return EmbeddedSearchPageVersion(profile) != kEmbeddedPageVersionDisabled; | 160 #if defined(OS_IOS) || defined(OS_ANDROID) |
161 return false; | |
162 #else | |
163 // On desktop, query extraction is part of instant extended, so if one is | |
sreeram
2013/03/05 17:45:55
Nit: instant -> instant
sreeram
2013/03/05 17:46:24
Gah. I meant: instant -> Instant
Yusuf
2013/03/05 18:57:31
Done.
| |
164 // enabled, the other is too. | |
165 return IsQueryExtractionEnabled(profile); | |
166 #endif // defined(OS_IOS) || defined(OS_ANDROID) | |
157 } | 167 } |
158 | 168 |
159 // Determine what embedded search page version to request from the user's | 169 // Determine what embedded search page version to request from the user's |
160 // default search provider. If 0, the embedded search UI should not be enabled. | 170 // default search provider. If 0, the embedded search UI should not be enabled. |
161 uint64 EmbeddedSearchPageVersion(const Profile* profile) { | 171 uint64 EmbeddedSearchPageVersion(const Profile* profile) { |
162 if (!profile || profile->IsOffTheRecord()) | 172 if (!profile || profile->IsOffTheRecord()) |
163 return kEmbeddedPageVersionDisabled; | 173 return kEmbeddedPageVersionDisabled; |
164 | 174 |
165 // Check the command-line/about:flags setting first, which should have | 175 // Check the command-line/about:flags setting first, which should have |
166 // precedence and allows the trial to not be reported (if it's never queried). | 176 // precedence and allows the trial to not be reported (if it's never queried). |
(...skipping 11 matching lines...) Expand all Loading... | |
178 | 188 |
179 RecordInstantExtendedOptInState(NOT_SET); | 189 RecordInstantExtendedOptInState(NOT_SET); |
180 FieldTrialFlags flags; | 190 FieldTrialFlags flags; |
181 if (GetFieldTrialInfo( | 191 if (GetFieldTrialInfo( |
182 base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName), | 192 base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName), |
183 &flags, NULL)) { | 193 &flags, NULL)) { |
184 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, | 194 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, |
185 kEmbeddedPageVersionDefault, | 195 kEmbeddedPageVersionDefault, |
186 flags); | 196 flags); |
187 } | 197 } |
188 | |
189 return kEmbeddedPageVersionDisabled; | 198 return kEmbeddedPageVersionDisabled; |
190 } | 199 } |
191 | 200 |
192 bool IsQueryExtractionEnabled(const Profile* profile) { | 201 bool IsQueryExtractionEnabled(const Profile* profile) { |
193 #if defined(OS_IOS) | 202 return EmbeddedSearchPageVersion(profile) != kEmbeddedPageVersionDisabled; |
194 const CommandLine* cl = CommandLine::ForCurrentProcess(); | |
195 return cl->HasSwitch(switches::kEnableQueryExtraction); | |
196 #else | |
197 // On desktop, query extraction is controlled by the instant-extended-api | |
198 // flag. | |
199 return IsInstantExtendedAPIEnabled(profile); | |
200 #endif | |
201 } | 203 } |
202 | 204 |
203 string16 GetSearchTermsFromNavigationEntry( | 205 string16 GetSearchTermsFromNavigationEntry( |
204 const content::NavigationEntry* entry) { | 206 const content::NavigationEntry* entry) { |
205 string16 search_terms; | 207 string16 search_terms; |
206 if (entry) | 208 if (entry) |
207 entry->GetExtraData(kInstantExtendedSearchTermsKey, &search_terms); | 209 entry->GetExtraData(kInstantExtendedSearchTermsKey, &search_terms); |
208 return search_terms; | 210 return search_terms; |
209 } | 211 } |
210 | 212 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 effective_url, | 279 effective_url, |
278 IsInstantExtendedAPIEnabled(profile), | 280 IsInstantExtendedAPIEnabled(profile), |
279 template_url); | 281 template_url); |
280 } | 282 } |
281 | 283 |
282 void EnableInstantExtendedAPIForTesting() { | 284 void EnableInstantExtendedAPIForTesting() { |
283 CommandLine* cl = CommandLine::ForCurrentProcess(); | 285 CommandLine* cl = CommandLine::ForCurrentProcess(); |
284 cl->AppendSwitch(switches::kEnableInstantExtendedAPI); | 286 cl->AppendSwitch(switches::kEnableInstantExtendedAPI); |
285 } | 287 } |
286 | 288 |
287 void EnableQueryExtractionForTesting() { | |
288 #if defined(OS_IOS) | |
289 CommandLine* cl = CommandLine::ForCurrentProcess(); | |
290 cl->AppendSwitch(switches::kEnableQueryExtraction); | |
291 #else | |
292 EnableInstantExtendedAPIForTesting(); | |
293 #endif | |
294 } | |
295 | |
296 bool ShouldAssignURLToInstantRendererImpl(const GURL& url, | 289 bool ShouldAssignURLToInstantRendererImpl(const GURL& url, |
297 bool extended_api_enabled, | 290 bool extended_api_enabled, |
298 TemplateURL* template_url) { | 291 TemplateURL* template_url) { |
299 if (!url.is_valid()) | 292 if (!url.is_valid()) |
300 return false; | 293 return false; |
301 | 294 |
302 if (url.SchemeIs(chrome::kChromeSearchScheme)) | 295 if (url.SchemeIs(chrome::kChromeSearchScheme)) |
303 return true; | 296 return true; |
304 | 297 |
305 if (extended_api_enabled && url == GURL(kLocalOmniboxPopupURL)) | 298 if (extended_api_enabled && url == GURL(kLocalOmniboxPopupURL)) |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
409 GURL::Replacements replacements; | 402 GURL::Replacements replacements; |
410 replacements.SetSchemeStr(search_scheme); | 403 replacements.SetSchemeStr(search_scheme); |
411 replacements.SetHostStr(search_host); | 404 replacements.SetHostStr(search_host); |
412 replacements.SetPortStr(search_port); | 405 replacements.SetPortStr(search_port); |
413 replacements.SetPathStr(search_path); | 406 replacements.SetPathStr(search_path); |
414 return instant_url.ReplaceComponents(replacements); | 407 return instant_url.ReplaceComponents(replacements); |
415 } | 408 } |
416 | 409 |
417 } // namespace search | 410 } // namespace search |
418 } // namespace chrome | 411 } // namespace chrome |
OLD | NEW |