| 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 return GURL(chrome::kChromeSearchLocalNtpUrl); | 437 return GURL(chrome::kChromeSearchLocalNtpUrl); |
| 462 | 438 |
| 463 return url; | 439 return url; |
| 464 } | 440 } |
| 465 | 441 |
| 466 GURL GetLocalInstantURL(Profile* profile) { | 442 GURL GetLocalInstantURL(Profile* profile) { |
| 467 return GURL(chrome::kChromeSearchLocalNtpUrl); | 443 return GURL(chrome::kChromeSearchLocalNtpUrl); |
| 468 } | 444 } |
| 469 | 445 |
| 470 bool ShouldPreferRemoteNTPOnStartup() { | 446 bool ShouldPreferRemoteNTPOnStartup() { |
| 471 // Check the command-line/about:flags setting first, which should have | |
| 472 // precedence and allows the trial to not be reported (if it's never queried). | |
| 473 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 474 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI) || | |
| 475 command_line->HasSwitch(switches::kEnableLocalFirstLoadNTP)) { | |
| 476 return false; | |
| 477 } | |
| 478 if (command_line->HasSwitch(switches::kDisableLocalFirstLoadNTP)) | |
| 479 return true; | |
| 480 | |
| 481 FieldTrialFlags flags; | 447 FieldTrialFlags flags; |
| 482 if (GetFieldTrialInfo(&flags, NULL)) { | 448 if (GetFieldTrialInfo(&flags)) { |
| 483 return GetBoolValueForFlagWithDefault(kUseRemoteNTPOnStartupFlagName, true, | 449 return GetBoolValueForFlagWithDefault(kUseRemoteNTPOnStartupFlagName, true, |
| 484 flags); | 450 flags); |
| 485 } | 451 } |
| 486 return false; | 452 return true; |
| 487 } | 453 } |
| 488 | 454 |
| 489 bool ShouldHideTopVerbatimMatch() { | 455 bool ShouldHideTopVerbatimMatch() { |
| 490 FieldTrialFlags flags; | 456 FieldTrialFlags flags; |
| 491 if (GetFieldTrialInfo(&flags, NULL)) { | 457 if (GetFieldTrialInfo(&flags)) { |
| 492 return GetBoolValueForFlagWithDefault(kHideVerbatimFlagName, false, flags); | 458 return GetBoolValueForFlagWithDefault(kHideVerbatimFlagName, false, flags); |
| 493 } | 459 } |
| 494 return false; | 460 return false; |
| 495 } | 461 } |
| 496 | 462 |
| 497 bool ShouldUseCacheableNTP() { | 463 bool ShouldUseCacheableNTP() { |
| 498 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 464 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 499 if (command_line->HasSwitch(switches::kUseCacheableNewTabPage)) | 465 if (command_line->HasSwitch(switches::kUseCacheableNewTabPage)) |
| 500 return true; | 466 return true; |
| 501 | 467 |
| 502 FieldTrialFlags flags; | 468 FieldTrialFlags flags; |
| 503 if (GetFieldTrialInfo(&flags, NULL)) { | 469 if (GetFieldTrialInfo(&flags)) { |
| 504 return GetBoolValueForFlagWithDefault(kUseCacheableNTP, false, flags); | 470 return GetBoolValueForFlagWithDefault(kUseCacheableNTP, false, flags); |
| 505 } | 471 } |
| 506 return false; | 472 return false; |
| 507 } | 473 } |
| 508 | 474 |
| 509 bool ShouldShowInstantNTP() { | 475 bool ShouldShowInstantNTP() { |
| 510 // If using the cacheable NTP, load the NTP directly instead of preloading its | 476 // If using the cacheable NTP, load the NTP directly instead of preloading its |
| 511 // contents using InstantNTP. | 477 // contents using InstantNTP. |
| 512 if (ShouldUseCacheableNTP()) | 478 if (ShouldUseCacheableNTP()) |
| 513 return false; | 479 return false; |
| 514 | 480 |
| 515 FieldTrialFlags flags; | 481 FieldTrialFlags flags; |
| 516 if (GetFieldTrialInfo(&flags, NULL)) { | 482 if (GetFieldTrialInfo(&flags)) { |
| 517 return GetBoolValueForFlagWithDefault(kShowNtpFlagName, true, flags); | 483 return GetBoolValueForFlagWithDefault(kShowNtpFlagName, true, flags); |
| 518 } | 484 } |
| 519 return true; | 485 return true; |
| 520 } | 486 } |
| 521 | 487 |
| 522 bool ShouldShowRecentTabsOnNTP() { | 488 bool ShouldShowRecentTabsOnNTP() { |
| 523 FieldTrialFlags flags; | 489 FieldTrialFlags flags; |
| 524 if (GetFieldTrialInfo(&flags, NULL)) { | 490 if (GetFieldTrialInfo(&flags)) { |
| 525 return GetBoolValueForFlagWithDefault( | 491 return GetBoolValueForFlagWithDefault( |
| 526 kRecentTabsOnNTPFlagName, false, flags); | 492 kRecentTabsOnNTPFlagName, false, flags); |
| 527 } | 493 } |
| 528 | 494 |
| 529 return false; | 495 return false; |
| 530 } | 496 } |
| 531 | 497 |
| 532 bool ShouldSuppressInstantExtendedOnSRP() { | |
| 533 FieldTrialFlags flags; | |
| 534 if (GetFieldTrialInfo(&flags, NULL)) { | |
| 535 return GetBoolValueForFlagWithDefault( | |
| 536 kSuppressInstantExtendedOnSRPFlagName, false, flags); | |
| 537 } | |
| 538 | |
| 539 return false; | |
| 540 } | |
| 541 | |
| 542 GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) { | 498 GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) { |
| 543 CHECK(ShouldAssignURLToInstantRenderer(url, profile)) | 499 CHECK(ShouldAssignURLToInstantRenderer(url, profile)) |
| 544 << "Error granting Instant access."; | 500 << "Error granting Instant access."; |
| 545 | 501 |
| 546 if (url.SchemeIs(chrome::kChromeSearchScheme)) | 502 if (url.SchemeIs(chrome::kChromeSearchScheme)) |
| 547 return url; | 503 return url; |
| 548 | 504 |
| 549 GURL effective_url(url); | 505 GURL effective_url(url); |
| 550 | 506 |
| 551 // Replace the scheme with "chrome-search:". | 507 // Replace the scheme with "chrome-search:". |
| (...skipping 16 matching lines...) Expand all Loading... |
| 568 } | 524 } |
| 569 } | 525 } |
| 570 | 526 |
| 571 effective_url = effective_url.ReplaceComponents(replacements); | 527 effective_url = effective_url.ReplaceComponents(replacements); |
| 572 return effective_url; | 528 return effective_url; |
| 573 } | 529 } |
| 574 | 530 |
| 575 int GetInstantLoaderStalenessTimeoutSec() { | 531 int GetInstantLoaderStalenessTimeoutSec() { |
| 576 int timeout_sec = kStalePageTimeoutDefault; | 532 int timeout_sec = kStalePageTimeoutDefault; |
| 577 FieldTrialFlags flags; | 533 FieldTrialFlags flags; |
| 578 if (GetFieldTrialInfo(&flags, NULL)) { | 534 if (GetFieldTrialInfo(&flags)) { |
| 579 timeout_sec = GetUInt64ValueForFlagWithDefault(kStalePageTimeoutFlagName, | 535 timeout_sec = GetUInt64ValueForFlagWithDefault(kStalePageTimeoutFlagName, |
| 580 kStalePageTimeoutDefault, | 536 kStalePageTimeoutDefault, |
| 581 flags); | 537 flags); |
| 582 } | 538 } |
| 583 | 539 |
| 584 // Require a minimum 5 minute timeout. | 540 // Require a minimum 5 minute timeout. |
| 585 if (timeout_sec < 0 || (timeout_sec > 0 && timeout_sec < 300)) | 541 if (timeout_sec < 0 || (timeout_sec > 0 && timeout_sec < 300)) |
| 586 timeout_sec = kStalePageTimeoutDefault; | 542 timeout_sec = kStalePageTimeoutDefault; |
| 587 | 543 |
| 588 // Randomize by upto 15% either side. | 544 // Randomize by upto 15% either side. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 InstantSupportState GetInstantSupportStateFromNavigationEntry( | 610 InstantSupportState GetInstantSupportStateFromNavigationEntry( |
| 655 const content::NavigationEntry& entry) { | 611 const content::NavigationEntry& entry) { |
| 656 string16 value; | 612 string16 value; |
| 657 if (!entry.GetExtraData(kInstantSupportStateKey, &value)) | 613 if (!entry.GetExtraData(kInstantSupportStateKey, &value)) |
| 658 return INSTANT_SUPPORT_UNKNOWN; | 614 return INSTANT_SUPPORT_UNKNOWN; |
| 659 | 615 |
| 660 return StringToInstantSupportState(value); | 616 return StringToInstantSupportState(value); |
| 661 } | 617 } |
| 662 | 618 |
| 663 bool ShouldPrefetchSearchResultsOnSRP() { | 619 bool ShouldPrefetchSearchResultsOnSRP() { |
| 664 // Check the command-line/about:flags setting first, which should have | |
| 665 // precedence and allows the trial to not be reported (if it's never queried). | |
| 666 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 667 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI) || | |
| 668 command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) { | |
| 669 return false; | |
| 670 } | |
| 671 | |
| 672 FieldTrialFlags flags; | 620 FieldTrialFlags flags; |
| 673 if (GetFieldTrialInfo(&flags, NULL)) { | 621 if (GetFieldTrialInfo(&flags)) { |
| 674 return GetBoolValueForFlagWithDefault(kPrefetchSearchResultsOnSRP, false, | 622 return GetBoolValueForFlagWithDefault(kPrefetchSearchResultsOnSRP, false, |
| 675 flags); | 623 flags); |
| 676 } | 624 } |
| 677 return false; | 625 return false; |
| 678 } | 626 } |
| 679 | 627 |
| 680 void EnableInstantExtendedAPIForTesting() { | 628 void EnableQueryExtractionForTesting() { |
| 681 CommandLine* cl = CommandLine::ForCurrentProcess(); | 629 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 682 cl->AppendSwitch(switches::kEnableInstantExtendedAPI); | 630 cl->AppendSwitch(switches::kEnableQueryExtraction); |
| 683 } | 631 } |
| 684 | 632 |
| 685 void DisableInstantExtendedAPIForTesting() { | 633 bool GetFieldTrialInfo(FieldTrialFlags* flags) { |
| 686 CommandLine* cl = CommandLine::ForCurrentProcess(); | |
| 687 cl->AppendSwitch(switches::kDisableInstantExtendedAPI); | |
| 688 } | |
| 689 | |
| 690 bool GetFieldTrialInfo(FieldTrialFlags* flags, | |
| 691 uint64* group_number) { | |
| 692 // Get the group name. If the EmbeddedSearch trial doesn't exist, look for | 634 // Get the group name. If the EmbeddedSearch trial doesn't exist, look for |
| 693 // the older InstantExtended name. | 635 // the older InstantExtended name. |
| 694 std::string group_name = base::FieldTrialList::FindFullName( | 636 std::string group_name = base::FieldTrialList::FindFullName( |
| 695 kEmbeddedSearchFieldTrialName); | 637 kEmbeddedSearchFieldTrialName); |
| 696 if (group_name.empty()) { | 638 if (group_name.empty()) { |
| 697 group_name = base::FieldTrialList::FindFullName( | 639 group_name = base::FieldTrialList::FindFullName( |
| 698 kInstantExtendedFieldTrialName); | 640 kInstantExtendedFieldTrialName); |
| 699 } | 641 } |
| 700 | 642 |
| 701 if (EndsWith(group_name, kDisablingSuffix, true)) | 643 if (EndsWith(group_name, kDisablingSuffix, true)) |
| 702 return false; | 644 return false; |
| 703 | 645 |
| 704 // We have a valid trial that isn't disabled. | 646 // We have a valid trial that isn't disabled. Extract the flags. |
| 705 // First extract the flags. | |
| 706 std::string group_prefix(group_name); | 647 std::string group_prefix(group_name); |
| 707 | |
| 708 size_t first_space = group_name.find(" "); | 648 size_t first_space = group_name.find(" "); |
| 709 if (first_space != std::string::npos) { | 649 if (first_space != std::string::npos) { |
| 710 // There is a flags section of the group name. Split that out and parse it. | 650 // There is a flags section of the group name. Split that out and parse it. |
| 711 group_prefix = group_name.substr(0, first_space); | 651 group_prefix = group_name.substr(0, first_space); |
| 712 if (!base::SplitStringIntoKeyValuePairs(group_name.substr(first_space), | 652 if (!base::SplitStringIntoKeyValuePairs(group_name.substr(first_space), |
| 713 ':', ' ', flags)) { | 653 ':', ' ', flags)) { |
| 714 // Failed to parse the flags section. Assume the whole group name is | 654 // Failed to parse the flags section. Assume the whole group name is |
| 715 // invalid. | 655 // invalid. |
| 716 return false; | 656 return false; |
| 717 } | 657 } |
| 718 } | 658 } |
| 719 | 659 |
| 720 // Now extract the group number, making sure we get a non-zero value. | |
| 721 uint64 temp_group_number = 0; | |
| 722 if (StartsWithASCII(group_name, kGroupNumberPrefix, true)) { | |
| 723 std::string group_suffix = group_prefix.substr(strlen(kGroupNumberPrefix)); | |
| 724 if (!base::StringToUint64(group_suffix, &temp_group_number)) | |
| 725 return false; | |
| 726 if (group_number) | |
| 727 *group_number = temp_group_number; | |
| 728 } else { | |
| 729 // Instant Extended is not enabled. | |
| 730 if (group_number) | |
| 731 *group_number = 0; | |
| 732 } | |
| 733 | |
| 734 return true; | 660 return true; |
| 735 } | 661 } |
| 736 | 662 |
| 737 // Given a FieldTrialFlags object, returns the string value of the provided | 663 // Given a FieldTrialFlags object, returns the string value of the provided |
| 738 // flag. | 664 // flag. |
| 739 std::string GetStringValueForFlagWithDefault(const std::string& flag, | 665 std::string GetStringValueForFlagWithDefault(const std::string& flag, |
| 740 const std::string& default_value, | 666 const std::string& default_value, |
| 741 const FieldTrialFlags& flags) { | 667 const FieldTrialFlags& flags) { |
| 742 FieldTrialFlags::const_iterator i; | 668 FieldTrialFlags::const_iterator i; |
| 743 for (i = flags.begin(); i != flags.end(); i++) { | 669 for (i = flags.begin(); i != flags.end(); i++) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 761 } | 687 } |
| 762 | 688 |
| 763 // Given a FieldTrialFlags object, returns the boolean value of the provided | 689 // Given a FieldTrialFlags object, returns the boolean value of the provided |
| 764 // flag. | 690 // flag. |
| 765 bool GetBoolValueForFlagWithDefault(const std::string& flag, | 691 bool GetBoolValueForFlagWithDefault(const std::string& flag, |
| 766 bool default_value, | 692 bool default_value, |
| 767 const FieldTrialFlags& flags) { | 693 const FieldTrialFlags& flags) { |
| 768 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); | 694 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); |
| 769 } | 695 } |
| 770 | 696 |
| 771 void ResetInstantExtendedOptInStateGateForTest() { | |
| 772 instant_extended_opt_in_state_gate = false; | |
| 773 } | |
| 774 | |
| 775 } // namespace chrome | 697 } // namespace chrome |
| OLD | NEW |