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" | |
| 10 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 11 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| 12 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 15 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/google/google_util.h" | 15 #include "chrome/browser/google/google_util.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
| 19 #include "chrome/browser/search/instant_service.h" | 18 #include "chrome/browser/search/instant_service.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 const char kStalePageTimeoutFlagName[] = "stale"; | 56 const char kStalePageTimeoutFlagName[] = "stale"; |
| 58 const int kStalePageTimeoutDefault = 3 * 3600; // 3 hours. | 57 const int kStalePageTimeoutDefault = 3 * 3600; // 3 hours. |
| 59 const int kStalePageTimeoutDisabled = 0; | 58 const int kStalePageTimeoutDisabled = 0; |
| 60 | 59 |
| 61 const char kHideVerbatimFlagName[] = "hide_verbatim"; | 60 const char kHideVerbatimFlagName[] = "hide_verbatim"; |
| 62 const char kUseRemoteNTPOnStartupFlagName[] = "use_remote_ntp_on_startup"; | 61 const char kUseRemoteNTPOnStartupFlagName[] = "use_remote_ntp_on_startup"; |
| 63 const char kShowNtpFlagName[] = "show_ntp"; | 62 const char kShowNtpFlagName[] = "show_ntp"; |
| 64 const char kRecentTabsOnNTPFlagName[] = "show_recent_tabs"; | 63 const char kRecentTabsOnNTPFlagName[] = "show_recent_tabs"; |
| 65 const char kUseCacheableNTP[] = "use_cacheable_ntp"; | 64 const char kUseCacheableNTP[] = "use_cacheable_ntp"; |
| 66 const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp"; | 65 const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp"; |
| 67 const char kSuppressInstantExtendedOnSRPFlagName[] = "suppress_on_srp"; | 66 const char kEnableQueryExtractionFlagName[] = "query_extraction"; |
| 68 | 67 |
| 69 // Constants for the field trial name and group prefix. | 68 // Constants for the field trial name and group prefix. |
| 70 // Note in M30 and below this field trial was named "InstantExtended" and in | 69 // Note in M30 and below this field trial was named "InstantExtended" and in |
| 71 // M31 was renamed to EmbeddedSearch for clarity and cleanliness. Since we | 70 // M31 was renamed to EmbeddedSearch for clarity and cleanliness. Since we |
| 72 // can't easilly sync up Finch configs with the pushing of this change to | 71 // can't easilly sync up Finch configs with the pushing of this change to |
| 73 // Dev & Canary, for now the code accepts both names. | 72 // Dev & Canary, for now the code accepts both names. |
| 74 // TODO(dcblack): Remove the InstantExtended name once M31 hits the Beta | 73 // TODO(dcblack): Remove the InstantExtended name once M31 hits the Beta |
| 75 // channel. | 74 // channel. |
| 76 const char kInstantExtendedFieldTrialName[] = "InstantExtended"; | 75 const char kInstantExtendedFieldTrialName[] = "InstantExtended"; |
| 77 const char kEmbeddedSearchFieldTrialName[] = "EmbeddedSearch"; | 76 const char kEmbeddedSearchFieldTrialName[] = "EmbeddedSearch"; |
| 78 const char kGroupNumberPrefix[] = "Group"; | 77 const char kGroupNumberPrefix[] = "Group"; |
|
David Black
2013/09/30 20:47:10
remove
samarth
2013/10/02 00:18:00
Done.
| |
| 79 | 78 |
| 80 // If the field trial's group name ends with this string its configuration will | 79 // If the field trial's group name ends with this string its configuration will |
| 81 // be ignored and Instant Extended will not be enabled by default. | 80 // be ignored and Instant Extended will not be enabled by default. |
| 82 const char kDisablingSuffix[] = "DISABLED"; | 81 const char kDisablingSuffix[] = "DISABLED"; |
| 83 | 82 |
| 84 // Remember if we reported metrics about opt-in/out state. | |
| 85 bool instant_extended_opt_in_state_gate = false; | |
| 86 | |
| 87 // Used to set the Instant support state of the Navigation entry. | 83 // Used to set the Instant support state of the Navigation entry. |
| 88 const char kInstantSupportStateKey[] = "instant_support_state"; | 84 const char kInstantSupportStateKey[] = "instant_support_state"; |
| 89 | 85 |
| 90 const char kInstantSupportEnabled[] = "Instant support enabled"; | 86 const char kInstantSupportEnabled[] = "Instant support enabled"; |
| 91 const char kInstantSupportDisabled[] = "Instant support disabled"; | 87 const char kInstantSupportDisabled[] = "Instant support disabled"; |
| 92 const char kInstantSupportUnknown[] = "Instant support unknown"; | 88 const char kInstantSupportUnknown[] = "Instant support unknown"; |
| 93 | 89 |
| 94 InstantSupportState StringToInstantSupportState(const string16& value) { | 90 InstantSupportState StringToInstantSupportState(const string16& value) { |
| 95 if (value == ASCIIToUTF16(kInstantSupportEnabled)) | 91 if (value == ASCIIToUTF16(kInstantSupportEnabled)) |
| 96 return INSTANT_SUPPORT_YES; | 92 return INSTANT_SUPPORT_YES; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 for (size_t i = 0; i < template_url->URLCount() - 1; ++i) { | 144 for (size_t i = 0; i < template_url->URLCount() - 1; ++i) { |
| 149 TemplateURLRef ref(template_url, i); | 145 TemplateURLRef ref(template_url, i); |
| 150 search_url = TemplateURLRefToGURL(ref, kDisableStartMargin, false); | 146 search_url = TemplateURLRefToGURL(ref, kDisableStartMargin, false); |
| 151 if (search_url.is_valid() && MatchesOriginAndPath(url, search_url)) | 147 if (search_url.is_valid() && MatchesOriginAndPath(url, search_url)) |
| 152 return true; | 148 return true; |
| 153 } | 149 } |
| 154 | 150 |
| 155 return false; | 151 return false; |
| 156 } | 152 } |
| 157 | 153 |
| 158 void RecordInstantExtendedOptInState() { | |
| 159 if (instant_extended_opt_in_state_gate) | |
| 160 return; | |
| 161 | |
| 162 instant_extended_opt_in_state_gate = true; | |
| 163 OptInState state = INSTANT_EXTENDED_NOT_SET; | |
| 164 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 165 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI)) | |
| 166 state = INSTANT_EXTENDED_OPT_OUT; | |
| 167 else if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) | |
| 168 state = INSTANT_EXTENDED_OPT_IN; | |
| 169 | |
| 170 UMA_HISTOGRAM_ENUMERATION("InstantExtended.NewOptInState", state, | |
| 171 INSTANT_EXTENDED_OPT_IN_STATE_ENUM_COUNT); | |
| 172 } | |
| 173 | |
| 174 // Returns true if |contents| is rendered inside the Instant process for | 154 // Returns true if |contents| is rendered inside the Instant process for |
| 175 // |profile|. | 155 // |profile|. |
| 176 bool IsRenderedInInstantProcess(const content::WebContents* contents, | 156 bool IsRenderedInInstantProcess(const content::WebContents* contents, |
| 177 Profile* profile) { | 157 Profile* profile) { |
| 178 const content::RenderProcessHost* process_host = | 158 const content::RenderProcessHost* process_host = |
| 179 contents->GetRenderProcessHost(); | 159 contents->GetRenderProcessHost(); |
| 180 if (!process_host) | 160 if (!process_host) |
| 181 return false; | 161 return false; |
| 182 | 162 |
| 183 const InstantService* instant_service = | 163 const InstantService* instant_service = |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 | 202 |
| 223 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref(); | 203 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref(); |
| 224 const GURL instant_url = | 204 const GURL instant_url = |
| 225 TemplateURLRefToGURL(instant_url_ref, kDisableStartMargin, false); | 205 TemplateURLRefToGURL(instant_url_ref, kDisableStartMargin, false); |
| 226 if (!instant_url.is_valid()) | 206 if (!instant_url.is_valid()) |
| 227 return false; | 207 return false; |
| 228 | 208 |
| 229 if (MatchesOriginAndPath(url, instant_url)) | 209 if (MatchesOriginAndPath(url, instant_url)) |
| 230 return true; | 210 return true; |
| 231 | 211 |
| 232 return !ShouldSuppressInstantExtendedOnSRP() && | 212 return IsQueryExtractionEnabled() && MatchesAnySearchURL(url, template_url); |
| 233 MatchesAnySearchURL(url, template_url); | |
| 234 } | 213 } |
| 235 | 214 |
| 236 string16 GetSearchTermsImpl(const content::WebContents* contents, | 215 string16 GetSearchTermsImpl(const content::WebContents* contents, |
| 237 const content::NavigationEntry* entry) { | 216 const content::NavigationEntry* entry) { |
| 238 if (!contents || !IsQueryExtractionEnabled()) | 217 if (!contents || !IsQueryExtractionEnabled()) |
| 239 return string16(); | 218 return string16(); |
| 240 | 219 |
| 241 // For security reasons, don't extract search terms if the page is not being | 220 // For security reasons, don't extract search terms if the page is not being |
| 242 // rendered in the privileged Instant renderer process. This is to protect | 221 // rendered in the privileged Instant renderer process. This is to protect |
| 243 // against a malicious page somehow scripting the search results page and | 222 // against a malicious page somehow scripting the search results page and |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 264 | 243 |
| 265 } // namespace | 244 } // namespace |
| 266 | 245 |
| 267 // Negative start-margin values prevent the "es_sm" parameter from being used. | 246 // Negative start-margin values prevent the "es_sm" parameter from being used. |
| 268 const int kDisableStartMargin = -1; | 247 const int kDisableStartMargin = -1; |
| 269 | 248 |
| 270 bool IsInstantExtendedAPIEnabled() { | 249 bool IsInstantExtendedAPIEnabled() { |
| 271 #if defined(OS_IOS) || defined(OS_ANDROID) | 250 #if defined(OS_IOS) || defined(OS_ANDROID) |
| 272 return false; | 251 return false; |
| 273 #else | 252 #else |
| 274 RecordInstantExtendedOptInState(); | |
| 275 return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled; | 253 return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled; |
|
David Black
2013/09/30 20:47:10
Do we actually want to retain the ability to turn
samarth
2013/10/02 00:18:00
Good point. I'd kept it in to give us the flexibi
| |
| 276 #endif // defined(OS_IOS) || defined(OS_ANDROID) | 254 #endif // defined(OS_IOS) || defined(OS_ANDROID) |
| 277 } | 255 } |
| 278 | 256 |
| 279 // Determine what embedded search page version to request from the user's | 257 // Determine what embedded search page version to request from the user's |
| 280 // default search provider. If 0, the embedded search UI should not be enabled. | 258 // default search provider. If 0, the embedded search UI should not be enabled. |
| 281 uint64 EmbeddedSearchPageVersion() { | 259 uint64 EmbeddedSearchPageVersion() { |
| 282 RecordInstantExtendedOptInState(); | |
| 283 | |
| 284 // Check the command-line/about:flags setting first, which should have | |
| 285 // precedence and allows the trial to not be reported (if it's never queried). | |
| 286 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 287 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI)) | |
| 288 return kEmbeddedPageVersionDisabled; | |
| 289 if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) { | |
| 290 // The user has set the about:flags switch to Enabled - give the default | |
| 291 // UI version. | |
| 292 return kEmbeddedPageVersionDefault; | |
| 293 } | |
| 294 | |
| 295 FieldTrialFlags flags; | 260 FieldTrialFlags flags; |
| 296 uint64 group_num = 0; | 261 if (GetFieldTrialInfo(&flags)) { |
| 297 if (GetFieldTrialInfo(&flags, &group_num)) { | |
| 298 if (group_num == 0) | |
| 299 return kEmbeddedPageVersionDisabled; | |
| 300 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, | 262 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, |
| 301 kEmbeddedPageVersionDefault, | 263 kEmbeddedPageVersionDefault, |
| 302 flags); | 264 flags); |
| 303 } | 265 } |
| 304 return kEmbeddedPageVersionDisabled; | 266 return kEmbeddedPageVersionDefault; |
| 305 } | 267 } |
| 306 | 268 |
| 307 bool IsQueryExtractionEnabled() { | 269 bool IsQueryExtractionEnabled() { |
| 308 return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled && | 270 #if defined(OS_IOS) || defined(OS_ANDROID) |
| 309 !ShouldSuppressInstantExtendedOnSRP(); | 271 return true; |
| 272 #else | |
| 273 if (!IsInstantExtendedAPIEnabled()) | |
| 274 return false; | |
| 275 | |
| 276 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 277 if (command_line->HasSwitch(switches::kEnableQueryExtraction)) | |
| 278 return true; | |
| 279 | |
| 280 FieldTrialFlags flags; | |
| 281 if (GetFieldTrialInfo(&flags)) { | |
| 282 return GetBoolValueForFlagWithDefault( | |
| 283 kEnableQueryExtractionFlagName, false, flags); | |
| 284 } | |
| 285 | |
| 286 return false; | |
| 287 #endif // defined(OS_IOS) || defined(OS_ANDROID) | |
| 310 } | 288 } |
| 311 | 289 |
| 312 string16 GetSearchTermsFromURL(Profile* profile, const GURL& url) { | 290 string16 GetSearchTermsFromURL(Profile* profile, const GURL& url) { |
| 313 string16 search_terms; | 291 string16 search_terms; |
| 314 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); | 292 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); |
| 315 if (template_url && IsSuitableURLForInstant(url, template_url)) | 293 if (template_url && IsSuitableURLForInstant(url, template_url)) |
| 316 template_url->ExtractSearchTermsFromURL(url, &search_terms); | 294 template_url->ExtractSearchTermsFromURL(url, &search_terms); |
| 317 return search_terms; | 295 return search_terms; |
| 318 } | 296 } |
| 319 | 297 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 401 return IsInstantURL(entry->GetVirtualURL(), profile) && | 379 return IsInstantURL(entry->GetVirtualURL(), profile) && |
| 402 GetSearchTermsImpl(contents, entry).empty(); | 380 GetSearchTermsImpl(contents, entry).empty(); |
| 403 } | 381 } |
| 404 | 382 |
| 405 bool IsSuggestPrefEnabled(Profile* profile) { | 383 bool IsSuggestPrefEnabled(Profile* profile) { |
| 406 return profile && !profile->IsOffTheRecord() && profile->GetPrefs() && | 384 return profile && !profile->IsOffTheRecord() && profile->GetPrefs() && |
| 407 profile->GetPrefs()->GetBoolean(prefs::kSearchSuggestEnabled); | 385 profile->GetPrefs()->GetBoolean(prefs::kSearchSuggestEnabled); |
| 408 } | 386 } |
| 409 | 387 |
| 410 GURL GetInstantURL(Profile* profile, int start_margin) { | 388 GURL GetInstantURL(Profile* profile, int start_margin) { |
| 411 if (!IsInstantExtendedAPIEnabled() || !IsSuggestPrefEnabled(profile)) | 389 if (!IsInstantExtendedAPIEnabled() || !IsSuggestPrefEnabled(profile)) |
|
David Black
2013/09/30 20:47:10
This IsSuggestPrefEnabled check here (and another
samarth
2013/10/02 00:18:00
Yeah it's arguable whether this makes sense anymor
| |
| 412 return GURL(); | 390 return GURL(); |
| 413 | 391 |
| 414 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); | 392 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); |
| 415 if (!template_url) | 393 if (!template_url) |
| 416 return GURL(); | 394 return GURL(); |
| 417 | 395 |
| 418 GURL instant_url = | 396 GURL instant_url = |
| 419 TemplateURLRefToGURL(template_url->instant_url_ref(), start_margin, true); | 397 TemplateURLRefToGURL(template_url->instant_url_ref(), start_margin, true); |
| 420 if (!instant_url.is_valid() || | 398 if (!instant_url.is_valid() || |
| 421 !template_url->HasSearchTermsReplacementKey(instant_url)) | 399 !template_url->HasSearchTermsReplacementKey(instant_url)) |
| 422 return GURL(); | 400 return GURL(); |
| 423 | 401 |
| 424 // Extended mode requires HTTPS. Force it unless the base URL was overridden | 402 // Extended mode requires HTTPS. Force it unless the base URL was overridden |
| 425 // on the command line, in which case we allow HTTP (see comments on | 403 // on the command line, in which case we allow HTTP (see comments on |
| 426 // IsSuitableURLForInstant()). | 404 // IsSuitableURLForInstant()). |
| 427 if (instant_url.SchemeIsSecure() || | 405 if (instant_url.SchemeIsSecure() || |
| 428 google_util::StartsWithCommandLineGoogleBaseURL(instant_url)) | 406 google_util::StartsWithCommandLineGoogleBaseURL(instant_url)) |
| 429 return instant_url; | 407 return instant_url; |
| 430 GURL::Replacements replacements; | 408 GURL::Replacements replacements; |
| 431 const std::string secure_scheme(content::kHttpsScheme); | 409 const std::string secure_scheme(content::kHttpsScheme); |
| 432 replacements.SetSchemeStr(secure_scheme); | 410 replacements.SetSchemeStr(secure_scheme); |
| 433 return instant_url.ReplaceComponents(replacements); | 411 return instant_url.ReplaceComponents(replacements); |
| 434 } | 412 } |
| 435 | 413 |
| 436 GURL GetLocalInstantURL(Profile* profile) { | 414 GURL GetLocalInstantURL(Profile* profile) { |
| 437 return GURL(chrome::kChromeSearchLocalNtpUrl); | 415 return GURL(chrome::kChromeSearchLocalNtpUrl); |
| 438 } | 416 } |
| 439 | 417 |
| 440 bool ShouldPreferRemoteNTPOnStartup() { | 418 bool ShouldPreferRemoteNTPOnStartup() { |
| 441 // Check the command-line/about:flags setting first, which should have | |
| 442 // precedence and allows the trial to not be reported (if it's never queried). | |
| 443 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 444 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI) || | |
| 445 command_line->HasSwitch(switches::kEnableLocalFirstLoadNTP)) { | |
| 446 return false; | |
| 447 } | |
| 448 if (command_line->HasSwitch(switches::kDisableLocalFirstLoadNTP)) | |
| 449 return true; | |
| 450 | |
| 451 FieldTrialFlags flags; | 419 FieldTrialFlags flags; |
| 452 if (GetFieldTrialInfo(&flags, NULL)) { | 420 if (GetFieldTrialInfo(&flags)) { |
| 453 return GetBoolValueForFlagWithDefault(kUseRemoteNTPOnStartupFlagName, true, | 421 return GetBoolValueForFlagWithDefault(kUseRemoteNTPOnStartupFlagName, true, |
| 454 flags); | 422 flags); |
| 455 } | 423 } |
| 456 return false; | 424 return false; |
|
David Black
2013/09/30 20:47:10
As per your comment on https://chromiumcodereview.
samarth
2013/10/02 00:18:00
Done.
| |
| 457 } | 425 } |
| 458 | 426 |
| 459 bool ShouldHideTopVerbatimMatch() { | 427 bool ShouldHideTopVerbatimMatch() { |
| 460 FieldTrialFlags flags; | 428 FieldTrialFlags flags; |
| 461 if (GetFieldTrialInfo(&flags, NULL)) { | 429 if (GetFieldTrialInfo(&flags)) { |
| 462 return GetBoolValueForFlagWithDefault(kHideVerbatimFlagName, false, flags); | 430 return GetBoolValueForFlagWithDefault(kHideVerbatimFlagName, false, flags); |
| 463 } | 431 } |
| 464 return false; | 432 return false; |
| 465 } | 433 } |
| 466 | 434 |
| 467 bool ShouldUseCacheableNTP() { | 435 bool ShouldUseCacheableNTP() { |
| 468 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 436 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 469 if (command_line->HasSwitch(switches::kUseCacheableNewTabPage)) | 437 if (command_line->HasSwitch(switches::kUseCacheableNewTabPage)) |
| 470 return true; | 438 return true; |
| 471 | 439 |
| 472 FieldTrialFlags flags; | 440 FieldTrialFlags flags; |
| 473 if (GetFieldTrialInfo(&flags, NULL)) { | 441 if (GetFieldTrialInfo(&flags)) { |
| 474 return GetBoolValueForFlagWithDefault(kUseCacheableNTP, false, flags); | 442 return GetBoolValueForFlagWithDefault(kUseCacheableNTP, false, flags); |
| 475 } | 443 } |
| 476 return false; | 444 return false; |
| 477 } | 445 } |
| 478 | 446 |
| 479 bool ShouldShowInstantNTP() { | 447 bool ShouldShowInstantNTP() { |
| 480 // If using the cacheable NTP, load the NTP directly instead of preloading its | 448 // If using the cacheable NTP, load the NTP directly instead of preloading its |
| 481 // contents using InstantNTP. | 449 // contents using InstantNTP. |
| 482 if (ShouldUseCacheableNTP()) | 450 if (ShouldUseCacheableNTP()) |
| 483 return false; | 451 return false; |
| 484 | 452 |
| 485 FieldTrialFlags flags; | 453 FieldTrialFlags flags; |
| 486 if (GetFieldTrialInfo(&flags, NULL)) { | 454 if (GetFieldTrialInfo(&flags)) { |
| 487 return GetBoolValueForFlagWithDefault(kShowNtpFlagName, true, flags); | 455 return GetBoolValueForFlagWithDefault(kShowNtpFlagName, true, flags); |
| 488 } | 456 } |
| 489 return true; | 457 return true; |
| 490 } | 458 } |
| 491 | 459 |
| 492 bool ShouldShowRecentTabsOnNTP() { | 460 bool ShouldShowRecentTabsOnNTP() { |
| 493 FieldTrialFlags flags; | 461 FieldTrialFlags flags; |
| 494 if (GetFieldTrialInfo(&flags, NULL)) { | 462 if (GetFieldTrialInfo(&flags)) { |
| 495 return GetBoolValueForFlagWithDefault( | 463 return GetBoolValueForFlagWithDefault( |
| 496 kRecentTabsOnNTPFlagName, false, flags); | 464 kRecentTabsOnNTPFlagName, false, flags); |
| 497 } | 465 } |
| 498 | 466 |
| 499 return false; | 467 return false; |
| 500 } | 468 } |
| 501 | 469 |
| 502 bool ShouldSuppressInstantExtendedOnSRP() { | |
| 503 FieldTrialFlags flags; | |
| 504 if (GetFieldTrialInfo(&flags, NULL)) { | |
| 505 return GetBoolValueForFlagWithDefault( | |
| 506 kSuppressInstantExtendedOnSRPFlagName, false, flags); | |
| 507 } | |
| 508 | |
| 509 return false; | |
| 510 } | |
| 511 | |
| 512 bool MatchesOriginAndPath(const GURL& my_url, const GURL& other_url) { | 470 bool MatchesOriginAndPath(const GURL& my_url, const GURL& other_url) { |
| 513 return MatchesOrigin(my_url, other_url) && my_url.path() == other_url.path(); | 471 return MatchesOrigin(my_url, other_url) && my_url.path() == other_url.path(); |
| 514 } | 472 } |
| 515 | 473 |
| 516 GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) { | 474 GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) { |
| 517 CHECK(ShouldAssignURLToInstantRenderer(url, profile)) | 475 CHECK(ShouldAssignURLToInstantRenderer(url, profile)) |
| 518 << "Error granting Instant access."; | 476 << "Error granting Instant access."; |
| 519 | 477 |
| 520 if (url.SchemeIs(chrome::kChromeSearchScheme)) | 478 if (url.SchemeIs(chrome::kChromeSearchScheme)) |
| 521 return url; | 479 return url; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 541 } | 499 } |
| 542 } | 500 } |
| 543 | 501 |
| 544 effective_url = effective_url.ReplaceComponents(replacements); | 502 effective_url = effective_url.ReplaceComponents(replacements); |
| 545 return effective_url; | 503 return effective_url; |
| 546 } | 504 } |
| 547 | 505 |
| 548 int GetInstantLoaderStalenessTimeoutSec() { | 506 int GetInstantLoaderStalenessTimeoutSec() { |
| 549 int timeout_sec = kStalePageTimeoutDefault; | 507 int timeout_sec = kStalePageTimeoutDefault; |
| 550 FieldTrialFlags flags; | 508 FieldTrialFlags flags; |
| 551 if (GetFieldTrialInfo(&flags, NULL)) { | 509 if (GetFieldTrialInfo(&flags)) { |
| 552 timeout_sec = GetUInt64ValueForFlagWithDefault(kStalePageTimeoutFlagName, | 510 timeout_sec = GetUInt64ValueForFlagWithDefault(kStalePageTimeoutFlagName, |
| 553 kStalePageTimeoutDefault, | 511 kStalePageTimeoutDefault, |
| 554 flags); | 512 flags); |
| 555 } | 513 } |
| 556 | 514 |
| 557 // Require a minimum 5 minute timeout. | 515 // Require a minimum 5 minute timeout. |
| 558 if (timeout_sec < 0 || (timeout_sec > 0 && timeout_sec < 300)) | 516 if (timeout_sec < 0 || (timeout_sec > 0 && timeout_sec < 300)) |
| 559 timeout_sec = kStalePageTimeoutDefault; | 517 timeout_sec = kStalePageTimeoutDefault; |
| 560 | 518 |
| 561 // Randomize by upto 15% either side. | 519 // Randomize by upto 15% either side. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 626 InstantSupportState GetInstantSupportStateFromNavigationEntry( | 584 InstantSupportState GetInstantSupportStateFromNavigationEntry( |
| 627 const content::NavigationEntry& entry) { | 585 const content::NavigationEntry& entry) { |
| 628 string16 value; | 586 string16 value; |
| 629 if (!entry.GetExtraData(kInstantSupportStateKey, &value)) | 587 if (!entry.GetExtraData(kInstantSupportStateKey, &value)) |
| 630 return INSTANT_SUPPORT_UNKNOWN; | 588 return INSTANT_SUPPORT_UNKNOWN; |
| 631 | 589 |
| 632 return StringToInstantSupportState(value); | 590 return StringToInstantSupportState(value); |
| 633 } | 591 } |
| 634 | 592 |
| 635 bool ShouldPrefetchSearchResultsOnSRP() { | 593 bool ShouldPrefetchSearchResultsOnSRP() { |
| 636 // Check the command-line/about:flags setting first, which should have | |
| 637 // precedence and allows the trial to not be reported (if it's never queried). | |
| 638 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 639 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI) || | |
| 640 command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) { | |
| 641 return false; | |
| 642 } | |
| 643 | |
| 644 FieldTrialFlags flags; | 594 FieldTrialFlags flags; |
| 645 if (GetFieldTrialInfo(&flags, NULL)) { | 595 if (GetFieldTrialInfo(&flags)) { |
| 646 return GetBoolValueForFlagWithDefault(kPrefetchSearchResultsOnSRP, false, | 596 return GetBoolValueForFlagWithDefault(kPrefetchSearchResultsOnSRP, false, |
| 647 flags); | 597 flags); |
| 648 } | 598 } |
| 649 return false; | 599 return false; |
| 650 } | 600 } |
| 651 | 601 |
| 652 void EnableInstantExtendedAPIForTesting() { | 602 void EnableQueryExtractionForTesting() { |
| 653 CommandLine* cl = CommandLine::ForCurrentProcess(); | 603 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 654 cl->AppendSwitch(switches::kEnableInstantExtendedAPI); | 604 cl->AppendSwitch(switches::kEnableQueryExtraction); |
| 655 } | 605 } |
| 656 | 606 |
| 657 void DisableInstantExtendedAPIForTesting() { | 607 bool GetFieldTrialInfo(FieldTrialFlags* flags) { |
| 658 CommandLine* cl = CommandLine::ForCurrentProcess(); | |
| 659 cl->AppendSwitch(switches::kDisableInstantExtendedAPI); | |
| 660 } | |
| 661 | |
| 662 bool GetFieldTrialInfo(FieldTrialFlags* flags, | |
| 663 uint64* group_number) { | |
| 664 // Get the group name. If the EmbeddedSearch trial doesn't exist, look for | 608 // Get the group name. If the EmbeddedSearch trial doesn't exist, look for |
| 665 // the older InstantExtended name. | 609 // the older InstantExtended name. |
| 666 std::string group_name = base::FieldTrialList::FindFullName( | 610 std::string group_name = base::FieldTrialList::FindFullName( |
| 667 kEmbeddedSearchFieldTrialName); | 611 kEmbeddedSearchFieldTrialName); |
| 668 if (group_name.empty()) { | 612 if (group_name.empty()) { |
| 669 group_name = base::FieldTrialList::FindFullName( | 613 group_name = base::FieldTrialList::FindFullName( |
| 670 kInstantExtendedFieldTrialName); | 614 kInstantExtendedFieldTrialName); |
| 671 } | 615 } |
| 672 | 616 |
| 673 if (EndsWith(group_name, kDisablingSuffix, true)) | 617 if (EndsWith(group_name, kDisablingSuffix, true)) |
| 674 return false; | 618 return false; |
| 675 | 619 |
| 676 // We have a valid trial that isn't disabled. | 620 // We have a valid trial that isn't disabled. Extract the flags. |
| 677 // First extract the flags. | |
| 678 std::string group_prefix(group_name); | 621 std::string group_prefix(group_name); |
| 679 | |
| 680 size_t first_space = group_name.find(" "); | 622 size_t first_space = group_name.find(" "); |
| 681 if (first_space != std::string::npos) { | 623 if (first_space != std::string::npos) { |
| 682 // There is a flags section of the group name. Split that out and parse it. | 624 // There is a flags section of the group name. Split that out and parse it. |
| 683 group_prefix = group_name.substr(0, first_space); | 625 group_prefix = group_name.substr(0, first_space); |
| 684 if (!base::SplitStringIntoKeyValuePairs(group_name.substr(first_space), | 626 if (!base::SplitStringIntoKeyValuePairs(group_name.substr(first_space), |
| 685 ':', ' ', flags)) { | 627 ':', ' ', flags)) { |
| 686 // Failed to parse the flags section. Assume the whole group name is | 628 // Failed to parse the flags section. Assume the whole group name is |
| 687 // invalid. | 629 // invalid. |
| 688 return false; | 630 return false; |
| 689 } | 631 } |
| 690 } | 632 } |
| 691 | 633 |
| 692 // Now extract the group number, making sure we get a non-zero value. | |
| 693 uint64 temp_group_number = 0; | |
| 694 if (StartsWithASCII(group_name, kGroupNumberPrefix, true)) { | |
| 695 std::string group_suffix = group_prefix.substr(strlen(kGroupNumberPrefix)); | |
| 696 if (!base::StringToUint64(group_suffix, &temp_group_number)) | |
| 697 return false; | |
| 698 if (group_number) | |
| 699 *group_number = temp_group_number; | |
| 700 } else { | |
| 701 // Instant Extended is not enabled. | |
| 702 if (group_number) | |
| 703 *group_number = 0; | |
| 704 } | |
| 705 | |
| 706 return true; | 634 return true; |
| 707 } | 635 } |
| 708 | 636 |
| 709 // Given a FieldTrialFlags object, returns the string value of the provided | 637 // Given a FieldTrialFlags object, returns the string value of the provided |
| 710 // flag. | 638 // flag. |
| 711 std::string GetStringValueForFlagWithDefault(const std::string& flag, | 639 std::string GetStringValueForFlagWithDefault(const std::string& flag, |
| 712 const std::string& default_value, | 640 const std::string& default_value, |
| 713 const FieldTrialFlags& flags) { | 641 const FieldTrialFlags& flags) { |
| 714 FieldTrialFlags::const_iterator i; | 642 FieldTrialFlags::const_iterator i; |
| 715 for (i = flags.begin(); i != flags.end(); i++) { | 643 for (i = flags.begin(); i != flags.end(); i++) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 748 return GURL(); | 676 return GURL(); |
| 749 | 677 |
| 750 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); | 678 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); |
| 751 if (!template_url) | 679 if (!template_url) |
| 752 return GURL(); | 680 return GURL(); |
| 753 | 681 |
| 754 return TemplateURLRefToGURL(template_url->new_tab_url_ref(), | 682 return TemplateURLRefToGURL(template_url->new_tab_url_ref(), |
| 755 kDisableStartMargin, false); | 683 kDisableStartMargin, false); |
| 756 } | 684 } |
| 757 | 685 |
| 758 void ResetInstantExtendedOptInStateGateForTest() { | |
| 759 instant_extended_opt_in_state_gate = false; | |
| 760 } | |
| 761 | |
| 762 } // namespace chrome | 686 } // namespace chrome |
| OLD | NEW |