| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 const uint64 kEmbeddedPageVersionDefault = 1; | 59 const uint64 kEmbeddedPageVersionDefault = 1; |
| 60 // Use this variant to enable EmbeddedSearch SearchBox API in the results page. | 60 // Use this variant to enable EmbeddedSearch SearchBox API in the results page. |
| 61 const uint64 kEmbeddedSearchEnabledVersion = 2; | 61 const uint64 kEmbeddedSearchEnabledVersion = 2; |
| 62 #else | 62 #else |
| 63 const uint64 kEmbeddedPageVersionDefault = 2; | 63 const uint64 kEmbeddedPageVersionDefault = 2; |
| 64 #endif | 64 #endif |
| 65 | 65 |
| 66 const char kHideVerbatimFlagName[] = "hide_verbatim"; | 66 const char kHideVerbatimFlagName[] = "hide_verbatim"; |
| 67 const char kPrefetchSearchResultsFlagName[] = "prefetch_results"; | 67 const char kPrefetchSearchResultsFlagName[] = "prefetch_results"; |
| 68 const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp"; | 68 const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp"; |
| 69 const char kPrerenderInstantUrlOnOmniboxFocus[] = |
| 70 "prerender_instant_url_on_omnibox_focus"; |
| 69 | 71 |
| 70 // Controls whether to reuse prerendered Instant Search base page to commit any | 72 // Controls whether to reuse prerendered Instant Search base page to commit any |
| 71 // search query. | 73 // search query. |
| 72 const char kReuseInstantSearchBasePage[] = "reuse_instant_search_base_page"; | 74 const char kReuseInstantSearchBasePage[] = "reuse_instant_search_base_page"; |
| 73 | 75 |
| 74 const char kDisplaySearchButtonFlagName[] = "display_search_button"; | 76 const char kDisplaySearchButtonFlagName[] = "display_search_button"; |
| 75 const char kOriginChipFlagName[] = "origin_chip"; | 77 const char kOriginChipFlagName[] = "origin_chip"; |
| 76 #if !defined(OS_IOS) && !defined(OS_ANDROID) | 78 #if !defined(OS_IOS) && !defined(OS_ANDROID) |
| 77 const char kEnableQueryExtractionFlagName[] = "query_extraction"; | 79 const char kEnableQueryExtractionFlagName[] = "query_extraction"; |
| 78 #endif | 80 #endif |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 GURL GetNewTabPageURL(Profile* profile) { | 561 GURL GetNewTabPageURL(Profile* profile) { |
| 560 return NewTabURLDetails::ForProfile(profile).url; | 562 return NewTabURLDetails::ForProfile(profile).url; |
| 561 } | 563 } |
| 562 | 564 |
| 563 GURL GetSearchResultPrefetchBaseURL(Profile* profile) { | 565 GURL GetSearchResultPrefetchBaseURL(Profile* profile) { |
| 564 return ShouldPrefetchSearchResults() ? | 566 return ShouldPrefetchSearchResults() ? |
| 565 GetInstantURL(profile, kDisableStartMargin, true) : GURL(); | 567 GetInstantURL(profile, kDisableStartMargin, true) : GURL(); |
| 566 } | 568 } |
| 567 | 569 |
| 568 bool ShouldPrefetchSearchResults() { | 570 bool ShouldPrefetchSearchResults() { |
| 571 if (!IsInstantExtendedAPIEnabled()) |
| 572 return false; |
| 573 |
| 569 if (CommandLine::ForCurrentProcess()->HasSwitch( | 574 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 570 switches::kPrefetchSearchResults)) { | 575 switches::kPrefetchSearchResults)) { |
| 571 return true; | 576 return true; |
| 572 } | 577 } |
| 573 | 578 |
| 574 FieldTrialFlags flags; | 579 FieldTrialFlags flags; |
| 575 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | 580 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
| 576 kPrefetchSearchResultsFlagName, false, flags); | 581 kPrefetchSearchResultsFlagName, false, flags); |
| 577 } | 582 } |
| 578 | 583 |
| 579 bool ShouldReuseInstantSearchBasePage() { | 584 bool ShouldPrerenderInstantUrlOnOmniboxFocus() { |
| 580 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 581 switches::kPrefetchSearchResults)) { | |
| 582 return true; | |
| 583 } | |
| 584 | |
| 585 if (!ShouldPrefetchSearchResults()) | 585 if (!ShouldPrefetchSearchResults()) |
| 586 return false; | 586 return false; |
| 587 | 587 |
| 588 FieldTrialFlags flags; |
| 589 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
| 590 kPrerenderInstantUrlOnOmniboxFocus, false, flags); |
| 591 } |
| 592 |
| 593 bool ShouldReuseInstantSearchBasePage() { |
| 594 if (!ShouldPrefetchSearchResults()) |
| 595 return false; |
| 596 |
| 588 FieldTrialFlags flags; | 597 FieldTrialFlags flags; |
| 589 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | 598 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
| 590 kReuseInstantSearchBasePage, false, flags); | 599 kReuseInstantSearchBasePage, false, flags); |
| 591 } | 600 } |
| 592 | 601 |
| 593 GURL GetLocalInstantURL(Profile* profile) { | 602 GURL GetLocalInstantURL(Profile* profile) { |
| 594 return GURL(chrome::kChromeSearchLocalNtpUrl); | 603 return GURL(chrome::kChromeSearchLocalNtpUrl); |
| 595 } | 604 } |
| 596 | 605 |
| 597 bool ShouldHideTopVerbatimMatch() { | 606 bool ShouldHideTopVerbatimMatch() { |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 | 819 |
| 811 // Given a FieldTrialFlags object, returns the boolean value of the provided | 820 // Given a FieldTrialFlags object, returns the boolean value of the provided |
| 812 // flag. | 821 // flag. |
| 813 bool GetBoolValueForFlagWithDefault(const std::string& flag, | 822 bool GetBoolValueForFlagWithDefault(const std::string& flag, |
| 814 bool default_value, | 823 bool default_value, |
| 815 const FieldTrialFlags& flags) { | 824 const FieldTrialFlags& flags) { |
| 816 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); | 825 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); |
| 817 } | 826 } |
| 818 | 827 |
| 819 } // namespace chrome | 828 } // namespace chrome |
| OLD | NEW |