| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/search/search.h" | 5 #include "components/search/search.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | |
| 10 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 11 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_split.h" | |
| 13 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | |
| 15 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 16 #include "components/google/core/browser/google_util.h" | 13 #include "components/google/core/browser/google_util.h" |
| 17 #include "components/search/search_switches.h" | |
| 18 #include "components/search_engines/template_url.h" | 14 #include "components/search_engines/template_url.h" |
| 19 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 20 | 16 |
| 21 namespace search { | 17 namespace search { |
| 22 | 18 |
| 23 namespace { | 19 namespace { |
| 24 | 20 |
| 25 // Configuration options for Embedded Search. | 21 // Configuration options for Embedded Search. |
| 26 // EmbeddedSearch field trials are named in such a way that we can parse out | 22 // EmbeddedSearch field trials are named in such a way that we can parse out |
| 27 // the experiment configuration from the trial's group name in order to give | 23 // the experiment configuration from the trial's group name in order to give |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 #elif defined(OS_ANDROID) | 67 #elif defined(OS_ANDROID) |
| 72 return EmbeddedSearchPageVersion() == kEmbeddedSearchEnabledVersion; | 68 return EmbeddedSearchPageVersion() == kEmbeddedSearchEnabledVersion; |
| 73 #else | 69 #else |
| 74 return true; | 70 return true; |
| 75 #endif // defined(OS_IOS) | 71 #endif // defined(OS_IOS) |
| 76 } | 72 } |
| 77 | 73 |
| 78 // Determine what embedded search page version to request from the user's | 74 // Determine what embedded search page version to request from the user's |
| 79 // default search provider. If 0, the embedded search UI should not be enabled. | 75 // default search provider. If 0, the embedded search UI should not be enabled. |
| 80 uint64_t EmbeddedSearchPageVersion() { | 76 uint64_t EmbeddedSearchPageVersion() { |
| 81 #if defined(OS_ANDROID) | |
| 82 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 83 switches::kEnableEmbeddedSearchAPI)) { | |
| 84 return kEmbeddedSearchEnabledVersion; | |
| 85 } | |
| 86 #endif | |
| 87 | |
| 88 FieldTrialFlags flags; | 77 FieldTrialFlags flags; |
| 89 if (GetFieldTrialInfo(&flags)) { | 78 if (GetFieldTrialInfo(&flags)) { |
| 90 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, | 79 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, |
| 91 kEmbeddedPageVersionDefault, | 80 kEmbeddedPageVersionDefault, |
| 92 flags); | 81 flags); |
| 93 } | 82 } |
| 94 return kEmbeddedPageVersionDefault; | 83 return kEmbeddedPageVersionDefault; |
| 95 } | 84 } |
| 96 | 85 |
| 97 bool GetFieldTrialInfo(FieldTrialFlags* flags) { | 86 bool GetFieldTrialInfo(FieldTrialFlags* flags) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 std::string ForceInstantResultsParam(bool for_prerender) { | 158 std::string ForceInstantResultsParam(bool for_prerender) { |
| 170 return (for_prerender || !IsInstantExtendedAPIEnabled()) ? "ion=1&" | 159 return (for_prerender || !IsInstantExtendedAPIEnabled()) ? "ion=1&" |
| 171 : std::string(); | 160 : std::string(); |
| 172 } | 161 } |
| 173 | 162 |
| 174 bool ShouldPrefetchSearchResults() { | 163 bool ShouldPrefetchSearchResults() { |
| 175 if (!IsInstantExtendedAPIEnabled()) | 164 if (!IsInstantExtendedAPIEnabled()) |
| 176 return false; | 165 return false; |
| 177 | 166 |
| 178 #if defined(OS_ANDROID) | 167 #if defined(OS_ANDROID) |
| 179 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 180 switches::kPrefetchSearchResults)) { | |
| 181 return true; | |
| 182 } | |
| 183 | |
| 184 FieldTrialFlags flags; | 168 FieldTrialFlags flags; |
| 185 return GetFieldTrialInfo(&flags) && | 169 return GetFieldTrialInfo(&flags) && |
| 186 GetBoolValueForFlagWithDefault(kPrefetchSearchResultsFlagName, false, | 170 GetBoolValueForFlagWithDefault(kPrefetchSearchResultsFlagName, false, |
| 187 flags); | 171 flags); |
| 188 #else | 172 #else |
| 189 return true; | 173 return true; |
| 190 #endif | 174 #endif |
| 191 } | 175 } |
| 192 | 176 |
| 193 bool ShouldReuseInstantSearchBasePage() { | 177 bool ShouldReuseInstantSearchBasePage() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 207 // |url| should either have a secure scheme or have a non-HTTPS base URL that | 191 // |url| should either have a secure scheme or have a non-HTTPS base URL that |
| 208 // the user specified using --google-base-url. (This allows testers to use | 192 // the user specified using --google-base-url. (This allows testers to use |
| 209 // --google-base-url to point at non-HTTPS servers, which eases testing.) | 193 // --google-base-url to point at non-HTTPS servers, which eases testing.) |
| 210 bool IsSuitableURLForInstant(const GURL& url, const TemplateURL* template_url) { | 194 bool IsSuitableURLForInstant(const GURL& url, const TemplateURL* template_url) { |
| 211 return template_url->HasSearchTermsReplacementKey(url) && | 195 return template_url->HasSearchTermsReplacementKey(url) && |
| 212 (url.SchemeIsCryptographic() || | 196 (url.SchemeIsCryptographic() || |
| 213 google_util::StartsWithCommandLineGoogleBaseURL(url)); | 197 google_util::StartsWithCommandLineGoogleBaseURL(url)); |
| 214 } | 198 } |
| 215 | 199 |
| 216 } // namespace search | 200 } // namespace search |
| OLD | NEW |