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

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

Issue 24733003: Update defaults for InstantExtended. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test exclusion. Created 7 years, 2 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 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/search/search.h" 5 #include "chrome/browser/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"
10 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
11 #include "base/rand_util.h" 10 #include "base/rand_util.h"
12 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_split.h" 12 #include "base/strings/string_split.h"
14 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/google/google_util.h" 15 #include "chrome/browser/google/google_util.h"
17 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/profiles/profile_manager.h" 17 #include "chrome/browser/profiles/profile_manager.h"
19 #include "chrome/browser/search/instant_service.h" 18 #include "chrome/browser/search/instant_service.h"
(...skipping 20 matching lines...) Expand all
40 namespace { 39 namespace {
41 40
42 // Configuration options for Embedded Search. 41 // Configuration options for Embedded Search.
43 // EmbeddedSearch field trials are named in such a way that we can parse out 42 // EmbeddedSearch field trials are named in such a way that we can parse out
44 // 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
45 // us maximum flexability in running experiments. 44 // us maximum flexability in running experiments.
46 // Field trial groups should be named things like "Group7 espv:2 instant:1". 45 // Field trial groups should be named things like "Group7 espv:2 instant:1".
47 // 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
48 // 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:
49 const char kEmbeddedPageVersionFlagName[] = "espv"; 48 const char kEmbeddedPageVersionFlagName[] = "espv";
50 const uint64 kEmbeddedPageVersionDisabled = 0;
51 #if defined(OS_IOS) || defined(OS_ANDROID) 49 #if defined(OS_IOS) || defined(OS_ANDROID)
52 const uint64 kEmbeddedPageVersionDefault = 1; 50 const uint64 kEmbeddedPageVersionDefault = 1;
53 #else 51 #else
54 const uint64 kEmbeddedPageVersionDefault = 2; 52 const uint64 kEmbeddedPageVersionDefault = 2;
55 #endif 53 #endif
56 54
57 // The staleness timeout can be set (in seconds) via this config. 55 // The staleness timeout can be set (in seconds) via this config.
58 const char kStalePageTimeoutFlagName[] = "stale"; 56 const char kStalePageTimeoutFlagName[] = "stale";
59 const int kStalePageTimeoutDefault = 3 * 3600; // 3 hours. 57 const int kStalePageTimeoutDefault = 3 * 3600; // 3 hours.
60 58
61 const char kHideVerbatimFlagName[] = "hide_verbatim"; 59 const char kHideVerbatimFlagName[] = "hide_verbatim";
62 const char kUseRemoteNTPOnStartupFlagName[] = "use_remote_ntp_on_startup"; 60 const char kUseRemoteNTPOnStartupFlagName[] = "use_remote_ntp_on_startup";
63 const char kShowNtpFlagName[] = "show_ntp"; 61 const char kShowNtpFlagName[] = "show_ntp";
64 const char kRecentTabsOnNTPFlagName[] = "show_recent_tabs"; 62 const char kRecentTabsOnNTPFlagName[] = "show_recent_tabs";
65 const char kUseCacheableNTP[] = "use_cacheable_ntp"; 63 const char kUseCacheableNTP[] = "use_cacheable_ntp";
66 const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp"; 64 const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp";
67 const char kSuppressInstantExtendedOnSRPFlagName[] = "suppress_on_srp"; 65 const char kEnableQueryExtractionFlagName[] = "query_extraction";
68 66
69 // Constants for the field trial name and group prefix. 67 // Constants for the field trial name and group prefix.
70 // Note in M30 and below this field trial was named "InstantExtended" and in 68 // Note in M30 and below this field trial was named "InstantExtended" and in
71 // M31 was renamed to EmbeddedSearch for clarity and cleanliness. Since we 69 // M31 was renamed to EmbeddedSearch for clarity and cleanliness. Since we
72 // can't easilly sync up Finch configs with the pushing of this change to 70 // can't easilly sync up Finch configs with the pushing of this change to
73 // Dev & Canary, for now the code accepts both names. 71 // Dev & Canary, for now the code accepts both names.
74 // TODO(dcblack): Remove the InstantExtended name once M31 hits the Beta 72 // TODO(dcblack): Remove the InstantExtended name once M31 hits the Beta
75 // channel. 73 // channel.
76 const char kInstantExtendedFieldTrialName[] = "InstantExtended"; 74 const char kInstantExtendedFieldTrialName[] = "InstantExtended";
77 const char kEmbeddedSearchFieldTrialName[] = "EmbeddedSearch"; 75 const char kEmbeddedSearchFieldTrialName[] = "EmbeddedSearch";
78 const char kGroupNumberPrefix[] = "Group";
79 76
80 // If the field trial's group name ends with this string its configuration will 77 // If the field trial's group name ends with this string its configuration will
81 // be ignored and Instant Extended will not be enabled by default. 78 // be ignored and Instant Extended will not be enabled by default.
82 const char kDisablingSuffix[] = "DISABLED"; 79 const char kDisablingSuffix[] = "DISABLED";
83 80
84 // Remember if we reported metrics about opt-in/out state.
85 bool instant_extended_opt_in_state_gate = false;
86
87 // Used to set the Instant support state of the Navigation entry. 81 // Used to set the Instant support state of the Navigation entry.
88 const char kInstantSupportStateKey[] = "instant_support_state"; 82 const char kInstantSupportStateKey[] = "instant_support_state";
89 83
90 const char kInstantSupportEnabled[] = "Instant support enabled"; 84 const char kInstantSupportEnabled[] = "Instant support enabled";
91 const char kInstantSupportDisabled[] = "Instant support disabled"; 85 const char kInstantSupportDisabled[] = "Instant support disabled";
92 const char kInstantSupportUnknown[] = "Instant support unknown"; 86 const char kInstantSupportUnknown[] = "Instant support unknown";
93 87
94 InstantSupportState StringToInstantSupportState(const string16& value) { 88 InstantSupportState StringToInstantSupportState(const string16& value) {
95 if (value == ASCIIToUTF16(kInstantSupportEnabled)) 89 if (value == ASCIIToUTF16(kInstantSupportEnabled))
96 return INSTANT_SUPPORT_YES; 90 return INSTANT_SUPPORT_YES;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 TemplateURLRef ref(template_url, i); 136 TemplateURLRef ref(template_url, i);
143 search_url = TemplateURLRefToGURL(ref, kDisableStartMargin, false); 137 search_url = TemplateURLRefToGURL(ref, kDisableStartMargin, false);
144 if (search_url.is_valid() && 138 if (search_url.is_valid() &&
145 search::MatchesOriginAndPath(url, search_url)) 139 search::MatchesOriginAndPath(url, search_url))
146 return true; 140 return true;
147 } 141 }
148 142
149 return false; 143 return false;
150 } 144 }
151 145
152 void RecordInstantExtendedOptInState() {
153 if (instant_extended_opt_in_state_gate)
154 return;
155
156 instant_extended_opt_in_state_gate = true;
157 OptInState state = INSTANT_EXTENDED_NOT_SET;
158 const CommandLine* command_line = CommandLine::ForCurrentProcess();
159 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI))
160 state = INSTANT_EXTENDED_OPT_OUT;
161 else if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI))
162 state = INSTANT_EXTENDED_OPT_IN;
163
164 UMA_HISTOGRAM_ENUMERATION("InstantExtended.NewOptInState", state,
165 INSTANT_EXTENDED_OPT_IN_STATE_ENUM_COUNT);
166 }
167
168 // Returns true if |contents| is rendered inside the Instant process for 146 // Returns true if |contents| is rendered inside the Instant process for
169 // |profile|. 147 // |profile|.
170 bool IsRenderedInInstantProcess(const content::WebContents* contents, 148 bool IsRenderedInInstantProcess(const content::WebContents* contents,
171 Profile* profile) { 149 Profile* profile) {
172 const content::RenderProcessHost* process_host = 150 const content::RenderProcessHost* process_host =
173 contents->GetRenderProcessHost(); 151 contents->GetRenderProcessHost();
174 if (!process_host) 152 if (!process_host)
175 return false; 153 return false;
176 154
177 const InstantService* instant_service = 155 const InstantService* instant_service =
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 195
218 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref(); 196 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref();
219 const GURL instant_url = 197 const GURL instant_url =
220 TemplateURLRefToGURL(instant_url_ref, kDisableStartMargin, false); 198 TemplateURLRefToGURL(instant_url_ref, kDisableStartMargin, false);
221 if (!instant_url.is_valid()) 199 if (!instant_url.is_valid())
222 return false; 200 return false;
223 201
224 if (search::MatchesOriginAndPath(url, instant_url)) 202 if (search::MatchesOriginAndPath(url, instant_url))
225 return true; 203 return true;
226 204
227 return !ShouldSuppressInstantExtendedOnSRP() && 205 return IsQueryExtractionEnabled() && MatchesAnySearchURL(url, template_url);
228 MatchesAnySearchURL(url, template_url);
229 } 206 }
230 207
231 string16 GetSearchTermsImpl(const content::WebContents* contents, 208 string16 GetSearchTermsImpl(const content::WebContents* contents,
232 const content::NavigationEntry* entry) { 209 const content::NavigationEntry* entry) {
233 if (!contents || !IsQueryExtractionEnabled()) 210 if (!contents || !IsQueryExtractionEnabled())
234 return string16(); 211 return string16();
235 212
236 // For security reasons, don't extract search terms if the page is not being 213 // For security reasons, don't extract search terms if the page is not being
237 // rendered in the privileged Instant renderer process. This is to protect 214 // rendered in the privileged Instant renderer process. This is to protect
238 // against a malicious page somehow scripting the search results page and 215 // against a malicious page somehow scripting the search results page and
(...skipping 20 matching lines...) Expand all
259 236
260 } // namespace 237 } // namespace
261 238
262 // Negative start-margin values prevent the "es_sm" parameter from being used. 239 // Negative start-margin values prevent the "es_sm" parameter from being used.
263 const int kDisableStartMargin = -1; 240 const int kDisableStartMargin = -1;
264 241
265 bool IsInstantExtendedAPIEnabled() { 242 bool IsInstantExtendedAPIEnabled() {
266 #if defined(OS_IOS) || defined(OS_ANDROID) 243 #if defined(OS_IOS) || defined(OS_ANDROID)
267 return false; 244 return false;
268 #else 245 #else
269 RecordInstantExtendedOptInState(); 246 return true;
270 return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled;
271 #endif // defined(OS_IOS) || defined(OS_ANDROID) 247 #endif // defined(OS_IOS) || defined(OS_ANDROID)
272 } 248 }
273 249
274 // Determine what embedded search page version to request from the user's 250 // Determine what embedded search page version to request from the user's
275 // default search provider. If 0, the embedded search UI should not be enabled. 251 // default search provider.
276 uint64 EmbeddedSearchPageVersion() { 252 uint64 EmbeddedSearchPageVersion() {
277 RecordInstantExtendedOptInState();
278
279 // Check the command-line/about:flags setting first, which should have
280 // precedence and allows the trial to not be reported (if it's never queried).
281 const CommandLine* command_line = CommandLine::ForCurrentProcess();
282 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI))
283 return kEmbeddedPageVersionDisabled;
284 if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) {
285 // The user has set the about:flags switch to Enabled - give the default
286 // UI version.
287 return kEmbeddedPageVersionDefault;
288 }
289
290 FieldTrialFlags flags; 253 FieldTrialFlags flags;
291 uint64 group_num = 0; 254 if (GetFieldTrialInfo(&flags)) {
292 if (GetFieldTrialInfo(&flags, &group_num)) {
293 if (group_num == 0)
294 return kEmbeddedPageVersionDisabled;
295 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, 255 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName,
296 kEmbeddedPageVersionDefault, 256 kEmbeddedPageVersionDefault,
297 flags); 257 flags);
298 } 258 }
299 return kEmbeddedPageVersionDisabled; 259 return kEmbeddedPageVersionDefault;
300 } 260 }
301 261
302 bool IsQueryExtractionEnabled() { 262 bool IsQueryExtractionEnabled() {
303 return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled && 263 #if defined(OS_IOS) || defined(OS_ANDROID)
304 !ShouldSuppressInstantExtendedOnSRP(); 264 return true;
265 #else
266 if (!IsInstantExtendedAPIEnabled())
267 return false;
268
269 const CommandLine* command_line = CommandLine::ForCurrentProcess();
270 if (command_line->HasSwitch(switches::kEnableQueryExtraction))
271 return true;
272
273 FieldTrialFlags flags;
274 if (GetFieldTrialInfo(&flags)) {
275 return GetBoolValueForFlagWithDefault(
276 kEnableQueryExtractionFlagName, false, flags);
277 }
278
279 return false;
280 #endif // defined(OS_IOS) || defined(OS_ANDROID)
305 } 281 }
306 282
307 string16 GetSearchTermsFromURL(Profile* profile, const GURL& url) { 283 string16 GetSearchTermsFromURL(Profile* profile, const GURL& url) {
308 string16 search_terms; 284 string16 search_terms;
309 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); 285 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile);
310 if (template_url && IsSuitableURLForInstant(url, template_url)) 286 if (template_url && IsSuitableURLForInstant(url, template_url))
311 template_url->ExtractSearchTermsFromURL(url, &search_terms); 287 template_url->ExtractSearchTermsFromURL(url, &search_terms);
312 return search_terms; 288 return search_terms;
313 } 289 }
314 290
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 430
455 return TemplateURLRefToGURL(template_url->new_tab_url_ref(), 431 return TemplateURLRefToGURL(template_url->new_tab_url_ref(),
456 kDisableStartMargin, false); 432 kDisableStartMargin, false);
457 } 433 }
458 434
459 GURL GetLocalInstantURL(Profile* profile) { 435 GURL GetLocalInstantURL(Profile* profile) {
460 return GURL(chrome::kChromeSearchLocalNtpUrl); 436 return GURL(chrome::kChromeSearchLocalNtpUrl);
461 } 437 }
462 438
463 bool ShouldPreferRemoteNTPOnStartup() { 439 bool ShouldPreferRemoteNTPOnStartup() {
464 // Check the command-line/about:flags setting first, which should have
465 // precedence and allows the trial to not be reported (if it's never queried).
466 const CommandLine* command_line = CommandLine::ForCurrentProcess();
467 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI) ||
468 command_line->HasSwitch(switches::kEnableLocalFirstLoadNTP)) {
469 return false;
470 }
471 if (command_line->HasSwitch(switches::kDisableLocalFirstLoadNTP))
472 return true;
473
474 FieldTrialFlags flags; 440 FieldTrialFlags flags;
475 if (GetFieldTrialInfo(&flags, NULL)) { 441 if (GetFieldTrialInfo(&flags)) {
476 return GetBoolValueForFlagWithDefault(kUseRemoteNTPOnStartupFlagName, true, 442 return GetBoolValueForFlagWithDefault(kUseRemoteNTPOnStartupFlagName, true,
477 flags); 443 flags);
478 } 444 }
479 return false; 445 return true;
480 } 446 }
481 447
482 bool ShouldHideTopVerbatimMatch() { 448 bool ShouldHideTopVerbatimMatch() {
483 FieldTrialFlags flags; 449 FieldTrialFlags flags;
484 if (GetFieldTrialInfo(&flags, NULL)) { 450 if (GetFieldTrialInfo(&flags)) {
485 return GetBoolValueForFlagWithDefault(kHideVerbatimFlagName, false, flags); 451 return GetBoolValueForFlagWithDefault(kHideVerbatimFlagName, false, flags);
486 } 452 }
487 return false; 453 return false;
488 } 454 }
489 455
490 bool ShouldUseCacheableNTP() { 456 bool ShouldUseCacheableNTP() {
491 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 457 const CommandLine* command_line = CommandLine::ForCurrentProcess();
492 if (command_line->HasSwitch(switches::kUseCacheableNewTabPage)) 458 if (command_line->HasSwitch(switches::kUseCacheableNewTabPage))
493 return true; 459 return true;
494 460
495 FieldTrialFlags flags; 461 FieldTrialFlags flags;
496 if (GetFieldTrialInfo(&flags, NULL)) { 462 if (GetFieldTrialInfo(&flags)) {
497 return GetBoolValueForFlagWithDefault(kUseCacheableNTP, false, flags); 463 return GetBoolValueForFlagWithDefault(kUseCacheableNTP, false, flags);
498 } 464 }
499 return false; 465 return false;
500 } 466 }
501 467
502 bool ShouldShowInstantNTP() { 468 bool ShouldShowInstantNTP() {
503 // If using the cacheable NTP, load the NTP directly instead of preloading its 469 // If using the cacheable NTP, load the NTP directly instead of preloading its
504 // contents using InstantNTP. 470 // contents using InstantNTP.
505 if (ShouldUseCacheableNTP()) 471 if (ShouldUseCacheableNTP())
506 return false; 472 return false;
507 473
508 FieldTrialFlags flags; 474 FieldTrialFlags flags;
509 if (GetFieldTrialInfo(&flags, NULL)) { 475 if (GetFieldTrialInfo(&flags)) {
510 return GetBoolValueForFlagWithDefault(kShowNtpFlagName, true, flags); 476 return GetBoolValueForFlagWithDefault(kShowNtpFlagName, true, flags);
511 } 477 }
512 return true; 478 return true;
513 } 479 }
514 480
515 bool ShouldShowRecentTabsOnNTP() { 481 bool ShouldShowRecentTabsOnNTP() {
516 FieldTrialFlags flags; 482 FieldTrialFlags flags;
517 if (GetFieldTrialInfo(&flags, NULL)) { 483 if (GetFieldTrialInfo(&flags)) {
518 return GetBoolValueForFlagWithDefault( 484 return GetBoolValueForFlagWithDefault(
519 kRecentTabsOnNTPFlagName, false, flags); 485 kRecentTabsOnNTPFlagName, false, flags);
520 } 486 }
521 487
522 return false; 488 return false;
523 } 489 }
524 490
525 bool ShouldSuppressInstantExtendedOnSRP() {
526 FieldTrialFlags flags;
527 if (GetFieldTrialInfo(&flags, NULL)) {
528 return GetBoolValueForFlagWithDefault(
529 kSuppressInstantExtendedOnSRPFlagName, false, flags);
530 }
531
532 return false;
533 }
534
535 GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) { 491 GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) {
536 CHECK(ShouldAssignURLToInstantRenderer(url, profile)) 492 CHECK(ShouldAssignURLToInstantRenderer(url, profile))
537 << "Error granting Instant access."; 493 << "Error granting Instant access.";
538 494
539 if (url.SchemeIs(chrome::kChromeSearchScheme)) 495 if (url.SchemeIs(chrome::kChromeSearchScheme))
540 return url; 496 return url;
541 497
542 GURL effective_url(url); 498 GURL effective_url(url);
543 499
544 // Replace the scheme with "chrome-search:". 500 // Replace the scheme with "chrome-search:".
(...skipping 16 matching lines...) Expand all
561 } 517 }
562 } 518 }
563 519
564 effective_url = effective_url.ReplaceComponents(replacements); 520 effective_url = effective_url.ReplaceComponents(replacements);
565 return effective_url; 521 return effective_url;
566 } 522 }
567 523
568 int GetInstantLoaderStalenessTimeoutSec() { 524 int GetInstantLoaderStalenessTimeoutSec() {
569 int timeout_sec = kStalePageTimeoutDefault; 525 int timeout_sec = kStalePageTimeoutDefault;
570 FieldTrialFlags flags; 526 FieldTrialFlags flags;
571 if (GetFieldTrialInfo(&flags, NULL)) { 527 if (GetFieldTrialInfo(&flags)) {
572 timeout_sec = GetUInt64ValueForFlagWithDefault(kStalePageTimeoutFlagName, 528 timeout_sec = GetUInt64ValueForFlagWithDefault(kStalePageTimeoutFlagName,
573 kStalePageTimeoutDefault, 529 kStalePageTimeoutDefault,
574 flags); 530 flags);
575 } 531 }
576 532
577 // Require a minimum 5 minute timeout. 533 // Require a minimum 5 minute timeout.
578 if (timeout_sec < 0 || (timeout_sec > 0 && timeout_sec < 300)) 534 if (timeout_sec < 0 || (timeout_sec > 0 && timeout_sec < 300))
579 timeout_sec = kStalePageTimeoutDefault; 535 timeout_sec = kStalePageTimeoutDefault;
580 536
581 // Randomize by upto 15% either side. 537 // Randomize by upto 15% either side.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 InstantSupportState GetInstantSupportStateFromNavigationEntry( 603 InstantSupportState GetInstantSupportStateFromNavigationEntry(
648 const content::NavigationEntry& entry) { 604 const content::NavigationEntry& entry) {
649 string16 value; 605 string16 value;
650 if (!entry.GetExtraData(kInstantSupportStateKey, &value)) 606 if (!entry.GetExtraData(kInstantSupportStateKey, &value))
651 return INSTANT_SUPPORT_UNKNOWN; 607 return INSTANT_SUPPORT_UNKNOWN;
652 608
653 return StringToInstantSupportState(value); 609 return StringToInstantSupportState(value);
654 } 610 }
655 611
656 bool ShouldPrefetchSearchResultsOnSRP() { 612 bool ShouldPrefetchSearchResultsOnSRP() {
657 // Check the command-line/about:flags setting first, which should have
658 // precedence and allows the trial to not be reported (if it's never queried).
659 const CommandLine* command_line = CommandLine::ForCurrentProcess();
660 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI) ||
661 command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) {
662 return false;
663 }
664
665 FieldTrialFlags flags; 613 FieldTrialFlags flags;
666 if (GetFieldTrialInfo(&flags, NULL)) { 614 if (GetFieldTrialInfo(&flags)) {
667 return GetBoolValueForFlagWithDefault(kPrefetchSearchResultsOnSRP, false, 615 return GetBoolValueForFlagWithDefault(kPrefetchSearchResultsOnSRP, false,
668 flags); 616 flags);
669 } 617 }
670 return false; 618 return false;
671 } 619 }
672 620
673 void EnableInstantExtendedAPIForTesting() { 621 void EnableQueryExtractionForTesting() {
674 CommandLine* cl = CommandLine::ForCurrentProcess(); 622 CommandLine* cl = CommandLine::ForCurrentProcess();
675 cl->AppendSwitch(switches::kEnableInstantExtendedAPI); 623 cl->AppendSwitch(switches::kEnableQueryExtraction);
676 } 624 }
677 625
678 void DisableInstantExtendedAPIForTesting() { 626 bool GetFieldTrialInfo(FieldTrialFlags* flags) {
679 CommandLine* cl = CommandLine::ForCurrentProcess();
680 cl->AppendSwitch(switches::kDisableInstantExtendedAPI);
681 }
682
683 bool GetFieldTrialInfo(FieldTrialFlags* flags,
684 uint64* group_number) {
685 // Get the group name. If the EmbeddedSearch trial doesn't exist, look for 627 // Get the group name. If the EmbeddedSearch trial doesn't exist, look for
686 // the older InstantExtended name. 628 // the older InstantExtended name.
687 std::string group_name = base::FieldTrialList::FindFullName( 629 std::string group_name = base::FieldTrialList::FindFullName(
688 kEmbeddedSearchFieldTrialName); 630 kEmbeddedSearchFieldTrialName);
689 if (group_name.empty()) { 631 if (group_name.empty()) {
690 group_name = base::FieldTrialList::FindFullName( 632 group_name = base::FieldTrialList::FindFullName(
691 kInstantExtendedFieldTrialName); 633 kInstantExtendedFieldTrialName);
692 } 634 }
693 635
694 if (EndsWith(group_name, kDisablingSuffix, true)) 636 if (EndsWith(group_name, kDisablingSuffix, true))
695 return false; 637 return false;
696 638
697 // We have a valid trial that isn't disabled. 639 // We have a valid trial that isn't disabled. Extract the flags.
698 // First extract the flags.
699 std::string group_prefix(group_name); 640 std::string group_prefix(group_name);
700
701 size_t first_space = group_name.find(" "); 641 size_t first_space = group_name.find(" ");
702 if (first_space != std::string::npos) { 642 if (first_space != std::string::npos) {
703 // There is a flags section of the group name. Split that out and parse it. 643 // There is a flags section of the group name. Split that out and parse it.
704 group_prefix = group_name.substr(0, first_space); 644 group_prefix = group_name.substr(0, first_space);
705 if (!base::SplitStringIntoKeyValuePairs(group_name.substr(first_space), 645 if (!base::SplitStringIntoKeyValuePairs(group_name.substr(first_space),
706 ':', ' ', flags)) { 646 ':', ' ', flags)) {
707 // Failed to parse the flags section. Assume the whole group name is 647 // Failed to parse the flags section. Assume the whole group name is
708 // invalid. 648 // invalid.
709 return false; 649 return false;
710 } 650 }
711 } 651 }
712 652
713 // Now extract the group number, making sure we get a non-zero value.
714 uint64 temp_group_number = 0;
715 if (StartsWithASCII(group_name, kGroupNumberPrefix, true)) {
716 std::string group_suffix = group_prefix.substr(strlen(kGroupNumberPrefix));
717 if (!base::StringToUint64(group_suffix, &temp_group_number))
718 return false;
719 if (group_number)
720 *group_number = temp_group_number;
721 } else {
722 // Instant Extended is not enabled.
723 if (group_number)
724 *group_number = 0;
725 }
726
727 return true; 653 return true;
728 } 654 }
729 655
730 // Given a FieldTrialFlags object, returns the string value of the provided 656 // Given a FieldTrialFlags object, returns the string value of the provided
731 // flag. 657 // flag.
732 std::string GetStringValueForFlagWithDefault(const std::string& flag, 658 std::string GetStringValueForFlagWithDefault(const std::string& flag,
733 const std::string& default_value, 659 const std::string& default_value,
734 const FieldTrialFlags& flags) { 660 const FieldTrialFlags& flags) {
735 FieldTrialFlags::const_iterator i; 661 FieldTrialFlags::const_iterator i;
736 for (i = flags.begin(); i != flags.end(); i++) { 662 for (i = flags.begin(); i != flags.end(); i++) {
(...skipping 17 matching lines...) Expand all
754 } 680 }
755 681
756 // Given a FieldTrialFlags object, returns the boolean value of the provided 682 // Given a FieldTrialFlags object, returns the boolean value of the provided
757 // flag. 683 // flag.
758 bool GetBoolValueForFlagWithDefault(const std::string& flag, 684 bool GetBoolValueForFlagWithDefault(const std::string& flag,
759 bool default_value, 685 bool default_value,
760 const FieldTrialFlags& flags) { 686 const FieldTrialFlags& flags) {
761 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); 687 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags);
762 } 688 }
763 689
764 void ResetInstantExtendedOptInStateGateForTest() {
765 instant_extended_opt_in_state_gate = false;
766 }
767
768 } // namespace chrome 690 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698