| 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 20 matching lines...) Expand all Loading... |
| 40 namespace { | 39 namespace { |
| 41 | 40 |
| 42 // Configuration options for Embedded Search. | 41 // Configuration options for Embedded Search. |
| 43 // EmbeddedSearch field trials are named in such a way that we can parse out | 42 // EmbeddedSearch field trials are named in such a way that we can parse out |
| 44 // the experiment configuration from the trial's group name in order to give | 43 // the experiment configuration from the trial's group name in order to give |
| 45 // us maximum flexability in running experiments. | 44 // us maximum flexability in running experiments. |
| 46 // Field trial groups should be named things like "Group7 espv:2 instant:1". | 45 // Field trial groups should be named things like "Group7 espv:2 instant:1". |
| 47 // The first token is always GroupN for some integer N, followed by a | 46 // The first token is always GroupN for some integer N, followed by a |
| 48 // space-delimited list of key:value pairs which correspond to these flags: | 47 // space-delimited list of key:value pairs which correspond to these flags: |
| 49 const char kEmbeddedPageVersionFlagName[] = "espv"; | 48 const char kEmbeddedPageVersionFlagName[] = "espv"; |
| 50 const uint64 kEmbeddedPageVersionDisabled = 0; | |
| 51 #if defined(OS_IOS) || defined(OS_ANDROID) | 49 #if defined(OS_IOS) || defined(OS_ANDROID) |
| 52 const uint64 kEmbeddedPageVersionDefault = 1; | 50 const uint64 kEmbeddedPageVersionDefault = 1; |
| 53 #else | 51 #else |
| 54 const uint64 kEmbeddedPageVersionDefault = 2; | 52 const uint64 kEmbeddedPageVersionDefault = 2; |
| 55 #endif | 53 #endif |
| 56 | 54 |
| 57 // The staleness timeout can be set (in seconds) via this config. | 55 // The staleness timeout can be set (in seconds) via this config. |
| 58 const char kStalePageTimeoutFlagName[] = "stale"; | 56 const char kStalePageTimeoutFlagName[] = "stale"; |
| 59 const int kStalePageTimeoutDefault = 3 * 3600; // 3 hours. | 57 const int kStalePageTimeoutDefault = 3 * 3600; // 3 hours. |
| 60 | 58 |
| 61 const char kHideVerbatimFlagName[] = "hide_verbatim"; | 59 const char kHideVerbatimFlagName[] = "hide_verbatim"; |
| 62 const char kUseRemoteNTPOnStartupFlagName[] = "use_remote_ntp_on_startup"; | 60 const char kUseRemoteNTPOnStartupFlagName[] = "use_remote_ntp_on_startup"; |
| 63 const char kShowNtpFlagName[] = "show_ntp"; | 61 const char kShowNtpFlagName[] = "show_ntp"; |
| 64 const char kRecentTabsOnNTPFlagName[] = "show_recent_tabs"; | 62 const char kRecentTabsOnNTPFlagName[] = "show_recent_tabs"; |
| 65 const char kUseCacheableNTP[] = "use_cacheable_ntp"; | 63 const char kUseCacheableNTP[] = "use_cacheable_ntp"; |
| 66 const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp"; | 64 const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp"; |
| 67 const char kSuppressInstantExtendedOnSRPFlagName[] = "suppress_on_srp"; | 65 const char kEnableQueryExtractionFlagName[] = "query_extraction"; |
| 68 | 66 |
| 69 // Constants for the field trial name and group prefix. | 67 // Constants for the field trial name and group prefix. |
| 70 // Note in M30 and below this field trial was named "InstantExtended" and in | 68 // 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 | 69 // 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 | 70 // can't easilly sync up Finch configs with the pushing of this change to |
| 73 // Dev & Canary, for now the code accepts both names. | 71 // Dev & Canary, for now the code accepts both names. |
| 74 // TODO(dcblack): Remove the InstantExtended name once M31 hits the Beta | 72 // TODO(dcblack): Remove the InstantExtended name once M31 hits the Beta |
| 75 // channel. | 73 // channel. |
| 76 const char kInstantExtendedFieldTrialName[] = "InstantExtended"; | 74 const char kInstantExtendedFieldTrialName[] = "InstantExtended"; |
| 77 const char kEmbeddedSearchFieldTrialName[] = "EmbeddedSearch"; | 75 const char kEmbeddedSearchFieldTrialName[] = "EmbeddedSearch"; |
| 78 const char kGroupNumberPrefix[] = "Group"; | |
| 79 | 76 |
| 80 // If the field trial's group name ends with this string its configuration will | 77 // 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. | 78 // be ignored and Instant Extended will not be enabled by default. |
| 82 const char kDisablingSuffix[] = "DISABLED"; | 79 const char kDisablingSuffix[] = "DISABLED"; |
| 83 | 80 |
| 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. | 81 // Used to set the Instant support state of the Navigation entry. |
| 88 const char kInstantSupportStateKey[] = "instant_support_state"; | 82 const char kInstantSupportStateKey[] = "instant_support_state"; |
| 89 | 83 |
| 90 const char kInstantSupportEnabled[] = "Instant support enabled"; | 84 const char kInstantSupportEnabled[] = "Instant support enabled"; |
| 91 const char kInstantSupportDisabled[] = "Instant support disabled"; | 85 const char kInstantSupportDisabled[] = "Instant support disabled"; |
| 92 const char kInstantSupportUnknown[] = "Instant support unknown"; | 86 const char kInstantSupportUnknown[] = "Instant support unknown"; |
| 93 | 87 |
| 94 InstantSupportState StringToInstantSupportState(const string16& value) { | 88 InstantSupportState StringToInstantSupportState(const string16& value) { |
| 95 if (value == ASCIIToUTF16(kInstantSupportEnabled)) | 89 if (value == ASCIIToUTF16(kInstantSupportEnabled)) |
| 96 return INSTANT_SUPPORT_YES; | 90 return INSTANT_SUPPORT_YES; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 TemplateURLRef ref(template_url, i); | 136 TemplateURLRef ref(template_url, i); |
| 143 search_url = TemplateURLRefToGURL(ref, kDisableStartMargin, false); | 137 search_url = TemplateURLRefToGURL(ref, kDisableStartMargin, false); |
| 144 if (search_url.is_valid() && | 138 if (search_url.is_valid() && |
| 145 search::MatchesOriginAndPath(url, search_url)) | 139 search::MatchesOriginAndPath(url, search_url)) |
| 146 return true; | 140 return true; |
| 147 } | 141 } |
| 148 | 142 |
| 149 return false; | 143 return false; |
| 150 } | 144 } |
| 151 | 145 |
| 152 void RecordInstantExtendedOptInState() { | |
| 153 if (instant_extended_opt_in_state_gate) | |
| 154 return; | |
| 155 | |
| 156 instant_extended_opt_in_state_gate = true; | |
| 157 OptInState state = INSTANT_EXTENDED_NOT_SET; | |
| 158 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 159 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI)) | |
| 160 state = INSTANT_EXTENDED_OPT_OUT; | |
| 161 else if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) | |
| 162 state = INSTANT_EXTENDED_OPT_IN; | |
| 163 | |
| 164 UMA_HISTOGRAM_ENUMERATION("InstantExtended.NewOptInState", state, | |
| 165 INSTANT_EXTENDED_OPT_IN_STATE_ENUM_COUNT); | |
| 166 } | |
| 167 | |
| 168 // Returns true if |contents| is rendered inside the Instant process for | 146 // Returns true if |contents| is rendered inside the Instant process for |
| 169 // |profile|. | 147 // |profile|. |
| 170 bool IsRenderedInInstantProcess(const content::WebContents* contents, | 148 bool IsRenderedInInstantProcess(const content::WebContents* contents, |
| 171 Profile* profile) { | 149 Profile* profile) { |
| 172 const content::RenderProcessHost* process_host = | 150 const content::RenderProcessHost* process_host = |
| 173 contents->GetRenderProcessHost(); | 151 contents->GetRenderProcessHost(); |
| 174 if (!process_host) | 152 if (!process_host) |
| 175 return false; | 153 return false; |
| 176 | 154 |
| 177 const InstantService* instant_service = | 155 const InstantService* instant_service = |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 195 |
| 218 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref(); | 196 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref(); |
| 219 const GURL instant_url = | 197 const GURL instant_url = |
| 220 TemplateURLRefToGURL(instant_url_ref, kDisableStartMargin, false); | 198 TemplateURLRefToGURL(instant_url_ref, kDisableStartMargin, false); |
| 221 if (!instant_url.is_valid()) | 199 if (!instant_url.is_valid()) |
| 222 return false; | 200 return false; |
| 223 | 201 |
| 224 if (search::MatchesOriginAndPath(url, instant_url)) | 202 if (search::MatchesOriginAndPath(url, instant_url)) |
| 225 return true; | 203 return true; |
| 226 | 204 |
| 227 return !ShouldSuppressInstantExtendedOnSRP() && | 205 return IsQueryExtractionEnabled() && MatchesAnySearchURL(url, template_url); |
| 228 MatchesAnySearchURL(url, template_url); | |
| 229 } | 206 } |
| 230 | 207 |
| 231 string16 GetSearchTermsImpl(const content::WebContents* contents, | 208 string16 GetSearchTermsImpl(const content::WebContents* contents, |
| 232 const content::NavigationEntry* entry) { | 209 const content::NavigationEntry* entry) { |
| 233 if (!contents || !IsQueryExtractionEnabled()) | 210 if (!contents || !IsQueryExtractionEnabled()) |
| 234 return string16(); | 211 return string16(); |
| 235 | 212 |
| 236 // For security reasons, don't extract search terms if the page is not being | 213 // For security reasons, don't extract search terms if the page is not being |
| 237 // rendered in the privileged Instant renderer process. This is to protect | 214 // rendered in the privileged Instant renderer process. This is to protect |
| 238 // against a malicious page somehow scripting the search results page and | 215 // against a malicious page somehow scripting the search results page and |
| (...skipping 20 matching lines...) Expand all Loading... |
| 259 | 236 |
| 260 } // namespace | 237 } // namespace |
| 261 | 238 |
| 262 // Negative start-margin values prevent the "es_sm" parameter from being used. | 239 // Negative start-margin values prevent the "es_sm" parameter from being used. |
| 263 const int kDisableStartMargin = -1; | 240 const int kDisableStartMargin = -1; |
| 264 | 241 |
| 265 bool IsInstantExtendedAPIEnabled() { | 242 bool IsInstantExtendedAPIEnabled() { |
| 266 #if defined(OS_IOS) || defined(OS_ANDROID) | 243 #if defined(OS_IOS) || defined(OS_ANDROID) |
| 267 return false; | 244 return false; |
| 268 #else | 245 #else |
| 269 RecordInstantExtendedOptInState(); | 246 return true; |
| 270 return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled; | |
| 271 #endif // defined(OS_IOS) || defined(OS_ANDROID) | 247 #endif // defined(OS_IOS) || defined(OS_ANDROID) |
| 272 } | 248 } |
| 273 | 249 |
| 274 // Determine what embedded search page version to request from the user's | 250 // Determine what embedded search page version to request from the user's |
| 275 // default search provider. If 0, the embedded search UI should not be enabled. | 251 // default search provider. |
| 276 uint64 EmbeddedSearchPageVersion() { | 252 uint64 EmbeddedSearchPageVersion() { |
| 277 RecordInstantExtendedOptInState(); | |
| 278 | |
| 279 // Check the command-line/about:flags setting first, which should have | |
| 280 // precedence and allows the trial to not be reported (if it's never queried). | |
| 281 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 282 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI)) | |
| 283 return kEmbeddedPageVersionDisabled; | |
| 284 if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) { | |
| 285 // The user has set the about:flags switch to Enabled - give the default | |
| 286 // UI version. | |
| 287 return kEmbeddedPageVersionDefault; | |
| 288 } | |
| 289 | |
| 290 FieldTrialFlags flags; | 253 FieldTrialFlags flags; |
| 291 uint64 group_num = 0; | 254 if (GetFieldTrialInfo(&flags)) { |
| 292 if (GetFieldTrialInfo(&flags, &group_num)) { | |
| 293 if (group_num == 0) | |
| 294 return kEmbeddedPageVersionDisabled; | |
| 295 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, | 255 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, |
| 296 kEmbeddedPageVersionDefault, | 256 kEmbeddedPageVersionDefault, |
| 297 flags); | 257 flags); |
| 298 } | 258 } |
| 299 return kEmbeddedPageVersionDisabled; | 259 return kEmbeddedPageVersionDefault; |
| 300 } | 260 } |
| 301 | 261 |
| 302 bool IsQueryExtractionEnabled() { | 262 bool IsQueryExtractionEnabled() { |
| 303 return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled && | 263 #if defined(OS_IOS) || defined(OS_ANDROID) |
| 304 !ShouldSuppressInstantExtendedOnSRP(); | 264 return true; |
| 265 #else |
| 266 if (!IsInstantExtendedAPIEnabled()) |
| 267 return false; |
| 268 |
| 269 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 270 if (command_line->HasSwitch(switches::kEnableQueryExtraction)) |
| 271 return true; |
| 272 |
| 273 FieldTrialFlags flags; |
| 274 if (GetFieldTrialInfo(&flags)) { |
| 275 return GetBoolValueForFlagWithDefault( |
| 276 kEnableQueryExtractionFlagName, false, flags); |
| 277 } |
| 278 |
| 279 return false; |
| 280 #endif // defined(OS_IOS) || defined(OS_ANDROID) |
| 305 } | 281 } |
| 306 | 282 |
| 307 string16 GetSearchTermsFromURL(Profile* profile, const GURL& url) { | 283 string16 GetSearchTermsFromURL(Profile* profile, const GURL& url) { |
| 308 string16 search_terms; | 284 string16 search_terms; |
| 309 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); | 285 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); |
| 310 if (template_url && IsSuitableURLForInstant(url, template_url)) | 286 if (template_url && IsSuitableURLForInstant(url, template_url)) |
| 311 template_url->ExtractSearchTermsFromURL(url, &search_terms); | 287 template_url->ExtractSearchTermsFromURL(url, &search_terms); |
| 312 return search_terms; | 288 return search_terms; |
| 313 } | 289 } |
| 314 | 290 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 | 428 |
| 453 return TemplateURLRefToGURL(template_url->new_tab_url_ref(), | 429 return TemplateURLRefToGURL(template_url->new_tab_url_ref(), |
| 454 kDisableStartMargin, false); | 430 kDisableStartMargin, false); |
| 455 } | 431 } |
| 456 | 432 |
| 457 GURL GetLocalInstantURL(Profile* profile) { | 433 GURL GetLocalInstantURL(Profile* profile) { |
| 458 return GURL(chrome::kChromeSearchLocalNtpUrl); | 434 return GURL(chrome::kChromeSearchLocalNtpUrl); |
| 459 } | 435 } |
| 460 | 436 |
| 461 bool ShouldPreferRemoteNTPOnStartup() { | 437 bool ShouldPreferRemoteNTPOnStartup() { |
| 462 // Check the command-line/about:flags setting first, which should have | |
| 463 // precedence and allows the trial to not be reported (if it's never queried). | |
| 464 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 465 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI) || | |
| 466 command_line->HasSwitch(switches::kEnableLocalFirstLoadNTP)) { | |
| 467 return false; | |
| 468 } | |
| 469 if (command_line->HasSwitch(switches::kDisableLocalFirstLoadNTP)) | |
| 470 return true; | |
| 471 | |
| 472 FieldTrialFlags flags; | 438 FieldTrialFlags flags; |
| 473 if (GetFieldTrialInfo(&flags, NULL)) { | 439 if (GetFieldTrialInfo(&flags)) { |
| 474 return GetBoolValueForFlagWithDefault(kUseRemoteNTPOnStartupFlagName, true, | 440 return GetBoolValueForFlagWithDefault(kUseRemoteNTPOnStartupFlagName, true, |
| 475 flags); | 441 flags); |
| 476 } | 442 } |
| 477 return false; | 443 return true; |
| 478 } | 444 } |
| 479 | 445 |
| 480 bool ShouldHideTopVerbatimMatch() { | 446 bool ShouldHideTopVerbatimMatch() { |
| 481 FieldTrialFlags flags; | 447 FieldTrialFlags flags; |
| 482 if (GetFieldTrialInfo(&flags, NULL)) { | 448 if (GetFieldTrialInfo(&flags)) { |
| 483 return GetBoolValueForFlagWithDefault(kHideVerbatimFlagName, false, flags); | 449 return GetBoolValueForFlagWithDefault(kHideVerbatimFlagName, false, flags); |
| 484 } | 450 } |
| 485 return false; | 451 return false; |
| 486 } | 452 } |
| 487 | 453 |
| 488 bool ShouldUseCacheableNTP() { | 454 bool ShouldUseCacheableNTP() { |
| 489 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 455 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 490 if (command_line->HasSwitch(switches::kUseCacheableNewTabPage)) | 456 if (command_line->HasSwitch(switches::kUseCacheableNewTabPage)) |
| 491 return true; | 457 return true; |
| 492 | 458 |
| 493 FieldTrialFlags flags; | 459 FieldTrialFlags flags; |
| 494 if (GetFieldTrialInfo(&flags, NULL)) { | 460 if (GetFieldTrialInfo(&flags)) { |
| 495 return GetBoolValueForFlagWithDefault(kUseCacheableNTP, false, flags); | 461 return GetBoolValueForFlagWithDefault(kUseCacheableNTP, false, flags); |
| 496 } | 462 } |
| 497 return false; | 463 return false; |
| 498 } | 464 } |
| 499 | 465 |
| 500 bool ShouldShowInstantNTP() { | 466 bool ShouldShowInstantNTP() { |
| 501 // If using the cacheable NTP, load the NTP directly instead of preloading its | 467 // If using the cacheable NTP, load the NTP directly instead of preloading its |
| 502 // contents using InstantNTP. | 468 // contents using InstantNTP. |
| 503 if (ShouldUseCacheableNTP()) | 469 if (ShouldUseCacheableNTP()) |
| 504 return false; | 470 return false; |
| 505 | 471 |
| 506 FieldTrialFlags flags; | 472 FieldTrialFlags flags; |
| 507 if (GetFieldTrialInfo(&flags, NULL)) { | 473 if (GetFieldTrialInfo(&flags)) { |
| 508 return GetBoolValueForFlagWithDefault(kShowNtpFlagName, true, flags); | 474 return GetBoolValueForFlagWithDefault(kShowNtpFlagName, true, flags); |
| 509 } | 475 } |
| 510 return true; | 476 return true; |
| 511 } | 477 } |
| 512 | 478 |
| 513 bool ShouldShowRecentTabsOnNTP() { | 479 bool ShouldShowRecentTabsOnNTP() { |
| 514 FieldTrialFlags flags; | 480 FieldTrialFlags flags; |
| 515 if (GetFieldTrialInfo(&flags, NULL)) { | 481 if (GetFieldTrialInfo(&flags)) { |
| 516 return GetBoolValueForFlagWithDefault( | 482 return GetBoolValueForFlagWithDefault( |
| 517 kRecentTabsOnNTPFlagName, false, flags); | 483 kRecentTabsOnNTPFlagName, false, flags); |
| 518 } | 484 } |
| 519 | 485 |
| 520 return false; | 486 return false; |
| 521 } | 487 } |
| 522 | 488 |
| 523 bool ShouldSuppressInstantExtendedOnSRP() { | |
| 524 FieldTrialFlags flags; | |
| 525 if (GetFieldTrialInfo(&flags, NULL)) { | |
| 526 return GetBoolValueForFlagWithDefault( | |
| 527 kSuppressInstantExtendedOnSRPFlagName, false, flags); | |
| 528 } | |
| 529 | |
| 530 return false; | |
| 531 } | |
| 532 | |
| 533 GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) { | 489 GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) { |
| 534 CHECK(ShouldAssignURLToInstantRenderer(url, profile)) | 490 CHECK(ShouldAssignURLToInstantRenderer(url, profile)) |
| 535 << "Error granting Instant access."; | 491 << "Error granting Instant access."; |
| 536 | 492 |
| 537 if (url.SchemeIs(chrome::kChromeSearchScheme)) | 493 if (url.SchemeIs(chrome::kChromeSearchScheme)) |
| 538 return url; | 494 return url; |
| 539 | 495 |
| 540 GURL effective_url(url); | 496 GURL effective_url(url); |
| 541 | 497 |
| 542 // Replace the scheme with "chrome-search:". | 498 // Replace the scheme with "chrome-search:". |
| (...skipping 16 matching lines...) Expand all Loading... |
| 559 } | 515 } |
| 560 } | 516 } |
| 561 | 517 |
| 562 effective_url = effective_url.ReplaceComponents(replacements); | 518 effective_url = effective_url.ReplaceComponents(replacements); |
| 563 return effective_url; | 519 return effective_url; |
| 564 } | 520 } |
| 565 | 521 |
| 566 int GetInstantLoaderStalenessTimeoutSec() { | 522 int GetInstantLoaderStalenessTimeoutSec() { |
| 567 int timeout_sec = kStalePageTimeoutDefault; | 523 int timeout_sec = kStalePageTimeoutDefault; |
| 568 FieldTrialFlags flags; | 524 FieldTrialFlags flags; |
| 569 if (GetFieldTrialInfo(&flags, NULL)) { | 525 if (GetFieldTrialInfo(&flags)) { |
| 570 timeout_sec = GetUInt64ValueForFlagWithDefault(kStalePageTimeoutFlagName, | 526 timeout_sec = GetUInt64ValueForFlagWithDefault(kStalePageTimeoutFlagName, |
| 571 kStalePageTimeoutDefault, | 527 kStalePageTimeoutDefault, |
| 572 flags); | 528 flags); |
| 573 } | 529 } |
| 574 | 530 |
| 575 // Require a minimum 5 minute timeout. | 531 // Require a minimum 5 minute timeout. |
| 576 if (timeout_sec < 0 || (timeout_sec > 0 && timeout_sec < 300)) | 532 if (timeout_sec < 0 || (timeout_sec > 0 && timeout_sec < 300)) |
| 577 timeout_sec = kStalePageTimeoutDefault; | 533 timeout_sec = kStalePageTimeoutDefault; |
| 578 | 534 |
| 579 // Randomize by upto 15% either side. | 535 // Randomize by upto 15% either side. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 InstantSupportState GetInstantSupportStateFromNavigationEntry( | 601 InstantSupportState GetInstantSupportStateFromNavigationEntry( |
| 646 const content::NavigationEntry& entry) { | 602 const content::NavigationEntry& entry) { |
| 647 string16 value; | 603 string16 value; |
| 648 if (!entry.GetExtraData(kInstantSupportStateKey, &value)) | 604 if (!entry.GetExtraData(kInstantSupportStateKey, &value)) |
| 649 return INSTANT_SUPPORT_UNKNOWN; | 605 return INSTANT_SUPPORT_UNKNOWN; |
| 650 | 606 |
| 651 return StringToInstantSupportState(value); | 607 return StringToInstantSupportState(value); |
| 652 } | 608 } |
| 653 | 609 |
| 654 bool ShouldPrefetchSearchResultsOnSRP() { | 610 bool ShouldPrefetchSearchResultsOnSRP() { |
| 655 // Check the command-line/about:flags setting first, which should have | |
| 656 // precedence and allows the trial to not be reported (if it's never queried). | |
| 657 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 658 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI) || | |
| 659 command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) { | |
| 660 return false; | |
| 661 } | |
| 662 | |
| 663 FieldTrialFlags flags; | 611 FieldTrialFlags flags; |
| 664 if (GetFieldTrialInfo(&flags, NULL)) { | 612 if (GetFieldTrialInfo(&flags)) { |
| 665 return GetBoolValueForFlagWithDefault(kPrefetchSearchResultsOnSRP, false, | 613 return GetBoolValueForFlagWithDefault(kPrefetchSearchResultsOnSRP, false, |
| 666 flags); | 614 flags); |
| 667 } | 615 } |
| 668 return false; | 616 return false; |
| 669 } | 617 } |
| 670 | 618 |
| 671 void EnableInstantExtendedAPIForTesting() { | 619 void EnableQueryExtractionForTesting() { |
| 672 CommandLine* cl = CommandLine::ForCurrentProcess(); | 620 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 673 cl->AppendSwitch(switches::kEnableInstantExtendedAPI); | 621 cl->AppendSwitch(switches::kEnableQueryExtraction); |
| 674 } | 622 } |
| 675 | 623 |
| 676 void DisableInstantExtendedAPIForTesting() { | 624 bool GetFieldTrialInfo(FieldTrialFlags* flags) { |
| 677 CommandLine* cl = CommandLine::ForCurrentProcess(); | |
| 678 cl->AppendSwitch(switches::kDisableInstantExtendedAPI); | |
| 679 } | |
| 680 | |
| 681 bool GetFieldTrialInfo(FieldTrialFlags* flags, | |
| 682 uint64* group_number) { | |
| 683 // Get the group name. If the EmbeddedSearch trial doesn't exist, look for | 625 // Get the group name. If the EmbeddedSearch trial doesn't exist, look for |
| 684 // the older InstantExtended name. | 626 // the older InstantExtended name. |
| 685 std::string group_name = base::FieldTrialList::FindFullName( | 627 std::string group_name = base::FieldTrialList::FindFullName( |
| 686 kEmbeddedSearchFieldTrialName); | 628 kEmbeddedSearchFieldTrialName); |
| 687 if (group_name.empty()) { | 629 if (group_name.empty()) { |
| 688 group_name = base::FieldTrialList::FindFullName( | 630 group_name = base::FieldTrialList::FindFullName( |
| 689 kInstantExtendedFieldTrialName); | 631 kInstantExtendedFieldTrialName); |
| 690 } | 632 } |
| 691 | 633 |
| 692 if (EndsWith(group_name, kDisablingSuffix, true)) | 634 if (EndsWith(group_name, kDisablingSuffix, true)) |
| 693 return false; | 635 return false; |
| 694 | 636 |
| 695 // We have a valid trial that isn't disabled. | 637 // We have a valid trial that isn't disabled. Extract the flags. |
| 696 // First extract the flags. | |
| 697 std::string group_prefix(group_name); | 638 std::string group_prefix(group_name); |
| 698 | |
| 699 size_t first_space = group_name.find(" "); | 639 size_t first_space = group_name.find(" "); |
| 700 if (first_space != std::string::npos) { | 640 if (first_space != std::string::npos) { |
| 701 // There is a flags section of the group name. Split that out and parse it. | 641 // There is a flags section of the group name. Split that out and parse it. |
| 702 group_prefix = group_name.substr(0, first_space); | 642 group_prefix = group_name.substr(0, first_space); |
| 703 if (!base::SplitStringIntoKeyValuePairs(group_name.substr(first_space), | 643 if (!base::SplitStringIntoKeyValuePairs(group_name.substr(first_space), |
| 704 ':', ' ', flags)) { | 644 ':', ' ', flags)) { |
| 705 // Failed to parse the flags section. Assume the whole group name is | 645 // Failed to parse the flags section. Assume the whole group name is |
| 706 // invalid. | 646 // invalid. |
| 707 return false; | 647 return false; |
| 708 } | 648 } |
| 709 } | 649 } |
| 710 | 650 |
| 711 // Now extract the group number, making sure we get a non-zero value. | |
| 712 uint64 temp_group_number = 0; | |
| 713 if (StartsWithASCII(group_name, kGroupNumberPrefix, true)) { | |
| 714 std::string group_suffix = group_prefix.substr(strlen(kGroupNumberPrefix)); | |
| 715 if (!base::StringToUint64(group_suffix, &temp_group_number)) | |
| 716 return false; | |
| 717 if (group_number) | |
| 718 *group_number = temp_group_number; | |
| 719 } else { | |
| 720 // Instant Extended is not enabled. | |
| 721 if (group_number) | |
| 722 *group_number = 0; | |
| 723 } | |
| 724 | |
| 725 return true; | 651 return true; |
| 726 } | 652 } |
| 727 | 653 |
| 728 // Given a FieldTrialFlags object, returns the string value of the provided | 654 // Given a FieldTrialFlags object, returns the string value of the provided |
| 729 // flag. | 655 // flag. |
| 730 std::string GetStringValueForFlagWithDefault(const std::string& flag, | 656 std::string GetStringValueForFlagWithDefault(const std::string& flag, |
| 731 const std::string& default_value, | 657 const std::string& default_value, |
| 732 const FieldTrialFlags& flags) { | 658 const FieldTrialFlags& flags) { |
| 733 FieldTrialFlags::const_iterator i; | 659 FieldTrialFlags::const_iterator i; |
| 734 for (i = flags.begin(); i != flags.end(); i++) { | 660 for (i = flags.begin(); i != flags.end(); i++) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 752 } | 678 } |
| 753 | 679 |
| 754 // Given a FieldTrialFlags object, returns the boolean value of the provided | 680 // Given a FieldTrialFlags object, returns the boolean value of the provided |
| 755 // flag. | 681 // flag. |
| 756 bool GetBoolValueForFlagWithDefault(const std::string& flag, | 682 bool GetBoolValueForFlagWithDefault(const std::string& flag, |
| 757 bool default_value, | 683 bool default_value, |
| 758 const FieldTrialFlags& flags) { | 684 const FieldTrialFlags& flags) { |
| 759 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); | 685 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); |
| 760 } | 686 } |
| 761 | 687 |
| 762 void ResetInstantExtendedOptInStateGateForTest() { | |
| 763 instant_extended_opt_in_state_gate = false; | |
| 764 } | |
| 765 | |
| 766 } // namespace chrome | 688 } // namespace chrome |
| OLD | NEW |