OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 // Configuration options for Embedded Search. | 40 // Configuration options for Embedded Search. |
41 // InstantExtended field trials are named in such a way that we can parse out | 41 // InstantExtended field trials are named in such a way that we can parse out |
42 // the experiment configuration from the trial's group name in order to give | 42 // the experiment configuration from the trial's group name in order to give |
43 // us maximum flexability in running experiments. | 43 // us maximum flexability in running experiments. |
44 // Field trial groups should be named things like "Group7 espv:2 instant:1". | 44 // Field trial groups should be named things like "Group7 espv:2 instant:1". |
45 // The first token is always GroupN for some integer N, followed by a | 45 // The first token is always GroupN for some integer N, followed by a |
46 // space-delimited list of key:value pairs which correspond to these flags: | 46 // space-delimited list of key:value pairs which correspond to these flags: |
47 const char kEmbeddedPageVersionFlagName[] = "espv"; | 47 const char kEmbeddedPageVersionFlagName[] = "espv"; |
48 const uint64 kEmbeddedPageVersionDisabled = 0; | 48 const uint64 kEmbeddedPageVersionDisabled = 0; |
| 49 #if defined(OS_IOS) || defined(OS_ANDROID) |
| 50 const uint64 kEmbeddedPageVersionDefault = 1; |
| 51 #else |
49 const uint64 kEmbeddedPageVersionDefault = 2; | 52 const uint64 kEmbeddedPageVersionDefault = 2; |
| 53 #endif |
50 | 54 |
51 const char kInstantExtendedActivationName[] = "instant"; | 55 const char kInstantExtendedActivationName[] = "instant"; |
52 const InstantExtendedDefault kInstantExtendedActivationDefault = | 56 const InstantExtendedDefault kInstantExtendedActivationDefault = |
53 INSTANT_DEFAULT_ON; | 57 INSTANT_DEFAULT_ON; |
54 | 58 |
55 // Constants for the field trial name and group prefix. | 59 // Constants for the field trial name and group prefix. |
56 const char kInstantExtendedFieldTrialName[] = "InstantExtended"; | 60 const char kInstantExtendedFieldTrialName[] = "InstantExtended"; |
57 const char kGroupNumberPrefix[] = "Group"; | 61 const char kGroupNumberPrefix[] = "Group"; |
58 | 62 |
59 // If the field trial's group name ends with this string its configuration will | 63 // If the field trial's group name ends with this string its configuration will |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 } | 214 } |
211 | 215 |
212 } // namespace | 216 } // namespace |
213 | 217 |
214 const char kInstantExtendedSearchTermsKey[] = "search_terms"; | 218 const char kInstantExtendedSearchTermsKey[] = "search_terms"; |
215 | 219 |
216 const char kLocalOmniboxPopupURL[] = | 220 const char kLocalOmniboxPopupURL[] = |
217 "chrome://local-omnibox-popup/local-omnibox-popup.html"; | 221 "chrome://local-omnibox-popup/local-omnibox-popup.html"; |
218 | 222 |
219 bool IsInstantExtendedAPIEnabled() { | 223 bool IsInstantExtendedAPIEnabled() { |
220 return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled; | 224 #if defined(OS_IOS) || defined(OS_ANDROID) |
| 225 return false; |
| 226 #else |
| 227 // On desktop, query extraction is part of Instant extended, so if one is |
| 228 // enabled, the other is too. |
| 229 return IsQueryExtractionEnabled(); |
| 230 #endif // defined(OS_IOS) || defined(OS_ANDROID) |
221 } | 231 } |
222 | 232 |
223 // Determine what embedded search page version to request from the user's | 233 // Determine what embedded search page version to request from the user's |
224 // default search provider. If 0, the embedded search UI should not be enabled. | 234 // default search provider. If 0, the embedded search UI should not be enabled. |
225 uint64 EmbeddedSearchPageVersion() { | 235 uint64 EmbeddedSearchPageVersion() { |
226 // Check the command-line/about:flags setting first, which should have | 236 // Check the command-line/about:flags setting first, which should have |
227 // precedence and allows the trial to not be reported (if it's never queried). | 237 // precedence and allows the trial to not be reported (if it's never queried). |
228 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 238 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
229 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI)) { | 239 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI)) { |
230 RecordInstantExtendedOptInState(OPT_OUT); | 240 RecordInstantExtendedOptInState(OPT_OUT); |
231 return kEmbeddedPageVersionDisabled; | 241 return kEmbeddedPageVersionDisabled; |
232 } | 242 } |
233 if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) { | 243 if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) { |
234 // The user has set the about:flags switch to Enabled - give the default | 244 // The user has set the about:flags switch to Enabled - give the default |
235 // UI version. | 245 // UI version. |
236 RecordInstantExtendedOptInState(OPT_IN); | 246 RecordInstantExtendedOptInState(OPT_IN); |
237 return kEmbeddedPageVersionDefault; | 247 return kEmbeddedPageVersionDefault; |
238 } | 248 } |
239 | 249 |
240 RecordInstantExtendedOptInState(NOT_SET); | 250 RecordInstantExtendedOptInState(NOT_SET); |
241 FieldTrialFlags flags; | 251 FieldTrialFlags flags; |
242 if (GetFieldTrialInfo( | 252 if (GetFieldTrialInfo( |
243 base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName), | 253 base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName), |
244 &flags, NULL)) { | 254 &flags, NULL)) { |
245 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, | 255 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, |
246 kEmbeddedPageVersionDefault, | 256 kEmbeddedPageVersionDefault, |
247 flags); | 257 flags); |
248 } | 258 } |
249 | |
250 return kEmbeddedPageVersionDisabled; | 259 return kEmbeddedPageVersionDisabled; |
251 } | 260 } |
252 | 261 |
253 bool IsQueryExtractionEnabled() { | 262 bool IsQueryExtractionEnabled() { |
254 #if defined(OS_IOS) | 263 return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled; |
255 const CommandLine* cl = CommandLine::ForCurrentProcess(); | |
256 return cl->HasSwitch(switches::kEnableQueryExtraction); | |
257 #else | |
258 // On desktop, query extraction is controlled by the instant-extended-api | |
259 // flag. | |
260 return IsInstantExtendedAPIEnabled(); | |
261 #endif | |
262 } | 264 } |
263 | 265 |
264 string16 GetSearchTermsFromNavigationEntry( | 266 string16 GetSearchTermsFromNavigationEntry( |
265 const content::NavigationEntry* entry) { | 267 const content::NavigationEntry* entry) { |
266 string16 search_terms; | 268 string16 search_terms; |
267 if (entry) | 269 if (entry) |
268 entry->GetExtraData(kInstantExtendedSearchTermsKey, &search_terms); | 270 entry->GetExtraData(kInstantExtendedSearchTermsKey, &search_terms); |
269 return search_terms; | 271 return search_terms; |
270 } | 272 } |
271 | 273 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 422 |
421 bool IsInstantEnabled(Profile* profile) { | 423 bool IsInstantEnabled(Profile* profile) { |
422 return GetInstantURL(profile).is_valid(); | 424 return GetInstantURL(profile).is_valid(); |
423 } | 425 } |
424 | 426 |
425 void EnableInstantExtendedAPIForTesting() { | 427 void EnableInstantExtendedAPIForTesting() { |
426 CommandLine* cl = CommandLine::ForCurrentProcess(); | 428 CommandLine* cl = CommandLine::ForCurrentProcess(); |
427 cl->AppendSwitch(switches::kEnableInstantExtendedAPI); | 429 cl->AppendSwitch(switches::kEnableInstantExtendedAPI); |
428 } | 430 } |
429 | 431 |
430 void EnableQueryExtractionForTesting() { | |
431 #if defined(OS_IOS) | |
432 CommandLine* cl = CommandLine::ForCurrentProcess(); | |
433 cl->AppendSwitch(switches::kEnableQueryExtraction); | |
434 #else | |
435 EnableInstantExtendedAPIForTesting(); | |
436 #endif | |
437 } | |
438 | |
439 bool GetFieldTrialInfo(const std::string& group_name, | 432 bool GetFieldTrialInfo(const std::string& group_name, |
440 FieldTrialFlags* flags, | 433 FieldTrialFlags* flags, |
441 uint64* group_number) { | 434 uint64* group_number) { |
442 if (EndsWith(group_name, kDisablingSuffix, true) || | 435 if (EndsWith(group_name, kDisablingSuffix, true) || |
443 !StartsWithASCII(group_name, kGroupNumberPrefix, true)) | 436 !StartsWithASCII(group_name, kGroupNumberPrefix, true)) |
444 return false; | 437 return false; |
445 | 438 |
446 // We have a valid trial that starts with "Group" and isn't disabled. | 439 // We have a valid trial that starts with "Group" and isn't disabled. |
447 // First extract the flags. | 440 // First extract the flags. |
448 std::string group_prefix(group_name); | 441 std::string group_prefix(group_name); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 GURL::Replacements replacements; | 514 GURL::Replacements replacements; |
522 replacements.SetSchemeStr(search_scheme); | 515 replacements.SetSchemeStr(search_scheme); |
523 replacements.SetHostStr(search_host); | 516 replacements.SetHostStr(search_host); |
524 replacements.SetPortStr(search_port); | 517 replacements.SetPortStr(search_port); |
525 replacements.SetPathStr(search_path); | 518 replacements.SetPathStr(search_path); |
526 return instant_url.ReplaceComponents(replacements); | 519 return instant_url.ReplaceComponents(replacements); |
527 } | 520 } |
528 | 521 |
529 } // namespace search | 522 } // namespace search |
530 } // namespace chrome | 523 } // namespace chrome |
OLD | NEW |