Chromium Code Reviews| 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 #endif | |
| 612 return true; | |
|
Jered
2014/07/14 16:18:27
nit: It would be slightly clearer to write #else .
kmadhusu
2014/07/14 19:37:15
Done.
| |
| 607 } | 613 } |
| 608 | 614 |
| 609 bool ShouldAllowPrefetchNonDefaultMatch() { | 615 bool ShouldAllowPrefetchNonDefaultMatch() { |
| 610 if (!ShouldPrefetchSearchResults()) | 616 if (!ShouldPrefetchSearchResults()) |
| 611 return false; | 617 return false; |
| 612 | 618 |
| 613 FieldTrialFlags flags; | 619 FieldTrialFlags flags; |
| 614 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | 620 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
| 615 kAllowPrefetchNonDefaultMatch, false, flags); | 621 kAllowPrefetchNonDefaultMatch, false, flags); |
| 616 } | 622 } |
| 617 | 623 |
| 618 bool ShouldPrerenderInstantUrlOnOmniboxFocus() { | 624 bool ShouldPrerenderInstantUrlOnOmniboxFocus() { |
| 619 if (!ShouldPrefetchSearchResults()) | 625 if (!ShouldPrefetchSearchResults()) |
| 620 return false; | 626 return false; |
| 621 | 627 |
| 622 FieldTrialFlags flags; | 628 FieldTrialFlags flags; |
| 623 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | 629 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
| 624 kPrerenderInstantUrlOnOmniboxFocus, false, flags); | 630 kPrerenderInstantUrlOnOmniboxFocus, false, flags); |
| 625 } | 631 } |
| 626 | 632 |
| 627 bool ShouldReuseInstantSearchBasePage() { | 633 bool ShouldReuseInstantSearchBasePage() { |
| 628 if (!ShouldPrefetchSearchResults()) | 634 if (!ShouldPrefetchSearchResults()) |
| 629 return false; | 635 return false; |
| 630 | 636 |
| 637 #if defined(OS_ANDROID) | |
| 631 FieldTrialFlags flags; | 638 FieldTrialFlags flags; |
| 632 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | 639 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
| 633 kReuseInstantSearchBasePage, false, flags); | 640 kReuseInstantSearchBasePage, false, flags); |
| 641 #endif | |
| 642 return true; | |
| 634 } | 643 } |
| 635 | 644 |
| 636 GURL GetLocalInstantURL(Profile* profile) { | 645 GURL GetLocalInstantURL(Profile* profile) { |
| 637 return GURL(chrome::kChromeSearchLocalNtpUrl); | 646 return GURL(chrome::kChromeSearchLocalNtpUrl); |
| 638 } | 647 } |
| 639 | 648 |
| 640 bool ShouldHideTopVerbatimMatch() { | 649 bool ShouldHideTopVerbatimMatch() { |
| 641 FieldTrialFlags flags; | 650 FieldTrialFlags flags; |
| 642 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | 651 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
| 643 kHideVerbatimFlagName, false, flags); | 652 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); | 868 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); |
| 860 } | 869 } |
| 861 | 870 |
| 862 bool ShouldUseAltInstantURL() { | 871 bool ShouldUseAltInstantURL() { |
| 863 FieldTrialFlags flags; | 872 FieldTrialFlags flags; |
| 864 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | 873 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
| 865 kUseAltInstantURL, false, flags); | 874 kUseAltInstantURL, false, flags); |
| 866 } | 875 } |
| 867 | 876 |
| 868 } // namespace chrome | 877 } // namespace chrome |
| OLD | NEW |