| 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" | 9 #include "base/command_line.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 // Dev & Canary, for now the code accepts both names. | 48 // Dev & Canary, for now the code accepts both names. |
| 49 // TODO(dcblack): Remove the InstantExtended name once M31 hits the Beta | 49 // TODO(dcblack): Remove the InstantExtended name once M31 hits the Beta |
| 50 // channel. | 50 // channel. |
| 51 const char kInstantExtendedFieldTrialName[] = "InstantExtended"; | 51 const char kInstantExtendedFieldTrialName[] = "InstantExtended"; |
| 52 const char kEmbeddedSearchFieldTrialName[] = "EmbeddedSearch"; | 52 const char kEmbeddedSearchFieldTrialName[] = "EmbeddedSearch"; |
| 53 | 53 |
| 54 // If the field trial's group name ends with this string its configuration will | 54 // If the field trial's group name ends with this string its configuration will |
| 55 // be ignored and Instant Extended will not be enabled by default. | 55 // be ignored and Instant Extended will not be enabled by default. |
| 56 const char kDisablingSuffix[] = "DISABLED"; | 56 const char kDisablingSuffix[] = "DISABLED"; |
| 57 | 57 |
| 58 #if !defined(OS_IOS) && !defined(OS_ANDROID) | |
| 59 const char kEnableQueryExtractionFlagName[] = "query_extraction"; | |
| 60 #endif | |
| 61 | |
| 62 #if defined(OS_ANDROID) | 58 #if defined(OS_ANDROID) |
| 63 const char kPrefetchSearchResultsFlagName[] = "prefetch_results"; | 59 const char kPrefetchSearchResultsFlagName[] = "prefetch_results"; |
| 64 | 60 |
| 65 // Controls whether to reuse prerendered Instant Search base page to commit any | 61 // Controls whether to reuse prerendered Instant Search base page to commit any |
| 66 // search query. | 62 // search query. |
| 67 const char kReuseInstantSearchBasePage[] = "reuse_instant_search_base_page"; | 63 const char kReuseInstantSearchBasePage[] = "reuse_instant_search_base_page"; |
| 68 #endif | 64 #endif |
| 69 | 65 |
| 70 } // namespace | 66 } // namespace |
| 71 | 67 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 152 |
| 157 // Given a FieldTrialFlags object, returns the boolean value of the provided | 153 // Given a FieldTrialFlags object, returns the boolean value of the provided |
| 158 // flag. | 154 // flag. |
| 159 bool GetBoolValueForFlagWithDefault(const std::string& flag, | 155 bool GetBoolValueForFlagWithDefault(const std::string& flag, |
| 160 bool default_value, | 156 bool default_value, |
| 161 const FieldTrialFlags& flags) { | 157 const FieldTrialFlags& flags) { |
| 162 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); | 158 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); |
| 163 } | 159 } |
| 164 | 160 |
| 165 std::string InstantExtendedEnabledParam(bool for_search) { | 161 std::string InstantExtendedEnabledParam(bool for_search) { |
| 166 if (for_search && !IsQueryExtractionEnabled()) | 162 // TODO(treib): Remove |for_search| and update callers that set it to true. |
| 163 if (for_search) |
| 167 return std::string(); | 164 return std::string(); |
| 168 return std::string(google_util::kInstantExtendedAPIParam) + "=" + | 165 return std::string(google_util::kInstantExtendedAPIParam) + "=" + |
| 169 base::Uint64ToString(EmbeddedSearchPageVersion()) + "&"; | 166 base::Uint64ToString(EmbeddedSearchPageVersion()) + "&"; |
| 170 } | 167 } |
| 171 | 168 |
| 172 std::string ForceInstantResultsParam(bool for_prerender) { | 169 std::string ForceInstantResultsParam(bool for_prerender) { |
| 173 return (for_prerender || !IsInstantExtendedAPIEnabled()) ? "ion=1&" | 170 return (for_prerender || !IsInstantExtendedAPIEnabled()) ? "ion=1&" |
| 174 : std::string(); | 171 : std::string(); |
| 175 } | 172 } |
| 176 | 173 |
| 177 bool IsQueryExtractionEnabled() { | |
| 178 #if defined(OS_IOS) || defined(OS_ANDROID) | |
| 179 return false; | |
| 180 #else | |
| 181 if (!IsInstantExtendedAPIEnabled()) | |
| 182 return false; | |
| 183 | |
| 184 const base::CommandLine* command_line = | |
| 185 base::CommandLine::ForCurrentProcess(); | |
| 186 if (command_line->HasSwitch(switches::kEnableQueryExtraction)) | |
| 187 return true; | |
| 188 | |
| 189 FieldTrialFlags flags; | |
| 190 return GetFieldTrialInfo(&flags) && | |
| 191 GetBoolValueForFlagWithDefault(kEnableQueryExtractionFlagName, false, | |
| 192 flags); | |
| 193 #endif // defined(OS_IOS) || defined(OS_ANDROID) | |
| 194 } | |
| 195 | |
| 196 bool ShouldPrefetchSearchResults() { | 174 bool ShouldPrefetchSearchResults() { |
| 197 if (!IsInstantExtendedAPIEnabled()) | 175 if (!IsInstantExtendedAPIEnabled()) |
| 198 return false; | 176 return false; |
| 199 | 177 |
| 200 #if defined(OS_ANDROID) | 178 #if defined(OS_ANDROID) |
| 201 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 179 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 202 switches::kPrefetchSearchResults)) { | 180 switches::kPrefetchSearchResults)) { |
| 203 return true; | 181 return true; |
| 204 } | 182 } |
| 205 | 183 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 228 | 206 |
| 229 // |url| should either have a secure scheme or have a non-HTTPS base URL that | 207 // |url| should either have a secure scheme or have a non-HTTPS base URL that |
| 230 // the user specified using --google-base-url. (This allows testers to use | 208 // the user specified using --google-base-url. (This allows testers to use |
| 231 // --google-base-url to point at non-HTTPS servers, which eases testing.) | 209 // --google-base-url to point at non-HTTPS servers, which eases testing.) |
| 232 bool IsSuitableURLForInstant(const GURL& url, const TemplateURL* template_url) { | 210 bool IsSuitableURLForInstant(const GURL& url, const TemplateURL* template_url) { |
| 233 return template_url->HasSearchTermsReplacementKey(url) && | 211 return template_url->HasSearchTermsReplacementKey(url) && |
| 234 (url.SchemeIsCryptographic() || | 212 (url.SchemeIsCryptographic() || |
| 235 google_util::StartsWithCommandLineGoogleBaseURL(url)); | 213 google_util::StartsWithCommandLineGoogleBaseURL(url)); |
| 236 } | 214 } |
| 237 | 215 |
| 238 void EnableQueryExtractionForTesting() { | |
| 239 #if !defined(OS_IOS) && !defined(OS_ANDROID) | |
| 240 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); | |
| 241 cl->AppendSwitch(switches::kEnableQueryExtraction); | |
| 242 #endif | |
| 243 } | |
| 244 | |
| 245 } // namespace search | 216 } // namespace search |
| OLD | NEW |