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/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" | 9 #include "base/metrics/histogram.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 const uint64 kEmbeddedPageVersionDefault = 1; | 58 const uint64 kEmbeddedPageVersionDefault = 1; |
59 #elif defined(OS_ANDROID) | 59 #elif defined(OS_ANDROID) |
60 const uint64 kEmbeddedPageVersionDefault = 1; | 60 const uint64 kEmbeddedPageVersionDefault = 1; |
61 // Use this variant to enable EmbeddedSearch SearchBox API in the results page. | 61 // Use this variant to enable EmbeddedSearch SearchBox API in the results page. |
62 const uint64 kEmbeddedSearchEnabledVersion = 2; | 62 const uint64 kEmbeddedSearchEnabledVersion = 2; |
63 #else | 63 #else |
64 const uint64 kEmbeddedPageVersionDefault = 2; | 64 const uint64 kEmbeddedPageVersionDefault = 2; |
65 #endif | 65 #endif |
66 | 66 |
67 const char kHideVerbatimFlagName[] = "hide_verbatim"; | 67 const char kHideVerbatimFlagName[] = "hide_verbatim"; |
68 const char kPrefetchSearchResultsFlagName[] = "prefetch_results"; | |
69 const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp"; | 68 const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp"; |
70 const char kAllowPrefetchNonDefaultMatch[] = "allow_prefetch_non_default_match"; | 69 const char kAllowPrefetchNonDefaultMatch[] = "allow_prefetch_non_default_match"; |
71 const char kPrerenderInstantUrlOnOmniboxFocus[] = | 70 const char kPrerenderInstantUrlOnOmniboxFocus[] = |
72 "prerender_instant_url_on_omnibox_focus"; | 71 "prerender_instant_url_on_omnibox_focus"; |
73 | 72 |
| 73 #if defined(OS_ANDROID) |
| 74 const char kPrefetchSearchResultsFlagName[] = "prefetch_results"; |
| 75 |
74 // Controls whether to reuse prerendered Instant Search base page to commit any | 76 // Controls whether to reuse prerendered Instant Search base page to commit any |
75 // search query. | 77 // search query. |
76 const char kReuseInstantSearchBasePage[] = "reuse_instant_search_base_page"; | 78 const char kReuseInstantSearchBasePage[] = "reuse_instant_search_base_page"; |
| 79 #endif |
77 | 80 |
78 // Controls whether to use the alternate Instant search base URL. This allows | 81 // Controls whether to use the alternate Instant search base URL. This allows |
79 // experimentation of Instant search. | 82 // experimentation of Instant search. |
80 const char kUseAltInstantURL[] = "use_alternate_instant_url"; | 83 const char kUseAltInstantURL[] = "use_alternate_instant_url"; |
81 const char kAltInstantURLPath[] = "search"; | 84 const char kAltInstantURLPath[] = "search"; |
82 const char kAltInstantURLQueryParams[] = "&qbp=1"; | 85 const char kAltInstantURLQueryParams[] = "&qbp=1"; |
83 | 86 |
84 const char kDisplaySearchButtonFlagName[] = "display_search_button"; | 87 const char kDisplaySearchButtonFlagName[] = "display_search_button"; |
85 const char kOriginChipFlagName[] = "origin_chip"; | 88 const char kOriginChipFlagName[] = "origin_chip"; |
86 #if !defined(OS_IOS) && !defined(OS_ANDROID) | 89 #if !defined(OS_IOS) && !defined(OS_ANDROID) |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 | 592 |
590 GURL GetSearchResultPrefetchBaseURL(Profile* profile) { | 593 GURL GetSearchResultPrefetchBaseURL(Profile* profile) { |
591 return ShouldPrefetchSearchResults() ? | 594 return ShouldPrefetchSearchResults() ? |
592 GetInstantURL(profile, kDisableStartMargin, true) : GURL(); | 595 GetInstantURL(profile, kDisableStartMargin, true) : GURL(); |
593 } | 596 } |
594 | 597 |
595 bool ShouldPrefetchSearchResults() { | 598 bool ShouldPrefetchSearchResults() { |
596 if (!IsInstantExtendedAPIEnabled()) | 599 if (!IsInstantExtendedAPIEnabled()) |
597 return false; | 600 return false; |
598 | 601 |
| 602 #if defined(OS_ANDROID) |
599 if (CommandLine::ForCurrentProcess()->HasSwitch( | 603 if (CommandLine::ForCurrentProcess()->HasSwitch( |
600 switches::kPrefetchSearchResults)) { | 604 switches::kPrefetchSearchResults)) { |
601 return true; | 605 return true; |
602 } | 606 } |
603 | 607 |
604 FieldTrialFlags flags; | 608 FieldTrialFlags flags; |
605 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | 609 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
606 kPrefetchSearchResultsFlagName, false, flags); | 610 kPrefetchSearchResultsFlagName, false, flags); |
| 611 #else |
| 612 return true; |
| 613 #endif |
607 } | 614 } |
608 | 615 |
609 bool ShouldAllowPrefetchNonDefaultMatch() { | 616 bool ShouldAllowPrefetchNonDefaultMatch() { |
610 if (!ShouldPrefetchSearchResults()) | 617 if (!ShouldPrefetchSearchResults()) |
611 return false; | 618 return false; |
612 | 619 |
613 FieldTrialFlags flags; | 620 FieldTrialFlags flags; |
614 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | 621 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
615 kAllowPrefetchNonDefaultMatch, false, flags); | 622 kAllowPrefetchNonDefaultMatch, false, flags); |
616 } | 623 } |
617 | 624 |
618 bool ShouldPrerenderInstantUrlOnOmniboxFocus() { | 625 bool ShouldPrerenderInstantUrlOnOmniboxFocus() { |
619 if (!ShouldPrefetchSearchResults()) | 626 if (!ShouldPrefetchSearchResults()) |
620 return false; | 627 return false; |
621 | 628 |
622 FieldTrialFlags flags; | 629 FieldTrialFlags flags; |
623 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | 630 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
624 kPrerenderInstantUrlOnOmniboxFocus, false, flags); | 631 kPrerenderInstantUrlOnOmniboxFocus, false, flags); |
625 } | 632 } |
626 | 633 |
627 bool ShouldReuseInstantSearchBasePage() { | 634 bool ShouldReuseInstantSearchBasePage() { |
628 if (!ShouldPrefetchSearchResults()) | 635 if (!ShouldPrefetchSearchResults()) |
629 return false; | 636 return false; |
630 | 637 |
| 638 #if defined(OS_ANDROID) |
631 FieldTrialFlags flags; | 639 FieldTrialFlags flags; |
632 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | 640 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
633 kReuseInstantSearchBasePage, false, flags); | 641 kReuseInstantSearchBasePage, false, flags); |
| 642 #else |
| 643 return true; |
| 644 #endif |
634 } | 645 } |
635 | 646 |
636 GURL GetLocalInstantURL(Profile* profile) { | 647 GURL GetLocalInstantURL(Profile* profile) { |
637 return GURL(chrome::kChromeSearchLocalNtpUrl); | 648 return GURL(chrome::kChromeSearchLocalNtpUrl); |
638 } | 649 } |
639 | 650 |
640 bool ShouldHideTopVerbatimMatch() { | 651 bool ShouldHideTopVerbatimMatch() { |
641 FieldTrialFlags flags; | 652 FieldTrialFlags flags; |
642 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | 653 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
643 kHideVerbatimFlagName, false, flags); | 654 kHideVerbatimFlagName, false, flags); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); | 870 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); |
860 } | 871 } |
861 | 872 |
862 bool ShouldUseAltInstantURL() { | 873 bool ShouldUseAltInstantURL() { |
863 FieldTrialFlags flags; | 874 FieldTrialFlags flags; |
864 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | 875 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
865 kUseAltInstantURL, false, flags); | 876 kUseAltInstantURL, false, flags); |
866 } | 877 } |
867 | 878 |
868 } // namespace chrome | 879 } // namespace chrome |
OLD | NEW |