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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 const char kPrefetchSearchResultsFlagName[] = "prefetch_results"; | 68 const char kPrefetchSearchResultsFlagName[] = "prefetch_results"; |
69 const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp"; | 69 const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp"; |
70 const char kAllowPrefetchNonDefaultMatch[] = "allow_prefetch_non_default_match"; | 70 const char kAllowPrefetchNonDefaultMatch[] = "allow_prefetch_non_default_match"; |
71 const char kPrerenderInstantUrlOnOmniboxFocus[] = | 71 const char kPrerenderInstantUrlOnOmniboxFocus[] = |
72 "prerender_instant_url_on_omnibox_focus"; | 72 "prerender_instant_url_on_omnibox_focus"; |
73 | 73 |
74 // Controls whether to reuse prerendered Instant Search base page to commit any | 74 // Controls whether to reuse prerendered Instant Search base page to commit any |
75 // search query. | 75 // search query. |
76 const char kReuseInstantSearchBasePage[] = "reuse_instant_search_base_page"; | 76 const char kReuseInstantSearchBasePage[] = "reuse_instant_search_base_page"; |
77 | 77 |
| 78 // Controls whether to use the alternate Instant search base URL. This allows |
| 79 // experimentation of Instant search. |
| 80 const char kUseAltInstantURL[] = "use_alternate_instant_url"; |
| 81 const char kAltInstantURLPath[] = "search"; |
| 82 const char kAltInstantURLQueryParams[] = "&qbp=1"; |
| 83 |
78 const char kDisplaySearchButtonFlagName[] = "display_search_button"; | 84 const char kDisplaySearchButtonFlagName[] = "display_search_button"; |
79 const char kOriginChipFlagName[] = "origin_chip"; | 85 const char kOriginChipFlagName[] = "origin_chip"; |
80 #if !defined(OS_IOS) && !defined(OS_ANDROID) | 86 #if !defined(OS_IOS) && !defined(OS_ANDROID) |
81 const char kEnableQueryExtractionFlagName[] = "query_extraction"; | 87 const char kEnableQueryExtractionFlagName[] = "query_extraction"; |
82 #endif | 88 #endif |
83 const char kShouldShowGoogleLocalNTPFlagName[] = "google_local_ntp"; | 89 const char kShouldShowGoogleLocalNTPFlagName[] = "google_local_ntp"; |
84 | 90 |
85 // Constants for the field trial name and group prefix. | 91 // Constants for the field trial name and group prefix. |
86 // Note in M30 and below this field trial was named "InstantExtended" and in | 92 // Note in M30 and below this field trial was named "InstantExtended" and in |
87 // M31 was renamed to EmbeddedSearch for clarity and cleanliness. Since we | 93 // M31 was renamed to EmbeddedSearch for clarity and cleanliness. Since we |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 !google_util::StartsWithCommandLineGoogleBaseURL(instant_url)) { | 550 !google_util::StartsWithCommandLineGoogleBaseURL(instant_url)) { |
545 GURL::Replacements replacements; | 551 GURL::Replacements replacements; |
546 const std::string secure_scheme(url::kHttpsScheme); | 552 const std::string secure_scheme(url::kHttpsScheme); |
547 replacements.SetSchemeStr(secure_scheme); | 553 replacements.SetSchemeStr(secure_scheme); |
548 instant_url = instant_url.ReplaceComponents(replacements); | 554 instant_url = instant_url.ReplaceComponents(replacements); |
549 } | 555 } |
550 | 556 |
551 if (!IsURLAllowedForSupervisedUser(instant_url, profile)) | 557 if (!IsURLAllowedForSupervisedUser(instant_url, profile)) |
552 return GURL(); | 558 return GURL(); |
553 | 559 |
| 560 if (ShouldUseAltInstantURL()) { |
| 561 GURL::Replacements replacements; |
| 562 const std::string path(kAltInstantURLPath); |
| 563 replacements.SetPathStr(path); |
| 564 const std::string query( |
| 565 instant_url.query() + std::string(kAltInstantURLQueryParams)); |
| 566 replacements.SetQueryStr(query); |
| 567 instant_url = instant_url.ReplaceComponents(replacements); |
| 568 } |
554 return instant_url; | 569 return instant_url; |
555 } | 570 } |
556 | 571 |
557 // Returns URLs associated with the default search engine for |profile|. | 572 // Returns URLs associated with the default search engine for |profile|. |
558 std::vector<GURL> GetSearchURLs(Profile* profile) { | 573 std::vector<GURL> GetSearchURLs(Profile* profile) { |
559 std::vector<GURL> result; | 574 std::vector<GURL> result; |
560 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); | 575 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); |
561 if (!template_url) | 576 if (!template_url) |
562 return result; | 577 return result; |
563 for (size_t i = 0; i < template_url->URLCount(); ++i) { | 578 for (size_t i = 0; i < template_url->URLCount(); ++i) { |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 } | 852 } |
838 | 853 |
839 // Given a FieldTrialFlags object, returns the boolean value of the provided | 854 // Given a FieldTrialFlags object, returns the boolean value of the provided |
840 // flag. | 855 // flag. |
841 bool GetBoolValueForFlagWithDefault(const std::string& flag, | 856 bool GetBoolValueForFlagWithDefault(const std::string& flag, |
842 bool default_value, | 857 bool default_value, |
843 const FieldTrialFlags& flags) { | 858 const FieldTrialFlags& flags) { |
844 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); | 859 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); |
845 } | 860 } |
846 | 861 |
| 862 bool ShouldUseAltInstantURL() { |
| 863 FieldTrialFlags flags; |
| 864 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
| 865 kUseAltInstantURL, false, flags); |
| 866 } |
| 867 |
847 } // namespace chrome | 868 } // namespace chrome |
OLD | NEW |